Search code examples
mapboxmapbox-gl-js

How to disable "close all popups" in MapBox?


Not too long ago, people had a really hard time getting all popups to close on map click in mapbox (How to close all popups programmatically in mapbox gl?).

They've since changed this to the default behavior, which is nice, but does not suit my current project.

How does one NOT have all popups close on click out?

And once that is disabled:

How does one programmatically close selected popups on click out?


Solution

  • Like this:

    const popup = new mapboxgl.Popup({ closeOnClick: false });
    
    map.on('click', () => popup.remove());