I'm using amCharts map to show markers (objects) on a map. These objects are moving all the time due to longitude and latitude changes, so I'm calling validateData()
every 4 seconds to update the map with the objects' new locations.
The problem is that after the user zooms in, the validateData()
call redraws the map and zooms back out. How can I redraw my map while keeping the same zoom level?
You need to store the map's current zoomLevel, zoomLongitude and zoomLatitude in your map's dataProvider before you call validateData. Here's a snippet from a demo on AmCharts' website that does precisely that:
// set same zoom levels to retain map position/zoom
map.dataProvider.zoomLevel = map.zoomLevel();
map.dataProvider.zoomLatitude = map.dataProvider.zoomLatitude = map.zoomLatitude();
map.dataProvider.zoomLongitude = map.dataProvider.zoomLongitude = map.zoomLongitude();
// update map
map.validateData();