Fix finding point to move

This commit is contained in:
PavelRatushny 2017-08-10 11:07:45 +03:00
parent 5251bb1bb7
commit 2b7f5f6f4e

View file

@ -133,7 +133,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
double pressedPointLat = tileBox.getLatFromPixel(point.x, point.y); double pressedPointLat = tileBox.getLatFromPixel(point.x, point.y);
double pressedPointLon = tileBox.getLonFromPixel(point.x, point.y); double pressedPointLon = tileBox.getLonFromPixel(point.x, point.y);
getPointToMove(pressedPointLat, pressedPointLon); getPointToMove(pressedPointLat, pressedPointLon);
if (movePointPos != -1) { if (pointBeforeMovement != null && movePointPos != -1) {
enterMovingPointMode(); enterMovingPointMode();
if (inMeasurementMode && inMovePointMode && enterMovePointModeListener != null) { if (inMeasurementMode && inMovePointMode && enterMovePointModeListener != null) {
enterMovePointModeListener.onEnterMovePointMode(); enterMovePointModeListener.onEnterMovePointMode();
@ -148,16 +148,19 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
} }
private void getPointToMove(double lat, double lon) { private void getPointToMove(double lat, double lon) {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
double lowestDistance = Double.MAX_VALUE; double lowestDistance = Double.MAX_VALUE;
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);
double latDiff = pt.getLatitude() - lat; if (tb.containsLatLon(pt.getLatitude(), pt.getLongitude())) {
double lonDiff = pt.getLongitude() - lon; double latDiff = pt.getLatitude() - lat;
double distToPoint = Math.sqrt(Math.pow(latDiff, 2) + Math.pow(lonDiff, 2)); double lonDiff = pt.getLongitude() - lon;
if (distToPoint < lowestDistance) { double distToPoint = Math.sqrt(Math.pow(latDiff, 2) + Math.pow(lonDiff, 2));
lowestDistance = distToPoint; if (distToPoint < lowestDistance) {
pointBeforeMovement = new WptPt(pt); lowestDistance = distToPoint;
movePointPos = i; pointBeforeMovement = new WptPt(pt);
movePointPos = i;
}
} }
} }
} }