使用传单检测是放大还是缩小 [英] Detecting if is zoom-in or zoom-out with leaflet
问题描述
我如何知道用户何时放大或缩小?如果用户在某个级别后缩放,我想开始动画.触发事件zoomstart时是否可以知道这一点?
How can I know when the user is zooming in or zooming out? I want to start an animation if the user zooms after some level. Is it possible to know this when the event zoomstart is triggered?
推荐答案
我如何知道用户何时放大或缩小?
How can I know when the user is zooming in or zooming out?
在每个 zoom
级别,计算 map.getZoom()
发生了多少变化.
At every zoom
level, calculate how much map.getZoom()
has changed.
在zoomstart事件触发的时候能知道吗?
Is it possible to know this when the event zoomstart is triggered?
没有.
考虑以下场景:用户,使用触摸屏(手机/平板电脑).
Consider the following scenario: A user, using a touchscreen (phone/tablet).
用户将两根手指放在屏幕上.半帧后,其中一根手指向中心移动了几个像素,触发了缩放级别的微小变化.
The user puts two fingers down on the screen. Half a frame after, one of the fingers moves a couple of pixels towards the center, triggering a pinch-zoom with a tiny change in the zoom level.
您的代码会捕获紧随其后发生的 zoomstart
和 zoom
事件.我知道!"- 您的代码显示 - 用户正在缩小!".
Your code catches the zoomstart
and zoom
events that happen inmediately after. "I know!" - your code says - "The user is zooming out!".
然后用户开始移动他们的手指越来越宽,放大.你的代码会变得混乱.
And then the user starts moving their fingers wider and wider, zooming in. And your code gets confused.
但是用户改变了主意,然后出于任何原因开始缩小.然后再进去.然后又出去了.然后他们抬起手指,缩放会捕捉到缩放级别.
But the user changes their mind, and then starts zooming out for whatever reason. And then in again. And then out again. And then they lift the fingers and the zoom snaps to a zoom level.
这就是为什么当您在传单.
This is why you can not know what the final zoom level is going to be when you listen to a zoomstart
or zoom
event in Leaflet.
这篇关于使用传单检测是放大还是缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!