-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
add geolocate bearing #10817
add geolocate bearing #10817
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks great! Added just a few nits.
this._userLocationDotMarker.setRotation(this._heading); | ||
this._dotElement.classList.add('mapboxgl-user-location-show-heading'); | ||
} else { | ||
this._dotElement.classList.remove('mapboxgl-user-location-show-heading'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move manipulating classList
in the update method from here to the trigger
method which hosts all other lines like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mourner I thought about that. The trigger would add an event listener for devicrorientation
but it should not show the heading until the information is available in _updateMarkerRotation
.
], this); | ||
|
||
this._updateMarkerRotationThrottled = throttle(this._updateMarkerRotation, 20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the deviceorientation
event called much more often than 20ms to necessitate throttling? Just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mourner The motion sensor frequency can be uncapped due to this bug https://w3c.github.io/deviceorientation/spec-source-orientation.html#security-and-privacy
Some say it's suggested to 60 Hz (equalling once every 16.6ms) but I couldn't find the source of this suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
By testing it on a real device, this is what I know:
Just wanted to let you know there is a limitation with Firefox x Android combination. Feel free to test this it here |
Thanks for finishing this off @tsuz !
I haven't looked into this in a while, but from memory the Which I why I originally had the code
To ensure we didn't use a non-absolute or non-compass bearing. Did you look into this further and find that we don't need to handle this case? |
|
Oh sorry I was just looking at your first commit, when you removed it, I should have checked the whole PR to see you added this back in again. All good. |
* cherry-picking showuserheading1 * cherry-picking showuserheading2 * make lint happy * add device orientation event * remove unintended merge * add tests, fix src * update tests * fix tests * fix lint errors * fix rotation * -1 * remove unused line * update css * remove deviceorientationabsolute note * fix example position of trigger * add appropriate listener reference for window * fix lint error * refactoring css * support iOS device * fix lint errors * fixing issue on ios device * fix flow errors Co-authored-by: Andrew Harvey <[email protected]>
Launch Checklist
Fixes #8329 #8034
This PR adds a heading to the current location if the data is available via Geolocate.
trimmed.mov
include before/after visuals or gifs if this PR includes visual changes
Which browser is this compatible with?
This event listener is compatible with all modern browsers. I was only able to test in Chrome's simulated mode, so I cannot guarantee this would work in other browsers (TODO create a debug page that can simulate these events)
https://developer.mozilla.org/en-US/docs/Web/API/Window/deviceorientation_event
Does this support landscape?
This supports portrait mode only, and that is because there is no way to confidently know that the device is in landscape mode. If there are good solutions to this, I am open to including it in this or subsequent PRs.
What to include in the changelog
I was not sure where to add as the changelog seems to be generated at releases, but I'd like to add this to the changelog.
@mapbox/map-design-team
@mapbox/static-apis
if this PR includes style spec API or visual changes@mapbox/gl-native
if this PR includes shader changes or needs a native portmapbox-gl-js
changelog:<changelog></changelog>
cc: @mapbox/map-design-team @mapbox/static-apis