JVector Map onRegionClick Event

ObiWanKobi picture ObiWanKobi · Jul 22, 2014 · Viewed 8.4k times · Source

So in JVector map I need a function that has each region linked to a URL. So if you click on South Africa it will take you to a page with information about South Africa. I know to start with onRegionClick: function () but where to go from there is a mystery to me.

Answer

j.f. picture j.f. · Jul 23, 2014

Well, as the documentation says:

onRegionClick

Callback function which will be called when the user clicks the region path. Region code will be passed to the callback as argument.

So each time a region is clicked, the region's code is passed to the handler. Then if the code is all you need on your next page, you could just pass that as is in the query string.

onRegionClick: function (event, code) {
    window.location.href = "yourpage?regionCode=" + code
},

If you need the actual name of the region instead of the code, there is a handy getRegionName method that you could use.

var regionName = map.getRegionName(code);