Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable finish drawing by clicking on existing vertex #1394

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"firstVertex": "Click to place first vertex",
"continueLine": "Click to continue drawing",
"finishLine": "Click any existing marker to finish",
"finishLineByBtn": "Click finish in the Toolbar to finish the Line",
"finishPoly": "Click first marker to finish",
"finishRect": "Click to finish",
"startCircle": "Click to place circle center",
Expand Down
17 changes: 12 additions & 5 deletions src/js/Draw/L.PM.Draw.Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ Draw.Line = Draw.extend({
latlng.equals(latlngs[0]) ||
(latlngs.length > 0 && latlng.equals(lastLatLng))
) {
// yes? finish the polygon
this._finishShape();

if (this.options.finishOnVertexClick) {
// yes? finish the polygon
this._finishShape(e);
}

// "why?", you ask? Because this happens when we snap the last vertex to the first one
// and then click without hitting the last marker. Click happens on the map
Expand Down Expand Up @@ -387,8 +390,10 @@ Draw.Line = Draw.extend({
this._layerGroup.addLayer(marker);
this._markers.push(marker);

// a click on any marker finishes this shape
marker.on('click', this._finishShape, this);
if (this.options.finishOnVertexClick) {
// a click on any marker finishes this shape
marker.on('click', this._finishShape, this);
}

return marker;
},
Expand All @@ -400,7 +405,9 @@ Draw.Line = Draw.extend({
if (length <= 1) {
text = getTranslation('tooltips.continueLine');
} else {
text = getTranslation('tooltips.finishLine');
text = this.options.finishOnVertexClick
? getTranslation('tooltips.finishLine')
: getTranslation('tooltips.finishLineByBtn');
}
this._hintMarker.setTooltipContent(text);
},
Expand Down
1 change: 1 addition & 0 deletions src/js/Draw/L.PM.Draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Draw = L.Class.extend({
pathOptions: null,
cursorMarker: true,
finishOn: null,
finishOnVertexClick: true,
markerStyle: {
draggable: true,
icon: L.icon(),
Expand Down