mapbox-gl-js
mapbox-gl-js copied to clipboard
setData causes symbols to flicker when -allow-overlap is set to false
mapbox-gl-js version: v0.43.0 and master
Steps to Trigger Behavior
- create a symbol layer with -allow-overlap set to false
- animate the positions of features using setData
I can reproduce with https://www.mapbox.com/mapbox-gl-js/example/animate-point-along-route/
This bug is only reproducible when the updates are spaced further apart (when the rendering is slower). I can reproduce more easily in Firefox.
Expected Behavior
Feature is animated without flickering.
Actual Behavior
Feature is animated with flickering.
The feature is flickering because it was moved far enough from the original feature that the CrossTileSymbolIndex
isn't able to match it with the previous symbol. Since it is treated as a new symbol it doesn't have an opacity to copy over and so it isn't visible until the next placement happens.
Possible fixes:
- force new placement after setData (the way backwards)
- come up with a way for users to specify keys used to match symbols (the way forwards)
cc @ChrisLoer
Does this also occur if the data is updated, let's say, only every minute and during that time a real vehicle has moved many kilometers? Implementing a key (using a property) would be an easy option - if there is a unique id available for each element in the data source.
@ttsirkia yes, it would still happen, but it would be less noticeable
Every now and then I try if it would be possible to upgrade to newer library version but this is one of the blocking issues. I have a map which shows real-time positions for trains and the data source updates every 15 seconds. During this time, trains typically move that much that labels will fade out and fade in. That distracts the user quite a lot.
Having a key for elements which are mainly updated with setData
would be very useful in this kind of cases where the data constantly updates.
Another way to fix the issue would be a layer-based or a global setting to disable the fading effect.
@ttsirkia does setting icon-allow-overlap: true
work as a workaround for you?
I'm using a glyph as a symbol to get an arrow which can be rotated and colored easily. That is already allowing overlapping.
Instead of using icon, use mapbox marker. Dynamically vary the latLng of the marker by requesting animation with the help of requestAnimationFrame() function and a very smooth animation can be produced. Works perfectly fine for me!.
The problem with mapbox icon is that its custom setData() method takes sometime to update the source and so the next animation frame is requested before the data is updated in the source.This causes flickering. Using mapbox marker, this can be solved. And then background-image css property can be used to assign a custom image to the marker.
Is there any updates on this? I'm still seeing this issue.
@andrewtuplin What version of GL JS are you on? Can you provide a minimal code example via jsbin or codepen if you are one of our most recent versions?
We had a fix to setData
in v2.8.0, but unsure if this resolves your use-case without more information. Thanks for using Mapbox!
I solved this already years ago by using this option: fadeDuration: 0
This is still exhibiting the same behavior in v3.6.2
. Not sure what the best way to handle it with defaults is but takes a bunch of digging to realize and find the fadeDuration option to 0.
https://github.com/mapbox/mapbox-gl-js/assets/5004319/80f4511b-8df5-4631-9242-90abec0e53f8
This is still exhibiting the same behavior in
v3.6.2
. Not sure what the best way to handle it with defaults is but takes a bunch of digging to realize and find the fadeDuration option to 0.
wow this issue has been menacing me for a long time but your suggestion fixes the issue.
originally the flicker was happening when using setLayoutProperty on mousemove.