0

To show a popup when clicking the map, I entered:

const popup = function(e){new maplibregl.Popup().setLngLat(e.lngLat).setHTML('MODIFICATIONS').addTo(map)}; map.on('click', popup); map.on('ClosePopups', popup.remove()); 

Why doesn't it work?

If the .addTo(map) is included at the end of the const, and removed from the map.on, the popup does appear OK.

In either way, the popup is NOT removed programmaticaly when the 'ClosePopups' button is activated. map.fire(ClosePopups);

2
  • Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works Commented Feb 21, 2023 at 8:38
  • if you solved your problem please post it as an answer (and then accept it) so that it can be found by other users in the future rather than editing it into your question Commented Feb 21, 2023 at 8:39

1 Answer 1

0

My solution: I added:

const popups = document.getElementsByClassName("maplibregl-popup"); 

and edit:

map.on('ClosePopups', () => {popups[0].remove()}); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.