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

Fix rotation bug for non-pitched compasses #8605

Merged
merged 4 commits into from
Aug 6, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ui/control/navigation_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultOptions: Options = {
* @param {Object} [options]
* @param {Boolean} [options.showCompass=true] If `true` the compass button is included.
* @param {Boolean} [options.showZoom=true] If `true` the zoom-in and zoom-out buttons are included.
* @param {Boolean} [options.visualizePitch=false] If `true` the pitch is visualized by rotating Y-axis of compass.
* @param {Boolean} [options.visualizePitch=false] If `true` the pitch is visualized by rotating X-axis of compass.
* @example
* var nav = new mapboxgl.NavigationControl();
* map.addControl(nav, 'top-left');
Expand Down Expand Up @@ -86,8 +86,8 @@ class NavigationControl {

_rotateCompassArrow() {
const rotate = this.options.visualizePitch ?
`rotateX(${this._map.transform.pitch}deg) rotateZ(${this._map.transform.angle * (180 / Math.PI)}deg)` :
`rotate(${this._map.transform.angle}deg)`;
`scale(${1/Math.pow(Math.cos(this._map.transform.pitch * (Math.PI / 180)),0.5)}) rotateX(${this._map.transform.pitch}deg) rotateZ(${this._map.transform.angle * (180 / Math.PI)}deg)` :
`rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`;

this._compassArrow.style.transform = rotate;
}
Expand Down