Leaflet: Events 'zoomanim' and 'zoom' not fired repeatedly

Created on 28 Jul 2017  Â·  9Comments  Â·  Source: Leaflet/Leaflet

How to reproduce

  • Leaflet version I'm using: 1.1.0
  • Browser (with version) I'm using: Chrome 59.0.3071.115
  • OS/Platform (with version) I'm using: Kubuntu 16.04
  • Create a basic map
  • Do map.on("zoomanim", e => console.log(e.zoom))
  • Do a zoom animation

What behaviour I'm expecting and which behaviour I'm seeing

The documentation states that the 'zoomanim' event should fire repeatedly during that zoom animation. But it just fires once like 'zoomstart'. The event 'zoom' also only fires once and not repeatedly like the docs state.

Minimal example reproducing the issue

  • [x] this example is as simple as possible
  • [x] this example does not rely on any third party code

http://playground-leaflet.rhcloud.com/xiho/edit?html,console,output

docs

Most helpful comment

What @perliedman said.

Also, please have a look at https://gis.stackexchange.com/questions/273514/leaflet-resize-marker-at-same-time-as-map-zoom-animation/273540#273540 - as I mention there, the "normal" zoom animation is performed through CSS, and one cannot fetch information about the value of CSS attributes in the middle of a CSS animation (at least not in a consistent, cross-browser way). Having some way of calculating the bezier curve value and manually firing zoomanim events is a definite possibility, but nobody has started to do any serious work on that. I, for one, would like that as a leaflet plugin, and then consider including it in the core leaflet code.

All 9 comments

same here!

@mourner @IvanSanchez do you have a comment here? From looking at the code, it doesn't look like zoomanim is intended to fire for every frame (the only time it's fired is when a zoom animation starts: https://github.com/Leaflet/Leaflet/blob/master/src/map/Map.js#L1607).

Might this just be a documentation error, and the intention has never been to fire it on every frame, or is it really an implementation error?

@tehGoti could you elaborate on what you mean when you say zoom isn't fired repeatedly? I modified your example to show zoom as well as zoomanim in the console: http://playground-leaflet.rhcloud.com/tezo/edit?html,console,output

The zoom event is fired repeatedly both when I zoom with the trackpad and even more so when I pinch zoom, but zoomanim is only fired once per zoom animation; as you can see from my comment above, I suspect this might actually be the intended behavior.

I have tested with Safari 10.1.2 and with Chrome 59.0.2071.115. The zoomanim event and the zoom event are both fired once per zoom animation in these browser.

@perliedman Which browser do you use? How can I reproduce the zoom event to be fired continuously?

@perliedman I understand the docs that when I zoom in via the zoom-in button or mouse wheel that I would get multiple zoom and zoomanim events during that animation. I can't test with a trackpad because I don't have one here. But the way the docs are written I understand that they should fire repeatedly regardless of the way I zoom in

Same here. Not 'zoomanim' nor 'zoom' fired repeatedly.

@filimonic @tehGoti as implied above, it looks like zoom is fired continously during a pinch zoom (touch) or trackpad zoom - that is, when the user interacts during the zoom, zoom will fire on every frame of that zoom.

For mouse wheel zooms, zoom and zoomanim will only fire once, since it is a single operation.

It looks like the docs are misleading on this point, and should be improved.

Having said this, I did not personally design this, nor have I worked on the implementation, so that this with a grain of salt, I would prefer if @mourner or possibly @IvanSanchez could confirm this.

What @perliedman said.

Also, please have a look at https://gis.stackexchange.com/questions/273514/leaflet-resize-marker-at-same-time-as-map-zoom-animation/273540#273540 - as I mention there, the "normal" zoom animation is performed through CSS, and one cannot fetch information about the value of CSS attributes in the middle of a CSS animation (at least not in a consistent, cross-browser way). Having some way of calculating the bezier curve value and manually firing zoomanim events is a definite possibility, but nobody has started to do any serious work on that. I, for one, would like that as a leaflet plugin, and then consider including it in the core leaflet code.

As far as I remember, that event was introduced for internal use — maybe the fix here would be to remove the public docs for it.

Was this page helpful?
0 / 5 - 0 ratings