Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Last active March 30, 2022 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carmoreira/608d1da472e4e186a07b25e6991054f8 to your computer and use it in GitHub Desktop.
Save carmoreira/608d1da472e4e186a07b25e6991054f8 to your computer and use it in GitHub Desktop.
Hide marker auto labels until specific zoom level is reached - Interactive Geo Maps
let mapID = 3491853; // replace with your map ID
let zoomLevel = 8; // 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.children.values.forEach(function(label) {
if(label.className === 'Label'){
label.show();
}
});
} else {
marker.children.values.forEach(function(label) {
if (label.className === 'Label') {
label.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