Add multiple events to the same layer in leaflet geoman

48 Views Asked by At

I want to add multiple event listeners on the same map layer when the global edit button is toggled.

Here is a working example where I enable dragging and rotating on a layer. I want to fire different events bases on the previous user interaction. This works fine for dragging and rotating. Is there a way to make this work with resizing? I would like to allow the user to resize/drag/rotate a layer when the pm:globaleditmodetoggled is toggled.

map.on('pm:globaleditmodetoggled', ({ map }) => {
map.eachLayer((mapLayer) => {
  if (mapLayer instanceof L.Rectangle) {
    mapLayer.pm.enableLayerDrag();
    mapLayer.pm.enableRotate();
    mapLayer.on('pm:dragstart', ({ layer }) => {
      if (layer instanceof L.Rectangle) {
        layer.pm.disableRotate();
      }
    });
    mapLayer.on('pm:dragend', ({ layer }) => {
      if (layer instanceof L.Rectangle) layer.pm.enableRotate();
    });
    mapLayer.on('pm:rotateend', ({ layer }) => {
      if (layer instanceof L.Rectangle) {
        layer.pm.enableRotate();
      }
    });
  }
});

});

0

There are 0 best solutions below