var mapLocations = [];
// Based on https://www.amcharts.com/demos/custom-html-elements-map-markers/
var map = AmCharts.makeChart("chartdiv", {
"type": "map",
"theme": "none",
"projection": "miller",
"imagesSettings": {
"rollOverColor": "#089282",
"rollOverScale": 3,
"selectedScale": 3,
"selectedColor": "#089282",
"color": "#13564e"
},
"areasSettings": {
"unlistedAreasColor": "#222222" /* change color of the map */
},
"dataProvider": {
"map": "worldLow",
"images": mapLocations
},
});
// Location updated emitted by the server via websockets
socket.on("map_update", function (msg) {
var message = "New event in " + msg.title + " (" + msg.latitude
+ "," + msg.longitude + ")";
console.log(message);
newLocation = new Location(msg.title, msg.latitude, msg.longitude);
mapLocations.push(newLocation);
map.dataProvider.images = mapLocations;
map.validateData(); //call to redraw the map with new data
});
With this code, only the latest location that is sent with the websocket is shown in the map. Even though if I log map I see an array of locations inside map.dataProvider.images
With this code, only the latest location that is sent with the websocket is shown in the map. Even though if I log map I see an array of locations inside map.dataProvider.images