AmMap - keeping the same zoom level and position after updating map data

2.8k Views Asked by At

I am updating the map areas of an AmMap map, but the zoom level and position is reset whenever I do.

My function which is updating the map is:

function setData(data) {
    var parsedData = JSON.parse(data);

    map.dataProvider.areas = parsedData.areas;
    map.validateData();
}

I have tried a bunch of things, but I can't get this to work.

Cheers for any help.

3

There are 3 best solutions below

1
On

before you update your data, get the current zoom values and pass them into the dataprovider. Take a look to following sample http://www.amcharts.com/tips/retaining-map-zoom-level-position-data-update/

0
On

Try to add var map = event.chart; at the method start.

0
On

In addition to Maertz answer, remember to set zoomLatitude and zoomLongitude to zero so you won't get the "Cannot read property 'scale' of undefined" error.