Variables 如何从标记中获取值并将其存储到变量
我设法用jVectorMap创建了一张地图,地图上有标记 现在,当用户单击标记时,如何从标记中获取值 JSIDLE链接:Variables 如何从标记中获取值并将其存储到变量,variables,save,jvectormap,Variables,Save,Jvectormap,我设法用jVectorMap创建了一张地图,地图上有标记 现在,当用户单击标记时,如何从标记中获取值 JSIDLE链接: 将markers数组指定给匿名函数中的一个变量,您可以在映射标记的指定和onMarkerClick闭包中引用该变量 JSIDLE链接: $(function(){ $('#map').vectorMap({ map: 'us_aea_en', zoomOnScroll: false, hoverOpac
将markers数组指定给匿名函数中的一个变量,您可以在映射标记的指定和onMarkerClick闭包中引用该变量 JSIDLE链接:
$(function(){
$('#map').vectorMap({
map: 'us_aea_en',
zoomOnScroll: false,
hoverOpacity: 0.7,
markerStyle: {
initial: {
fill: '#F8E23B',
stroke: '#383f47'
}
},
markers: [
{latLng: [41.50, -87.37], name: 'Chicago', newvalue: '300'},
{latLng: [32.46, -96.46], name: 'Dallas', newvalue: '301'},
{latLng: [36.10, -115.12], name: 'Las Vegas', newvalue: '302'},
{latLng: [34.3, -118.15], name: 'Los Angeles', newvalue: '303'},
{latLng: [40.43, -74.00], name: 'New York City', newvalue: '304'}
],
onMarkerClick: function(event, index){
var a = 2;
var b=2+newval; //need to get the value from each markers and save the value to newval
alert(b);
}
});
});
$(function () {
//assign markers to a variable
var mapMarkers = [
{latLng: [41.50, -87.37], name: 'Chicago', newvalue: '300'},
{latLng: [32.46, -96.46], name: 'Dallas', newvalue: '301'},
{latLng: [36.10, -115.12], name: 'Las Vegas', newvalue: '302'},
{latLng: [34.3, -118.15], name: 'Los Angeles', newvalue: '303'},
{latLng: [40.43, -74.00], name: 'New York City', newvalue: '304'}
];
$('#map').vectorMap({
map: 'us_aea_en',
zoomOnScroll: false,
hoverOpacity: 0.7,
markerStyle: {
initial: {
fill: '#F8E23B',
stroke: '#383f47'
}
},
markers: mapMarkers,
onMarkerClick: function (event, index) {
var a = 2;
//retrieve marker by the index and parse the string value as an integer
var newval = parseInt(mapMarkers[index].newvalue);
var b = 2 + newval; //need to get the value from each markers and save the value to newval
alert(b);
}
});
});