Wednesday, 23 June 2021

how to keep class attribute stored for Leaflet.js markers

so i have a set of markers each stored in different Layers... lets say:

let earth= {
    layer:{
        ...
        Markers:{...}
    }
}
let mars= {
    layer:{
        ...
        Markers:{...}
    }
}
let pluto= {
    layer:{
        ...
        Markers:{...}
    }
}

now how i switch to different maps (with individual markers) is with

function setMap(selectedMap, htmlElement, ifSub = false) {
        if (currentMap != selectedMap) {
            map.removeLayer(window[currentMap].Layer)
            map.addLayer(window[selectedMap].Layer)

            currentMap = selectedMap

        }
    }

With a button (and on launch) i have given some of the markers on pluto a class (lets say "Visited") which changes css for them.

However when i change the map to Earth and back to Pluto the markers from Pluto "forget" that they had a class in the first place. how would i keep the css stored with the marker? and added back to the marker when map.addLayer(...) is called?



from how to keep class attribute stored for Leaflet.js markers

No comments:

Post a Comment