Vue2leaflet: Strange reset zoom and center

Created on 15 May 2018  路  6Comments  路  Source: vue-leaflet/Vue2Leaflet

Description

Reset zoom and center don't work together after a map navigation (zoom and move)

Live Demo

https://jsfiddle.net/m5vxnpga/1/

Expected Results

Map in the correct position (original)

Actual Results

Map isn't always in the position that I choose

Browsers Affected

  • [X] Chrome
  • [X] Firefox

Versions

  • Leaflet: v1.3.1
  • Vue: v2.5.13
  • Vue2Leaflet: v1.0.2

Most helpful comment

@KoRiGaN Thanks!
It works but I have to access to internal mapObejct and I think it could be helpful have a same method in <l-map> component.

All 6 comments

Hi @jtommy,

Thanks for opening this issue. I tried it 6 times and was not able to reproduce this issue.
Do you know how to reproduce it easily?
Do you have any error when this appends?

Micka

@KoRiGaN For example try to move the map on the right and zoom out, then click on "reset" button
Edit: I dont' have any errors in console

@KoRiGaN A workaround is for example:

this.zoom = 13
setTimeout(() => {
   this.center = L.latLng(47.413220, -1.219482)
}, 1000)

but the effect is very ugly.

Hi @jtommy,

This issue seems to be that both center and zoom are changed in Leaflet using setView method, but this method takes time during animation.
The second call to setView (setting the center) seems to be ignored if the zoom change is still ongoing.

The best fix is to call the setView on the map directly:

 this.$refs.map.setView(L.latLng(47.413220, -1.219482), 13);

@KoRiGaN Thanks!
It works but I have to access to internal mapObejct and I think it could be helpful have a same method in <l-map> component.

Hi @jtommy,

This issue seems to be that both center and zoom are changed in Leaflet using setView method, but this method takes time during animation.
The second call to setView (setting the center) seems to be ignored if the zoom change is still ongoing.

The best fix is to call the setView on the map directly:

 this.$refs.map.setView(L.latLng(47.413220, -1.219482), 13);

Well I don't have setView on may map object reference :(
But i realized that if i make a zoom and then a center, it works.

this.$refs.myMap.setZoom(coords.zoom)
this.$refs.myMap.setCenter([coords.lat, coords.long])
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mawieutc picture mawieutc  路  4Comments

lufias picture lufias  路  3Comments

hoticer picture hoticer  路  3Comments

mpallante picture mpallante  路  4Comments

DmitriyVTitov picture DmitriyVTitov  路  4Comments