L.Map.setZoom
叫L.Map.setView
那个叫L.Map._animateZoomIfClose
。如果map._animatingZoom
为真,则任何缩放都将停止。map._animatingZoom
像寻找缩放动画一样工作:
- 检查
L.Map._animateZoomIfClose
是否true
停止缩放,否则调用L.Map._animateZoom
。
- 设置为
true
atL.Map._animateZoom
并开始 css 转换。
- 在 css 过渡结束时设置为
false
at 。L.Map._onZoomTransitionEnd
为什么是原样?我认为因为很难打破 css 过渡工作。
因此,如果您将禁用任何 css 转换和转换,您的代码必须正常工作。您还可以添加自己的扩展:如果map._animatingZoom === true
然后将您的操作放入数组,则在map._catchTransitionEnd
调用时处理此并将您的操作从数组和处理中转移:
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);
}
}
});