Last active
March 30, 2022 14:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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