Allow GeolocateControl to be cancellable
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
My particular use case involves geolocating UK users and firing the normal GeolocateControl behaviour if they're within the UK, displaying error messaging if they're outside it. Currently the `geolocate` event isn't cancellable because it merely contains the `Position` data and not any methods governing how the rest of the interaction works.
I've added a Stack Overflow question [here](https://stackoverflow.com/questions/50759799/canceling-geolocation-behaviour-in-mapboxgl) in case there's a workaround I'm missing but having looked through the source of [geolocate_control.js](https://github.com/mapbox/mapbox-gl-js/blob/master/src/ui/control/geolocate_control.js) it really doesn't seem possible at present.
## Design
`geolocate` should be a cancelable event; calling `event.preventDefault` should cause the behaviour of zooming/panning to the user position and placing the relevant marker to be cancelled. This can be accomplished by moving the firing of the `geolocate` event from [here](https://github.com/mapbox/mapbox-gl-js/blob/master/src/ui/control/geolocate_control.js#L183) to the beginning of the `_onSuccess` callback.
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 in src/ui/control/geolocate_control.js and trace the _onSuccess callback and current geolocate event firing. Move the event to the beginning of _onSuccess as described, and verify that preventDefault cancels zooming, panning, and marker placement while normal events retain their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100