Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Last active November 17, 2021 09:07
Show Gist options
  • Save carmoreira/37d378a5404f6f079f21aca38cec4bac to your computer and use it in GitHub Desktop.
Save carmoreira/37d378a5404f6f079f21aca38cec4bac to your computer and use it in GitHub Desktop.
Interactive Geo Maps - Listen to click event on regions and trigger custom code
// replace with your map ID and region code.
let mapID = 236162;
let mapContainer = document.getElementById('map_' + mapID);
mapContainer.addEventListener('mapready', function(ev) {
iMaps.maps[mapID].series[0].mapPolygons.each(function(region) {
region.events.on("hit", function(ev) {
let data = region.dataItem.dataContext;
// run my custom code here if clicked region
// region code will be data.id
// region name will be data.name
}, this);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment