@maptiler/sdk 1.2.1 → 2.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.
Files changed (63) hide show
  1. package/.eslintrc.cjs +1 -0
  2. package/dist/maptiler-sdk.css +1 -1
  3. package/dist/maptiler-sdk.d.ts +171 -240
  4. package/dist/maptiler-sdk.min.mjs +3 -3
  5. package/dist/maptiler-sdk.mjs +462 -458
  6. package/dist/maptiler-sdk.mjs.map +1 -1
  7. package/package.json +3 -3
  8. package/readme.md +16 -1
  9. package/CHANGELOG.md +0 -168
  10. package/colorramp.md +0 -93
  11. package/dist/maptiler-sdk.umd.js +0 -7702
  12. package/dist/maptiler-sdk.umd.js.map +0 -1
  13. package/dist/maptiler-sdk.umd.min.js +0 -582
  14. package/src/AttributionControl.ts +0 -13
  15. package/src/CanvasSource.ts +0 -13
  16. package/src/FullscreenControl.ts +0 -13
  17. package/src/GeoJSONSource.ts +0 -13
  18. package/src/GeolocateControl.ts +0 -13
  19. package/src/ImageSource.ts +0 -13
  20. package/src/LogoControl.ts +0 -13
  21. package/src/Map.ts +0 -1352
  22. package/src/MaptilerGeolocateControl.ts +0 -207
  23. package/src/MaptilerLogoControl.ts +0 -58
  24. package/src/MaptilerNavigationControl.ts +0 -69
  25. package/src/MaptilerTerrainControl.ts +0 -72
  26. package/src/Marker.ts +0 -13
  27. package/src/Minimap.ts +0 -373
  28. package/src/NavigationControl.ts +0 -13
  29. package/src/Point.ts +0 -334
  30. package/src/Popup.ts +0 -13
  31. package/src/RasterDEMTileSource.ts +0 -13
  32. package/src/RasterTileSource.ts +0 -13
  33. package/src/ScaleControl.ts +0 -13
  34. package/src/Style.ts +0 -13
  35. package/src/TerrainControl.ts +0 -13
  36. package/src/VectorTileSource.ts +0 -13
  37. package/src/VideoSource.ts +0 -13
  38. package/src/colorramp.ts +0 -1216
  39. package/src/config.ts +0 -96
  40. package/src/converters/index.ts +0 -1
  41. package/src/converters/xml.ts +0 -681
  42. package/src/defaults.ts +0 -20
  43. package/src/helpers/index.ts +0 -27
  44. package/src/helpers/stylehelper.ts +0 -395
  45. package/src/helpers/vectorlayerhelpers.ts +0 -1511
  46. package/src/index.ts +0 -201
  47. package/src/language.ts +0 -183
  48. package/src/mapstyle.ts +0 -46
  49. package/src/style/style_template.css +0 -146
  50. package/src/style/svg/v6-compass.svg +0 -12
  51. package/src/style/svg/v6-fullscreen-off.svg +0 -7
  52. package/src/style/svg/v6-fullscreen.svg +0 -7
  53. package/src/style/svg/v6-geolocate-active-error.svg +0 -10
  54. package/src/style/svg/v6-geolocate-active.svg +0 -7
  55. package/src/style/svg/v6-geolocate-background.svg +0 -8
  56. package/src/style/svg/v6-geolocate-disabled.svg +0 -10
  57. package/src/style/svg/v6-geolocate.svg +0 -7
  58. package/src/style/svg/v6-terrain-on.svg +0 -7
  59. package/src/style/svg/v6-terrain.svg +0 -7
  60. package/src/style/svg/v6-zoom-minus.svg +0 -7
  61. package/src/style/svg/v6-zoom-plus.svg +0 -7
  62. package/src/tools.ts +0 -171
  63. package/src/unit.ts +0 -1
@@ -1,207 +0,0 @@
1
- import type { LngLatLike, MapLibreEvent } from "maplibre-gl";
2
- import maplibregl from "maplibre-gl";
3
- import { GeolocateControl } from "./GeolocateControl";
4
- import { DOMcreate } from "./tools";
5
-
6
- const Marker = maplibregl.Marker;
7
- const LngLat = maplibregl.LngLat;
8
- const LngLatBounds = maplibregl.LngLatBounds;
9
-
10
- type MoveEndEvent = MapLibreEvent<
11
- MouseEvent | TouchEvent | WheelEvent | undefined
12
- > & { geolocateSource?: boolean };
13
-
14
- /**
15
- * The MaptilerGeolocateControl is an extension of the original GeolocateControl
16
- * with a few changes. In this version, the active mode persists as long as the
17
- * location is still centered. This means it's robust to rotation, pitch and zoom.
18
- *
19
- */
20
- export class MaptilerGeolocateControl extends GeolocateControl {
21
- private lastUpdatedCenter = new LngLat(0, 0);
22
-
23
- /**
24
- * Update the camera location to center on the current position
25
- *
26
- * @param {Position} position the Geolocation API Position
27
- * @private
28
- */
29
- _updateCamera = (position: GeolocationPosition) => {
30
- const center = new LngLat(
31
- position.coords.longitude,
32
- position.coords.latitude,
33
- );
34
- const radius = position.coords.accuracy;
35
- const bearing = this._map.getBearing();
36
- const options = {
37
- bearing,
38
- ...this.options.fitBoundsOptions,
39
- linear: true,
40
- };
41
-
42
- const currentMapZoom = this._map.getZoom();
43
-
44
- if (currentMapZoom > (this.options?.fitBoundsOptions?.maxZoom ?? 30)) {
45
- options.zoom = currentMapZoom;
46
- }
47
-
48
- this._map.fitBounds(LngLatBounds.fromLngLat(center, radius), options, {
49
- geolocateSource: true, // tag this camera change so it won't cause the control to change to background state
50
- });
51
-
52
- let hasFittingBeenDisrupted = false;
53
-
54
- const flagFittingDisruption = () => {
55
- hasFittingBeenDisrupted = true;
56
- };
57
-
58
- this._map.once("click", flagFittingDisruption);
59
- this._map.once("dblclick", flagFittingDisruption);
60
- this._map.once("dragstart", flagFittingDisruption);
61
- this._map.once("mousedown", flagFittingDisruption);
62
- this._map.once("touchstart", flagFittingDisruption);
63
- this._map.once("wheel", flagFittingDisruption);
64
-
65
- this._map.once("moveend", () => {
66
- // Removing the events if not used
67
- this._map.off("click", flagFittingDisruption);
68
- this._map.off("dblclick", flagFittingDisruption);
69
- this._map.off("dragstart", flagFittingDisruption);
70
- this._map.off("mousedown", flagFittingDisruption);
71
- this._map.off("touchstart", flagFittingDisruption);
72
- this._map.off("wheel", flagFittingDisruption);
73
-
74
- if (hasFittingBeenDisrupted) {
75
- return;
76
- }
77
-
78
- this.lastUpdatedCenter = this._map.getCenter();
79
- });
80
- };
81
-
82
- _setupUI = (supported: boolean) => {
83
- this.lastUpdatedCenter = this._map.getCenter();
84
-
85
- this._container.addEventListener("contextmenu", (e: MouseEvent) =>
86
- e.preventDefault(),
87
- );
88
- this._geolocateButton = DOMcreate(
89
- "button",
90
- "maplibregl-ctrl-geolocate",
91
- this._container,
92
- );
93
- DOMcreate(
94
- "span",
95
- "maplibregl-ctrl-icon",
96
- this._geolocateButton,
97
- ).setAttribute("aria-hidden", "true");
98
- this._geolocateButton.type = "button";
99
-
100
- if (supported === false) {
101
- // warnOnce('Geolocation support is not available so the GeolocateControl will be disabled.');
102
- const title = this._map._getUIString(
103
- "GeolocateControl.LocationNotAvailable",
104
- );
105
- this._geolocateButton.disabled = true;
106
- this._geolocateButton.title = title;
107
- this._geolocateButton.setAttribute("aria-label", title);
108
- } else {
109
- const title = this._map._getUIString("GeolocateControl.FindMyLocation");
110
- this._geolocateButton.title = title;
111
- this._geolocateButton.setAttribute("aria-label", title);
112
- }
113
-
114
- if (this.options.trackUserLocation) {
115
- this._geolocateButton.setAttribute("aria-pressed", "false");
116
- this._watchState = "OFF";
117
- }
118
-
119
- // when showUserLocation is enabled, keep the Geolocate button disabled until the device location marker is setup on the map
120
- if (this.options.showUserLocation) {
121
- this._dotElement = DOMcreate("div", "maplibregl-user-location-dot");
122
- this._userLocationDotMarker = new Marker({ element: this._dotElement });
123
-
124
- this._circleElement = DOMcreate(
125
- "div",
126
- "maplibregl-user-location-accuracy-circle",
127
- );
128
- this._accuracyCircleMarker = new Marker({
129
- element: this._circleElement,
130
- pitchAlignment: "map",
131
- });
132
-
133
- if (this.options.trackUserLocation) this._watchState = "OFF";
134
-
135
- this._map.on("move", this._onZoom);
136
- }
137
-
138
- this._geolocateButton.addEventListener("click", this.trigger.bind(this));
139
-
140
- this._setup = true;
141
-
142
- // when the camera is changed (and it's not as a result of the Geolocation Control) change
143
- // the watch mode to background watch, so that the marker is updated but not the camera.
144
- // Addition: Yet the status change does not occur if the ditance it has moved to is less than
145
- // one meter from the last auto-updated position. This is to guarrantee that if the move
146
- // is a zoom, rotation or pitch (where the center stays the same) then we can keep the ACTIVE_LOCK
147
- // mode ON.
148
- if (this.options.trackUserLocation) {
149
- this._map.on("moveend", (event: MoveEndEvent) => {
150
- const fromResize =
151
- event.originalEvent && event.originalEvent.type === "resize";
152
- const movingDistance = this.lastUpdatedCenter.distanceTo(
153
- this._map.getCenter(),
154
- );
155
-
156
- if (
157
- !event.geolocateSource &&
158
- this._watchState === "ACTIVE_LOCK" &&
159
- !fromResize &&
160
- movingDistance > 1
161
- ) {
162
- this._watchState = "BACKGROUND";
163
- this._geolocateButton.classList.add(
164
- "maplibregl-ctrl-geolocate-background",
165
- );
166
- this._geolocateButton.classList.remove(
167
- "maplibregl-ctrl-geolocate-active",
168
- );
169
-
170
- this.fire(new Event("trackuserlocationend"));
171
- }
172
- });
173
- }
174
- };
175
-
176
- _updateCircleRadius() {
177
- if (
178
- this._watchState !== "BACKGROUND" &&
179
- this._watchState !== "ACTIVE_LOCK"
180
- ) {
181
- return;
182
- }
183
-
184
- const lastKnownLocation: LngLatLike = [
185
- this._lastKnownPosition.coords.longitude,
186
- this._lastKnownPosition.coords.latitude,
187
- ];
188
-
189
- const projectedLocation = this._map.project(lastKnownLocation);
190
- const a = this._map.unproject([projectedLocation.x, projectedLocation.y]);
191
- const b = this._map.unproject([
192
- projectedLocation.x + 20,
193
- projectedLocation.y,
194
- ]);
195
- const metersPerPixel = a.distanceTo(b) / 20;
196
-
197
- const circleDiameter = Math.ceil((2.0 * this._accuracy) / metersPerPixel);
198
- this._circleElement.style.width = `${circleDiameter}px`;
199
- this._circleElement.style.height = `${circleDiameter}px`;
200
- }
201
-
202
- _onZoom = () => {
203
- if (this.options.showUserLocation && this.options.showAccuracyCircle) {
204
- this._updateCircleRadius();
205
- }
206
- };
207
- }
@@ -1,58 +0,0 @@
1
- import type { LogoOptions as LogoOptionsML } from "maplibre-gl";
2
- import { defaults } from "./defaults";
3
- import { LogoControl } from "./LogoControl";
4
- import type { Map } from "./Map";
5
-
6
- type LogoOptions = LogoOptionsML & {
7
- logoURL?: string;
8
- linkURL?: string;
9
- };
10
-
11
- /**
12
- * This LogoControl extends the MapLibre LogoControl but instead can use any image URL and
13
- * any link URL. By default this is using MapTiler logo and URL.
14
- */
15
- export class MaptilerLogoControl extends LogoControl {
16
- declare _compact: boolean;
17
- private logoURL = "";
18
- private linkURL = "";
19
-
20
- constructor(options: LogoOptions = {}) {
21
- super(options);
22
-
23
- this.logoURL = options.logoURL ?? defaults.maptilerLogoURL;
24
- this.linkURL = options.linkURL ?? defaults.maptilerURL;
25
- }
26
-
27
- onAdd(map: Map): HTMLElement {
28
- this._map = map;
29
- this._compact = this.options.compact ?? false;
30
- this._container = window.document.createElement("div");
31
- this._container.className = "maplibregl-ctrl";
32
- const anchor = window.document.createElement("a");
33
- anchor.style.backgroundRepeat = "no-repeat";
34
- anchor.style.cursor = "pointer";
35
- anchor.style.display = "block";
36
- anchor.style.height = "23px";
37
- anchor.style.margin = "0 0 -4px -4px";
38
- anchor.style.overflow = "hidden";
39
- anchor.style.width = "88px";
40
- anchor.style.backgroundImage = `url(${this.logoURL})`;
41
- anchor.style.backgroundSize = "100px 30px";
42
- anchor.style.width = "100px";
43
- anchor.style.height = "30px";
44
-
45
- anchor.target = "_blank";
46
- anchor.rel = "noopener";
47
- anchor.href = this.linkURL;
48
- anchor.setAttribute("aria-label", "MapTiler logo");
49
- anchor.setAttribute("rel", "noopener");
50
- this._container.appendChild(anchor);
51
- this._container.style.display = "block";
52
-
53
- this._map.on("resize", this._updateCompact);
54
- this._updateCompact();
55
-
56
- return this._container;
57
- }
58
- }
@@ -1,69 +0,0 @@
1
- import { NavigationControl } from "./NavigationControl";
2
-
3
- type HTMLButtonElementPlus = HTMLButtonElement & {
4
- clickFunction: (e?: Event) => unknown;
5
- };
6
-
7
- export class MaptilerNavigationControl extends 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?: Event) => 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(
59
- Math.cos(this._map.transform.pitch * (Math.PI / 180)),
60
- 0.5,
61
- ),
62
- )}) rotateX(${Math.min(70, this._map.transform.pitch)}deg) rotateZ(${
63
- this._map.transform.angle * (180 / Math.PI)
64
- }deg)`
65
- : `rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`;
66
-
67
- this._compassIcon.style.transform = rotate;
68
- };
69
- }
@@ -1,72 +0,0 @@
1
- import { bindAll, DOMcreate, DOMremove } from "./tools";
2
-
3
- import type { Map } from "./Map";
4
- import type { IControl } from "maplibre-gl";
5
-
6
- /**
7
- * A `MaptilerTerrainControl` control adds a button to turn terrain on and off
8
- * by triggering the terrain logic that is already deployed in the Map object.
9
- */
10
- export class MaptilerTerrainControl implements IControl {
11
- _map!: Map;
12
- _container!: HTMLElement;
13
- _terrainButton!: HTMLButtonElement;
14
-
15
- constructor() {
16
- bindAll(["_toggleTerrain", "_updateTerrainIcon"], this);
17
- }
18
-
19
- onAdd(map: Map): HTMLElement {
20
- this._map = map;
21
- this._container = DOMcreate("div", "maplibregl-ctrl maplibregl-ctrl-group");
22
- this._terrainButton = DOMcreate(
23
- "button",
24
- "maplibregl-ctrl-terrain",
25
- this._container,
26
- );
27
- DOMcreate("span", "maplibregl-ctrl-icon", this._terrainButton).setAttribute(
28
- "aria-hidden",
29
- "true",
30
- );
31
- this._terrainButton.type = "button";
32
- this._terrainButton.addEventListener("click", this._toggleTerrain);
33
-
34
- this._updateTerrainIcon();
35
- this._map.on("terrain", this._updateTerrainIcon);
36
- return this._container;
37
- }
38
-
39
- onRemove(): void {
40
- DOMremove(this._container);
41
- this._map.off("terrain", this._updateTerrainIcon);
42
- // @ts-expect-error: map will only be undefined on remove
43
- this._map = undefined;
44
- }
45
-
46
- _toggleTerrain(): void {
47
- if (this._map.hasTerrain()) {
48
- this._map.disableTerrain();
49
- } else {
50
- this._map.enableTerrain();
51
- }
52
-
53
- this._updateTerrainIcon();
54
- }
55
-
56
- _updateTerrainIcon(): void {
57
- this._terrainButton.classList.remove("maplibregl-ctrl-terrain");
58
- this._terrainButton.classList.remove("maplibregl-ctrl-terrain-enabled");
59
- // if (this._map.terrain) {
60
- if (this._map.hasTerrain()) {
61
- this._terrainButton.classList.add("maplibregl-ctrl-terrain-enabled");
62
- this._terrainButton.title = this._map._getUIString(
63
- "TerrainControl.disableTerrain",
64
- );
65
- } else {
66
- this._terrainButton.classList.add("maplibregl-ctrl-terrain");
67
- this._terrainButton.title = this._map._getUIString(
68
- "TerrainControl.enableTerrain",
69
- );
70
- }
71
- }
72
- }
package/src/Marker.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * This is an extension of MapLibre Marker to make it fully type compatible with the SDK
3
- */
4
-
5
- import maplibregl from "maplibre-gl";
6
- import type { Map as MapMLGL } from "maplibre-gl";
7
- import { Map } from "./Map";
8
-
9
- export class Marker extends maplibregl.Marker {
10
- addTo(map: Map | MapMLGL): this {
11
- return super.addTo(map as MapMLGL);
12
- }
13
- }