From b35446d026be6ff429697ce11b8250ce9cd9e153 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 22 Sep 2017 19:46:28 +0300 Subject: [PATCH] Fix drawing distance between location and marker after map rotation --- .../osmand/plus/views/MapMarkersLayer.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 0fce81858b..5911e821e9 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -242,13 +242,13 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi textAttrs.updatePaints(view, nightMode, tileBox); textAttrs.paint2.setStyle(Paint.Style.FILL); - int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); - int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + int locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); + int locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); int[] colors = MapMarker.getColors(map); for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { MapMarker marker = activeMapMarkers.get(i); - int markerX = tileBox.getPixXFromLonNoRot(marker.getLongitude()); - int markerY = tileBox.getPixYFromLatNoRot(marker.getLatitude()); + int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude()); + int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude()); linePath.reset(); tx.clear(); @@ -264,12 +264,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi float[] pos = new float[2]; pm.getPosTan(pm.getLength() / 2, pos, null); - lineAttrs.paint.setColor(colors[marker.colorIndex]); - canvas.drawPath(linePath, lineAttrs.paint); - float generalDist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude()); String generalDistSt = OsmAndFormatter.getFormattedDistance(generalDist, view.getApplication()); - if (locX < 0 || locX > tileBox.getPixWidth() || locY < 0 || locY > tileBox.getPixHeight()) { + boolean locationInvisible = locX < 0 || locX > tileBox.getPixWidth() || locY < 0 || locY > tileBox.getPixHeight(); + if (locationInvisible) { float centerToMarkerDist = (float) MapUtils.getDistance(tileBox.getLatLonFromPixel(pos[0], pos[1]), marker.getLatitude(), marker.getLongitude()); String centerToMarkerDistSt = OsmAndFormatter.getFormattedDistance(centerToMarkerDist, view.getApplication()); if (locX >= markerX) { @@ -277,14 +275,19 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } else { distanceText = generalDistSt + " | " + centerToMarkerDistSt; } - canvas.drawCircle(pos[0], pos[1], 5, new Paint()); } else { distanceText = generalDistSt; } Rect bounds = new Rect(); textAttrs.paint2.getTextBounds(distanceText, 0, distanceText.length(), bounds); float hOffset = pm.getLength() / 2 - bounds.width() / 2; + lineAttrs.paint.setColor(colors[marker.colorIndex]); + canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); + canvas.drawPath(linePath, lineAttrs.paint); + if (locationInvisible && !(pos[0] == 0 && pos[1] == 0)) { + canvas.drawCircle(pos[0], pos[1], 5, new Paint()); + } if (locX >= markerX) { canvas.rotate(180, pos[0], pos[1]); canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3); @@ -294,6 +297,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3); canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2); } + canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); } }