Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Last active Mar 30, 2022
Embed
What would you like to do?
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