mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

setData causes symbols to flicker when -allow-overlap is set to false

Open ansis opened this issue 7 years ago • 12 comments

mapbox-gl-js version: v0.43.0 and master

Steps to Trigger Behavior

  1. create a symbol layer with -allow-overlap set to false
  2. 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

ansis avatar Jan 24 '18 23:01 ansis

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 avatar Jan 25 '18 10:01 ttsirkia

@ttsirkia yes, it would still happen, but it would be less noticeable

ansis avatar Feb 06 '18 17:02 ansis

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.

ttsirkia avatar Mar 26 '18 18:03 ttsirkia

Another way to fix the issue would be a layer-based or a global setting to disable the fading effect.

ttsirkia avatar Mar 26 '18 18:03 ttsirkia

@ttsirkia does setting icon-allow-overlap: true work as a workaround for you?

ansis avatar Apr 18 '18 19:04 ansis

I'm using a glyph as a symbol to get an arrow which can be rotated and colored easily. That is already allowing overlapping.

ttsirkia avatar Apr 18 '18 19:04 ttsirkia

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.

samarth1sharma avatar Dec 04 '18 06:12 samarth1sharma

Is there any updates on this? I'm still seeing this issue.

andrewtuplin avatar Nov 17 '22 18:11 andrewtuplin

@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!

avpeery avatar Nov 18 '22 00:11 avpeery

I solved this already years ago by using this option: fadeDuration: 0

ttsirkia avatar Nov 18 '22 07:11 ttsirkia

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.

ingalls avatar Dec 01 '23 01:12 ingalls

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.

allthesignals avatar Jan 08 '24 18:01 allthesignals