mapbox / mapbox/mapbox-gl-js

off('load') then on('load') does not work using setStyle

Open
#10,946 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle: good first issue
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**:
v2.4.0

**browser**:
Chrome Version 92.0.4515.159

### Steps to Trigger Behavior

Reproduce steps
1. add `Map.on('load', func)`
2. add `Map.off('load', func)`
3. add `Map.on('load', func2)`
4. call `Map.setStyle()`

### Link to Demonstration

https://jsfiddle.net/tsuzk/6o8m9nad

This should work because of [this test](https://github.com/mapbox/mapbox-gl-js/blob/v2.4.1/test/unit/ui/map.test.js#L136-L151)

### Expected Behavior

The `Map.on('load', func2)` should get called after `Map.setStyle()`

### Actual Behavior

The `Map.on('load', func2)` does not get called after `Map.setStyle()`

### Workaround

re-instantiate the map with a new stlye https://jsfiddle.net/tsuzk/6o8m9nad/1/

### Other info

- This occurs on v1.9.0 so it's not a new behavior in v2.

### Priority

Low, since there is a proper workaround

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 test/unit/ui/map.test.js, especially the linked load-listener test, and reproduce the issue using the provided JSFiddle steps around Map.on, Map.off, and Map.setStyle. Trace the relevant map event and style-reset behavior. Done means the second load callback is invoked after setStyle without requiring a new map instance.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.