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

Changing interface orientation stops GeolocateControl location follow me #7053

Closed
dieterdreist opened this issue Jul 31, 2018 · 2 comments · Fixed by #8736
Closed

Changing interface orientation stops GeolocateControl location follow me #7053

dieterdreist opened this issue Jul 31, 2018 · 2 comments · Fixed by #8736
Assignees
Labels

Comments

@dieterdreist
Copy link

dieterdreist commented Jul 31, 2018

mapbox-gl-js version:
v0.47.0 and previous

browser:
mobile safari (ios), latest stable

Steps to Trigger Behavior

  1. with "show my position and map follow me" activated, rotate the device

Link to Demonstration

any map

e.g.
https://jsbin.com/libehaziqo/edit?html,output

Expected Behavior

keeps following

Actual Behavior

stops following as if the used had panned the map.

@mourner mourner added the needs investigation 🔍 Issues that require further research (e.g. it's not clear whether it's GL JS or something else) label Jul 31, 2018
@andrewharvey
Copy link
Collaborator

andrewharvey commented Jun 30, 2019

Thanks for reporting this @dieterdreist. I can confirm this is a bug. This happens because when trackResize is true (which is the default) then when the device orientation changes you naturally have resized the map container so this map.resize method is called:

mapbox-gl-js/src/ui/map.js

Lines 475 to 499 in 97a78c3

/**
* Resizes the map according to the dimensions of its
* `container` element.
*
* This method must be called after the map's `container` is resized by another script,
* or when the map is shown after being initially hidden with CSS.
*
* @param eventData Additional properties to be added to event objects of events triggered by this method.
* @returns {Map} `this`
*/
resize(eventData?: Object) {
const dimensions = this._containerDimensions();
const width = dimensions[0];
const height = dimensions[1];
this._resizeCanvas(width, height);
this.transform.resize(width, height);
this.painter.resize(width, height);
this.fire(new Event('movestart', eventData))
.fire(new Event('move', eventData))
.fire(new Event('resize', eventData))
.fire(new Event('moveend', eventData));
return this;
}

However that then fires movestart. According to the API movestart is,

Fired just before the map begins a transition from one view to another, as the result of either user interaction or methods such as Map#jumpTo.

We use movestart to detect when the user pans the map so to cancel the following behaviour of the geolocate control, however in this case since the map has transitioned from one view to another due to the orientation change, then movestart fires and the tracking is cancelled.

this._map.on('movestart', (event) => {

I suppose the solution here to to listen on other events:

touchstart
dragstart
zoomstart
rotatestart
pitchstart
boxzoomstart

But care must be taken to ensure we cover all the interaction scenarios, and even then I'm not sure how we'll detect when someone calls flyTo or other camera methods in the API, as naturally we should stop tracking in those circumstances also.

@andrewharvey andrewharvey added bug 🐞 and removed needs investigation 🔍 Issues that require further research (e.g. it's not clear whether it's GL JS or something else) labels Jun 30, 2019
@andrewharvey andrewharvey changed the title Changing interface orientation stops location follow me Changing interface orientation stops GeolocateControl location follow me Jun 30, 2019
@asheemmamoowala asheemmamoowala added this to the release-r milestone Aug 9, 2019
@arindam1993 arindam1993 self-assigned this Sep 6, 2019
@arindam1993
Copy link
Contributor

Hi @andrewharvey 👋

I took a different approach to fixing it, #8736 , please review 🙏 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants