0

I've got a click event for the main part of my leaflet map. But if the user clicks on a specific layer I want to do something else and not the other action. I thought I could stop the propagation of the map click using this answer

map.originalEvent.preventDefault()

But I still get both events.

Here's a cutting from my code

    this.map.on('click', (event) => {
        console.log('map clicked')
    })


    this.boundaryLayer = L.geoJSON().addTo(this.map);
    this.boundaryLayer.on('click', (event) => {
        console.log('boundary clicked', event);
        event.originalEvent.preventDefault();
    });
Craig
  • 8,093
  • 8
  • 42
  • 74

1 Answers1

0

This code stops the map's click event from being fired

    this.boundaryLayer.on('click', (event) => {
            console.log('boundary clicked', event);
            L.DomEvent.stopPropagation(event);
    });
Craig
  • 8,093
  • 8
  • 42
  • 74