To reproduce this problem, you can go to http://leafletjs.com/ and in the javascript console, write the following:
> map.getZoom()
15
> map.setZoom(10);map.setZoom(1);
Object
> map.getZoom()
10
I was expecting the final getZoom to return 1
. Why does this happen?
The problem may be related with the zoom animation. If a setZoom is called before the animation ends, it gets ignored.
I'm integrating leaflet with emberjs and wanted to allow zoom changes by external changes. If the user changes zoom quickly, the effect isn't the desired.
A reset view control for Leaflet. Move the map then click the reset button to see the reset effect.
You can get the current zoom level using getZoom().
Leaflet works with latitude, longitude and “zoom level”. Lower zoom levels means that the map shows entire continents, while higher zoom levels means that the map can show details of a city.
Zoom − By default, this control exists at the top left corner of the map. It has two buttons "+" and "–", using which you can zoom-in or zoom-out the map. You can remove the default zoom control by setting the zoomControl option of the map options to false.
L.Map.setZoom
called L.Map.setView
that called L.Map._animateZoomIfClose
.
If map._animatingZoom
is true then any zoom will stop. map._animatingZoom
work like look for zoom animation:
L.Map._animateZoomIfClose
if true
stop zoom else call L.Map._animateZoom
.true
at L.Map._animateZoom
and start css transition.false
at L.Map._onZoomTransitionEnd
on css transition end.Why it's as is? I think because it's difficult break css transition work.
So if you will disable any css transform and transition your code must work right. You also can add own extension: if map._animatingZoom === true
then put your action to array, when map._catchTransitionEnd
called process this and shift your action from array and process:
if (L.DomUtil.TRANSITION) {
L.Map.addInitHook(function () {
L.DomEvent.on(this._mapPane, L.DomUtil.TRANSITION_END, function () {
var zoom = this._zoomActions.shift();
if (zoom !== undefined) {
this.setZoom(zoom);
}
}, this);
});
}
L.Map.include(!L.DomUtil.TRANSITION ? {} : {
_zoomActions: [],
queueZoom: function (zoom) {
if (map._animatingZoom) {
this._zoomActions.push(zoom);
} else {
this.setZoom(zoom);
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With