Last active
November 17, 2021 09:07
-
-
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
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
// 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