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