Using Mapbox GL JS and following the provided example which shows how to attach markers to the map
// add markers to map
geojson.features.forEach(function(marker) {
// create a HTML element for each feature
var el = document.createElement('div');
el.className = 'marker';
// make a marker for each feature and add to the map
new mapboxgl.Marker(el)
.setLngLat(marker.geometry.coordinates)
.addTo(map);
});
how can I hide/show on click event different markers
Something like this?
function hide() {
let markers = document.getElementsByClassName("marker");
for (let i = 0; i < markers.length; i++) {
markers[i].style.visibility = "hidden";
}
}
function show() {
let markers = document.getElementsByClassName("marker");
for (let i = 0; i < markers.length; i++) {
markers[i].style.visibility = "visible";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With