mapbox / mapbox/mapbox-gl-js

map.setStyle() does not preserve render of inline geojson data

Open
#8,326 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation :mag:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

`map.setStyle()` causes the render of the inline geojson data to disappear, despite `map.getStyle().sources.[sourceId].data` showing data to be present.

I can force the render by calling `setData()`, so I do have a workaround, but it would be nice if the workaround isn't needed.

```
const style = map.getStyle()
// modify style as desired
map.setStyle(style)

// force a render of inline geojson, otherwise it just disappears
Object.keys(style.sources).forEach(sourceId => {
const { type, data } = style.sources[sourceId]
if (type === 'geojson' && typeof data !== 'string') {
map.getSource(sourceId).setData(data)
}
})
```

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

Reproduce the issue by applying map.setStyle() to a style containing inline GeoJSON, then inspect map.getStyle() and compare the render before and after. Verify that the inline GeoJSON remains rendered without the workaround's setData() calls, while preserving the existing source data.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
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.