From 18b2910a1ee998c83db0c07b54a3281dae585a1e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 15 Aug 2017 15:21:40 +0300 Subject: [PATCH] Add point to tap position --- .../MeasurementToolFragment.java | 16 +++++++++++++-- .../measurementtool/MeasurementToolLayer.java | 20 ++++++++++++++++++- .../command/AddPointCommand.java | 10 ++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 2378c8c81f..f5a5d22823 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -286,7 +286,7 @@ public class MeasurementToolFragment extends Fragment { mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - addPoint(); + addCenterPoint(); } }); @@ -660,7 +660,19 @@ public class MeasurementToolFragment extends Fragment { private void addPoint() { MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { - commandManager.execute(new AddPointCommand(measurementLayer)); + commandManager.execute(new AddPointCommand(measurementLayer, false)); + enable(undoBtn, upDownBtn); + disable(redoBtn); + updateText(); + adapter.notifyDataSetChanged(); + saved = false; + } + } + + private void addCenterPoint() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + commandManager.execute(new AddPointCommand(measurementLayer, true)); enable(undoBtn, upDownBtn); disable(redoBtn); updateText(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 8daf6992f0..5043cff19c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -48,6 +48,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL private OnEnterMovePointModeListener enterMovePointModeListener; private int selectedPointPos = -1; private WptPt selectedCachedPoint; + private LatLon pressedPointLatLon; @Override public void initLayer(OsmandMapTileView view) { @@ -135,6 +136,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL if (selectedPointPos != -1) { singleTapListener.onSelectPoint(); } else { + pressedPointLatLon = tileBox.getLatLonFromPixel(point.x, point.y); singleTapListener.onAddPoint(); } } @@ -330,7 +332,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL canvas.rotate(tb.getRotate(), center.x, center.y); } - public WptPt addPoint(int position) { + public WptPt addCenterPoint(int position) { RotatedTileBox tb = view.getCurrentRotatedTileBox(); LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY()); WptPt pt = new WptPt(); @@ -344,6 +346,22 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL return null; } + public WptPt addPoint(int position) { + if (pressedPointLatLon != null) { + WptPt pt = new WptPt(); + pt.lat = pressedPointLatLon.getLatitude(); + pt.lon = pressedPointLatLon.getLongitude(); + boolean allowed = measurementPoints.size() == 0 || !measurementPoints.get(measurementPoints.size() - 1).equals(pt); + if (allowed) { + measurementPoints.add(position, pt); + moveMapToPoint(position); + pressedPointLatLon = null; + return pt; + } + } + return null; + } + WptPt getMovedPointToApply() { RotatedTileBox tb = view.getCurrentRotatedTileBox(); LatLon latLon = tb.getCenterLatLon(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java index 8913d04e2b..8eb11ecc35 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java @@ -8,20 +8,26 @@ public class AddPointCommand implements Command { private final MeasurementToolLayer measurementLayer; private final int position; private WptPt point; + private boolean center; public AddPointCommand(MeasurementToolLayer measurementLayer, int position) { this.measurementLayer = measurementLayer; this.position = position; } - public AddPointCommand(MeasurementToolLayer measurementLayer) { + public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) { this.measurementLayer = measurementLayer; + this.center = center; position = measurementLayer.getPointsCount(); } @Override public boolean execute() { - point = measurementLayer.addPoint(position); + if (center) { + point = measurementLayer.addCenterPoint(position); + } else { + point = measurementLayer.addPoint(position); + } measurementLayer.refreshMap(); return point != null; }