Skip to content
Advertisement

How to reset a leaflet map after a case in JS

Hi, i have the following problem: I have a map in leaflet linked to a change function in jquery, depending on the ID that I receive in the “select” of the previous query, the case is entered below in JS:

JavaScript

At the moment of choosing another case (Stored in a select in HTML ) the data that the first case that I have chosen gave me is still stored in the map, how could I get these data that are in the map to be deleted so that Does the other case apply?

If there is a need for another part of the code or if there is any inconsistency, you can tell me, thanks!

Advertisement

Answer

To reset everything on your map you can use the eachLayer method of your map, to remove all layers previously added:

JavaScript

[EDIT] To only delete a specific layer, you need to keep track of it:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement