Below is my code:
$.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]
});
}
It works when I pass data as JSON format directly in marks, but when I pass data variable it doesn't work.
Updated: This my json data:
[
{ 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>'
}
]
You have to define dataType property if you aspect response in json format. currently you are getting data as string.
or use
data=JSON.parse(data)
in your success handler.Moreover what you have shown in example is object literal , not an json. see http://json.org/ . JSON.parse() will give error on your example.