Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Created July 7, 2023 11:33
Show Gist options
  • Save carmoreira/57d0156cc2feb6f5179ef5897c1f81ca to your computer and use it in GitHub Desktop.
Save carmoreira/57d0156cc2feb6f5179ef5897c1f81ca to your computer and use it in GitHub Desktop.
Hide Markers until specific zoom level is reached - Interactive Geo Maps
let mapID = 955; // replace with your map ID
let zoomLevel = 3; // replace with the zoom level you want to show the labels at
let igmNow = Date.now();
function igmHideMarkers(igmap) {
igmNow = Date.now();
let series = iMaps.maps[mapID].series;
series.forEach(function(serie) {
if (typeof serie.mapImages === 'undefined') {
return;
}
serie.mapImages.each(function(marker) {
if (igmap.zoomLevel >= zoomLevel) {
marker.show();
} else {
marker.hide();
}
});
});
}
let mapContainer = document.getElementById('map_' + mapID);
mapContainer.addEventListener('mapready', function(ev) {
let igmap = iMaps.maps[mapID].map;
igmHideMarkers(igmap);
igmap.events.on("zoomlevelchanged", function(ev) {
if (Date.now() >= igmNow + 500) {
igmHideMarkers(igmap);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment