Change logic for drawing distance
This commit is contained in:
parent
3dd6f2ef02
commit
d77b1fff96
1 changed files with 25 additions and 11 deletions
|
@ -77,6 +77,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
private TIntArrayList tx = new TIntArrayList();
|
private TIntArrayList tx = new TIntArrayList();
|
||||||
private TIntArrayList ty = new TIntArrayList();
|
private TIntArrayList ty = new TIntArrayList();
|
||||||
private Path linePath = new Path();
|
private Path linePath = new Path();
|
||||||
|
private String distanceText;
|
||||||
|
|
||||||
private ContextMenuLayer contextMenuLayer;
|
private ContextMenuLayer contextMenuLayer;
|
||||||
|
|
||||||
|
@ -260,25 +261,38 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
|
|
||||||
calculatePath(tileBox, tx, ty, linePath);
|
calculatePath(tileBox, tx, ty, linePath);
|
||||||
PathMeasure pm = new PathMeasure(linePath, false);
|
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());
|
canvas.drawPath(linePath, lineAttrs.paint);
|
||||||
String text = OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
|
|
||||||
|
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();
|
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;
|
float hOffset = pm.getLength() / 2 - bounds.width() / 2;
|
||||||
|
|
||||||
lineAttrs.paint.setColor(colors[marker.colorIndex]);
|
lineAttrs.paint.setColor(colors[marker.colorIndex]);
|
||||||
canvas.drawPath(linePath, lineAttrs.paint);
|
if (locX >= markerX) {
|
||||||
if (locX - markerX >= 0) {
|
|
||||||
float[] pos = new float[2];
|
|
||||||
pm.getPosTan(pm.getLength() / 2, pos, null);
|
|
||||||
canvas.rotate(180, pos[0], pos[1]);
|
canvas.rotate(180, pos[0], pos[1]);
|
||||||
canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3);
|
canvas.drawTextOnPath(distanceText, 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.paint2);
|
||||||
canvas.rotate(-180, pos[0], pos[1]);
|
canvas.rotate(-180, pos[0], pos[1]);
|
||||||
} else {
|
} else {
|
||||||
canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3);
|
canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3);
|
||||||
canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2);
|
canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue