Mapbox-gl-js: setData causes symbols to flicker when -allow-overlap is set to false

Created on 25 Jan 2018  ·  7Comments  ·  Source: mapbox/mapbox-gl-js

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

bug

Most helpful comment

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.

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mollymerp picture mollymerp  ·  3Comments

shotor picture shotor  ·  3Comments

stevage picture stevage  ·  3Comments

aderaaij picture aderaaij  ·  3Comments

BernhardRode picture BernhardRode  ·  3Comments