Jvector Map how to add and get link from marker

D J picture D J · Feb 5, 2013 · Viewed 10.5k times · Source

I am trying to get data from the marker array and call it back on the onmarkerclick function so I can go to a URL once a marker is clicked, everything I try seems to fail. I wish to add a URL in to the marker array and return this into the onmarkerclick. Thanks for your help in advanced:

 $(function(){
    $('#map1').vectorMap({
                  map: 'world_mill_en',
                  scale: ['#C8EEFF', '#0071A4'],
                  normalizeFunction: 'polynomial',
                  hoverOpacity: 0.7,
                  hoverColor: false,
                  markerStyle: {
                    initial: {
                          fill: '#F8E23B',
                          stroke: '#383f47'
                    }
                  },
                  backgroundColor: '#383f47',
                  markers: [{latLng: [48.921537, -66.829834], name: "something", weburl : "/blah/foo"

            },{latLng: [45.995944, -64.171143], name: "something else", weburl : "/blah/foo"

            },],
                  onMarkerClick: function(events, label, index, weburl) {
                    alert (1+weburl);                
                   }
            });
});

Answer

Rajat Singhal picture Rajat Singhal · Feb 5, 2013

So much coincidence, I faced the same problem yesterday only..:)

The solution I found was to create an array outside, and access it by the index in the click-function..

var markers = [
    {latLng: [48.921537, -66.829834], name: "something", weburl : "/blah/foo"},
    {latLng: [45.995944, -64.171143], name: "something else", weburl : "/blah/foo-else"}
];

$(function(){
    $('#map1').vectorMap({
                  ...
                  markers: markers,
                  onMarkerClick: function(event, index) {
                      // alter the weburl
                      alert(markers[index].weburl);
                  }
            });
});