Fix walking line on zoom

This commit is contained in:
crimean 2019-02-05 17:57:14 +03:00
parent c1826a74d1
commit 76d5d36b1e
7 changed files with 76 additions and 76 deletions

View file

@ -24,8 +24,6 @@ import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final int POINTS_TO_DRAW = 50;
@ -42,8 +40,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private int marginApplyingPointIconX;
private int marginApplyingPointIconY;
private final Path path = new Path();
private final TIntArrayList tx = new TIntArrayList();
private final TIntArrayList ty = new TIntArrayList();
private final List<Float> tx = new ArrayList<>();
private final List<Float> ty = new ArrayList<>();
private OnMeasureDistanceToCenter measureDistanceToCenterListener;
private OnSingleTapListener singleTapListener;
private OnEnterMovePointModeListener enterMovePointModeListener;
@ -218,26 +216,26 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
if (before.points.size() > 0 || after.points.size() > 0) {
path.reset();
tx.reset();
ty.reset();
tx.clear();
ty.clear();
if (before.points.size() > 0) {
WptPt pt = before.points.get(before.points.size() - 1);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
float locX = tb.getPixXFromLonNoRot(pt.lon);
float locY = tb.getPixYFromLatNoRot(pt.lat);
tx.add(locX);
ty.add(locY);
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
tx.add((float)tb.getCenterPixelX());
ty.add((float)tb.getCenterPixelY());
}
if (after.points.size() > 0) {
if (before.points.size() == 0) {
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
tx.add((float)tb.getCenterPixelX());
ty.add((float)tb.getCenterPixelY());
}
WptPt pt = after.points.get(0);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
float locX = tb.getPixXFromLonNoRot(pt.lon);
float locY = tb.getPixYFromLatNoRot(pt.lat);
tx.add(locX);
ty.add(locY);
}

View file

@ -49,8 +49,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider,
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
@ -93,8 +91,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private float textSize;
private int verticalOffset;
private TIntArrayList tx = new TIntArrayList();
private TIntArrayList ty = new TIntArrayList();
private List<Float> tx = new ArrayList<>();
private List<Float> ty = new ArrayList<>();
private Path linePath = new Path();
private LatLon fingerLocation;
@ -270,22 +268,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
boolean drawMarkerName = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1;
int locX;
int locY;
float locX;
float locY;
if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()
&& !MapViewTrackingUtilities.isSmallSpeedForAnimation(myLoc)
&& !map.getMapViewTrackingUtilities().isMovingToMyLocation()) {
locX = (int) tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
locY = (int) tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
locX = tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
locY = tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
} else {
locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
locX = tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
locY = tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
}
int[] colors = MapMarker.getColors(map);
for (int i = 0; i < activeMapMarkers.size() && i < displayedWidgets; i++) {
MapMarker marker = activeMapMarkers.get(i);
int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude());
int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude());
float markerX = tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude());
float markerY = tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude());
linePath.reset();
tx.clear();

View file

@ -47,8 +47,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
public abstract class OsmandMapLayer {
protected List<LatLon> fullObjectsLatLon;
@ -142,12 +140,11 @@ public abstract class OsmandMapLayer {
}
}
protected boolean isIn(int x, int y, int lx, int ty, int rx, int by) {
protected boolean isIn(float x, float y, int lx, int ty, int rx, int by) {
return x >= lx && x <= rx && y >= ty && y <= by;
}
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) {
public int calculatePath(RotatedTileBox tb, List<Float> xs, List<Float> ys, Path path) {
List<Pair<Path, GeometryWayStyle>> paths = new ArrayList<>();
int res = calculatePath(tb, xs, ys, null, paths);
if (paths.size() > 0) {
@ -440,10 +437,10 @@ public abstract class OsmandMapLayer {
}
}
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, List<GeometryWayStyle> styles, List<Pair<Path, GeometryWayStyle>> paths) {
public int calculatePath(RotatedTileBox tb, List<Float> xs, List<Float> ys, List<GeometryWayStyle> styles, List<Pair<Path, GeometryWayStyle>> paths) {
boolean segmentStarted = false;
int prevX = xs.get(0) / 100;
int prevY = ys.get(0) / 100;
float prevX = xs.get(0);
float prevY = ys.get(0);
int height = tb.getPixHeight();
int width = tb.getPixWidth();
int cnt = 0;
@ -452,14 +449,14 @@ public abstract class OsmandMapLayer {
Path path = new Path();
boolean prevIn = isIn(prevX, prevY, 0, 0, width, height);
for (int i = 1; i < xs.size(); i++) {
int currX = xs.get(i) / 100;
int currY = ys.get(i) / 100;
float currX = xs.get(i);
float currY = ys.get(i);
boolean currIn = isIn(currX, currY, 0, 0, width, height);
boolean draw = false;
if (prevIn && currIn) {
draw = true;
} else {
long intersection = MapAlgorithms.calculateIntersection(currX, currY, prevX, prevY, 0, width, height, 0);
long intersection = MapAlgorithms.calculateIntersection((int)currX, (int)currY, (int)prevX, (int)prevY, 0, width, height, 0);
if (intersection != -1) {
if (prevIn && (i == 1)) {
cnt++;
@ -471,7 +468,7 @@ public abstract class OsmandMapLayer {
draw = true;
}
if (i == xs.size() - 1 && !currIn) {
long inter = MapAlgorithms.calculateIntersection(prevX, prevY, currX, currY, 0, width, height, 0);
long inter = MapAlgorithms.calculateIntersection((int)prevX, (int)prevY, (int)currX, (int)currY, 0, width, height, 0);
if (inter != -1) {
currX = (int) (inter >> 32);
currY = (int) (inter & 0xffffffff);

View file

@ -711,6 +711,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return additional.fps;
}
public boolean isAnimatingZoom() {
return animatedDraggingThread.isAnimatingZoom();
}
@SuppressLint("WrongCall")
public void drawOverMap(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
if (mapRenderer == null) {

View file

@ -53,7 +53,6 @@ import java.util.Set;
import java.util.TreeMap;
import gnu.trove.list.array.TByteArrayList;
import gnu.trove.list.array.TIntArrayList;
public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
@ -563,7 +562,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
}
private void drawArrowsOverPath(Canvas canvas, RotatedTileBox tb, TIntArrayList tx, TIntArrayList ty,
private void drawArrowsOverPath(Canvas canvas, RotatedTileBox tb, List<Float> tx, List<Float> ty,
List<Double> angles, List<Double> distances, double distPixToFinish, List<GeometryWayStyle> styles) {
int h = tb.getPixHeight();
int w = tb.getPixWidth();
@ -573,9 +572,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
int bottom = h + h/4;
boolean hasStyles = styles != null && styles.size() == tx.size();
double zoomCoef = tb.getZoomAnimation() > 0 ? (Math.pow(2, tb.getZoomAnimation() + tb.getZoomFloatPart())) : 1f;
Bitmap arrow = wayContext.getArrowBitmap();
double pxStep = arrow.getHeight() * 4f;
int arrowHeight = arrow.getHeight();
double pxStep = arrowHeight * 4f * zoomCoef;
double dist = 0;
if (distPixToFinish != 0) {
dist = distPixToFinish - pxStep * ((int) (distPixToFinish / pxStep)); // dist < 1
@ -590,23 +591,26 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
GeometryWalkWayStyle walkWayStyle = new GeometryWalkWayStyle(wayContext);
Bitmap walkArrow = walkWayStyle.getPointBitmap();
int walkArrowHeight = walkArrow.getHeight();
double pxStepWalk = walkArrowHeight * 1.2f * zoomCoef;
double pxStepRegular = arrowHeight * 4f * zoomCoef;
GeometryWayStyle prevStyle = null;
for (int i = tx.size() - 2; i >= 0; i --) {
GeometryWayStyle style = hasStyles ? styles.get(i) : null;
float px = tx.get(i) / 100f;
float py = ty.get(i) / 100f;
float x = tx.get(i + 1) / 100f;
float y = ty.get(i + 1) / 100f;
float px = tx.get(i);
float py = ty.get(i);
float x = tx.get(i + 1);
float y = ty.get(i + 1);
double distSegment = distances.get(i + 1);
double angle = angles.get(i + 1);
if (distSegment == 0) {
continue;
}
if (style != null && style.isWalkLine()) {
pxStep = walkArrow.getHeight() * 1.2f;
pxStep = pxStepWalk;
} else {
pxStep = arrow.getHeight() * 4f;
pxStep = pxStepRegular;
}
if (style != null && !style.equals(prevStyle) && (prevStyle != null || style.hasAnchors())) {
prevStyle = style;
@ -626,7 +630,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
double pdy = (y - py) * percent;
float iconx = (float) (px + pdx);
float icony = (float) (py + pdy);
if (isIn((int)(iconx), (int) (icony), left, top, right, bottom)) {
if (isIn(iconx, icony, left, top, right, bottom)) {
arrows.add(new PathPoint(iconx, icony, angle, style));
}
dist -= pxStep;
@ -645,7 +649,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
double lon = stop.getLocation().getLongitude();
float x = tb.getPixXFromLatLon(lat, lon);
float y = tb.getPixYFromLatLon(lat, lon);
if (isIn((int) (x), (int) (y), left, top, right, bottom)) {
if (isIn(x, y, left, top, right, bottom)) {
if (i != start && i != end) {
stops.add(new PathTransportStop(x, y, style));
}
@ -657,7 +661,9 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
for (int i = arrows.size() - 1; i >= 0; i--) {
PathPoint a = arrows.get(i);
a.draw(canvas, wayContext);
if (!tb.isZoomAnimated() || a.style.isWalkLine()) {
a.draw(canvas, wayContext);
}
}
for (int i = anchors.size() - 1; i >= 0; i--) {
PathAnchor anchor = anchors.get(i);
@ -757,8 +763,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
Map<Integer, GeometryWayStyle> styleMap = Collections.emptyMap();
// cache arrays
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
List<Float> tx = new ArrayList<>();
List<Float> ty = new ArrayList<>();
List<Double> angles = new ArrayList<>();
List<Double> distances = new ArrayList<>();
List<GeometryWayStyle> styles = new ArrayList<>();
@ -903,7 +909,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
styles.clear();
}
private void addLocation(RotatedTileBox tb, Location ls, GeometryWayStyle style, TIntArrayList tx, TIntArrayList ty,
private void addLocation(RotatedTileBox tb, Location ls, GeometryWayStyle style, List<Float> tx, List<Float> ty,
List<Double> angles, List<Double> distances, double dist, List<GeometryWayStyle> styles) {
float x = tb.getPixXFromLatLon(ls.getLatitude(), ls.getLongitude());
float y = tb.getPixYFromLatLon(ls.getLatitude(), ls.getLongitude());
@ -911,8 +917,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
float py = y;
int previous = tx.size() - 1;
if (previous >= 0 && previous < tx.size()) {
px = tx.get(previous) / 100f;
py = ty.get(previous) / 100f;
px = tx.get(previous);
py = ty.get(previous);
}
double angle = 0;
if (px != x || py != y) {
@ -923,8 +929,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
if(dist != 0) {
distSegment = dist;
}
tx.add((int) (x * 100f));
ty.add((int) (y * 100f));
tx.add(x);
ty.add(y);
angles.add(angle);
distances.add(distSegment);
styles.add(style);
@ -933,7 +939,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private RouteSimplificationGeometry routeGeometry = new RouteSimplificationGeometry();
private void drawRouteSegment(RotatedTileBox tb, Canvas canvas, TIntArrayList tx, TIntArrayList ty,
private void drawRouteSegment(RotatedTileBox tb, Canvas canvas, List<Float> tx, List<Float> ty,
List<Double> angles, List<Double> distances, double distToFinish, List<GeometryWayStyle> styles) {
if (tx.size() < 2) {
return;
@ -960,7 +966,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
attrs.customColor = 0;
attrsPT.customColor = 0;
if (tb.getZoomAnimation() == 0) {
if (!view.isAnimatingZoom()) {
drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles);
}
} finally {

View file

@ -27,8 +27,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import gnu.trove.list.array.TIntArrayList;
import java.util.List;
public class RulerControlLayer extends OsmandMapLayer {
@ -68,8 +67,8 @@ public class RulerControlLayer extends OsmandMapLayer {
private boolean touched;
private boolean wasZoom;
private TIntArrayList tx = new TIntArrayList();
private TIntArrayList ty = new TIntArrayList();
private List<Float> tx = new ArrayList<>();
private List<Float> ty = new ArrayList<>();
private Path linePath = new Path();
private Bitmap centerIconDay;
@ -309,15 +308,15 @@ public class RulerControlLayer extends OsmandMapLayer {
private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, Location currLoc, boolean night) {
float x = tb.getPixXFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
float y = tb.getPixYFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
int currX = (int) tb.getPixXFromLatLon(currLoc.getLatitude(), currLoc.getLongitude());
int currY = (int) tb.getPixYFromLatLon(currLoc.getLatitude(), currLoc.getLongitude());
float currX = tb.getPixXFromLatLon(currLoc.getLatitude(), currLoc.getLongitude());
float currY = tb.getPixYFromLatLon(currLoc.getLatitude(), currLoc.getLongitude());
linePath.reset();
tx.reset();
ty.reset();
tx.clear();
ty.clear();
tx.add((int) x);
ty.add((int) y);
tx.add(x);
ty.add(y);
tx.add(currX);
ty.add(currY);

View file

@ -23,9 +23,9 @@ import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.transport.TransportStopType;
import java.util.ArrayList;
@ -34,8 +34,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import gnu.trove.list.array.TIntArrayList;
public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final int startZoom = 12;
private static final int startZoomRoute = 10;
@ -202,12 +200,12 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
List<Way> ws = stopRoute.route.getForwardWays();
if (ws != null) {
for (Way w : ws) {
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
List<Float> tx = new ArrayList<>();
List<Float> ty = new ArrayList<>();
for (int i = 0; i < w.getNodes().size(); i++) {
Node o = w.getNodes().get(i);
int x = (int) tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = (int) tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
float x = tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
tx.add(x);
ty.add(y);
}