Disable the Flyer toolbar when the user creates the form and turns it on when the form is deleted

I would like to prevent the user from creating several shapes on the map. For example, if the user creates a polygon, all form icons in the toolbar should be disabled. When a user deletes a previously created form, then the toolbar icons should be enabled.

How can i do this? I tried to remove the toolbar for a draw: the created event and add a new toolbar to the draw: deleted event, but this leads to errors (see the attached screenshot).

Error screenshot

+4
source share
1 answer

remove() addTo().

, . - L.Control.Draw, - "draw":

self.drawControlFull = new L.Control.Draw();

self.drawControlEdit = new L.Control.Draw({
  edit: {
    featureGroup: editableLayers,
    edit: false
  },
  draw: false
});

map.addControl(drawControlFull);

draw:created draw:deleted / :

map.on('draw:created', function(e) {
  var type = e.layerType,
    layer = e.layer;

    self.drawControlFull.remove();
    self.drawControlEdit.addTo(map);

  editableLayers.addLayer(layer);
});

map.on('draw:deleted', function (e) {
    self.drawControlEdit.remove();
    self.drawControlFull.addTo(map);
});

, , , . jsFiddle, , .

+3

Source: https://habr.com/ru/post/1653677/


All Articles