Jvector映射如何从标记添加和获取链接 [英] Jvector Map how to add and get link from marker

查看:97
本文介绍了Jvector映射如何从标记添加和获取链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从标记数组中获取数据并在onmarkerclick函数上调用它,这样我可以在点击标记后转到URL,我尝试的所有内容似乎都失败了。我希望在标记数组中添加一个URL并将其返回到onmarkerclick。感谢您的高级帮助:

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);                
                   }
            });
});


推荐答案

这么多巧合,我昨天只面临同样的问题.. :)

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

我找到的解决方案是在外部创建一个数组,并通过click-function中的索引访问它。

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);
                  }
            });
});

这篇关于Jvector映射如何从标记添加和获取链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆