D
D
Darkhan Kamaliev2019-03-19 11:55:46
JavaScript
Darkhan Kamaliev, 2019-03-19 11:55:46

Data in the method is not updated when using api 2gis?

Good day, not so long ago with js and vue.

map_get(coor) {
                console.log(coor)
                this.dialog = true;
                var map;
                var STO = DG.then(function () {
                    map = DG.map('map', {
                        center: [coor.latitude,coor.longitude],
                        zoom: 13
                    });

                 DG.marker([coor.latitude,coor.longitude]).addTo(map).bindPopup('Наше СТО');
                });

I transfer the coordinates, but the next time the data is not updated (the previously loaded map is simply displayed), although I transfer new coordinates.
How to fix it? Or is it possible to redraw it every time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-19
@darakanoit

On the first call, create a map and a marker, make them properties of the component, update the coordinates on subsequent calls:

if (!this.map) {
  this.map = DG.map(...);
  this.marker = DG.marker(...);
} else {
  this.map.panTo(...)
  this.marker.setLatLng(...);
}

https://jsfiddle.net/o04vc57k/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question