Reputation: 9055
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
Upvotes: 4
Views: 6726
Reputation: 2702
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";
}
}
Upvotes: 7