|
| 1 | +import type { NavigationControlOptions } from "maplibre-gl"; |
1 | 2 | import { NavigationControl } from "./MLAdapters/NavigationControl";
|
2 | 3 |
|
3 | 4 | type HTMLButtonElementPlus = HTMLButtonElement & {
|
4 | 5 | clickFunction: (e?: Event) => unknown;
|
5 | 6 | };
|
6 | 7 |
|
7 | 8 | export class MaptilerNavigationControl extends NavigationControl {
|
8 |
| - constructor() { |
| 9 | + constructor(options: NavigationControlOptions = {}) { |
9 | 10 | super({
|
10 |
| - showCompass: true, |
11 |
| - showZoom: true, |
12 |
| - visualizePitch: true, |
| 11 | + showCompass: options.showCompass ?? true, |
| 12 | + showZoom: options.showZoom ?? true, |
| 13 | + visualizePitch: options.visualizePitch ?? true, |
13 | 14 | });
|
14 | 15 |
|
15 | 16 | // Removing the default click event
|
16 |
| - this._compass.removeEventListener("click", (this._compass as HTMLButtonElementPlus).clickFunction); |
| 17 | + if (this._compass) { |
| 18 | + this._compass.removeEventListener("click", (this._compass as HTMLButtonElementPlus).clickFunction); |
17 | 19 |
|
18 |
| - // Adding custom click event |
19 |
| - this._compass.addEventListener("click", (e) => { |
20 |
| - { |
21 |
| - const currentPitch = this._map.getPitch(); |
22 |
| - if (currentPitch === 0) { |
23 |
| - this._map.easeTo({ pitch: Math.min(this._map.getMaxPitch(), 80) }); |
24 |
| - } else { |
25 |
| - if (this.options.visualizePitch) { |
26 |
| - this._map.resetNorthPitch({}, { originalEvent: e }); |
| 20 | + // Adding custom click event |
| 21 | + this._compass.addEventListener("click", (e) => { |
| 22 | + { |
| 23 | + const currentPitch = this._map.getPitch(); |
| 24 | + if (currentPitch === 0) { |
| 25 | + this._map.easeTo({ pitch: Math.min(this._map.getMaxPitch(), 80) }); |
27 | 26 | } else {
|
28 |
| - this._map.resetNorth({}, { originalEvent: e }); |
| 27 | + if (this.options.visualizePitch) { |
| 28 | + this._map.resetNorthPitch({}, { originalEvent: e }); |
| 29 | + } else { |
| 30 | + this._map.resetNorth({}, { originalEvent: e }); |
| 31 | + } |
29 | 32 | }
|
30 | 33 | }
|
31 |
| - } |
32 |
| - }); |
| 34 | + }); |
| 35 | + } |
33 | 36 | }
|
34 | 37 |
|
35 | 38 | /**
|
|
0 commit comments