Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.98k stars 994 forks source link

is editing possible when using L.Draw.Rectangle? #941

Open novaknole opened 5 years ago

novaknole commented 5 years ago

How to reproduce

What behaviour I'm expecting and which behaviour I'm seeing

Here is my code

 var polygonDrawer = new L.Draw.Rectangle(this.map);
      polygonDrawer.setOptions({
        shapeOptions: {
          color: 'green'
        }
      })

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

        layer.addTo(this.map);
      });

      polygonDrawer.enable();

The thing is when I start drawing and finish, sometimes I want to edit it. but it doesn't let me edit it at all. I don't want to use drawcontrols or toolbars, because I only have 2 buttons with my custom designs and this seems to be easier for me. So how do I make editing possible with the above following code?

azophy commented 5 years ago

what buttons do you have on your custom design? from my experience we need to add a custom input such as button or keypress to trigger the layer.editing.enable() as shown in the edit_handler example on the docs. Here's what I do :

// button_edit is variable used to store my edit button object
 L.DomEvent.on(button_edit, 'click', function(e) {
        drawnItems.eachLayer(function (layer) {
            if (layer instanceof L.Polygon){
                layer.editing.enable();
            }
        });
    });