mapbox / mapbox/mapbox-gl-js

Allow interaction states for `GeolocateControl` to be changed programmatically

Open
#13,067 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Hey team!

On your docs for GeolocateControl, it describes:

In this mode the GeolocateControl has three interaction states:

active - The map's camera automatically updates as the user's location changes, keeping the location dot in the center. This is the initial state, and the state upon clicking the GeolocateControl button.
passive - The user's location dot automatically updates, but the map's camera does not. Occurs upon the user initiating a map movement.
disabled - Occurs if geolocation is not available, disabled, or denied.

These interaction states can't be controlled programmatically. Instead, they are set based on user interactions.

My company has a use-case where we want to centre the user on their country when they arrive on the page. It is significantly important for us to show a large coverage of the country in order to change a commonly held opinion. However, we'd also like to add the option for users to see their location on the map as it is helpful for route planning.


I'm currently undergoing a large redesign and need to implement a method where we can show a user location without changing the bounds set around the country. I'm required to build a custom interaction for requesting current location which fits with our design and as such must programmatically trigger your control.

On map load, we're currently using flyTo to zoom in on their country bounds. During testing, this will get abruptly interrupted if location permission has been granted previously so it can fly to that location instead.


Obviously, the solution from my perspective would be to just use the already defined passive mode. I have their lat and lng from the navigator.permissions query so I can simply use flyTo if I want to zoom in to their location programmatically.

I believe all I need is an option on GeolocateControl to permanently override any interaction state which would be active to passive.

I'm hopeful this is an easy update and can be implemented quickly. Really appreciate your work.

Please let me know if anything needs clarification.

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 the GeolocateControl documentation and its active, passive, and disabled interaction states. Compare the requested programmatic override with the issue's flyTo and navigator.permissions use cases. Done means a documented way to trigger the control while retaining passive behavior and preserving the requested country bounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.