Add point to tap position
This commit is contained in:
parent
c3b70afd1c
commit
18b2910a1e
3 changed files with 41 additions and 5 deletions
|
@ -286,7 +286,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
|
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
addPoint();
|
addCenterPoint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -660,7 +660,19 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private void addPoint() {
|
private void addPoint() {
|
||||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
if (measurementLayer != null) {
|
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);
|
enable(undoBtn, upDownBtn);
|
||||||
disable(redoBtn);
|
disable(redoBtn);
|
||||||
updateText();
|
updateText();
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
private OnEnterMovePointModeListener enterMovePointModeListener;
|
private OnEnterMovePointModeListener enterMovePointModeListener;
|
||||||
private int selectedPointPos = -1;
|
private int selectedPointPos = -1;
|
||||||
private WptPt selectedCachedPoint;
|
private WptPt selectedCachedPoint;
|
||||||
|
private LatLon pressedPointLatLon;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initLayer(OsmandMapTileView view) {
|
public void initLayer(OsmandMapTileView view) {
|
||||||
|
@ -135,6 +136,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
if (selectedPointPos != -1) {
|
if (selectedPointPos != -1) {
|
||||||
singleTapListener.onSelectPoint();
|
singleTapListener.onSelectPoint();
|
||||||
} else {
|
} else {
|
||||||
|
pressedPointLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||||
singleTapListener.onAddPoint();
|
singleTapListener.onAddPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,7 +332,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
canvas.rotate(tb.getRotate(), center.x, center.y);
|
canvas.rotate(tb.getRotate(), center.x, center.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WptPt addPoint(int position) {
|
public WptPt addCenterPoint(int position) {
|
||||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||||
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
|
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||||
WptPt pt = new WptPt();
|
WptPt pt = new WptPt();
|
||||||
|
@ -344,6 +346,22 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
return null;
|
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() {
|
WptPt getMovedPointToApply() {
|
||||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||||
LatLon latLon = tb.getCenterLatLon();
|
LatLon latLon = tb.getCenterLatLon();
|
||||||
|
|
|
@ -8,20 +8,26 @@ public class AddPointCommand implements Command {
|
||||||
private final MeasurementToolLayer measurementLayer;
|
private final MeasurementToolLayer measurementLayer;
|
||||||
private final int position;
|
private final int position;
|
||||||
private WptPt point;
|
private WptPt point;
|
||||||
|
private boolean center;
|
||||||
|
|
||||||
public AddPointCommand(MeasurementToolLayer measurementLayer, int position) {
|
public AddPointCommand(MeasurementToolLayer measurementLayer, int position) {
|
||||||
this.measurementLayer = measurementLayer;
|
this.measurementLayer = measurementLayer;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddPointCommand(MeasurementToolLayer measurementLayer) {
|
public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) {
|
||||||
this.measurementLayer = measurementLayer;
|
this.measurementLayer = measurementLayer;
|
||||||
|
this.center = center;
|
||||||
position = measurementLayer.getPointsCount();
|
position = measurementLayer.getPointsCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute() {
|
public boolean execute() {
|
||||||
point = measurementLayer.addPoint(position);
|
if (center) {
|
||||||
|
point = measurementLayer.addCenterPoint(position);
|
||||||
|
} else {
|
||||||
|
point = measurementLayer.addPoint(position);
|
||||||
|
}
|
||||||
measurementLayer.refreshMap();
|
measurementLayer.refreshMap();
|
||||||
return point != null;
|
return point != null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue