I want to enable the user to draw a Line (which is a Polyline with only 2 points).
I enable drawing and the listen for vertexadded
. When the _rings
marker count equals 2, I disable drawing.
This feels wrong for several reasons:
_rings
Am I missing a simpler way of doing this?
map.pm.enableDraw('Line', {
snappable: true,
snapDistance: 20,
});
map.on('pm:drawstart', (event: any) => {
const { workingLayer } = event;
workingLayer.on('pm:vertexadded', (e: any) => {
if (workingLayer._rings[0].length >= 2) {
map.pm.disableDraw('Line', {
snappable: true,
snapDistance: 20,
});
}
});
});
layer.getLatLngs()
instead of the variable _rings
.map.pm.disableDraw()
, finish the shape with map.pm.Draw.Line._finishShape()
to add the drawn layer to the mapmap.pm.enableGlobalEditMode()
to enable editing for all layers or you can enable the wanted layer with layer.pm.enable()
hideMiddleMarkers: true
map.pm.setGlobalOptions({hideMiddleMarkers: true})
map.on('pm:drawstart', (event) => {
const { workingLayer } = event;
workingLayer.on('pm:vertexadded', (e) => {
if (workingLayer.getLatLngs().length >= 2) {
map.pm.Draw.Line._finishShape()
}
});
});
map.pm.enableDraw('Line');