@maptiler/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +10 -0
- package/.github/workflows/npm-publish.yml +23 -0
- package/LICENSE +29 -0
- package/demos/maptiler-sdk.css +147 -0
- package/demos/maptiler-sdk.umd.js +3287 -0
- package/demos/simple.html +63 -0
- package/dist/maptiler-sdk.css +147 -0
- package/dist/maptiler-sdk.d.ts +531 -0
- package/dist/maptiler-sdk.min.mjs +1 -0
- package/dist/maptiler-sdk.mjs +1128 -0
- package/dist/maptiler-sdk.mjs.map +1 -0
- package/dist/maptiler-sdk.umd.js +3287 -0
- package/dist/maptiler-sdk.umd.js.map +1 -0
- package/dist/maptiler-sdk.umd.min.js +579 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/custom.css +118 -0
- package/docs/assets/highlight.css +134 -0
- package/docs/assets/main.js +54 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1257 -0
- package/docs/classes/Map.html +273 -0
- package/docs/classes/Point.html +549 -0
- package/docs/classes/SdkConfig.html +188 -0
- package/docs/demos/maptiler-sdk.css +147 -0
- package/docs/demos/maptiler-sdk.umd.js +3287 -0
- package/docs/demos/simple.html +63 -0
- package/docs/functions/addProtocol.html +146 -0
- package/docs/functions/clearPrewarmedResources.html +92 -0
- package/docs/functions/clearStorage.html +124 -0
- package/docs/functions/getRTLTextPluginStatus.html +92 -0
- package/docs/functions/prewarm.html +92 -0
- package/docs/functions/removeProtocol.html +106 -0
- package/docs/functions/setRTLTextPlugin.html +112 -0
- package/docs/functions/supported.html +97 -0
- package/docs/images/JS-logo.svg +4 -0
- package/docs/images/TS-logo.svg +6 -0
- package/docs/images/maptiler-logo.svg +19 -0
- package/docs/images/maptiler-sdk-logo.afdesign +0 -0
- package/docs/images/maptiler-sdk-logo.svg +66 -0
- package/docs/images/screenshots/alps.gif +0 -0
- package/docs/images/screenshots/grandcanyon.gif +0 -0
- package/docs/images/screenshots/lang-arabic.png +0 -0
- package/docs/images/screenshots/lang-hebrew.png +0 -0
- package/docs/images/screenshots/multilang.gif +0 -0
- package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/docs/images/screenshots/static-with-path.png +0 -0
- package/docs/images/screenshots/style-basic-v2.png +0 -0
- package/docs/images/screenshots/style-bright.png +0 -0
- package/docs/images/screenshots/style-dataviz-dark.png +0 -0
- package/docs/images/screenshots/style-hybrid.png +0 -0
- package/docs/images/screenshots/style-osm.png +0 -0
- package/docs/images/screenshots/style-outdoor.png +0 -0
- package/docs/images/screenshots/style-pastel.png +0 -0
- package/docs/images/screenshots/style-satellite.png +0 -0
- package/docs/images/screenshots/style-streets-v2-dark.png +0 -0
- package/docs/images/screenshots/style-streets-v2-light.png +0 -0
- package/docs/images/screenshots/style-streets-v2.png +0 -0
- package/docs/images/screenshots/style-toner.png +0 -0
- package/docs/images/screenshots/style-topo.png +0 -0
- package/docs/images/screenshots/style-topographique.png +0 -0
- package/docs/images/screenshots/style-voyager.png +0 -0
- package/docs/images/screenshots/style-winter.png +0 -0
- package/docs/index.html +601 -0
- package/docs/modules.html +142 -0
- package/docs/types/LanguageKey.html +90 -0
- package/docs/types/LanguageString.html +90 -0
- package/docs/types/MapOptions.html +90 -0
- package/docs/types/Matrix2.html +90 -0
- package/docs/types/Unit.html +88 -0
- package/docs/variables/AJAXError.html +88 -0
- package/docs/variables/AttributionControl.html +88 -0
- package/docs/variables/CanvasSource.html +88 -0
- package/docs/variables/Evented.html +88 -0
- package/docs/variables/FullscreenControl.html +88 -0
- package/docs/variables/GeoJSONSource.html +88 -0
- package/docs/variables/GeolocateControl.html +88 -0
- package/docs/variables/GeolocationType.html +95 -0
- package/docs/variables/ImageSource.html +88 -0
- package/docs/variables/Language.html +249 -0
- package/docs/variables/LngLat.html +88 -0
- package/docs/variables/LngLatBounds.html +88 -0
- package/docs/variables/LogoControl.html +88 -0
- package/docs/variables/Marker.html +88 -0
- package/docs/variables/MercatorCoordinate.html +88 -0
- package/docs/variables/NavigationControl.html +88 -0
- package/docs/variables/Popup.html +88 -0
- package/docs/variables/RasterDEMTileSource.html +88 -0
- package/docs/variables/RasterTileSource.html +88 -0
- package/docs/variables/ScaleControl.html +88 -0
- package/docs/variables/Style.html +88 -0
- package/docs/variables/TerrainControl.html +88 -0
- package/docs/variables/VectorTileSource.html +88 -0
- package/docs/variables/VideoSource.html +88 -0
- package/docs/variables/config.html +88 -0
- package/docs/variables/maxParallelImageRequests.html +88 -0
- package/docs/variables/version.html +88 -0
- package/docs/variables/workerCount.html +88 -0
- package/docs/variables/workerUrl.html +88 -0
- package/docsmd/.nojekyll +1 -0
- package/docsmd/README.md +710 -0
- package/docsmd/assets/custom.css +118 -0
- package/docsmd/classes/Map.md +292 -0
- package/docsmd/classes/Point.md +603 -0
- package/docsmd/classes/SdkConfig.md +186 -0
- package/docsmd/images/JS-logo.svg +4 -0
- package/docsmd/images/TS-logo.svg +6 -0
- package/docsmd/images/maptiler-logo.svg +19 -0
- package/docsmd/images/maptiler-sdk-logo.afdesign +0 -0
- package/docsmd/images/maptiler-sdk-logo.svg +66 -0
- package/docsmd/images/screenshots/alps.gif +0 -0
- package/docsmd/images/screenshots/grandcanyon.gif +0 -0
- package/docsmd/images/screenshots/lang-arabic.png +0 -0
- package/docsmd/images/screenshots/lang-hebrew.png +0 -0
- package/docsmd/images/screenshots/multilang.gif +0 -0
- package/docsmd/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/docsmd/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/docsmd/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/docsmd/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/docsmd/images/screenshots/static-with-path.png +0 -0
- package/docsmd/images/screenshots/style-basic-v2.png +0 -0
- package/docsmd/images/screenshots/style-bright.png +0 -0
- package/docsmd/images/screenshots/style-dataviz-dark.png +0 -0
- package/docsmd/images/screenshots/style-hybrid.png +0 -0
- package/docsmd/images/screenshots/style-osm.png +0 -0
- package/docsmd/images/screenshots/style-outdoor.png +0 -0
- package/docsmd/images/screenshots/style-pastel.png +0 -0
- package/docsmd/images/screenshots/style-satellite.png +0 -0
- package/docsmd/images/screenshots/style-streets-v2-dark.png +0 -0
- package/docsmd/images/screenshots/style-streets-v2-light.png +0 -0
- package/docsmd/images/screenshots/style-streets-v2.png +0 -0
- package/docsmd/images/screenshots/style-toner.png +0 -0
- package/docsmd/images/screenshots/style-topo.png +0 -0
- package/docsmd/images/screenshots/style-topographique.png +0 -0
- package/docsmd/images/screenshots/style-voyager.png +0 -0
- package/docsmd/images/screenshots/style-winter.png +0 -0
- package/images/JS-logo.svg +4 -0
- package/images/TS-logo.svg +6 -0
- package/images/maptiler-logo.svg +19 -0
- package/images/maptiler-sdk-logo.afdesign +0 -0
- package/images/maptiler-sdk-logo.svg +66 -0
- package/images/screenshots/alps.gif +0 -0
- package/images/screenshots/grandcanyon.gif +0 -0
- package/images/screenshots/lang-arabic.png +0 -0
- package/images/screenshots/lang-hebrew.png +0 -0
- package/images/screenshots/multilang.gif +0 -0
- package/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/images/screenshots/static-with-path.png +0 -0
- package/images/screenshots/style-basic-v2.png +0 -0
- package/images/screenshots/style-bright.png +0 -0
- package/images/screenshots/style-dataviz-dark.png +0 -0
- package/images/screenshots/style-hybrid.png +0 -0
- package/images/screenshots/style-osm.png +0 -0
- package/images/screenshots/style-outdoor.png +0 -0
- package/images/screenshots/style-pastel.png +0 -0
- package/images/screenshots/style-satellite.png +0 -0
- package/images/screenshots/style-streets-v2-dark.png +0 -0
- package/images/screenshots/style-streets-v2-light.png +0 -0
- package/images/screenshots/style-streets-v2.png +0 -0
- package/images/screenshots/style-toner.png +0 -0
- package/images/screenshots/style-topo.png +0 -0
- package/images/screenshots/style-topographique.png +0 -0
- package/images/screenshots/style-voyager.png +0 -0
- package/images/screenshots/style-winter.png +0 -0
- package/package.json +71 -0
- package/readme.md +609 -0
- package/rollup.config.js +161 -0
- package/scripts/replace-path-with-content.js +51 -0
- package/src/CustomGeolocateControl.ts +193 -0
- package/src/CustomLogoControl.ts +59 -0
- package/src/Map.ts +897 -0
- package/src/MaptilerNavigationControl.ts +66 -0
- package/src/Point.ts +336 -0
- package/src/TerrainControl.ts +87 -0
- package/src/config.ts +92 -0
- package/src/defaults.ts +20 -0
- package/src/index.ts +171 -0
- package/src/language.ts +139 -0
- package/src/mapstyle.ts +38 -0
- package/src/style/style_template.css +146 -0
- package/src/style/svg/v6-compass.svg +12 -0
- package/src/style/svg/v6-fullscreen-off.svg +7 -0
- package/src/style/svg/v6-fullscreen.svg +7 -0
- package/src/style/svg/v6-geolocate-active-error.svg +10 -0
- package/src/style/svg/v6-geolocate-active.svg +7 -0
- package/src/style/svg/v6-geolocate-background.svg +8 -0
- package/src/style/svg/v6-geolocate-disabled.svg +10 -0
- package/src/style/svg/v6-geolocate.svg +7 -0
- package/src/style/svg/v6-terrain-on.svg +7 -0
- package/src/style/svg/v6-terrain.svg +7 -0
- package/src/style/svg/v6-zoom-minus.svg +7 -0
- package/src/style/svg/v6-zoom-plus.svg +7 -0
- package/src/tools.ts +45 -0
- package/src/unit.ts +1 -0
- package/tsconfig.json +11 -0
- package/typedoc.css +118 -0
- package/typedoc.json +13 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import maplibregl from "maplibre-gl";
|
|
2
|
+
|
|
3
|
+
type HTMLButtonElementPlus = HTMLButtonElement & {
|
|
4
|
+
clickFunction: (e?: any) => unknown;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export class MaptilerNavigationControl extends maplibregl.NavigationControl {
|
|
8
|
+
constructor() {
|
|
9
|
+
super({
|
|
10
|
+
showCompass: true,
|
|
11
|
+
showZoom: true,
|
|
12
|
+
visualizePitch: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Removing the default click event
|
|
16
|
+
this._compass.removeEventListener(
|
|
17
|
+
"click",
|
|
18
|
+
(this._compass as HTMLButtonElementPlus).clickFunction
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// Adding custom click event
|
|
22
|
+
this._compass.addEventListener("click", (e) => {
|
|
23
|
+
{
|
|
24
|
+
const currentPitch = this._map.getPitch();
|
|
25
|
+
if (currentPitch === 0) {
|
|
26
|
+
this._map.easeTo({ pitch: Math.min(this._map.getMaxPitch(), 80) });
|
|
27
|
+
} else {
|
|
28
|
+
if (this.options.visualizePitch) {
|
|
29
|
+
this._map.resetNorthPitch({}, { originalEvent: e });
|
|
30
|
+
} else {
|
|
31
|
+
this._map.resetNorth({}, { originalEvent: e });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Overloading: the button now stores its click callback so that we can later on delete it and replace it
|
|
40
|
+
*/
|
|
41
|
+
_createButton(
|
|
42
|
+
className: string,
|
|
43
|
+
fn: (e?: any) => unknown
|
|
44
|
+
): HTMLButtonElementPlus {
|
|
45
|
+
const button = super._createButton(className, fn) as HTMLButtonElementPlus;
|
|
46
|
+
button.clickFunction = fn;
|
|
47
|
+
return button;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Overloading: Limit how flat the compass icon can get
|
|
52
|
+
*/
|
|
53
|
+
_rotateCompassArrow() {
|
|
54
|
+
const rotate = this.options.visualizePitch
|
|
55
|
+
? `scale(${Math.min(
|
|
56
|
+
1.5,
|
|
57
|
+
1 /
|
|
58
|
+
Math.pow(Math.cos(this._map.transform.pitch * (Math.PI / 180)), 0.5)
|
|
59
|
+
)}) rotateX(${Math.min(70, this._map.transform.pitch)}deg) rotateZ(${
|
|
60
|
+
this._map.transform.angle * (180 / Math.PI)
|
|
61
|
+
}deg)`
|
|
62
|
+
: `rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`;
|
|
63
|
+
|
|
64
|
+
this._compassIcon.style.transform = rotate;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/Point.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is TypeScript rewrite of the Point class to use instead of the version imported in MapLibre.
|
|
3
|
+
* It also uses a class instead of prototypes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Row major 2x2 matrix
|
|
8
|
+
*/
|
|
9
|
+
export type Matrix2 = [number, number, number, number];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* a point
|
|
13
|
+
* @param x
|
|
14
|
+
* @param y
|
|
15
|
+
*/
|
|
16
|
+
export class Point {
|
|
17
|
+
public x: number;
|
|
18
|
+
public y: number;
|
|
19
|
+
|
|
20
|
+
constructor(x: number, y: number) {
|
|
21
|
+
this.x = x;
|
|
22
|
+
this.y = y;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private _matMult(m: Matrix2): Point {
|
|
26
|
+
const x = m[0] * this.x + m[1] * this.y;
|
|
27
|
+
const y = m[2] * this.x + m[3] * this.y;
|
|
28
|
+
this.x = x;
|
|
29
|
+
this.y = y;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _add(p: Point): Point {
|
|
34
|
+
this.x += p.x;
|
|
35
|
+
this.y += p.y;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private _sub(p: Point): Point {
|
|
40
|
+
this.x -= p.x;
|
|
41
|
+
this.y -= p.y;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private _mult(k: number): Point {
|
|
46
|
+
this.x *= k;
|
|
47
|
+
this.y *= k;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private _div(k: number): Point {
|
|
52
|
+
this.x /= k;
|
|
53
|
+
this.y /= k;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private _multByPoint(p: Point): Point {
|
|
58
|
+
this.x *= p.x;
|
|
59
|
+
this.y *= p.y;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private _divByPoint(p: Point): Point {
|
|
64
|
+
this.x /= p.x;
|
|
65
|
+
this.y /= p.y;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private _unit(): Point {
|
|
70
|
+
this._div(this.mag());
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private _perp(): Point {
|
|
75
|
+
const y = this.y;
|
|
76
|
+
this.y = this.x;
|
|
77
|
+
this.x = -y;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private _rotate(angle: number): Point {
|
|
82
|
+
const cos = Math.cos(angle);
|
|
83
|
+
const sin = Math.sin(angle);
|
|
84
|
+
const x = cos * this.x - sin * this.y;
|
|
85
|
+
const y = sin * this.x + cos * this.y;
|
|
86
|
+
this.x = x;
|
|
87
|
+
this.y = y;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private _rotateAround(angle: number, p: Point): Point {
|
|
92
|
+
const cos = Math.cos(angle);
|
|
93
|
+
const sin = Math.sin(angle);
|
|
94
|
+
const x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y);
|
|
95
|
+
const y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
|
|
96
|
+
this.x = x;
|
|
97
|
+
this.y = y;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private _round(): Point {
|
|
102
|
+
this.x = Math.round(this.x);
|
|
103
|
+
this.y = Math.round(this.y);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Clone this point, returning a new point that can be modified
|
|
109
|
+
* without affecting the old one.
|
|
110
|
+
* @return {Point} the clone
|
|
111
|
+
*/
|
|
112
|
+
clone(): Point {
|
|
113
|
+
return new Point(this.x, this.y);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Add this point's x & y coordinates to another point,
|
|
118
|
+
* yielding a new point.
|
|
119
|
+
* @param {Point} p the other point
|
|
120
|
+
* @return {Point} output point
|
|
121
|
+
*/
|
|
122
|
+
add(p: Point): Point {
|
|
123
|
+
return this.clone()._add(p);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Subtract this point's x & y coordinates to from point,
|
|
128
|
+
* yielding a new point.
|
|
129
|
+
* @param {Point} p the other point
|
|
130
|
+
* @return {Point} output point
|
|
131
|
+
*/
|
|
132
|
+
sub(p: Point): Point {
|
|
133
|
+
return this.clone()._sub(p);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Multiply this point's x & y coordinates by point,
|
|
138
|
+
* yielding a new point.
|
|
139
|
+
* @param {Point} p the other point
|
|
140
|
+
* @return {Point} output point
|
|
141
|
+
*/
|
|
142
|
+
multByPoint(p: Point): Point {
|
|
143
|
+
return this.clone()._multByPoint(p);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Divide this point's x & y coordinates by point,
|
|
148
|
+
* yielding a new point.
|
|
149
|
+
* @param {Point} p the other point
|
|
150
|
+
* @return {Point} output point
|
|
151
|
+
*/
|
|
152
|
+
divByPoint(p: Point): Point {
|
|
153
|
+
return this.clone()._divByPoint(p);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Multiply this point's x & y coordinates by a factor,
|
|
158
|
+
* yielding a new point.
|
|
159
|
+
* @param {Number} k factor
|
|
160
|
+
* @return {Point} output point
|
|
161
|
+
*/
|
|
162
|
+
mult(k: number): Point {
|
|
163
|
+
return this.clone()._mult(k);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Divide this point's x & y coordinates by a factor,
|
|
168
|
+
* yielding a new point.
|
|
169
|
+
* @param {Point} k factor
|
|
170
|
+
* @return {Point} output point
|
|
171
|
+
*/
|
|
172
|
+
div(k: number): Point {
|
|
173
|
+
return this.clone()._div(k);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Rotate this point around the 0, 0 origin by an angle a,
|
|
178
|
+
* given in radians
|
|
179
|
+
* @param {Number} a angle to rotate around, in radians
|
|
180
|
+
* @return {Point} output point
|
|
181
|
+
*/
|
|
182
|
+
rotate(a: number): Point {
|
|
183
|
+
return this.clone()._rotate(a);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Rotate this point around p point by an angle a,
|
|
188
|
+
* given in radians
|
|
189
|
+
* @param {Number} a angle to rotate around, in radians
|
|
190
|
+
* @param {Point} p Point to rotate around
|
|
191
|
+
* @return {Point} output point
|
|
192
|
+
*/
|
|
193
|
+
rotateAround(a: number, p: Point): Point {
|
|
194
|
+
return this.clone()._rotateAround(a, p);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Multiply this point by a 4x1 transformation matrix
|
|
199
|
+
* @param {Array<Number>} m transformation matrix
|
|
200
|
+
* @return {Point} output point
|
|
201
|
+
*/
|
|
202
|
+
matMult(m: Matrix2): Point {
|
|
203
|
+
return this.clone()._matMult(m);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Calculate this point but as a unit vector from 0, 0, meaning
|
|
208
|
+
* that the distance from the resulting point to the 0, 0
|
|
209
|
+
* coordinate will be equal to 1 and the angle from the resulting
|
|
210
|
+
* point to the 0, 0 coordinate will be the same as before.
|
|
211
|
+
* @return {Point} unit vector point
|
|
212
|
+
*/
|
|
213
|
+
unit(): Point {
|
|
214
|
+
return this.clone()._unit();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Compute a perpendicular point, where the new y coordinate
|
|
219
|
+
* is the old x coordinate and the new x coordinate is the old y
|
|
220
|
+
* coordinate multiplied by -1
|
|
221
|
+
* @return {Point} perpendicular point
|
|
222
|
+
*/
|
|
223
|
+
perp(): Point {
|
|
224
|
+
return this.clone()._perp();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Return a version of this point with the x & y coordinates
|
|
229
|
+
* rounded to integers.
|
|
230
|
+
* @return {Point} rounded point
|
|
231
|
+
*/
|
|
232
|
+
round(): Point {
|
|
233
|
+
return this.clone()._round();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Return the magnitude of this point: this is the Euclidean
|
|
238
|
+
* distance from the 0, 0 coordinate to this point's x and y
|
|
239
|
+
* coordinates.
|
|
240
|
+
* @return {Number} magnitude
|
|
241
|
+
*/
|
|
242
|
+
mag(): number {
|
|
243
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Judge whether this point is equal to another point, returning
|
|
248
|
+
* true or false.
|
|
249
|
+
* @param {Point} other the other point
|
|
250
|
+
* @return {boolean} whether the points are equal
|
|
251
|
+
*/
|
|
252
|
+
equals(other): boolean {
|
|
253
|
+
return this.x === other.x && this.y === other.y;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Calculate the distance from this point to another point
|
|
258
|
+
* @param {Point} p the other point
|
|
259
|
+
* @return {Number} distance
|
|
260
|
+
*/
|
|
261
|
+
dist(p): number {
|
|
262
|
+
return Math.sqrt(this.distSqr(p));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Calculate the distance from this point to another point,
|
|
267
|
+
* without the square root step. Useful if you're comparing
|
|
268
|
+
* relative distances.
|
|
269
|
+
* @param {Point} p the other point
|
|
270
|
+
* @return {Number} distance
|
|
271
|
+
*/
|
|
272
|
+
distSqr(p): number {
|
|
273
|
+
const dx = p.x - this.x;
|
|
274
|
+
const dy = p.y - this.y;
|
|
275
|
+
return dx * dx + dy * dy;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get the angle from the 0, 0 coordinate to this point, in radians
|
|
280
|
+
* coordinates.
|
|
281
|
+
* @return {Number} angle
|
|
282
|
+
*/
|
|
283
|
+
angle(): number {
|
|
284
|
+
return Math.atan2(this.y, this.x);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Get the angle from this point to another point, in radians
|
|
289
|
+
* @param {Point} b the other point
|
|
290
|
+
* @return {Number} angle
|
|
291
|
+
*/
|
|
292
|
+
angleTo(b: Point): number {
|
|
293
|
+
return Math.atan2(this.y - b.y, this.x - b.x);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Get the angle between this point and another point, in radians
|
|
298
|
+
* @param {Point} b the other point
|
|
299
|
+
* @return {Number} angle
|
|
300
|
+
*/
|
|
301
|
+
angleWith(b: Point): number {
|
|
302
|
+
return this.angleWithSep(b.x, b.y);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/*
|
|
306
|
+
* Find the angle of the two vectors, solving the formula for
|
|
307
|
+
* the cross product a x b = |a||b|sin(θ) for θ.
|
|
308
|
+
* @param {Number} x the x-coordinate
|
|
309
|
+
* @param {Number} y the y-coordinate
|
|
310
|
+
* @return {Number} the angle in radians
|
|
311
|
+
*/
|
|
312
|
+
angleWithSep(x: number, y: number): number {
|
|
313
|
+
return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Construct a point from an array if necessary, otherwise if the input
|
|
318
|
+
* is already a Point, or an unknown type, return it unchanged
|
|
319
|
+
* @param {Array<number> | Point} a any kind of input value
|
|
320
|
+
* @return {Point} constructed point, or passed-through value.
|
|
321
|
+
* @example
|
|
322
|
+
* // this
|
|
323
|
+
* var point = Point.convert([0, 1]);
|
|
324
|
+
* // is equivalent to
|
|
325
|
+
* var point = new Point(0, 1);
|
|
326
|
+
*/
|
|
327
|
+
static convert(a: Point | Array<number>) {
|
|
328
|
+
if (a instanceof Point) {
|
|
329
|
+
return a;
|
|
330
|
+
}
|
|
331
|
+
if (Array.isArray(a)) {
|
|
332
|
+
return new Point(a[0], a[1]);
|
|
333
|
+
}
|
|
334
|
+
return a;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { bindAll, DOMcreate, DOMremove } from "./tools";
|
|
2
|
+
|
|
3
|
+
import { Map } from "./Map";
|
|
4
|
+
import maplibregl from "maplibre-gl";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An `TerrainControl` control adds a button to turn terrain on and off.
|
|
8
|
+
*
|
|
9
|
+
* @implements {IControl}
|
|
10
|
+
* @param {Object} [options]
|
|
11
|
+
* @param {string} [options.id] The ID of the raster-dem source to use.
|
|
12
|
+
* @param {Object} [options.options]
|
|
13
|
+
* @param {number} [options.options.exaggeration]
|
|
14
|
+
* @example
|
|
15
|
+
* var map = new maplibregl.Map({TerrainControl: false})
|
|
16
|
+
* .addControl(new maplibregl.TerrainControl({
|
|
17
|
+
* source: "terrain"
|
|
18
|
+
* }));
|
|
19
|
+
*/
|
|
20
|
+
export class TerrainControl implements maplibregl.IControl {
|
|
21
|
+
_map: Map;
|
|
22
|
+
_container: HTMLElement;
|
|
23
|
+
_terrainButton: HTMLButtonElement;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
bindAll(["_toggleTerrain", "_updateTerrainIcon"], this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onAdd(map: Map) {
|
|
30
|
+
this._map = map;
|
|
31
|
+
this._container = DOMcreate("div", "maplibregl-ctrl maplibregl-ctrl-group");
|
|
32
|
+
this._terrainButton = DOMcreate(
|
|
33
|
+
"button",
|
|
34
|
+
"maplibregl-ctrl-terrain",
|
|
35
|
+
this._container
|
|
36
|
+
);
|
|
37
|
+
DOMcreate("span", "maplibregl-ctrl-icon", this._terrainButton).setAttribute(
|
|
38
|
+
"aria-hidden",
|
|
39
|
+
"true"
|
|
40
|
+
);
|
|
41
|
+
this._terrainButton.type = "button";
|
|
42
|
+
this._terrainButton.addEventListener("click", this._toggleTerrain);
|
|
43
|
+
|
|
44
|
+
this._updateTerrainIcon();
|
|
45
|
+
this._map.on("terrain", this._updateTerrainIcon);
|
|
46
|
+
return this._container;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onRemove() {
|
|
50
|
+
DOMremove(this._container);
|
|
51
|
+
this._map.off("terrain", this._updateTerrainIcon);
|
|
52
|
+
this._map = undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_toggleTerrain() {
|
|
56
|
+
// if (this._map.getTerrain()) {
|
|
57
|
+
// this._map.setTerrain(null);
|
|
58
|
+
// } else {
|
|
59
|
+
// this._map.setTerrain(this.options);
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
if (this._map.hasTerrain()) {
|
|
63
|
+
this._map.disableTerrain();
|
|
64
|
+
} else {
|
|
65
|
+
this._map.enableTerrain();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this._updateTerrainIcon();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_updateTerrainIcon() {
|
|
72
|
+
this._terrainButton.classList.remove("maplibregl-ctrl-terrain");
|
|
73
|
+
this._terrainButton.classList.remove("maplibregl-ctrl-terrain-enabled");
|
|
74
|
+
// if (this._map.terrain) {
|
|
75
|
+
if (this._map.hasTerrain()) {
|
|
76
|
+
this._terrainButton.classList.add("maplibregl-ctrl-terrain-enabled");
|
|
77
|
+
this._terrainButton.title = this._map._getUIString(
|
|
78
|
+
"TerrainControl.disableTerrain"
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
this._terrainButton.classList.add("maplibregl-ctrl-terrain");
|
|
82
|
+
this._terrainButton.title = this._map._getUIString(
|
|
83
|
+
"TerrainControl.enableTerrain"
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { Language, LanguageString } from "./language";
|
|
3
|
+
import { config as clientConfig, FetchFunction } from "@maptiler/client";
|
|
4
|
+
import { Unit } from "./unit";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration class for the SDK
|
|
8
|
+
*/
|
|
9
|
+
class SdkConfig extends EventEmitter {
|
|
10
|
+
/**
|
|
11
|
+
* The primary language. By default, the language of the web browser is used.
|
|
12
|
+
*/
|
|
13
|
+
primaryLanguage: LanguageString | null = Language.AUTO;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The secondary language, to overwrite the default language defined in the map style.
|
|
17
|
+
* This settings is highly dependant on the style compatibility and may not work in most cases.
|
|
18
|
+
*/
|
|
19
|
+
secondaryLanguage: LanguageString | null = null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Setting on whether of not the SDK runs with a session logic.
|
|
23
|
+
* A "session" is started at the initialization of the SDK and finished when the browser
|
|
24
|
+
* page is being refreshed.
|
|
25
|
+
* When `session` is enabled (default: true), the extra URL param `mtsid` is added to queries
|
|
26
|
+
* on the MapTiler Cloud API. This allows MapTiler to enable "session based billing".
|
|
27
|
+
*/
|
|
28
|
+
session = true;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Unit to be used
|
|
32
|
+
*/
|
|
33
|
+
private _unit: Unit = "metric";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* MapTiler Cloud API key
|
|
37
|
+
*/
|
|
38
|
+
private _apiKey = "";
|
|
39
|
+
|
|
40
|
+
constructor() {
|
|
41
|
+
super();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Set the unit system
|
|
46
|
+
*/
|
|
47
|
+
set unit(u: Unit) {
|
|
48
|
+
this._unit = u;
|
|
49
|
+
this.emit("unit", u);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the unit system
|
|
54
|
+
*/
|
|
55
|
+
get unit(): Unit {
|
|
56
|
+
return this._unit;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Set the MapTiler Cloud API key
|
|
61
|
+
*/
|
|
62
|
+
set apiKey(k: string) {
|
|
63
|
+
this._apiKey = k;
|
|
64
|
+
clientConfig.apiKey = k;
|
|
65
|
+
this.emit("apiKey", k);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the MapTiler Cloud API key
|
|
70
|
+
*/
|
|
71
|
+
get apiKey(): string {
|
|
72
|
+
return this._apiKey;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Set a the custom fetch function to replace the default one
|
|
77
|
+
*/
|
|
78
|
+
set fetch(f: FetchFunction) {
|
|
79
|
+
clientConfig.fetch = f;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get the fetch fucntion
|
|
84
|
+
*/
|
|
85
|
+
get fetch(): FetchFunction | null {
|
|
86
|
+
return clientConfig.fetch;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const config = new SdkConfig();
|
|
91
|
+
|
|
92
|
+
export { config, SdkConfig };
|
package/src/defaults.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Language } from "./language";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Some default settings for the SDK
|
|
5
|
+
*/
|
|
6
|
+
const defaults = {
|
|
7
|
+
maptilerLogoURL: "https://api.maptiler.com/resources/logo.svg",
|
|
8
|
+
maptilerURL: "https://www.maptiler.com/",
|
|
9
|
+
maptilerApiHost: "api.maptiler.com",
|
|
10
|
+
rtlPluginURL:
|
|
11
|
+
"https://cdn.maptiler.com/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.min.js",
|
|
12
|
+
primaryLanguage: Language.AUTO,
|
|
13
|
+
secondaryLanguage: Language.LOCAL,
|
|
14
|
+
terrainSourceURL: "https://api.maptiler.com/tiles/terrain-rgb/tiles.json",
|
|
15
|
+
terrainSourceId: "maptiler-terrain",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.freeze(defaults);
|
|
19
|
+
|
|
20
|
+
export { defaults };
|