mapbox / mapbox/mapbox-gl-js

Support custom layers in setStyle

Open
#7,576 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api :memo: feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

## Motivation

Custom layers are great, but it seems like one can only be added with `addLayer`. However many vdom applications use `setStyle` to manage changes with layers. This seems to be overwriting the custom layer which then disappears.

## Design Alternatives

Ideally, `setStyle` could be used with custom layers. However, there is a question of how diffing should work. I think there are two alternatives:

1. match up the layer by id and then do an equality check - if it doesn't match remove the old and add the new.
2. Add `diff(otherLayer) -> patch` and `patch(patch)` optional methods on custom layers. This would allow for possibly more performant mutation, but would make for much more API surface.

## Design

I think going with option 1 would be a lot simpler in the short run, and waiting to see demand for something more complicated would help.

### Mock-Up

### Concepts

### Implementation

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 by tracing the setStyle and addLayer entry points to understand how custom layers are currently replaced. Compare the proposed layer-by-id equality approach with the optional diff and patch alternative. Done should mean setStyle can manage custom layers without making them disappear, with the chosen behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.