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() {
|
||||
@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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
if (center) {
|
||||
point = measurementLayer.addCenterPoint(position);
|
||||
} else {
|
||||
point = measurementLayer.addPoint(position);
|
||||
}
|
||||
measurementLayer.refreshMap();
|
||||
return point != null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue