Use (shallow) merge semantics for `map.setStyle()`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
`Map#setStyle()` currently does a deep equality comparison when diffing sources: https://github.com/mapbox/mapbox-gl-js/blob/a5a8dfe5b90737dbb295eaca7f41c667ae4060a8/src/style-spec/diff.js#L153
This is unnecessarily costly for styles using inline / dynamically-created GeoJSON data. And more generally, it's very common that the caller of `map.setStyle()` knows that the sources haven't changed.
See also @averas's comment here: https://github.com/mapbox/mapbox-gl-js/pull/3643#issuecomment-275741172
## Design Alternatives
#4006
#4000
## Design
Per the title, I propose that we do a shallow merge from `map.setStyle()`. In practice, this means that a user could omit omit any top-level field (`sources`, `layers`, etc.) of the style they're passing to `map.setStyle()`, and we would just use the existing style state for that field.
### Mock-Up
```js
map.setStyle({
layers: [ ... new layers ...]
// don't worry about setting sources:, sprite:, etc.
})
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at map.setStyle() and inspect the source diffing logic in src/style-spec/diff.js at the linked comparison. Trace how omitted top-level style fields are handled and how source equality is checked; done means omitted fields preserve existing style state and source comparison uses shallow merge semantics rather than deep equality.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100