visgl / visgl/react-map-gl

Dynamically changing the layer order is not possible

Open
#939 11 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
TypeScript
Stars
8.5k
Forks
1.4k
Avg merge
5d 17h
Merged PRs (30d)
3

Description

Hello, In my use case I have a list of layers whose order can be messed up with.
I made this sandbox to test the behaviour of inverting the second and third items in a list of four. The second item is put at the top of the layering.

Reproduce the bug:
https://codesandbox.io/s/shy-waterfall-fwky3

I tried adding the array index in the layer key but the third layer goes to the top instead of bellow the forth. Maybe this is because the forth layer's key didn't change, so it is not kept above all other layers ?

I also tried using a random key for the layers. This eliminates the order issue but might be bad for performance. In the second sandbox I tried to dynamically change the key of the layers only after a change in order and not on every render.

Expected behaviour:
https://codesandbox.io/s/brave-firefly-zr9oc

If a fix might break other use cases, maybe a new prop to the Layer component that specify we want to keep the order could be possible?

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Layer component and reproduce the ordering difference using the two linked CodeSandbox cases. Compare the reported index-based and random-key approaches, then verify that dynamically swapping layers preserves the expected stacking order without requiring random keys.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.