Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a "statechange" event on GeolocateControl #5136

Open
nrako opened this issue Aug 11, 2017 · 0 comments
Open

Expose a "statechange" event on GeolocateControl #5136

nrako opened this issue Aug 11, 2017 · 0 comments

Comments

@nrako
Copy link

nrako commented Aug 11, 2017

Motivation

Discussion started here: #4479 (comment)

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:

_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...
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants