Expose a "statechange" event on GeolocateControl
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
Discussion started here: https://github.com/mapbox/mapbox-gl-js/pull/4479#issuecomment-321203924
The `GeolocateControl` doesn't expose events necessary to act on all of its states. `trackuserlocationstart` and `trackuserlocationend` aren't enough to detect some user actions. For instance, it's impossible to know if the user toggled off tracking.
To achieve this I currently have to use a `MutationObserver` on the `.mapboxgl-ctrl-geolocate` watching for `classList` changes.
## Design
Fire a new `statechange` event on every `_watchState` change and pass along its value.
### Implementation
Replace all `this._watchState = ...` with:
```javascript
_setState(state) => {
if (this._watchState !== state) {
this._watchState = state
this.fire('statechange', state)
// ... conditions logic to fire trackuserlocationstart and trackuserlocationend
// bonus?
this._updateUI(state) // centralize the different classList updates spread in _onSucces, _onError, _onClick...
}
}
```
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 the GeolocateControl entry point and inspect each _watchState assignment and the existing control tests. Done means a statechange event is emitted for every state transition and carries the new state, without losing the existing tracking events.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100