Move measurementPoints from layer and modify recreateSegments
This commit is contained in:
parent
fb9a3f8466
commit
bc1d51bf5d
9 changed files with 92 additions and 92 deletions
|
@ -135,6 +135,21 @@ public class MeasurementEditingContext {
|
|||
before.points.addAll(measurementPoints);
|
||||
addBeforeRenders();
|
||||
after = new TrkSegment();
|
||||
}
|
||||
|
||||
public void recreateSegments(int position) {
|
||||
before = new TrkSegment();
|
||||
before.points.addAll(measurementPoints.subList(0, position));
|
||||
addBeforeRenders();
|
||||
after = new TrkSegment();
|
||||
if (position != measurementPoints.size() - 1) {
|
||||
after.points.addAll(measurementPoints.subList(position + 1, measurementPoints.size()));
|
||||
addAfterRenders();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSegments() {
|
||||
before = new TrkSegment();
|
||||
after = new TrkSegment();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCal
|
|||
import net.osmand.plus.measurementtool.command.AddPointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
|
||||
import net.osmand.plus.measurementtool.command.MeasurementCommandManager;
|
||||
import net.osmand.plus.measurementtool.command.MeasurementModeCommand.MeasurementCommandType;
|
||||
import net.osmand.plus.measurementtool.command.MovePointCommand;
|
||||
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||
|
@ -146,7 +145,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||
|
||||
measurementLayer.setMeasurementEditingContext(editingCtx);
|
||||
measurementLayer.setEditingCtx(editingCtx);
|
||||
|
||||
if (selectedPointPos != -1 && selectedCachedPoint != null) {
|
||||
measurementLayer.setSelectedPointPos(selectedPointPos);
|
||||
|
@ -300,7 +299,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
undoBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MeasurementCommandType type = commandManager.undo();
|
||||
commandManager.undo();
|
||||
editingCtx.recreateSegments();
|
||||
if (commandManager.canUndo()) {
|
||||
enable(undoBtn);
|
||||
|
@ -436,7 +435,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
});
|
||||
mapActivity.showTopToolbar(toolBarController);
|
||||
|
||||
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints(),
|
||||
adapter = new MeasurementToolAdapter(getMapActivity(), editingCtx.getPoints(),
|
||||
newGpxData != null ? newGpxData.getActionType() : null);
|
||||
if (portrait) {
|
||||
pointsRv = mainView.findViewById(R.id.measure_points_recycler_view);
|
||||
|
@ -594,7 +593,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
@Override
|
||||
public void clearAllOnClick() {
|
||||
commandManager.execute(new ClearPointsCommand(measurementLayer));
|
||||
editingCtx.recreateSegments();
|
||||
editingCtx.clearSegments();
|
||||
if (calculationProgress != null) {
|
||||
calculationProgress.isCancelled = true;
|
||||
}
|
||||
|
@ -973,7 +972,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (measurementLayer != null && positionToAddPoint != -1) {
|
||||
if (addPointToPosition(positionToAddPoint)) {
|
||||
selectedPointPos += 1;
|
||||
selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
|
||||
selectedCachedPoint = new WptPt(editingCtx.getPoints().get(selectedPointPos));
|
||||
measurementLayer.setSelectedPointPos(selectedPointPos);
|
||||
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
|
||||
measurementLayer.refreshMap();
|
||||
|
@ -1008,7 +1007,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null && positionToAddPoint != -1) {
|
||||
if (addPointToPosition(positionToAddPoint)) {
|
||||
selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
|
||||
selectedCachedPoint = new WptPt(editingCtx.getPoints().get(selectedPointPos));
|
||||
measurementLayer.setSelectedPointPos(selectedPointPos);
|
||||
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
|
||||
measurementLayer.refreshMap();
|
||||
|
@ -1120,11 +1119,6 @@ public class MeasurementToolFragment extends Fragment {
|
|||
editingCtx.recreateSegments();
|
||||
doAddOrMovePointCommonStuff();
|
||||
}
|
||||
TrkSegment before = new TrkSegment();
|
||||
before.points.addAll(editingCtx.getPoints());
|
||||
editingCtx.setBefore(before);
|
||||
TrkSegment after = new TrkSegment();
|
||||
editingCtx.setAfter(after);
|
||||
}
|
||||
|
||||
private void addCenterPoint() {
|
||||
|
@ -1141,7 +1135,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
added = commandManager.execute(new AddPointCommand(measurementLayer, position));
|
||||
editingCtx.recreateSegments();
|
||||
editingCtx.recreateSegments(position);
|
||||
doAddOrMovePointCommonStuff();
|
||||
}
|
||||
return added;
|
||||
|
@ -1353,7 +1347,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
toSave = new File(dir, fileName);
|
||||
GPXFile gpx = new GPXFile();
|
||||
if (measurementLayer != null) {
|
||||
List<WptPt> points = measurementLayer.getMeasurementPoints();
|
||||
List<WptPt> points = editingCtx.getPoints();
|
||||
if (saveType == SaveType.LINE) {
|
||||
TrkSegment segment = new TrkSegment();
|
||||
segment.points.addAll(points);
|
||||
|
@ -1377,7 +1371,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
} else {
|
||||
toSave = new File(gpx.path);
|
||||
if (measurementLayer != null) {
|
||||
List<WptPt> points = measurementLayer.getMeasurementPoints();
|
||||
List<WptPt> points = editingCtx.getPoints();
|
||||
if (actionType != null) {
|
||||
switch (actionType) {
|
||||
case ADD_SEGMENT:
|
||||
|
@ -1577,10 +1571,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
|
||||
private void dismiss(MapActivity mapActivity) {
|
||||
try {
|
||||
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
|
||||
if (measurementToolLayer != null) {
|
||||
measurementToolLayer.getMeasurementPoints().clear();
|
||||
}
|
||||
editingCtx.getPoints().clear();
|
||||
if (pointsListOpened) {
|
||||
hidePointsList();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
|
||||
private OsmandMapTileView view;
|
||||
private boolean inMeasurementMode;
|
||||
private List<WptPt> measurementPoints = new LinkedList<>();
|
||||
private List<WptPt> snappedToRoadPoints = new LinkedList<>();
|
||||
private Bitmap centerIconDay;
|
||||
private Bitmap centerIconNight;
|
||||
|
@ -52,7 +51,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
private LatLon pressedPointLatLon;
|
||||
private boolean overlapped;
|
||||
private int pointsToDraw = 50;
|
||||
private MeasurementEditingContext measurementEditingContext;
|
||||
private MeasurementEditingContext editingCtx;
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
|
@ -79,8 +78,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
this.singleTapListener = listener;
|
||||
}
|
||||
|
||||
void setMeasurementEditingContext(MeasurementEditingContext measurementEditingContext) {
|
||||
this.measurementEditingContext = measurementEditingContext;
|
||||
void setEditingCtx(MeasurementEditingContext editingCtx) {
|
||||
this.editingCtx = editingCtx;
|
||||
}
|
||||
|
||||
void setOnEnterMovePointModeListener(OnEnterMovePointModeListener listener) {
|
||||
|
@ -107,6 +106,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
return selectedPointPos;
|
||||
}
|
||||
|
||||
public MeasurementEditingContext getEditingCtx() {
|
||||
return editingCtx;
|
||||
}
|
||||
|
||||
public boolean isInMeasurementMode() {
|
||||
return inMeasurementMode;
|
||||
}
|
||||
|
@ -115,24 +118,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
this.inMeasurementMode = inMeasurementMode;
|
||||
}
|
||||
|
||||
public List<WptPt> getMeasurementPoints() {
|
||||
return measurementPoints;
|
||||
}
|
||||
|
||||
void setMeasurementPoints(List<WptPt> points) {
|
||||
measurementPoints = points;
|
||||
}
|
||||
|
||||
public List<WptPt> getSnappedToRoadPoints() {
|
||||
return snappedToRoadPoints;
|
||||
}
|
||||
|
||||
public void setSnappedToRoadPoints(List<WptPt> snappedToRoadPoints) {
|
||||
this.snappedToRoadPoints = snappedToRoadPoints;
|
||||
}
|
||||
|
||||
String getDistanceSt() {
|
||||
float dist = 0;
|
||||
List<WptPt> measurementPoints = editingCtx.getPoints();
|
||||
if (measurementPoints.size() > 0) {
|
||||
for (int i = 1; i < measurementPoints.size(); i++) {
|
||||
dist += MapUtils.getDistance(measurementPoints.get(i - 1).lat, measurementPoints.get(i - 1).lon,
|
||||
|
@ -146,9 +138,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
if (singleTapListener != null) {
|
||||
if (inMeasurementMode
|
||||
&& !measurementEditingContext.isInMovePointMode()
|
||||
&& !measurementEditingContext.isInAddPointBeforeMode()
|
||||
&& !measurementEditingContext.isInAddPointAfterMode()) {
|
||||
&& !editingCtx.isInMovePointMode()
|
||||
&& !editingCtx.isInAddPointBeforeMode()
|
||||
&& !editingCtx.isInAddPointAfterMode()) {
|
||||
if (!overlapped) {
|
||||
selectPoint(point.x, point.y, true);
|
||||
}
|
||||
|
@ -169,14 +161,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
@Override
|
||||
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
|
||||
if (inMeasurementMode) {
|
||||
if (!overlapped && !measurementEditingContext.isInMovePointMode()
|
||||
&& !measurementEditingContext.isInAddPointBeforeMode()
|
||||
&& !measurementEditingContext.isInAddPointAfterMode()
|
||||
&& measurementPoints.size() > 0) {
|
||||
if (!overlapped && !editingCtx.isInMovePointMode()
|
||||
&& !editingCtx.isInAddPointBeforeMode()
|
||||
&& !editingCtx.isInAddPointAfterMode()
|
||||
&& editingCtx.getPointsCount() > 0) {
|
||||
selectPoint(point.x, point.y, false);
|
||||
if (selectedCachedPoint != null && selectedPointPos != -1) {
|
||||
enterMovingPointMode();
|
||||
if (inMeasurementMode && measurementEditingContext.isInMovePointMode() && enterMovePointModeListener != null) {
|
||||
if (inMeasurementMode && editingCtx.isInMovePointMode() && enterMovePointModeListener != null) {
|
||||
enterMovePointModeListener.onEnterMovePointMode();
|
||||
}
|
||||
}
|
||||
|
@ -186,25 +178,25 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
}
|
||||
|
||||
void enterMovingPointMode() {
|
||||
measurementEditingContext.setInMovePointMode(true);
|
||||
editingCtx.setInMovePointMode(true);
|
||||
moveMapToPoint(selectedPointPos);
|
||||
}
|
||||
|
||||
void enterAddingPointAfterMode() {
|
||||
measurementEditingContext.setInAddPointAfterMode(true);
|
||||
editingCtx.setInAddPointAfterMode(true);
|
||||
moveMapToPoint(selectedPointPos);
|
||||
}
|
||||
|
||||
void enterAddingPointBeforeMode() {
|
||||
measurementEditingContext.setInAddPointBeforeMode(true);
|
||||
editingCtx.setInAddPointBeforeMode(true);
|
||||
moveMapToPoint(selectedPointPos);
|
||||
}
|
||||
|
||||
private void selectPoint(double x, double y, boolean singleTap) {
|
||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||
double lowestDistance = view.getResources().getDimension(R.dimen.measurement_tool_select_radius);
|
||||
for (int i = 0; i < measurementPoints.size(); i++) {
|
||||
WptPt pt = measurementPoints.get(i);
|
||||
for (int i = 0; i < editingCtx.getPointsCount(); i++) {
|
||||
WptPt pt = editingCtx.getPoints().get(i);
|
||||
if (tb.containsLatLon(pt.getLatitude(), pt.getLongitude())) {
|
||||
double xDiff = tb.getPixXFromLonNoRot(pt.getLongitude()) - x;
|
||||
double yDiff = tb.getPixYFromLatNoRot(pt.getLatitude()) - y;
|
||||
|
@ -213,6 +205,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
lowestDistance = distToPoint;
|
||||
selectedCachedPoint = new WptPt(pt);
|
||||
selectedPointPos = i;
|
||||
editingCtx.recreateSegments(selectedPointPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +215,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
}
|
||||
|
||||
void selectPoint(int position) {
|
||||
selectedCachedPoint = new WptPt(measurementPoints.get(position));
|
||||
selectedCachedPoint = new WptPt(editingCtx.getPoints().get(position));
|
||||
selectedPointPos = position;
|
||||
if (singleTapListener != null) {
|
||||
singleTapListener.onSelectPoint(selectedPointPos, selectedCachedPoint);
|
||||
|
@ -234,10 +227,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
if (inMeasurementMode) {
|
||||
lineAttrs.updatePaints(view, settings, tb);
|
||||
|
||||
TrkSegment before = measurementEditingContext.getBeforeTrkSegmentLine();
|
||||
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
|
||||
before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
||||
|
||||
TrkSegment after = measurementEditingContext.getAfterTrkSegmentLine();
|
||||
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
|
||||
after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
||||
}
|
||||
}
|
||||
|
@ -247,14 +240,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
if (inMeasurementMode) {
|
||||
lineAttrs.updatePaints(view, settings, tb);
|
||||
|
||||
if (!measurementEditingContext.isInMovePointMode()
|
||||
&& !measurementEditingContext.isInAddPointBeforeMode()
|
||||
&& !measurementEditingContext.isInAddPointAfterMode()) {
|
||||
if (!editingCtx.isInMovePointMode()
|
||||
&& !editingCtx.isInAddPointBeforeMode()
|
||||
&& !editingCtx.isInAddPointAfterMode()) {
|
||||
drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
|
||||
if (measureDistanceToCenterListener != null) {
|
||||
float distance = 0;
|
||||
if (measurementPoints.size() > 0) {
|
||||
WptPt lastPoint = measurementPoints.get(measurementPoints.size() - 1);
|
||||
if (editingCtx.getPointsCount() > 0) {
|
||||
WptPt lastPoint = editingCtx.getPoints().get(editingCtx.getPointsCount() - 1);
|
||||
LatLon centerLatLon = tb.getCenterLatLon();
|
||||
distance = (float) MapUtils.getDistance(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
|
||||
}
|
||||
|
@ -266,7 +259,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
if (snappedToRoadPoints.size() > 0) {
|
||||
drawPoints = snappedToRoadPoints;
|
||||
} else {
|
||||
drawPoints = measurementPoints;
|
||||
drawPoints = editingCtx.getPoints();
|
||||
}
|
||||
|
||||
if (drawPoints.size() > 0) {
|
||||
|
@ -287,6 +280,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
canvas.drawPath(path, lineAttrs.paint);
|
||||
}
|
||||
|
||||
List<WptPt> measurementPoints = editingCtx.getPoints();
|
||||
overlapped = false;
|
||||
int drawn = 0;
|
||||
for (int i = 0; i < measurementPoints.size(); i++) {
|
||||
|
@ -294,7 +288,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
int locX = tb.getPixXFromLonNoRot(pt.lon);
|
||||
int locY = tb.getPixYFromLatNoRot(pt.lat);
|
||||
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
|
||||
if (!(measurementEditingContext.isInMovePointMode() && i == selectedPointPos)) {
|
||||
if (!(editingCtx.isInMovePointMode() && i == selectedPointPos)) {
|
||||
drawn++;
|
||||
if (drawn > pointsToDraw) {
|
||||
overlapped = true;
|
||||
|
@ -308,7 +302,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
int locX = tb.getPixXFromLonNoRot(pt.lon);
|
||||
int locY = tb.getPixYFromLatNoRot(pt.lat);
|
||||
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
|
||||
if (!(measurementEditingContext.isInMovePointMode() && 0 == selectedPointPos)) {
|
||||
if (!(editingCtx.isInMovePointMode() && 0 == selectedPointPos)) {
|
||||
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +310,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
locX = tb.getPixXFromLonNoRot(pt.lon);
|
||||
locY = tb.getPixYFromLatNoRot(pt.lat);
|
||||
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
|
||||
if (!(measurementEditingContext.isInMovePointMode() && measurementPoints.size() - 1 == selectedPointPos)) {
|
||||
if (!(editingCtx.isInMovePointMode() && measurementPoints.size() - 1 == selectedPointPos)) {
|
||||
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
|
||||
}
|
||||
}
|
||||
|
@ -326,16 +320,16 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
int locX = tb.getPixXFromLonNoRot(pt.lon);
|
||||
int locY = tb.getPixYFromLatNoRot(pt.lat);
|
||||
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
|
||||
if (!(measurementEditingContext.isInMovePointMode() && i == selectedPointPos)) {
|
||||
if (!(editingCtx.isInMovePointMode() && i == selectedPointPos)) {
|
||||
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (measurementEditingContext.isInMovePointMode()
|
||||
|| measurementEditingContext.isInAddPointBeforeMode()
|
||||
|| measurementEditingContext.isInAddPointAfterMode()) {
|
||||
if (editingCtx.isInMovePointMode()
|
||||
|| editingCtx.isInAddPointBeforeMode()
|
||||
|| editingCtx.isInAddPointAfterMode()) {
|
||||
int locX = tb.getCenterPixelX();
|
||||
int locY = tb.getCenterPixelY();
|
||||
canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint);
|
||||
|
@ -344,15 +338,15 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
}
|
||||
|
||||
void exitMovePointMode() {
|
||||
measurementEditingContext.setInMovePointMode(false);
|
||||
editingCtx.setInMovePointMode(false);
|
||||
}
|
||||
|
||||
void exitAddPointAfterMode() {
|
||||
measurementEditingContext.setInAddPointAfterMode(false);
|
||||
editingCtx.setInAddPointAfterMode(false);
|
||||
}
|
||||
|
||||
void exitAddPointBeforeMode() {
|
||||
measurementEditingContext.setInAddPointBeforeMode(false);
|
||||
editingCtx.setInAddPointBeforeMode(false);
|
||||
}
|
||||
|
||||
private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) {
|
||||
|
@ -373,9 +367,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
WptPt pt = new WptPt();
|
||||
pt.lat = l.getLatitude();
|
||||
pt.lon = l.getLongitude();
|
||||
boolean allowed = measurementPoints.size() == 0 || !measurementPoints.get(measurementPoints.size() - 1).equals(pt);
|
||||
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
|
||||
if (allowed) {
|
||||
measurementPoints.add(position, pt);
|
||||
editingCtx.getPoints().add(position, pt);
|
||||
return pt;
|
||||
}
|
||||
return null;
|
||||
|
@ -387,9 +381,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
pt.lat = pressedPointLatLon.getLatitude();
|
||||
pt.lon = pressedPointLatLon.getLongitude();
|
||||
pressedPointLatLon = null;
|
||||
boolean allowed = measurementPoints.size() == 0 || !measurementPoints.get(measurementPoints.size() - 1).equals(pt);
|
||||
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
|
||||
if (allowed) {
|
||||
measurementPoints.add(position, pt);
|
||||
editingCtx.getPoints().add(position, pt);
|
||||
moveMapToPoint(position);
|
||||
return pt;
|
||||
}
|
||||
|
@ -400,20 +394,20 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
WptPt getMovedPointToApply() {
|
||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||
LatLon latLon = tb.getCenterLatLon();
|
||||
WptPt pt = measurementPoints.get(selectedPointPos);
|
||||
WptPt pt = editingCtx.getPoints().get(selectedPointPos);
|
||||
pt.lat = latLon.getLatitude();
|
||||
pt.lon = latLon.getLongitude();
|
||||
return pt;
|
||||
}
|
||||
|
||||
public void moveMapToPoint(int pos) {
|
||||
if (measurementPoints.size() > 0) {
|
||||
if (pos >= measurementPoints.size()) {
|
||||
pos = measurementPoints.size() - 1;
|
||||
if (editingCtx.getPointsCount() > 0) {
|
||||
if (pos >= editingCtx.getPointsCount()) {
|
||||
pos = editingCtx.getPointsCount() - 1;
|
||||
} else if (pos < 0) {
|
||||
pos = 0;
|
||||
}
|
||||
WptPt pt = measurementPoints.get(pos);
|
||||
WptPt pt = editingCtx.getPoints().get(pos);
|
||||
view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
}
|
||||
});
|
||||
|
||||
List<WptPt> points = measurementLayer.getMeasurementPoints();
|
||||
List<WptPt> points = measurementLayer.getEditingCtx().getPoints();
|
||||
int pos = measurementLayer.getSelectedPointPos();
|
||||
WptPt pt = points.get(pos);
|
||||
String pointTitle = pt.name;
|
||||
|
|
|
@ -18,7 +18,7 @@ public class AddPointCommand extends MeasurementModeCommand {
|
|||
public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) {
|
||||
this.measurementLayer = measurementLayer;
|
||||
this.center = center;
|
||||
position = measurementLayer.getMeasurementPoints().size();
|
||||
position = measurementLayer.getEditingCtx().getPointsCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,13 +34,13 @@ public class AddPointCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public void undo() {
|
||||
measurementLayer.getMeasurementPoints().remove(position);
|
||||
measurementLayer.getEditingCtx().getPoints().remove(position);
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() {
|
||||
measurementLayer.getMeasurementPoints().add(position, point);
|
||||
measurementLayer.getEditingCtx().getPoints().add(position, point);
|
||||
measurementLayer.refreshMap();
|
||||
measurementLayer.moveMapToPoint(position);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class ClearPointsCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
List<WptPt> pts = measurementLayer.getMeasurementPoints();
|
||||
List<WptPt> pts = measurementLayer.getEditingCtx().getPoints();
|
||||
List<WptPt> snappedPts = measurementLayer.getSnappedToRoadPoints();
|
||||
points = new LinkedList<>(pts);
|
||||
snappedToRoadPoints = new LinkedList<>(snappedPts);
|
||||
|
@ -29,14 +29,14 @@ public class ClearPointsCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public void undo() {
|
||||
measurementLayer.getMeasurementPoints().addAll(points);
|
||||
measurementLayer.getEditingCtx().getPoints().addAll(points);
|
||||
measurementLayer.getSnappedToRoadPoints().addAll(snappedToRoadPoints);
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() {
|
||||
measurementLayer.getMeasurementPoints().clear();
|
||||
measurementLayer.getEditingCtx().getPoints().clear();
|
||||
measurementLayer.getSnappedToRoadPoints().clear();
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
|
|
@ -23,15 +23,15 @@ public class MovePointCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public void undo() {
|
||||
measurementLayer.getMeasurementPoints().remove(position);
|
||||
measurementLayer.getMeasurementPoints().add(position, oldPoint);
|
||||
measurementLayer.getEditingCtx().getPoints().remove(position);
|
||||
measurementLayer.getEditingCtx().getPoints().add(position, oldPoint);
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() {
|
||||
measurementLayer.getMeasurementPoints().remove(position);
|
||||
measurementLayer.getMeasurementPoints().add(position, newPoint);
|
||||
measurementLayer.getEditingCtx().getPoints().remove(position);
|
||||
measurementLayer.getEditingCtx().getPoints().add(position, newPoint);
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,21 +15,21 @@ public class RemovePointCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
point = measurementLayer.getMeasurementPoints().remove(position);
|
||||
point = measurementLayer.getEditingCtx().getPoints().remove(position);
|
||||
measurementLayer.refreshMap();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
measurementLayer.getMeasurementPoints().add(position, point);
|
||||
measurementLayer.getEditingCtx().getPoints().add(position, point);
|
||||
measurementLayer.refreshMap();
|
||||
measurementLayer.moveMapToPoint(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() {
|
||||
measurementLayer.getMeasurementPoints().remove(position);
|
||||
measurementLayer.getEditingCtx().getPoints().remove(position);
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ReorderPointCommand extends MeasurementModeCommand {
|
|||
}
|
||||
|
||||
private void swap() {
|
||||
Collections.swap(measurementLayer.getMeasurementPoints(), from, to);
|
||||
Collections.swap(measurementLayer.getEditingCtx().getPoints(), from, to);
|
||||
measurementLayer.refreshMap();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue