-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Allow GeolocateControl to be cancellable #6789
Comments
👍 from me for making the GeolocateControl support this use case. Did you want to put together a PR which makes it possible? I guess the workaround at the moment would be to replace the private mapbox-gl-js/src/ui/control/geolocate_control.js Lines 187 to 194 in a3aaa76
to something which first checks if the position is within some polygon/bounds you define and from there either fit to bounds or display your error message. |
Hi! Thanks for the workaround, that was super helpful, I've been able to resolve my issue as a result. If you're still wanting a PR for cancellable |
@Aendrew, any updates on this? Would be very grateful if you implement this feature, for example, by forcing the control to respect the maxBounds of the map instance. |
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 thePosition
data and not any methods governing how the rest of the interaction works.I've added a Stack Overflow question here in case there's a workaround I'm missing but having looked through the source of geolocate_control.js it really doesn't seem possible at present.
Design
geolocate
should be a cancelable event; callingevent.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 thegeolocate
event from here to the beginning of the_onSuccess
callback.The text was updated successfully, but these errors were encountered: