@maptiler/client 1.0.2 → 1.1.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 (120) hide show
  1. package/.github/workflows/npm-publish.yml +0 -1
  2. package/dist/maptiler-client.cjs +465 -21
  3. package/dist/maptiler-client.cjs.map +1 -1
  4. package/dist/maptiler-client.d.ts +395 -2
  5. package/dist/maptiler-client.min.mjs +1 -1
  6. package/dist/maptiler-client.mjs +461 -22
  7. package/dist/maptiler-client.mjs.map +1 -1
  8. package/dist/maptiler-client.umd.js +465 -21
  9. package/dist/maptiler-client.umd.js.map +1 -1
  10. package/dist/maptiler-client.umd.min.js +1 -1
  11. package/docs/assets/custom.css +118 -0
  12. package/docs/assets/highlight.css +10 -10
  13. package/docs/assets/main.js +56 -52
  14. package/docs/assets/search.js +1 -1
  15. package/docs/assets/style.css +23 -0
  16. package/docs/classes/{ClientConfig.html → config.ClientConfig.html} +34 -24
  17. package/docs/classes/{ServiceError.html → services_ServiceError.ServiceError.html} +26 -16
  18. package/docs/functions/language.getAutoLanguageGeocoding.html +60 -0
  19. package/docs/functions/services_simplify.default.html +65 -0
  20. package/docs/images/maptiler-logo-256.png +0 -0
  21. package/docs/index.html +118 -57
  22. package/docs/modules/config.html +71 -0
  23. package/docs/modules/language.html +71 -0
  24. package/docs/modules/services_ServiceError.html +61 -0
  25. package/docs/modules/services_coordinates.html +84 -0
  26. package/docs/modules/services_data.html +66 -0
  27. package/docs/modules/services_geocoding.html +76 -0
  28. package/docs/modules/services_geolocation.html +68 -0
  29. package/docs/modules/services_simplify.html +61 -0
  30. package/docs/modules/services_staticMaps.html +74 -0
  31. package/docs/modules.html +23 -83
  32. package/docs/types/config.FetchFunction.html +71 -0
  33. package/docs/types/language.LanguageGeocodingString.html +58 -0
  34. package/docs/types/services_coordinates.CoordinateExport.html +71 -0
  35. package/docs/types/services_coordinates.CoordinateGrid.html +69 -0
  36. package/docs/types/services_coordinates.CoordinateId.html +71 -0
  37. package/docs/types/services_coordinates.CoordinateSearch.html +93 -0
  38. package/docs/types/services_coordinates.CoordinateSearchResult.html +75 -0
  39. package/docs/types/services_coordinates.CoordinateTransformResult.html +76 -0
  40. package/docs/types/services_coordinates.CoordinateTransformation.html +89 -0
  41. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +83 -0
  42. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +85 -0
  43. package/docs/types/services_coordinates.XYZ.html +73 -0
  44. package/docs/types/services_data.GetDataOptions.html +64 -0
  45. package/docs/types/services_geocoding.Coordinates.html +60 -0
  46. package/docs/types/services_geocoding.FeatureHierarchy.html +71 -0
  47. package/docs/types/services_geocoding.GeocodingFeature.html +60 -0
  48. package/docs/types/services_geocoding.GeocodingOptions.html +79 -0
  49. package/docs/types/services_geocoding.GeocodingSearchResult.html +77 -0
  50. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +71 -0
  51. package/docs/types/services_geolocation.GeolocationInfoOptions.html +65 -0
  52. package/docs/types/services_geolocation.GeolocationResult.html +128 -0
  53. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +61 -0
  54. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +61 -0
  55. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +61 -0
  56. package/docs/types/{StaticMapBaseOptions.html → services_staticMaps.StaticMapBaseOptions.html} +26 -45
  57. package/docs/types/services_staticMaps.StaticMapMarker.html +61 -0
  58. package/docs/variables/config.config.html +58 -0
  59. package/docs/variables/{LanguageGeocoding.html → language.LanguageGeocoding.html} +20 -42
  60. package/docs/variables/services_coordinates.coordinates.html +110 -0
  61. package/docs/variables/services_data.data.html +80 -0
  62. package/docs/variables/{geocoding.html → services_geocoding.geocoding.html} +35 -53
  63. package/docs/variables/services_geolocation.geolocation.html +79 -0
  64. package/docs/variables/services_staticMaps.staticMaps.html +128 -0
  65. package/docsmd/README.md +143 -36
  66. package/docsmd/assets/custom.css +118 -0
  67. package/docsmd/classes/ClientConfig.md +5 -5
  68. package/docsmd/classes/MapStyleVariant.md +217 -0
  69. package/docsmd/classes/ReferenceMapStyle.md +169 -0
  70. package/docsmd/classes/ServiceError.md +3 -3
  71. package/examples/test-browser-umd.html +1 -1
  72. package/images/maptiler-logo-256.png +0 -0
  73. package/package.json +5 -5
  74. package/readme.md +65 -5
  75. package/src/index.ts +17 -0
  76. package/src/mapstyle.ts +841 -0
  77. package/src/services/staticMaps.ts +5 -4
  78. package/tsconfig.json +0 -1
  79. package/typedoc.css +118 -0
  80. package/typedoc.json +7 -3
  81. package/docs/types/AutomaticStaticMapOptions.html +0 -80
  82. package/docs/types/BoundedStaticMapOptions.html +0 -80
  83. package/docs/types/CenteredStaticMapOptions.html +0 -80
  84. package/docs/types/CoordinateExport.html +0 -85
  85. package/docs/types/CoordinateGrid.html +0 -83
  86. package/docs/types/CoordinateId.html +0 -85
  87. package/docs/types/CoordinateSearch.html +0 -107
  88. package/docs/types/CoordinateSearchResult.html +0 -89
  89. package/docs/types/CoordinateTransformResult.html +0 -90
  90. package/docs/types/CoordinateTransformation.html +0 -103
  91. package/docs/types/Coordinates.html +0 -78
  92. package/docs/types/CoordinatesSearchOptions.html +0 -97
  93. package/docs/types/CoordinatesTransformOptions.html +0 -99
  94. package/docs/types/FeatureHierarchy.html +0 -89
  95. package/docs/types/FetchFunction.html +0 -93
  96. package/docs/types/GeocodingFeature.html +0 -78
  97. package/docs/types/GeocodingOptions.html +0 -97
  98. package/docs/types/GeocodingSearchResult.html +0 -95
  99. package/docs/types/GeolocationInfoOptions.html +0 -87
  100. package/docs/types/GeolocationResult.html +0 -150
  101. package/docs/types/GetDataOptions.html +0 -87
  102. package/docs/types/LanguageGeocodingString.html +0 -80
  103. package/docs/types/ReverseGeocodingOptions.html +0 -89
  104. package/docs/types/StaticMapMarker.html +0 -80
  105. package/docs/types/XYZ.html +0 -87
  106. package/docs/variables/config.html +0 -80
  107. package/docs/variables/coordinates-1.html +0 -124
  108. package/docs/variables/data.html +0 -103
  109. package/docs/variables/geolocation.html +0 -101
  110. package/docs/variables/staticMaps.html +0 -147
  111. package/docsmd/images/JS-logo.svg +0 -4
  112. package/docsmd/images/TS-logo.svg +0 -6
  113. package/docsmd/images/maptiler-client-logo.afdesign +0 -0
  114. package/docsmd/images/maptiler-client-logo.svg +0 -75
  115. package/docsmd/images/maptiler-logo.svg +0 -23
  116. package/docsmd/images/screenshots/static-bounded-europe-1024.png +0 -0
  117. package/docsmd/images/screenshots/static-bounded-europe-2048.png +0 -0
  118. package/docsmd/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  119. package/docsmd/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  120. package/docsmd/images/screenshots/static-with-path.png +0 -0
@@ -0,0 +1,841 @@
1
+ /**
2
+ * Type for object containing style details
3
+ */
4
+ export type MapStylePreset = {
5
+ referenceStyleID: string;
6
+ name: string;
7
+ description: string;
8
+ variants: Array<{
9
+ id: string;
10
+ name: string;
11
+ variantType: string;
12
+ description: string;
13
+ imageURL: string;
14
+ }>;
15
+ };
16
+
17
+ /**
18
+ * An instance of MapStyleVariant contains information about a style to use that belong to a reference style
19
+ */
20
+ export class MapStyleVariant {
21
+ constructor(
22
+ /**
23
+ * Human-friendly name
24
+ */
25
+ private name: string,
26
+
27
+ /**
28
+ * Variant name the variant is addressed to from its reference style: `MapStyle.REFERNCE_STYLE_NAME.VARIANT_TYPE`
29
+ */
30
+ private variantType: string,
31
+
32
+ /**
33
+ * MapTiler Cloud id
34
+ */
35
+ private id: string,
36
+
37
+ /**
38
+ * Reference map style, used to retrieve sibling variants
39
+ */
40
+ private referenceStyle: ReferenceMapStyle,
41
+
42
+ /**
43
+ * Human-friendly description
44
+ */
45
+ private description: string,
46
+
47
+ /**
48
+ * URL to an image describing the style variant
49
+ */
50
+ private imageURL: string
51
+ ) {}
52
+
53
+ /**
54
+ * Get the human-friendly name
55
+ * @returns
56
+ */
57
+ getName(): string {
58
+ return this.name;
59
+ }
60
+
61
+ getFullName(): string {
62
+ return `${this.referenceStyle.getName()} ${this.name}`;
63
+ }
64
+
65
+ /**
66
+ * Get the variant type (eg. "DEFAULT", "DARK", "PASTEL", etc.)
67
+ * @returns
68
+ */
69
+ getType(): string {
70
+ return this.variantType;
71
+ }
72
+
73
+ /**
74
+ * Get the MapTiler Cloud id
75
+ * @returns
76
+ */
77
+ getId(): string {
78
+ return this.id;
79
+ }
80
+
81
+ /**
82
+ * Get the human-friendly description
83
+ */
84
+ getDescription(): string {
85
+ return this.description;
86
+ }
87
+
88
+ /**
89
+ * Get the reference style this variant belongs to
90
+ * @returns
91
+ */
92
+ getReferenceStyle(): ReferenceMapStyle {
93
+ return this.referenceStyle;
94
+ }
95
+
96
+ /**
97
+ * Check if a variant of a given type exists for _this_ variants
98
+ * (eg. if this is a "DARK", then we can check if there is a "LIGHT" variant of it)
99
+ * @param variantType
100
+ * @returns
101
+ */
102
+ hasVariant(variantType: string): boolean {
103
+ return this.referenceStyle.hasVariant(variantType);
104
+ }
105
+
106
+ /**
107
+ * Retrieve the variant of a given type. If not found, will return the "DEFAULT" variant.
108
+ * (eg. _this_ "DARK" variant does not have any "PASTEL" variant, then the "DEFAULT" is returned)
109
+ * @param variantType
110
+ * @returns
111
+ */
112
+ getVariant(variantType: string): MapStyleVariant {
113
+ return this.referenceStyle.getVariant(variantType);
114
+ }
115
+
116
+ /**
117
+ * Get all the variants for _this_ variants, except _this_ current one
118
+ * @returns
119
+ */
120
+ getVariants(): Array<MapStyleVariant> {
121
+ return this.referenceStyle.getVariants().filter((v) => v !== this);
122
+ }
123
+
124
+ /**
125
+ * Get the image URL that represent _this_ variant
126
+ * @returns
127
+ */
128
+ getImageURL(): string {
129
+ return this.imageURL;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * An instance of reference style contains a list of StyleVariants ordered by relevance
135
+ */
136
+ export class ReferenceMapStyle {
137
+ /**
138
+ * Variants that belong to this reference style, key being the reference type
139
+ */
140
+ private variants: { [key: string]: MapStyleVariant } = {};
141
+
142
+ /**
143
+ * Variants that belong to this reference style, ordered by relevance
144
+ */
145
+ private orderedVariants: Array<MapStyleVariant> = [];
146
+
147
+ constructor(
148
+ /**
149
+ * Human-friendly name of this reference style
150
+ */
151
+ private name: string,
152
+
153
+ /**
154
+ * ID of this reference style
155
+ */
156
+ private id: string
157
+ ) {}
158
+
159
+ /**
160
+ * Get the human-friendly name of this reference style
161
+ * @returns
162
+ */
163
+ getName(): string {
164
+ return this.name;
165
+ }
166
+
167
+ /**
168
+ * Get the id of _this_ reference style
169
+ * @returns
170
+ */
171
+ getId(): string {
172
+ return this.id;
173
+ }
174
+
175
+ /**
176
+ * Add a variant to _this_ reference style
177
+ * @param v
178
+ */
179
+ addVariant(v: MapStyleVariant) {
180
+ this.variants[v.getType()] = v;
181
+ this.orderedVariants.push(v);
182
+ }
183
+
184
+ /**
185
+ * Check if a given variant type exists for this reference style
186
+ * @param variantType
187
+ * @returns
188
+ */
189
+ hasVariant(variantType: string): boolean {
190
+ return variantType in this.variants;
191
+ }
192
+
193
+ /**
194
+ * Get a given variant. If the given type of variant does not exist for this reference style,
195
+ * then the most relevant default variant is returned instead
196
+ * @param variantType
197
+ * @returns
198
+ */
199
+ getVariant(variantType: string): MapStyleVariant {
200
+ return variantType in this.variants
201
+ ? this.variants[variantType]
202
+ : this.orderedVariants[0];
203
+ }
204
+
205
+ /**
206
+ * Get the list of variants for this reference style
207
+ * @returns
208
+ */
209
+ getVariants(): Array<MapStyleVariant> {
210
+ return Object.values(this.variants);
211
+ }
212
+
213
+ /**
214
+ * Get the defualt variant for this reference style
215
+ * @returns
216
+ */
217
+ getDefaultVariant(): MapStyleVariant {
218
+ return this.orderedVariants[0];
219
+ }
220
+ }
221
+
222
+ /**
223
+ * All the styles and variants maintained by MapTiler.
224
+ */
225
+ export type MapStyleType = {
226
+ /**
227
+ * Suitable for navigation, with high level of detail on urban areas, plenty of POIs and 3D buildings
228
+ */
229
+ STREETS: ReferenceMapStyle & {
230
+ /**
231
+ * Suitable for navigation, with high level of detail on urban areas, plenty of POIs and 3D buildings.
232
+ */
233
+ DEFAULT: MapStyleVariant;
234
+ /**
235
+ * Suitable for navigation, with high level of detail on urban areas, plenty of POIs and 3D buildings, in dark mode.
236
+ */
237
+ DARK: MapStyleVariant;
238
+ /**
239
+ * Suitable for navigation, with high level of detail on urban areas, plenty of POIs and 3D buildings, in light mode.
240
+ */
241
+ LIGHT: MapStyleVariant;
242
+ /**
243
+ * Suitable for navigation, with high level of detail on urban areas, plenty of POIs and 3D buildings, with a pastel color palette.
244
+ */
245
+ PASTEL: MapStyleVariant;
246
+ };
247
+
248
+ /**
249
+ * Suitable for outdoor activities. With elevation isolines and hillshading.
250
+ */
251
+ OUTDOOR: ReferenceMapStyle & {
252
+ /**
253
+ * Suitable for outdoor activities. With elevation isolines and hillshading.
254
+ */
255
+ DEFAULT: MapStyleVariant;
256
+ };
257
+
258
+ /**
259
+ * Suitabe for winter outdoor activities. With ski tracks, elevation isolines and hillshading.
260
+ */
261
+ WINTER: ReferenceMapStyle & {
262
+ /**
263
+ * Suitabe for winter outdoor activities. With ski tracks, elevation isolines and hillshading.
264
+ */
265
+ DEFAULT: MapStyleVariant;
266
+ };
267
+
268
+ /**
269
+ * High resolution imagery only, without any label.
270
+ */
271
+ SATELLITE: ReferenceMapStyle & {
272
+ /**
273
+ * High resolution imagery only, without any label.
274
+ */
275
+ DEFAULT: MapStyleVariant;
276
+ };
277
+
278
+ /**
279
+ * High resolution imagery with labels, political borders and roads.
280
+ */
281
+ HYBRID: ReferenceMapStyle & {
282
+ /**
283
+ * High resolution imagery with labels, political borders and roads.
284
+ */
285
+ DEFAULT: MapStyleVariant;
286
+ };
287
+
288
+ /**
289
+ * A minimalist street-oriented style without POI
290
+ */
291
+ BASIC: ReferenceMapStyle & {
292
+ /**
293
+ * A minimalist street-oriented style without POI
294
+ */
295
+ DEFAULT: MapStyleVariant;
296
+ /**
297
+ * A minimalist street-oriented style without POI, in dark mode
298
+ */
299
+ DARK: MapStyleVariant;
300
+ /**
301
+ * A minimalist street-oriented style without POI, in light mode
302
+ */
303
+ LIGHT: MapStyleVariant;
304
+ };
305
+
306
+ /**
307
+ * A bright street-oriented style, a nice alternative to `streets`
308
+ */
309
+ BRIGHT: ReferenceMapStyle & {
310
+ /**
311
+ * A bright street-oriented style, a nice alternative to `streets`
312
+ */
313
+ DEFAULT: MapStyleVariant;
314
+ /**
315
+ * A bright street-oriented style, a nice alternative to `streets`, in dark mode
316
+ */
317
+ DARK: MapStyleVariant;
318
+ /**
319
+ * A bright street-oriented style, a nice alternative to `streets`, in light mode
320
+ */
321
+ LIGHT: MapStyleVariant;
322
+ /**
323
+ * A bright street-oriented style, a nice alternative to `streets`, with a soft pastel color palette
324
+ */
325
+ PASTEL: MapStyleVariant;
326
+ };
327
+
328
+ /**
329
+ * Classic OpenStreetMap style
330
+ */
331
+ OPENSTREETMAP: ReferenceMapStyle & {
332
+ DEFAULT: MapStyleVariant;
333
+ };
334
+
335
+ /**
336
+ * A nice high-contrast, yet less saturated alternative to the `outdoor` style, with hillshading, 3D buildings and fairly high street details
337
+ */
338
+ TOPO: ReferenceMapStyle & {
339
+ /**
340
+ * A nice high-contrast, yet less saturated alternative to the `outdoor` style, with hillshading, 3D buildings and fairly high street details
341
+ */
342
+ DEFAULT: MapStyleVariant;
343
+ /**
344
+ * A nice high-contrast, and high saturation alternative to the `outdoor` style, with hillshading, 3D buildings and fairly high street details
345
+ */
346
+ SHINY: MapStyleVariant;
347
+ /**
348
+ * A nice low-contrast, alternative to the `outdoor` style, with hillshading, 3D buildings and fairly high street details, using a soft pastel color palette
349
+ */
350
+ PASTEL: MapStyleVariant;
351
+
352
+ /**
353
+ * A nice very high-contrast, yet less saturated alternative to the `outdoor` style, with hillshading, 3D buildings and fairly high street details
354
+ */
355
+ TOPOGRAPHIQUE: MapStyleVariant;
356
+ };
357
+
358
+ /**
359
+ * A nice alternative to `streets` with a soft color palette
360
+ */
361
+ VOYAGER: ReferenceMapStyle & {
362
+ /**
363
+ * A nice alternative to `streets` with a soft color palette
364
+ */
365
+ DEFAULT: MapStyleVariant;
366
+ /**
367
+ * A nice alternative to `streets`, in very dark mode
368
+ */
369
+ DARK: MapStyleVariant;
370
+ /**
371
+ * A nice alternative to `streets`, in light mode
372
+ */
373
+ LIGHT: MapStyleVariant;
374
+ /**
375
+ * A nice alternative to `streets` with a soft sepia color palette and vintage look
376
+ */
377
+ VINTAGE: MapStyleVariant;
378
+ };
379
+
380
+ /**
381
+ * A bold very high contrast black and white (no gray!) style for the city
382
+ */
383
+ TONER: ReferenceMapStyle & {
384
+ /**
385
+ * A bold very high contrast black and white (no gray!) style for the city
386
+ */
387
+ DEFAULT: MapStyleVariant;
388
+ /**
389
+ * A bold very high contrast black and white (no gray!) style for the city, without any label
390
+ */
391
+ BACKGROUND: MapStyleVariant;
392
+ /**
393
+ * A bold very high contrast, yet faded, style for the city
394
+ */
395
+ LITE: MapStyleVariant;
396
+ /**
397
+ * A bold very high contrast black and white (no gray!) style for the city, with no building, only roads!
398
+ */
399
+ LINES: MapStyleVariant;
400
+ };
401
+
402
+ /**
403
+ * Minimalist style, perfect for data visualization
404
+ */
405
+ STAGE: ReferenceMapStyle & {
406
+ /**
407
+ * Minimalist style, perfect for data visualization
408
+ */
409
+ DEFAULT: MapStyleVariant;
410
+
411
+ /**
412
+ * Minimalist style, perfect for data visualization in dark mode
413
+ */
414
+ DARK: MapStyleVariant;
415
+
416
+ /**
417
+ * Minimalist style, perfect for data visualization in light mode
418
+ */
419
+ LIGHT: MapStyleVariant;
420
+ };
421
+
422
+ /**
423
+ * Explore deep see trenches and mountains, with isolines and depth labels
424
+ */
425
+ OCEAN: ReferenceMapStyle & {
426
+ /**
427
+ * Explore deep see trenches and mountains, with isolines and depth labels
428
+ */
429
+ DEFAULT: MapStyleVariant;
430
+ };
431
+ };
432
+
433
+ export const mapStylePresetList: Array<MapStylePreset> = [
434
+ {
435
+ referenceStyleID: "STREETS",
436
+ name: "Streets",
437
+ description: "",
438
+ variants: [
439
+ {
440
+ id: "streets-v2",
441
+ name: "Default",
442
+ variantType: "DEFAULT",
443
+ description: "",
444
+ imageURL: "",
445
+ },
446
+ {
447
+ id: "streets-v2-dark",
448
+ name: "Dark",
449
+ variantType: "DARK",
450
+ description: "",
451
+ imageURL: "",
452
+ },
453
+ {
454
+ id: "streets-v2-light",
455
+ name: "Light",
456
+ variantType: "LIGHT",
457
+ description: "",
458
+ imageURL: "",
459
+ },
460
+ {
461
+ id: "streets-v2-pastel",
462
+ name: "Pastel",
463
+ variantType: "PASTEL",
464
+ description: "",
465
+ imageURL: "",
466
+ },
467
+ ],
468
+ },
469
+
470
+ {
471
+ referenceStyleID: "OUTDOOR",
472
+ name: "Outdoor",
473
+ description: "",
474
+ variants: [
475
+ {
476
+ id: "outdoor-v2",
477
+ name: "Default",
478
+ variantType: "DEFAULT",
479
+ description: "",
480
+ imageURL: "",
481
+ },
482
+ ],
483
+ },
484
+
485
+ {
486
+ referenceStyleID: "WINTER",
487
+ name: "Winter",
488
+ description: "",
489
+ variants: [
490
+ {
491
+ id: "winter-v2",
492
+ name: "Winter",
493
+ variantType: "DEFAULT",
494
+ description: "",
495
+ imageURL: "",
496
+ },
497
+ ],
498
+ },
499
+
500
+ {
501
+ referenceStyleID: "SATELLITE",
502
+ name: "Satellite",
503
+ description: "",
504
+ variants: [
505
+ {
506
+ id: "satellite",
507
+ name: "Default",
508
+ variantType: "DEFAULT",
509
+ description: "",
510
+ imageURL: "",
511
+ },
512
+ ],
513
+ },
514
+
515
+ {
516
+ referenceStyleID: "HYBRID",
517
+ name: "Hybrid",
518
+ description: "",
519
+ variants: [
520
+ {
521
+ id: "hybrid",
522
+ name: "Default",
523
+ variantType: "DEFAULT",
524
+ description: "",
525
+ imageURL: "",
526
+ },
527
+ ],
528
+ },
529
+
530
+ {
531
+ referenceStyleID: "BASIC",
532
+ name: "Basic",
533
+ description: "",
534
+ variants: [
535
+ {
536
+ id: "basic-v2",
537
+ name: "Default",
538
+ variantType: "DEFAULT",
539
+ description: "",
540
+ imageURL: "",
541
+ },
542
+ {
543
+ id: "basic-v2-dark",
544
+ name: "Dark",
545
+ variantType: "DARK",
546
+ description: "",
547
+ imageURL: "",
548
+ },
549
+ {
550
+ id: "basic-v2-light",
551
+ name: "Light",
552
+ variantType: "LIGHT",
553
+ description: "",
554
+ imageURL: "",
555
+ },
556
+ ],
557
+ },
558
+
559
+ {
560
+ referenceStyleID: "BRIGHT",
561
+ name: "Bright",
562
+ description: "",
563
+ variants: [
564
+ {
565
+ id: "bright-v2",
566
+ name: "Default",
567
+ variantType: "DEFAULT",
568
+ description: "",
569
+ imageURL: "",
570
+ },
571
+ {
572
+ id: "bright-v2-dark",
573
+ name: "Dark",
574
+ variantType: "DARK",
575
+ description: "",
576
+ imageURL: "",
577
+ },
578
+ {
579
+ id: "bright-v2-light",
580
+ name: "Light",
581
+ variantType: "LIGHT",
582
+ description: "",
583
+ imageURL: "",
584
+ },
585
+ {
586
+ id: "bright-v2-pastel",
587
+ name: "Pastel",
588
+ variantType: "PASTEL",
589
+ description: "",
590
+ imageURL: "",
591
+ },
592
+ ],
593
+ },
594
+
595
+ {
596
+ referenceStyleID: "OPENSTREETMAP",
597
+ name: "OpenStreetMap",
598
+ description: "",
599
+ variants: [
600
+ {
601
+ id: "openstreetmap",
602
+ name: "Default",
603
+ variantType: "DEFAULT",
604
+ description: "",
605
+ imageURL: "",
606
+ },
607
+ ],
608
+ },
609
+
610
+ {
611
+ referenceStyleID: "TOPO",
612
+ name: "Topo",
613
+ description: "",
614
+ variants: [
615
+ {
616
+ id: "topo-v2",
617
+ name: "Default",
618
+ variantType: "DEFAULT",
619
+ description: "",
620
+ imageURL: "",
621
+ },
622
+ {
623
+ id: "topo-v2-shiny",
624
+ name: "Shiny",
625
+ variantType: "SHINY",
626
+ description: "",
627
+ imageURL: "",
628
+ },
629
+ {
630
+ id: "topo-v2-pastel",
631
+ name: "Pastel",
632
+ variantType: "PASTEL",
633
+ description: "",
634
+ imageURL: "",
635
+ },
636
+ {
637
+ id: "topo-v2-topographique",
638
+ name: "Topographique",
639
+ variantType: "TOPOGRAPHIQUE",
640
+ description: "",
641
+ imageURL: "",
642
+ },
643
+ ],
644
+ },
645
+
646
+ {
647
+ referenceStyleID: "VOYAGER",
648
+ name: "Voyager",
649
+ description: "",
650
+ variants: [
651
+ {
652
+ id: "voyager-v2",
653
+ name: "Default",
654
+ variantType: "DEFAULT",
655
+ description: "",
656
+ imageURL: "",
657
+ },
658
+ {
659
+ id: "voyager-v2-darkmatter",
660
+ name: "Darkmatter",
661
+ variantType: "DARK",
662
+ description: "",
663
+ imageURL: "",
664
+ },
665
+ {
666
+ id: "voyager-v2-positron",
667
+ name: "Positron",
668
+ variantType: "LIGHT",
669
+ description: "",
670
+ imageURL: "",
671
+ },
672
+ {
673
+ id: "voyager-v2-vintage",
674
+ name: "Vintage",
675
+ variantType: "VINTAGE",
676
+ description: "",
677
+ imageURL: "",
678
+ },
679
+ ],
680
+ },
681
+
682
+ {
683
+ referenceStyleID: "TONER",
684
+ name: "Toner",
685
+ description: "",
686
+ variants: [
687
+ {
688
+ id: "toner-v2",
689
+ name: "Default",
690
+ variantType: "DEFAULT",
691
+ description: "",
692
+ imageURL: "",
693
+ },
694
+ {
695
+ id: "toner-v2-background",
696
+ name: "Background",
697
+ variantType: "BACKGROUND",
698
+ description: "",
699
+ imageURL: "",
700
+ },
701
+ {
702
+ id: "toner-v2-lite",
703
+ name: "Lite",
704
+ variantType: "LITE",
705
+ description: "",
706
+ imageURL: "",
707
+ },
708
+ {
709
+ id: "toner-v2-lines",
710
+ name: "Lines",
711
+ variantType: "LINES",
712
+ description: "",
713
+ imageURL: "",
714
+ },
715
+ ],
716
+ },
717
+
718
+ {
719
+ referenceStyleID: "STAGE",
720
+ name: "Stage",
721
+ description: "",
722
+ variants: [
723
+ {
724
+ id: "stage",
725
+ name: "Default",
726
+ variantType: "DEFAULT",
727
+ description: "",
728
+ imageURL: "",
729
+ },
730
+ {
731
+ id: "stage-dark",
732
+ name: "Dark",
733
+ variantType: "DARK",
734
+ description: "",
735
+ imageURL: "",
736
+ },
737
+ {
738
+ id: "stage-light",
739
+ name: "Light",
740
+ variantType: "LIGHT",
741
+ description: "",
742
+ imageURL: "",
743
+ },
744
+ ],
745
+ },
746
+
747
+ {
748
+ referenceStyleID: "OCEAN",
749
+ name: "Ocean",
750
+ description: "",
751
+ variants: [
752
+ {
753
+ id: "ocean",
754
+ name: "Default",
755
+ variantType: "DEFAULT",
756
+ description: "",
757
+ imageURL: "",
758
+ },
759
+ ],
760
+ },
761
+ ];
762
+
763
+ function makeReferenceStyleProxy(referenceStyle: ReferenceMapStyle) {
764
+ return new Proxy(referenceStyle, {
765
+ get(target, prop, receiver) {
766
+ if (target.hasVariant(prop as string)) {
767
+ return target.getVariant(prop as string);
768
+ }
769
+
770
+ // This variant does not exist for this style, but since it's full uppercase
771
+ // we guess that the dev tries to access a style variant. So instead of
772
+ // returning the default (STREETS.DEFAULT), we return the non-variant of the current style
773
+ if (prop.toString().toUpperCase() === (prop as string)) {
774
+ return referenceStyle.getDefaultVariant();
775
+ }
776
+
777
+ return Reflect.get(target, prop, receiver);
778
+ },
779
+ });
780
+ }
781
+
782
+ function buildMapStyles(): MapStyleType {
783
+ const mapStyle = {};
784
+
785
+ for (let i = 0; i < mapStylePresetList.length; i += 1) {
786
+ const refStyleInfo = mapStylePresetList[i];
787
+
788
+ const refStyle = makeReferenceStyleProxy(
789
+ new ReferenceMapStyle(refStyleInfo.name, refStyleInfo.referenceStyleID)
790
+ );
791
+
792
+ for (let j = 0; j < refStyleInfo.variants.length; j += 1) {
793
+ const variantInfo = refStyleInfo.variants[j];
794
+ const variant = new MapStyleVariant(
795
+ variantInfo.name, // name
796
+ variantInfo.variantType, // variantType
797
+ variantInfo.id, // id
798
+ refStyle, // referenceStyle
799
+ variantInfo.description,
800
+ variantInfo.imageURL // imageURL
801
+ );
802
+
803
+ refStyle.addVariant(variant);
804
+ }
805
+ mapStyle[refStyleInfo.referenceStyleID] = refStyle;
806
+ }
807
+ return mapStyle as MapStyleType;
808
+ }
809
+
810
+ export function styleToStyle(
811
+ style: string | ReferenceMapStyle | MapStyleVariant | null | undefined
812
+ ): string {
813
+ if (!style) {
814
+ return MapStyle[mapStylePresetList[0].referenceStyleID]
815
+ .getDefaultVariant()
816
+ .getId();
817
+ }
818
+
819
+ // If the provided style is a shorthand (eg. "streets-v2") then we make sure it's trimmed and lowercase
820
+ if (typeof style === "string" || style instanceof String) {
821
+ return style.trim().toLowerCase();
822
+ }
823
+
824
+ if (style instanceof MapStyleVariant) {
825
+ return style.getId();
826
+ }
827
+
828
+ if (style instanceof ReferenceMapStyle) {
829
+ return style.getDefaultVariant().getId();
830
+ }
831
+ }
832
+
833
+ /**
834
+ * Contains all the reference map style created by MapTiler team as well as all the variants.
835
+ * For example, `MapStyle.STREETS` and the variants:
836
+ * - `MapStyle.STREETS.DARK`
837
+ * - `MapStyle.STREETS.LIGHT`
838
+ * - `MapStyle.STREETS.PASTEL`
839
+ *
840
+ */
841
+ export const MapStyle: MapStyleType = buildMapStyles();