@maptiler/sdk 1.2.1 → 2.0.1

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 +461 -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,27 +0,0 @@
1
- import {
2
- addPolyline,
3
- addPolygon,
4
- addPoint,
5
- addHeatmap,
6
- } from "./vectorlayerhelpers";
7
-
8
- export type {
9
- ZoomStringValues,
10
- ZoomNumberValues,
11
- PropertyValues,
12
- CommonShapeLayerOptions,
13
- PolylineLayerOptions,
14
- PolygonLayerOptions,
15
- PointLayerOptions,
16
- HeatmapLayerOptions,
17
- } from "./vectorlayerhelpers";
18
-
19
- /**
20
- * Helpers are a set of functions to facilitate the creation of sources and layers
21
- */
22
- export const helpers = {
23
- addPolyline,
24
- addPolygon,
25
- addPoint,
26
- addHeatmap,
27
- };
@@ -1,395 +0,0 @@
1
- import {
2
- DataDrivenPropertyValueSpecification,
3
- ExpressionSpecification,
4
- } from "maplibre-gl";
5
- import { generateRandomString } from "../tools";
6
- import { ColorRamp, RgbaColor } from "../colorramp";
7
- import {
8
- DataDrivenStyle,
9
- PropertyValues,
10
- ZoomNumberValues,
11
- ZoomStringValues,
12
- } from "./vectorlayerhelpers";
13
-
14
- export type ColorPalette = [string, string, string, string];
15
-
16
- export const colorPalettes: Array<ColorPalette> = [
17
- // https://colorhunt.co/palette/1d5b79468b97ef6262f3aa60
18
- ["#1D5B79", "#468B97", "#EF6262", "#F3AA60"],
19
-
20
- // https://colorhunt.co/palette/614bc333bbc585e6c5c8ffe0
21
- ["#614BC3", "#33BBC5", "#85E6C5", "#C8FFE0"],
22
-
23
- // https://colorhunt.co/palette/4619597a316fcd6688aed8cc
24
- ["#461959", "#7A316F", "#CD6688", "#AED8CC"],
25
-
26
- // https://colorhunt.co/palette/0079ff00dfa2f6fa70ff0060
27
- ["#0079FF", "#00DFA2", "#F6FA70", "#FF0060"],
28
-
29
- //https://colorhunt.co/palette/39b5e0a31acbff78f0f5ea5a
30
- ["#39B5E0", "#A31ACB", "#FF78F0", "#F5EA5A"],
31
-
32
- // https://colorhunt.co/palette/37e2d5590696c70a80fbcb0a
33
- ["#37E2D5", "#590696", "#C70A80", "#FBCB0A"],
34
-
35
- // https://colorhunt.co/palette/ffd36efff56d99ffcd9fb4ff
36
- ["#FFD36E", "#FFF56D", "#99FFCD", "#9FB4FF"],
37
-
38
- // https://colorhunt.co/palette/00ead3fff5b7ff449f005f99
39
- ["#00EAD3", "#FFF5B7", "#FF449F", "#005F99"],
40
-
41
- // https://colorhunt.co/palette/10a19d540375ff7000ffbf00
42
- ["#10A19D", "#540375", "#FF7000", "#FFBF00"],
43
- ];
44
-
45
- export function getRandomColor(): string {
46
- return colorPalettes[~~(Math.random() * colorPalettes.length)][
47
- ~~(Math.random() * 4)
48
- ];
49
- }
50
-
51
- export function generateRandomSourceName(): string {
52
- return `maptiler_source_${generateRandomString()}`;
53
- }
54
-
55
- export function generateRandomLayerName(): string {
56
- return `maptiler_layer_${generateRandomString()}`;
57
- }
58
-
59
- /**
60
- * Linera interpolation to find a value at an arbitrary zoom level, given a list of tuple zoom-value
61
- */
62
- export function lerpZoomNumberValues(znv: ZoomNumberValues, z: number): number {
63
- // before the range
64
- if (z <= znv[0].zoom) {
65
- return znv[0].value;
66
- }
67
-
68
- // after the range
69
- if (z >= znv[znv.length - 1].zoom) {
70
- return znv[znv.length - 1].value;
71
- }
72
-
73
- // somewhere within the range
74
- for (let i = 0; i < znv.length - 1; i += 1) {
75
- if (z >= znv[i].zoom && z < znv[i + 1].zoom) {
76
- const zoomRange = znv[i + 1].zoom - znv[i].zoom;
77
- const normalizedDistanceFromLowerBound = (z - znv[i].zoom) / zoomRange;
78
- return (
79
- normalizedDistanceFromLowerBound * znv[i + 1].value +
80
- (1 - normalizedDistanceFromLowerBound) * znv[i].value
81
- );
82
- }
83
- }
84
-
85
- return 0;
86
- }
87
-
88
- export function paintColorOptionsToPaintSpec(
89
- color: ZoomStringValues,
90
- ): DataDrivenPropertyValueSpecification<string> {
91
- return [
92
- "interpolate",
93
- ["linear"],
94
- ["zoom"],
95
- ...color.map((el) => [el.zoom, el.value]).flat(),
96
- ];
97
- }
98
-
99
- export function rampedOptionsToLayerPaintSpec(
100
- ramp: ZoomNumberValues,
101
- ): DataDrivenPropertyValueSpecification<number> {
102
- return [
103
- "interpolate",
104
- ["linear"],
105
- ["zoom"],
106
- ...ramp.map((el) => [el.zoom, el.value]).flat(),
107
- ];
108
- }
109
-
110
- export function computeRampedOutlineWidth(
111
- lineWidth: number | ZoomNumberValues,
112
- outlineWidth: number | ZoomNumberValues,
113
- ): number | DataDrivenPropertyValueSpecification<number> {
114
- // case 1: the line is fixed-width and the outline is fixed-width
115
- if (typeof outlineWidth === "number" && typeof lineWidth === "number") {
116
- return 2 * outlineWidth + lineWidth;
117
- }
118
-
119
- // case 2: the line is ramped-width, the outline is fixed-width
120
- else if (typeof outlineWidth === "number" && Array.isArray(lineWidth)) {
121
- return [
122
- "interpolate",
123
- ["linear"],
124
- ["zoom"],
125
- ...lineWidth.map((el) => [el.zoom, 2 * outlineWidth + el.value]).flat(),
126
- ];
127
- }
128
-
129
- // case 3: the line is fixed-width, the outline is ramped-width
130
- else if (typeof lineWidth === "number" && Array.isArray(outlineWidth)) {
131
- return [
132
- "interpolate",
133
- ["linear"],
134
- ["zoom"],
135
- ...outlineWidth.map((el) => [el.zoom, 2 * el.value + lineWidth]).flat(),
136
- ];
137
- }
138
-
139
- // case 4: the line is ramped-width, the outline is ramped-width
140
- if (Array.isArray(lineWidth) && Array.isArray(outlineWidth)) {
141
- // We must create an artificial set of zoom stops that includes all the zoom stops from both lists
142
- // const allStops = [...lineWidth.map(el => el.zoom), ...outlineWidth.map(el => el.zoom)].sort((a: number, b: number) => a < b ? -1 : 1);
143
- const allStops = Array.from(
144
- new Set([
145
- ...lineWidth.map((el) => el.zoom),
146
- ...outlineWidth.map((el) => el.zoom),
147
- ]),
148
- ).sort((a: number, b: number) => (a < b ? -1 : 1));
149
-
150
- return [
151
- "interpolate",
152
- ["linear"],
153
- ["zoom"],
154
- ...allStops
155
- .map((z) => [
156
- z,
157
- 2 * lerpZoomNumberValues(outlineWidth, z) +
158
- lerpZoomNumberValues(lineWidth, z),
159
- ])
160
- .flat(),
161
- ];
162
- }
163
-
164
- return 0;
165
- }
166
-
167
- export function rampedPropertyValueWeight(
168
- ramp: PropertyValues,
169
- property: string,
170
- ): DataDrivenPropertyValueSpecification<number> {
171
- return [
172
- "interpolate",
173
- ["linear"],
174
- ["get", property],
175
- ...ramp.map((el) => [el.propertyValue, el.value]).flat(),
176
- ];
177
- }
178
-
179
- /**
180
- * Create a dash array from a string pattern that uses underscore and whitespace characters
181
- */
182
- export function dashArrayMaker(pattern: string): Array<number> {
183
- // if the pattern starts with whitespaces, then move them towards the end
184
- const startTrimmedPattern = pattern.trimStart();
185
- const fixedPattern = `${startTrimmedPattern}${" ".repeat(
186
- pattern.length - startTrimmedPattern.length,
187
- )}`;
188
- const patternArr = Array.from(fixedPattern);
189
-
190
- const isOnlyDashesAndSpaces = patternArr.every((c) => c === " " || c === "_");
191
- if (!isOnlyDashesAndSpaces) {
192
- throw new Error(
193
- "A dash pattern must be composed only of whitespace and underscore characters.",
194
- );
195
- }
196
-
197
- const hasBothDashesAndWhitespaces =
198
- patternArr.some((c) => c === "_") && patternArr.some((c) => c === " ");
199
- if (!hasBothDashesAndWhitespaces) {
200
- throw new Error(
201
- "A dash pattern must contain at least one underscore and one whitespace character",
202
- );
203
- }
204
-
205
- const dashArray = [1];
206
-
207
- for (let i = 1; i < patternArr.length; i += 1) {
208
- const previous = patternArr[i - 1];
209
- const current = patternArr[i];
210
-
211
- if (previous === current) {
212
- dashArray[dashArray.length - 1] += 1;
213
- } else {
214
- dashArray.push(1);
215
- }
216
- }
217
-
218
- return dashArray;
219
- }
220
-
221
- export function colorDrivenByProperty(
222
- style: DataDrivenStyle,
223
- property: string,
224
- ): DataDrivenPropertyValueSpecification<string> {
225
- return [
226
- "interpolate",
227
- ["linear"],
228
- ["get", property],
229
- ...style.map((el) => [el.value, el.color]).flat(),
230
- ];
231
- }
232
-
233
- export function radiusDrivenByProperty(
234
- style: DataDrivenStyle,
235
- property: string,
236
- zoomCompensation = true,
237
- ): DataDrivenPropertyValueSpecification<number> {
238
- if (!zoomCompensation) {
239
- return [
240
- "interpolate",
241
- ["linear"],
242
- ["get", property],
243
- ...style.map((el) => [el.value, el.pointRadius]).flat(),
244
- ];
245
- }
246
-
247
- return [
248
- "interpolate",
249
- ["linear"],
250
- ["zoom"],
251
-
252
- 0,
253
- [
254
- "interpolate",
255
- ["linear"],
256
- ["get", property],
257
- ...style.map((el) => [el.value, el.pointRadius * 0.025]).flat(),
258
- ],
259
-
260
- 2,
261
- [
262
- "interpolate",
263
- ["linear"],
264
- ["get", property],
265
- ...style.map((el) => [el.value, el.pointRadius * 0.05]).flat(),
266
- ],
267
-
268
- 4,
269
- [
270
- "interpolate",
271
- ["linear"],
272
- ["get", property],
273
- ...style.map((el) => [el.value, el.pointRadius * 0.1]).flat(),
274
- ],
275
-
276
- 8,
277
- [
278
- "interpolate",
279
- ["linear"],
280
- ["get", property],
281
- ...style.map((el) => [el.value, el.pointRadius * 0.25]).flat(),
282
- ],
283
-
284
- 16,
285
- [
286
- "interpolate",
287
- ["linear"],
288
- ["get", property],
289
- ...style.map((el) => [el.value, el.pointRadius]).flat(),
290
- ],
291
- ];
292
- }
293
-
294
- export function radiusDrivenByPropertyHeatmap(
295
- style: PropertyValues,
296
- property: string,
297
- zoomCompensation = true,
298
- ): DataDrivenPropertyValueSpecification<number> {
299
- if (!zoomCompensation) {
300
- return [
301
- "interpolate",
302
- ["linear"],
303
- ["get", property],
304
- ...style.map((el) => [el.propertyValue, el.value]).flat(),
305
- ];
306
- }
307
-
308
- return [
309
- "interpolate",
310
- ["linear"],
311
- ["zoom"],
312
-
313
- 0,
314
- [
315
- "interpolate",
316
- ["linear"],
317
- ["get", property],
318
- ...style.map((el) => [el.propertyValue, el.value * 0.025]).flat(),
319
- ],
320
-
321
- 2,
322
- [
323
- "interpolate",
324
- ["linear"],
325
- ["get", property],
326
- ...style.map((el) => [el.propertyValue, el.value * 0.05]).flat(),
327
- ],
328
-
329
- 4,
330
- [
331
- "interpolate",
332
- ["linear"],
333
- ["get", property],
334
- ...style.map((el) => [el.propertyValue, el.value * 0.1]).flat(),
335
- ],
336
-
337
- 8,
338
- [
339
- "interpolate",
340
- ["linear"],
341
- ["get", property],
342
- ...style.map((el) => [el.propertyValue, el.value * 0.25]).flat(),
343
- ],
344
-
345
- 16,
346
- [
347
- "interpolate",
348
- ["linear"],
349
- ["get", property],
350
- ...style.map((el) => [el.propertyValue, el.value]).flat(),
351
- ],
352
- ];
353
- }
354
-
355
- /**
356
- * Turns a ColorRamp instance into a MapLibre style for ramping the opacity, driven by a property
357
- */
358
- export function opacityDrivenByProperty(
359
- colorramp: ColorRamp,
360
- property: string,
361
- ): DataDrivenPropertyValueSpecification<number> {
362
- // If all opacities are the same, just return the number without any ramping logic
363
- if (colorramp.every((el) => el.color[3] === colorramp[0].color[3])) {
364
- return colorramp[0].color[3] ? colorramp[0].color[3] / 255 : 1;
365
- }
366
-
367
- return [
368
- "interpolate",
369
- ["linear"],
370
- ["get", property],
371
- ...colorramp
372
- .getRawColorStops()
373
- .map((el) => {
374
- const value = el.value;
375
- const color: RgbaColor = el.color;
376
- return [value, color.length === 4 ? color[3] / 255 : 1];
377
- })
378
- .flat(),
379
- ];
380
- }
381
-
382
- export function heatmapIntensityFromColorRamp(
383
- colorRamp: ColorRamp,
384
- steps = 10,
385
- ): ExpressionSpecification {
386
- return [
387
- "interpolate",
388
- ["linear"],
389
- ["heatmap-density"],
390
- ...Array.from({ length: steps + 1 }, (_, i) => {
391
- const unitStep = i / steps;
392
- return [unitStep, colorRamp.getColorHex(unitStep)];
393
- }).flat(),
394
- ];
395
- }