Skip to content

Commit ca18208

Browse files
committed
Now passing the options to the control
1 parent e5f27fa commit ca18208

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/MaptilerNavigationControl.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1+
import type { NavigationControlOptions } from "maplibre-gl";
12
import { NavigationControl } from "./MLAdapters/NavigationControl";
23

34
type HTMLButtonElementPlus = HTMLButtonElement & {
45
clickFunction: (e?: Event) => unknown;
56
};
67

78
export class MaptilerNavigationControl extends NavigationControl {
8-
constructor() {
9+
constructor(options: NavigationControlOptions = {}) {
910
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,
1314
});
1415

1516
// 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);
1719

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) });
2726
} 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+
}
2932
}
3033
}
31-
}
32-
});
34+
});
35+
}
3336
}
3437

3538
/**

0 commit comments

Comments
 (0)