Skip to content

Commit 0ef22bb

Browse files
underootgithub-actions[bot]
authored andcommitted
Fix pitch and bearing change with NavigationControl
GitOrigin-RevId: f2db49c70ee86781e67a98c00deb2dee2cdf0449
1 parent b339726 commit 0ef22bb

3 files changed

Lines changed: 79 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
],
193193
"size-limit": [
194194
{
195-
"limit": "466 kb",
195+
"limit": "500 kb",
196196
"gzip": true,
197197
"path": "dist/mapbox-gl.js"
198198
},

src/ui/control/navigation_control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class MouseRotateWrapper {
223223
}
224224

225225
mousedown(e: MouseEvent) {
226-
this.down(Object.assign({}, e, {type: e.type, ctrlKey: true, preventDefault: () => e.preventDefault()}), DOM.mousePos(this.element, e));
226+
this.down(Object.assign({}, e, {button: e.button, type: e.type, ctrlKey: true, preventDefault: () => e.preventDefault()}), DOM.mousePos(this.element, e));
227227
window.addEventListener('mousemove', this.mousemove);
228228
window.addEventListener('mouseup', this.mouseup);
229229
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-nocheck
3+
import {test, expect, vi, describe, createMap} from '../../../util/vitest';
4+
import NavigationControl from '../../../../src/ui/control/navigation_control';
5+
import simulate from '../../../util/simulate_interaction';
6+
7+
describe('NavigationControl', () => {
8+
describe('compass drag', () => {
9+
test('mouse drag on compass updates bearing', () => {
10+
const map = createMap({interactive: true});
11+
const nav = new NavigationControl({showCompass: true});
12+
map.addControl(nav);
13+
14+
const compass = map.getContainer().querySelector('.mapboxgl-ctrl-compass');
15+
expect(compass).toBeTruthy();
16+
17+
const setBearingSpy = vi.spyOn(map, 'setBearing');
18+
19+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
20+
simulate.mousedown(compass, {button: 0, buttons: 1, clientX: 0, clientY: 0});
21+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
22+
simulate.mousemove(window.document, {buttons: 1, clientX: 10, clientY: 0});
23+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
24+
simulate.mouseup(window.document, {button: 0, buttons: 0});
25+
26+
expect(setBearingSpy).toHaveBeenCalled();
27+
28+
map.remove();
29+
});
30+
31+
test('mouse drag on compass updates pitch when visualizePitch is enabled', () => {
32+
const map = createMap({interactive: true});
33+
const nav = new NavigationControl({showCompass: true, visualizePitch: true});
34+
map.addControl(nav);
35+
36+
const compass = map.getContainer().querySelector('.mapboxgl-ctrl-compass');
37+
expect(compass).toBeTruthy();
38+
39+
const setPitchSpy = vi.spyOn(map, 'setPitch');
40+
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
42+
simulate.mousedown(compass, {button: 0, buttons: 1, clientX: 0, clientY: 0});
43+
// Vertical movement to change pitch
44+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
45+
simulate.mousemove(window.document, {buttons: 1, clientX: 0, clientY: -10});
46+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
47+
simulate.mouseup(window.document, {button: 0, buttons: 0});
48+
49+
expect(setPitchSpy).toHaveBeenCalled();
50+
51+
map.remove();
52+
});
53+
54+
test('mouse drag on compass does not update pitch when visualizePitch is disabled', () => {
55+
const map = createMap({interactive: true});
56+
const nav = new NavigationControl({showCompass: true, visualizePitch: false});
57+
map.addControl(nav);
58+
59+
const compass = map.getContainer().querySelector('.mapboxgl-ctrl-compass');
60+
expect(compass).toBeTruthy();
61+
62+
const setPitchSpy = vi.spyOn(map, 'setPitch');
63+
64+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
65+
simulate.mousedown(compass, {button: 0, buttons: 1, clientX: 0, clientY: 0});
66+
// Vertical movement
67+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
68+
simulate.mousemove(window.document, {buttons: 1, clientX: 0, clientY: -10});
69+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
70+
simulate.mouseup(window.document, {button: 0, buttons: 0});
71+
72+
expect(setPitchSpy).not.toHaveBeenCalled();
73+
74+
map.remove();
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)