question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vector layers drift away on flyTo when zoomAnimation = false

See original GitHub issue

drifting

  • I’ve looked at the documentation to make sure the behavior is documented and expected
  • I’m sure this is a Leaflet code issue, not an issue with my own code nor with the framework I’m using (Cordova, Ionic, Angular, React…)
  • I’ve searched through the issues to make sure it’s not yet reported

Steps to reproduce Steps to reproduce the behavior:

  • create a map with option zoomAnimation: false
  • create a vector layer (e.g a polygon) and add to map
  • use map.flyTo() to pan to any point

Expected behavior Vector layers follow the movement of the map.

Current behavior Vector layers drift away while panning. When the target is reached they snap to their proper location. This is even more perceptible when the zoom levels between the current position and the target differ.

Environment

  • Leaflet version: 1.7.1
  • Browser (with version): Firefox 85.0.1
  • OS/Platform (with version): Ubuntu 20.10

Additional context My current workaround is to set mapInstance._zoomAnimated = true before I add a layer and map._zoomAnimated = false right after. This way the animation handler will be registered in src/layer/vector/Renderer.js while keeping the zoom animation disabled.

Minimal example reproducing the issue

https://plnkr.co/edit/qHqGIded24Z4MYtO

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Fischerfredlcommented, Feb 24, 2021

I can offer to investigate further as soon as I have the time. Could be next week.

1reaction
Fischerfredlcommented, Feb 23, 2021

I have got a more general applicable workaround that might help:

const originalOnAdd = L.Renderer.prototype.onAdd
L.Renderer.prototype.onAdd = function () {
  originalOnAdd.call(this)
  if (!this._zoomAnimated) {
    L.DomUtil.addClass(this._container, 'leaflet-zoom-animated')
  }
}

It specifically runs the excluded code path in Renderer.js - onAdd method where the leaflet-zoom-animated class is set to the renderer-container. This fixes the difting layers while keeping other zoomAnimation effects disabled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet Vector Layers Not Rendering During FlyTo Animation
The vectors should redraw properly. The quote by @nathansnider is referring to the fact that vectors are not reprojected, but they animate with ......
Read more >
leaflet/CHANGELOG.md - UNPKG
62, * Fix `L.TileLayer`regression, which caused incorrect tile URLs ... 530, * Fixed vector layer positioning during a zoom animation in low zoom...
Read more >
leaflet | Yarn - Package Manager
Added Layer class which all layers added to a map should inherit from. · Added remove method to layers and controls ( marker....
Read more >
OpenLayers 3 Vector wrong position with zoom - Stack Overflow
I try draw a vector image on map using OpenLayers 3. The image behaves strange when using zoom on the map. To demonstrate...
Read more >
ol/layer/Vector~VectorLayer - OpenLayers
This means that no vectors will be shown clipped, but the setting will have a performance impact for large amounts of vector data....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found