Delete last vertex drawn of polygon
See original GitHub issueI am creating a polygon using leaflet.draw plugin in mapbox. My requirement is to restrict the user to draw outside a particular boundary and in case user clicks outside that boundary ,last drawn vertex should get deleted and line drawn to that vertex should also get removed. I am writing following code to achieve this.
mapData=document.getElementById('mapTest');
L.mapbox.accessToken = 'pk.eyJ1Ijoicml0aWthIiwiYSI6IlpnRThghmhbifQ.i9VWs0WDpjyxMn1YFzKOow';
var map = L.mapbox.map(mapData, 'abc.j565ghh0o')
.setView( [38.893596444352134, -77.0381498336792], 12);
featureGroup = L.featureGroup().addTo(map);
drawControl = new L.Control.Draw({
edit: {
featureGroup: featureGroup
},
draw: {
polygon: true,
polyline: false,
rectangle: false,
circle: false,
marker: false
}
}).addTo(map);
map.on('draw:created', showPolygonArea);
map.on('draw:edited', showPolygonAreaEdited);
function showPolygonAreaEdited(e) {
e.layers.eachLayer(function(layer) {
showPolygonArea({ layer: layer });
});
}
function showPolygonArea(e) {
featureGroup.clearLayers();
featureGroup.addLayer(e.layer);
var layer = e.layer;
latLngs = layer.getLatLngs();
mapZoom=map.getZoom();
}
map.on('click', function(e) {
var currentLoc=e.latlng;
if(polygonParent!="")
{
var a=polygonParent.getBounds();
containsCurrentLocation=a.contains(currentLoc);
}
if(containsCurrentLocation==false)
{
alert("Select point within the boundary.");
// how to remove last vertex here?? }
});
Issue Analytics
- State:
- Created 9 years ago
- Comments:5
Top Results From Across the Web
Deleting last vertex using ArcMap Keyboard Shortcut?
As I was working on ArcMap 10.1 and 10.2 there was also a Backspace key working to delete last vertices, while continuing drawing....
Read more >Deleting a Vertex | Maps JavaScript API - Google Developers
This example demonstrates how a user can delete a vertex, or a point on the line, by right-clicking on a vertex to show...
Read more >Delete a vertice of polygon on edited shape - Microsoft Learn
If the button is clicked, delete the vertex from the shape by getting all the positions/coordinates in the shape as an array (getCoordinates) ......
Read more >Leaflet.draw delete last point - Stack Overflow
Call the deleteLastVertex method on your draw instance: var drawPolyline = new L.Draw.Polyline(map, drawControl.options.polyline).enable(); ...
Read more >Deleting a vertex—ArcMap | Documentation
Deleting a vertex · Click the Delete Vertex tool Delete Vertex Tool on the Edit Vertices toolbar and drag a box around the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Wait until the next version, it will be easier then. You’ll be able to do something like this:
Note that the call to deleteLastVertex will trigger an L.Draw.Event.DRAWVERTEX event.
For edit mode, it’s a little tricker. It sounds like you’ve found the marker you want to delete; in that case, you can do this:
The tricky parts are making sure you have the right edit handler, and then updating the markers once the marker click has finished firing. And again, this is only once the new version is released.
On Thu, Dec 15, 2016 at 6:13 AM, mikila85 notifications@github.com wrote:
@germanjoey There’s no
e.drawHandler
from the eventL.Draw.Event.DRAWVERTEX
. Where did you find this ?