With leaflet.js using leaflet.draw.js after using the draw tool to draw one of the shapes on a custom map. I have a form that pops up which says save or cancel. If the user presses cancel, then I want the drawing to be deleted. For example I was drawing a rectangle.
Here is my current source
map.on('draw:created', function(e) {
var layer = e.layer;
var type = e.layerType;
$("#add-drawing").fadeIn(500);
featureGroup.addLayer(e.layer); // Adds rectangle
$("a.cancelD").on("click", function() {
$("#add-drawing").fadeOut(500);
// THESE ARE THE METHODS I HAVE TRIED TO REMOVE THE RECTANGLE
map.removeLayer(layer);
featureGroup.removeLayer(layer);
map.removeLayer(e);
featureGroup.removeLayer(e);
});
});
None of this seems to be working. I can use the toolbox to remove the layer, but then I won't have any information submitted in the form I wish to submit.
How can I remove objects that I have drawn when pressing the cancel button on a form?