下面是我的代码:
$.ajax({
type: "GET",
url: "content/content.json",
success: function( data ) {
check = true;
ajaxMap = data;
drawMap(data);
}
});
function drawMap( data ) {
$('#map').mapSvg({
source: 'maps/test.svg',
colors: {
selected: "#00431e",
disabled: "#ffffff"
},
tooltipsMode: 'custom',
zoom: true,
zoomButtons: {'show': true, 'location': 'left'},
pan: true,
responsive: true,
zoomLimit: [0,500],
marks: data, // here I pass data from JSON file
tooltipsMode: 'custom',
zoom: true,
pan: true,
responsive: 0,
zoomLimit: [0,100]
});
}
当我直接在标记中以 JSON 格式传递数据时它可以工作,但是当我传递数据变量时它不起作用。
更新: 这是我的 json 数据:
[
{ c: [50.84199288,122.83167],
attrs: {'src': 'markers/pin-yellow.png'},
tooltip: '<h2>Dublin - Ireland</h2><p>Embassies and High Commissions</p><a href="http://www.dfat.gov.au/geo/ireland/" title="http://www.dfat.gov.au/geo/ireland/">Read More</a>'
},
{ c: [44.94199288,119.93167],
attrs: {'src': 'markers/pin-yellow.png'},
tooltip: '<h2>London - United Kingdom</h2><p>Embassies and High Commissions</p><a href="http://www.dfat.gov.au/geo/united_kingdom/" title="http://www.dfat.gov.au/geo/united_kingdom/">Read More</a>'
},
{ c: [28.94199288,100.93167],
attrs: {'src': 'markers/pin-yellow.png'},
tooltip: '<h2>Header</h2><p>Embassies and High Commissions</p><a href="#" title="">Read More</a>'
},
{ c: [44.94199288,115.93167],
attrs: {'src': 'markers/pin-yellow.png'},
tooltip: '<h2>Header</h2><p>Embassies and High Commissions</p><a href="#" title="">Read More</a>'
},
{ c: [20.94199288,135.93167],
attrs: {'src': 'markers/pin-yellow.png'},
tooltip: '<h2>Header</h2><p>Embassies and High Commissions</p><a href="#" title="">Read More</a>'
}
]