From d77b1fff96ce2b37a3157d2e50a9af9de845b390 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 22 Sep 2017 14:01:54 +0300 Subject: [PATCH] Change logic for drawing distance --- .../osmand/plus/views/MapMarkersLayer.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 20560dd6dd..32f2c4c4c7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -77,6 +77,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private TIntArrayList tx = new TIntArrayList(); private TIntArrayList ty = new TIntArrayList(); private Path linePath = new Path(); + private String distanceText; private ContextMenuLayer contextMenuLayer; @@ -260,25 +261,38 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi calculatePath(tileBox, tx, ty, linePath); PathMeasure pm = new PathMeasure(linePath, false); + float[] pos = new float[2]; + pm.getPosTan(pm.getLength() / 2, pos, null); - float dist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude()); - String text = OsmAndFormatter.getFormattedDistance(dist, view.getApplication()); + 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()) { + 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) { + distanceText = centerToMarkerDistSt + " | " + generalDistSt; + } else { + distanceText = generalDistSt + " | " + centerToMarkerDistSt; + } + canvas.drawCircle(pos[0], pos[1], 5, new Paint()); + } else { + distanceText = generalDistSt; + } Rect bounds = new Rect(); - textAttrs.paint2.getTextBounds(text, 0, text.length(), bounds); + textAttrs.paint2.getTextBounds(distanceText, 0, distanceText.length(), bounds); float hOffset = pm.getLength() / 2 - bounds.width() / 2; lineAttrs.paint.setColor(colors[marker.colorIndex]); - canvas.drawPath(linePath, lineAttrs.paint); - if (locX - markerX >= 0) { - float[] pos = new float[2]; - pm.getPosTan(pm.getLength() / 2, pos, null); + if (locX >= markerX) { canvas.rotate(180, pos[0], pos[1]); - canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3); - canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint2); + canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3); + canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint2); canvas.rotate(-180, pos[0], pos[1]); } else { - canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3); - canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2); + canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3); + canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2); } } }