Search code examples
angulartypescriptleafletleaflet.draw

How to reference the deleted layers in Leaflet.draw?


I am trying to delete a Leaflet.draw layer from my database in firestore. I can easily delete it from the database side, but i struggle with connecting the document name with the layer name.

More specifically, i can't seem to get the id of the layer to be deleted/edited. Once i have that i should be able to connect it to the document id

This is what i got currently:

map.on(L.Draw.Event.DELETED, e => {
      this.deleteMarkerAnnotation(this.dummyValue)
      console.log(e.propagatedFrom.layers.eachLayer(layer => { console.log(layer) }))
    })

I get an error: Cannot read property 'layers' of undefined


Solution

  • propagatedFrom is indeed undefined. It is not provided on the event object

    just remove propagatedFrom and use e.layers instead.

    map.on(L.Draw.Event.DELETED, e => {
       e.layers.eachLayer(layer => {
          console.log(layer)
       });
    })