Fix clear all with snap to road

This commit is contained in:
Alex 2017-08-27 10:45:59 +03:00
parent 0395e35999
commit fcfe307ec2
2 changed files with 18 additions and 1 deletions

View file

@ -38,6 +38,7 @@ public class MeasurementEditingContext {
private WptPt originalPointToMove; private WptPt originalPointToMove;
private boolean inSnapToRoadMode; private boolean inSnapToRoadMode;
private boolean needUpdateCacheForSnap;
private SnapToRoadProgressListener progressListener; private SnapToRoadProgressListener progressListener;
private ApplicationMode snapToRoadAppMode; private ApplicationMode snapToRoadAppMode;
private RouteCalculationProgress calculationProgress; private RouteCalculationProgress calculationProgress;
@ -56,6 +57,15 @@ public class MeasurementEditingContext {
return inSnapToRoadMode; return inSnapToRoadMode;
} }
public boolean isNeedUpdateCacheForSnap() {
return needUpdateCacheForSnap;
}
public void setNeedUpdateCacheForSnap(boolean needUpdateCacheForSnap) {
this.needUpdateCacheForSnap = needUpdateCacheForSnap;
updateCacheForSnapIfNeeded(true);
}
int getSelectedPointPosition() { int getSelectedPointPosition() {
return selectedPointPosition; return selectedPointPosition;
} }
@ -168,9 +178,11 @@ public class MeasurementEditingContext {
after.points.clear(); after.points.clear();
beforeCacheForSnap = null; beforeCacheForSnap = null;
afterCacheForSnap = null; afterCacheForSnap = null;
needUpdateCacheForSnap = false;
} }
void scheduleRouteCalculateIfNotEmpty() { void scheduleRouteCalculateIfNotEmpty() {
needUpdateCacheForSnap = true;
if (application == null || (before.points.size() < 1 && after.points.size() < 1)) { if (application == null || (before.points.size() < 1 && after.points.size() < 1)) {
return; return;
} }
@ -219,7 +231,7 @@ public class MeasurementEditingContext {
} }
private void updateCacheForSnapIfNeeded(boolean both) { private void updateCacheForSnapIfNeeded(boolean both) {
if (inSnapToRoadMode) { if (needUpdateCacheForSnap) {
recreateCacheForSnap(beforeCacheForSnap = new TrkSegment(), before); recreateCacheForSnap(beforeCacheForSnap = new TrkSegment(), before);
if (both) { if (both) {
recreateCacheForSnap(afterCacheForSnap = new TrkSegment(), after); recreateCacheForSnap(afterCacheForSnap = new TrkSegment(), after);

View file

@ -9,6 +9,7 @@ import java.util.List;
public class ClearPointsCommand extends MeasurementModeCommand { public class ClearPointsCommand extends MeasurementModeCommand {
private List<WptPt> points; private List<WptPt> points;
private boolean needUpdateCache;
public ClearPointsCommand(MeasurementToolLayer measurementLayer) { public ClearPointsCommand(MeasurementToolLayer measurementLayer) {
this.measurementLayer = measurementLayer; this.measurementLayer = measurementLayer;
@ -17,6 +18,7 @@ public class ClearPointsCommand extends MeasurementModeCommand {
@Override @Override
public boolean execute() { public boolean execute() {
List<WptPt> pts = measurementLayer.getEditingCtx().getPoints(); List<WptPt> pts = measurementLayer.getEditingCtx().getPoints();
needUpdateCache = measurementLayer.getEditingCtx().isNeedUpdateCacheForSnap();
points = new LinkedList<>(pts); points = new LinkedList<>(pts);
pts.clear(); pts.clear();
measurementLayer.getEditingCtx().clearSegments(); measurementLayer.getEditingCtx().clearSegments();
@ -27,6 +29,9 @@ public class ClearPointsCommand extends MeasurementModeCommand {
@Override @Override
public void undo() { public void undo() {
measurementLayer.getEditingCtx().addPoints(points); measurementLayer.getEditingCtx().addPoints(points);
if (needUpdateCache) {
measurementLayer.getEditingCtx().setNeedUpdateCacheForSnap(true);
}
measurementLayer.refreshMap(); measurementLayer.refreshMap();
} }