Add calculatePath() to onDraw()

This commit is contained in:
Alexander Sytnyk 2017-08-01 13:46:46 +03:00
parent 4c7e97d7e7
commit 1f9a7518d5

View file

@ -18,6 +18,8 @@ import net.osmand.util.MapUtils;
import java.util.LinkedList; import java.util.LinkedList;
import gnu.trove.list.array.TIntArrayList;
public class MeasurementToolLayer extends OsmandMapLayer { public class MeasurementToolLayer extends OsmandMapLayer {
private OsmandMapTileView view; private OsmandMapTileView view;
@ -27,10 +29,12 @@ public class MeasurementToolLayer extends OsmandMapLayer {
private Bitmap centerIconNight; private Bitmap centerIconNight;
private Bitmap pointIcon; private Bitmap pointIcon;
private Paint bitmapPaint; private Paint bitmapPaint;
private RenderingLineAttributes lineAttrs; private RenderingLineAttributes lineAttrs = new RenderingLineAttributes("rulerLine");
private Path path; private Path path = new Path();
private int marginX; private int marginX;
private int marginY; private int marginY;
private TIntArrayList tx = new TIntArrayList();
private TIntArrayList ty = new TIntArrayList();
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
@ -45,9 +49,6 @@ public class MeasurementToolLayer extends OsmandMapLayer {
bitmapPaint.setDither(true); bitmapPaint.setDither(true);
bitmapPaint.setFilterBitmap(true); bitmapPaint.setFilterBitmap(true);
lineAttrs = new RenderingLineAttributes("rulerLine");
path = new Path();
marginY = pointIcon.getHeight() / 2; marginY = pointIcon.getHeight() / 2;
marginX = pointIcon.getWidth() / 2; marginX = pointIcon.getWidth() / 2;
} }
@ -87,6 +88,8 @@ public class MeasurementToolLayer extends OsmandMapLayer {
if (measurementPoints.size() > 0) { if (measurementPoints.size() > 0) {
path.reset(); path.reset();
tx.reset();
ty.reset();
for (int i = 0; i < measurementPoints.size(); i++) { for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i); WptPt pt = measurementPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon); int locX = tb.getPixXFromLonNoRot(pt.lon);
@ -96,12 +99,17 @@ public class MeasurementToolLayer extends OsmandMapLayer {
} else { } else {
path.lineTo(locX, locY); path.lineTo(locX, locY);
} }
tx.add(locX);
ty.add(locY);
if (tb.containsLatLon(pt.lat, pt.lon)) { if (tb.containsLatLon(pt.lat, pt.lon)) {
canvas.drawBitmap(pointIcon, locX - marginX, locY - marginY, bitmapPaint); canvas.drawBitmap(pointIcon, locX - marginX, locY - marginY, bitmapPaint);
} }
} }
path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY()); path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
calculatePath(tb, tx, ty, path);
canvas.drawPath(path, lineAttrs.paint); canvas.drawPath(path, lineAttrs.paint);
} }
} }