@maptiler/client 1.0.3 → 1.1.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.
- package/dist/maptiler-client.cjs +586 -21
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +405 -2
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +582 -22
- package/dist/maptiler-client.mjs.map +1 -1
- package/dist/maptiler-client.umd.js +586 -21
- package/dist/maptiler-client.umd.js.map +1 -1
- package/dist/maptiler-client.umd.min.js +1 -1
- package/docs/assets/custom.css +28 -1
- package/docs/classes/config.ClientConfig.html +9 -9
- package/docs/classes/services_ServiceError.ServiceError.html +7 -7
- package/docs/functions/language.getAutoLanguageGeocoding.html +5 -5
- package/docs/functions/services_simplify.default.html +5 -5
- package/docs/index.html +111 -30
- package/docs/modules/config.html +5 -5
- package/docs/modules/language.html +5 -5
- package/docs/modules/services_ServiceError.html +5 -5
- package/docs/modules/services_coordinates.html +5 -5
- package/docs/modules/services_data.html +5 -5
- package/docs/modules/services_geocoding.html +5 -5
- package/docs/modules/services_geolocation.html +5 -5
- package/docs/modules/services_simplify.html +5 -5
- package/docs/modules/services_staticMaps.html +5 -5
- package/docs/modules.html +4 -4
- package/docs/types/config.FetchFunction.html +5 -5
- package/docs/types/language.LanguageGeocodingString.html +5 -5
- package/docs/types/services_coordinates.CoordinateExport.html +5 -5
- package/docs/types/services_coordinates.CoordinateGrid.html +5 -5
- package/docs/types/services_coordinates.CoordinateId.html +5 -5
- package/docs/types/services_coordinates.CoordinateSearch.html +5 -5
- package/docs/types/services_coordinates.CoordinateSearchResult.html +5 -5
- package/docs/types/services_coordinates.CoordinateTransformResult.html +5 -5
- package/docs/types/services_coordinates.CoordinateTransformation.html +5 -5
- package/docs/types/services_coordinates.CoordinatesSearchOptions.html +5 -5
- package/docs/types/services_coordinates.CoordinatesTransformOptions.html +5 -5
- package/docs/types/services_coordinates.XYZ.html +5 -5
- package/docs/types/services_data.GetDataOptions.html +5 -5
- package/docs/types/services_geocoding.Coordinates.html +5 -5
- package/docs/types/services_geocoding.FeatureHierarchy.html +5 -5
- package/docs/types/services_geocoding.GeocodingFeature.html +5 -5
- package/docs/types/services_geocoding.GeocodingOptions.html +5 -5
- package/docs/types/services_geocoding.GeocodingSearchResult.html +5 -5
- package/docs/types/services_geocoding.ReverseGeocodingOptions.html +5 -5
- package/docs/types/services_geolocation.GeolocationInfoOptions.html +5 -5
- package/docs/types/services_geolocation.GeolocationResult.html +5 -5
- package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +5 -5
- package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +5 -5
- package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +5 -5
- package/docs/types/services_staticMaps.StaticMapBaseOptions.html +7 -7
- package/docs/types/services_staticMaps.StaticMapMarker.html +5 -5
- package/docs/variables/config.config.html +5 -5
- package/docs/variables/language.LanguageGeocoding.html +5 -5
- package/docs/variables/services_coordinates.coordinates.html +5 -5
- package/docs/variables/services_data.data.html +5 -5
- package/docs/variables/services_geocoding.geocoding.html +5 -5
- package/docs/variables/services_geolocation.geolocation.html +5 -5
- package/docs/variables/services_staticMaps.staticMaps.html +5 -5
- package/docsmd/README.md +145 -36
- package/docsmd/assets/custom.css +28 -1
- package/docsmd/classes/ClientConfig.md +5 -5
- package/docsmd/classes/MapStyleVariant.md +234 -0
- package/docsmd/classes/ReferenceMapStyle.md +169 -0
- package/docsmd/classes/ServiceError.md +3 -3
- package/examples/test-browser-umd.html +1 -1
- package/package.json +1 -1
- package/readme.md +86 -27
- package/src/index.ts +17 -0
- package/src/mapstyle.ts +874 -0
- package/src/services/staticMaps.ts +5 -4
- package/tsconfig.json +0 -1
- package/typedoc.css +28 -1
package/dist/maptiler-client.mjs
CHANGED
|
@@ -9,18 +9,37 @@ function tryGettingFetch() {
|
|
|
9
9
|
}
|
|
10
10
|
class ClientConfig {
|
|
11
11
|
constructor() {
|
|
12
|
+
/**
|
|
13
|
+
* MapTiler Cloud API key
|
|
14
|
+
*/
|
|
12
15
|
this._apiKey = "";
|
|
16
|
+
/**
|
|
17
|
+
* The fetch function. To be set if in Node < 18, otherwise
|
|
18
|
+
* will be automatically resolved.
|
|
19
|
+
*/
|
|
13
20
|
this._fetch = tryGettingFetch();
|
|
14
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Set the MapTiler Cloud API key
|
|
24
|
+
*/
|
|
15
25
|
set apiKey(k) {
|
|
16
26
|
this._apiKey = k;
|
|
17
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the MapTiler Cloud API key
|
|
30
|
+
*/
|
|
18
31
|
get apiKey() {
|
|
19
32
|
return this._apiKey;
|
|
20
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Set a the custom fetch function to replace the default one
|
|
36
|
+
*/
|
|
21
37
|
set fetch(f) {
|
|
22
38
|
this._fetch = f;
|
|
23
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the fetch fucntion
|
|
42
|
+
*/
|
|
24
43
|
get fetch() {
|
|
25
44
|
return this._fetch;
|
|
26
45
|
}
|
|
@@ -438,6 +457,547 @@ const data = {
|
|
|
438
457
|
get
|
|
439
458
|
};
|
|
440
459
|
|
|
460
|
+
function expandMapStyle(style) {
|
|
461
|
+
const maptilerDomainRegex = /^maptiler:\/\/(.*)/;
|
|
462
|
+
let match;
|
|
463
|
+
const trimmed = style.trim();
|
|
464
|
+
let expandedStyle;
|
|
465
|
+
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
|
|
466
|
+
expandedStyle = trimmed;
|
|
467
|
+
} else if ((match = maptilerDomainRegex.exec(trimmed)) !== null) {
|
|
468
|
+
expandedStyle = `https://api.maptiler.com/maps/${match[1]}/style.json`;
|
|
469
|
+
} else {
|
|
470
|
+
expandedStyle = `https://api.maptiler.com/maps/${trimmed}/style.json`;
|
|
471
|
+
}
|
|
472
|
+
return expandedStyle;
|
|
473
|
+
}
|
|
474
|
+
class MapStyleVariant {
|
|
475
|
+
constructor(name, variantType, id, referenceStyle, description, imageURL) {
|
|
476
|
+
this.name = name;
|
|
477
|
+
this.variantType = variantType;
|
|
478
|
+
this.id = id;
|
|
479
|
+
this.referenceStyle = referenceStyle;
|
|
480
|
+
this.description = description;
|
|
481
|
+
this.imageURL = imageURL;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Get the human-friendly name
|
|
485
|
+
* @returns
|
|
486
|
+
*/
|
|
487
|
+
getName() {
|
|
488
|
+
return this.name;
|
|
489
|
+
}
|
|
490
|
+
getFullName() {
|
|
491
|
+
return `${this.referenceStyle.getName()} ${this.name}`;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Get the variant type (eg. "DEFAULT", "DARK", "PASTEL", etc.)
|
|
495
|
+
* @returns
|
|
496
|
+
*/
|
|
497
|
+
getType() {
|
|
498
|
+
return this.variantType;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Get the MapTiler Cloud id
|
|
502
|
+
* @returns
|
|
503
|
+
*/
|
|
504
|
+
getId() {
|
|
505
|
+
return this.id;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Get the human-friendly description
|
|
509
|
+
*/
|
|
510
|
+
getDescription() {
|
|
511
|
+
return this.description;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Get the reference style this variant belongs to
|
|
515
|
+
* @returns
|
|
516
|
+
*/
|
|
517
|
+
getReferenceStyle() {
|
|
518
|
+
return this.referenceStyle;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Check if a variant of a given type exists for _this_ variants
|
|
522
|
+
* (eg. if this is a "DARK", then we can check if there is a "LIGHT" variant of it)
|
|
523
|
+
* @param variantType
|
|
524
|
+
* @returns
|
|
525
|
+
*/
|
|
526
|
+
hasVariant(variantType) {
|
|
527
|
+
return this.referenceStyle.hasVariant(variantType);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Retrieve the variant of a given type. If not found, will return the "DEFAULT" variant.
|
|
531
|
+
* (eg. _this_ "DARK" variant does not have any "PASTEL" variant, then the "DEFAULT" is returned)
|
|
532
|
+
* @param variantType
|
|
533
|
+
* @returns
|
|
534
|
+
*/
|
|
535
|
+
getVariant(variantType) {
|
|
536
|
+
return this.referenceStyle.getVariant(variantType);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Get all the variants for _this_ variants, except _this_ current one
|
|
540
|
+
* @returns
|
|
541
|
+
*/
|
|
542
|
+
getVariants() {
|
|
543
|
+
return this.referenceStyle.getVariants().filter((v) => v !== this);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Get the image URL that represent _this_ variant
|
|
547
|
+
* @returns
|
|
548
|
+
*/
|
|
549
|
+
getImageURL() {
|
|
550
|
+
return this.imageURL;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Get the style as usable by MapLibre, a string (URL) or a plain style description (StyleSpecification)
|
|
554
|
+
* @returns
|
|
555
|
+
*/
|
|
556
|
+
getExpandedStyleURL() {
|
|
557
|
+
return expandMapStyle(this.getId());
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
class ReferenceMapStyle {
|
|
561
|
+
constructor(name, id) {
|
|
562
|
+
this.name = name;
|
|
563
|
+
this.id = id;
|
|
564
|
+
/**
|
|
565
|
+
* Variants that belong to this reference style, key being the reference type
|
|
566
|
+
*/
|
|
567
|
+
this.variants = {};
|
|
568
|
+
/**
|
|
569
|
+
* Variants that belong to this reference style, ordered by relevance
|
|
570
|
+
*/
|
|
571
|
+
this.orderedVariants = [];
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Get the human-friendly name of this reference style
|
|
575
|
+
* @returns
|
|
576
|
+
*/
|
|
577
|
+
getName() {
|
|
578
|
+
return this.name;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Get the id of _this_ reference style
|
|
582
|
+
* @returns
|
|
583
|
+
*/
|
|
584
|
+
getId() {
|
|
585
|
+
return this.id;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Add a variant to _this_ reference style
|
|
589
|
+
* @param v
|
|
590
|
+
*/
|
|
591
|
+
addVariant(v) {
|
|
592
|
+
this.variants[v.getType()] = v;
|
|
593
|
+
this.orderedVariants.push(v);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Check if a given variant type exists for this reference style
|
|
597
|
+
* @param variantType
|
|
598
|
+
* @returns
|
|
599
|
+
*/
|
|
600
|
+
hasVariant(variantType) {
|
|
601
|
+
return variantType in this.variants;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Get a given variant. If the given type of variant does not exist for this reference style,
|
|
605
|
+
* then the most relevant default variant is returned instead
|
|
606
|
+
* @param variantType
|
|
607
|
+
* @returns
|
|
608
|
+
*/
|
|
609
|
+
getVariant(variantType) {
|
|
610
|
+
return variantType in this.variants ? this.variants[variantType] : this.orderedVariants[0];
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Get the list of variants for this reference style
|
|
614
|
+
* @returns
|
|
615
|
+
*/
|
|
616
|
+
getVariants() {
|
|
617
|
+
return Object.values(this.variants);
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Get the defualt variant for this reference style
|
|
621
|
+
* @returns
|
|
622
|
+
*/
|
|
623
|
+
getDefaultVariant() {
|
|
624
|
+
return this.orderedVariants[0];
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const mapStylePresetList = [
|
|
628
|
+
{
|
|
629
|
+
referenceStyleID: "STREETS",
|
|
630
|
+
name: "Streets",
|
|
631
|
+
description: "",
|
|
632
|
+
variants: [
|
|
633
|
+
{
|
|
634
|
+
id: "streets-v2",
|
|
635
|
+
name: "Default",
|
|
636
|
+
variantType: "DEFAULT",
|
|
637
|
+
description: "",
|
|
638
|
+
imageURL: ""
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
id: "streets-v2-dark",
|
|
642
|
+
name: "Dark",
|
|
643
|
+
variantType: "DARK",
|
|
644
|
+
description: "",
|
|
645
|
+
imageURL: ""
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
id: "streets-v2-light",
|
|
649
|
+
name: "Light",
|
|
650
|
+
variantType: "LIGHT",
|
|
651
|
+
description: "",
|
|
652
|
+
imageURL: ""
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
id: "streets-v2-pastel",
|
|
656
|
+
name: "Pastel",
|
|
657
|
+
variantType: "PASTEL",
|
|
658
|
+
description: "",
|
|
659
|
+
imageURL: ""
|
|
660
|
+
}
|
|
661
|
+
]
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
referenceStyleID: "OUTDOOR",
|
|
665
|
+
name: "Outdoor",
|
|
666
|
+
description: "",
|
|
667
|
+
variants: [
|
|
668
|
+
{
|
|
669
|
+
id: "outdoor-v2",
|
|
670
|
+
name: "Default",
|
|
671
|
+
variantType: "DEFAULT",
|
|
672
|
+
description: "",
|
|
673
|
+
imageURL: ""
|
|
674
|
+
}
|
|
675
|
+
]
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
referenceStyleID: "WINTER",
|
|
679
|
+
name: "Winter",
|
|
680
|
+
description: "",
|
|
681
|
+
variants: [
|
|
682
|
+
{
|
|
683
|
+
id: "winter-v2",
|
|
684
|
+
name: "Winter",
|
|
685
|
+
variantType: "DEFAULT",
|
|
686
|
+
description: "",
|
|
687
|
+
imageURL: ""
|
|
688
|
+
}
|
|
689
|
+
]
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
referenceStyleID: "SATELLITE",
|
|
693
|
+
name: "Satellite",
|
|
694
|
+
description: "",
|
|
695
|
+
variants: [
|
|
696
|
+
{
|
|
697
|
+
id: "satellite",
|
|
698
|
+
name: "Default",
|
|
699
|
+
variantType: "DEFAULT",
|
|
700
|
+
description: "",
|
|
701
|
+
imageURL: ""
|
|
702
|
+
}
|
|
703
|
+
]
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
referenceStyleID: "HYBRID",
|
|
707
|
+
name: "Hybrid",
|
|
708
|
+
description: "",
|
|
709
|
+
variants: [
|
|
710
|
+
{
|
|
711
|
+
id: "hybrid",
|
|
712
|
+
name: "Default",
|
|
713
|
+
variantType: "DEFAULT",
|
|
714
|
+
description: "",
|
|
715
|
+
imageURL: ""
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
referenceStyleID: "BASIC",
|
|
721
|
+
name: "Basic",
|
|
722
|
+
description: "",
|
|
723
|
+
variants: [
|
|
724
|
+
{
|
|
725
|
+
id: "basic-v2",
|
|
726
|
+
name: "Default",
|
|
727
|
+
variantType: "DEFAULT",
|
|
728
|
+
description: "",
|
|
729
|
+
imageURL: ""
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
id: "basic-v2-dark",
|
|
733
|
+
name: "Dark",
|
|
734
|
+
variantType: "DARK",
|
|
735
|
+
description: "",
|
|
736
|
+
imageURL: ""
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
id: "basic-v2-light",
|
|
740
|
+
name: "Light",
|
|
741
|
+
variantType: "LIGHT",
|
|
742
|
+
description: "",
|
|
743
|
+
imageURL: ""
|
|
744
|
+
}
|
|
745
|
+
]
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
referenceStyleID: "BRIGHT",
|
|
749
|
+
name: "Bright",
|
|
750
|
+
description: "",
|
|
751
|
+
variants: [
|
|
752
|
+
{
|
|
753
|
+
id: "bright-v2",
|
|
754
|
+
name: "Default",
|
|
755
|
+
variantType: "DEFAULT",
|
|
756
|
+
description: "",
|
|
757
|
+
imageURL: ""
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
id: "bright-v2-dark",
|
|
761
|
+
name: "Dark",
|
|
762
|
+
variantType: "DARK",
|
|
763
|
+
description: "",
|
|
764
|
+
imageURL: ""
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
id: "bright-v2-light",
|
|
768
|
+
name: "Light",
|
|
769
|
+
variantType: "LIGHT",
|
|
770
|
+
description: "",
|
|
771
|
+
imageURL: ""
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
id: "bright-v2-pastel",
|
|
775
|
+
name: "Pastel",
|
|
776
|
+
variantType: "PASTEL",
|
|
777
|
+
description: "",
|
|
778
|
+
imageURL: ""
|
|
779
|
+
}
|
|
780
|
+
]
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
referenceStyleID: "OPENSTREETMAP",
|
|
784
|
+
name: "OpenStreetMap",
|
|
785
|
+
description: "",
|
|
786
|
+
variants: [
|
|
787
|
+
{
|
|
788
|
+
id: "openstreetmap",
|
|
789
|
+
name: "Default",
|
|
790
|
+
variantType: "DEFAULT",
|
|
791
|
+
description: "",
|
|
792
|
+
imageURL: ""
|
|
793
|
+
}
|
|
794
|
+
]
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
referenceStyleID: "TOPO",
|
|
798
|
+
name: "Topo",
|
|
799
|
+
description: "",
|
|
800
|
+
variants: [
|
|
801
|
+
{
|
|
802
|
+
id: "topo-v2",
|
|
803
|
+
name: "Default",
|
|
804
|
+
variantType: "DEFAULT",
|
|
805
|
+
description: "",
|
|
806
|
+
imageURL: ""
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
id: "topo-v2-shiny",
|
|
810
|
+
name: "Shiny",
|
|
811
|
+
variantType: "SHINY",
|
|
812
|
+
description: "",
|
|
813
|
+
imageURL: ""
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
id: "topo-v2-pastel",
|
|
817
|
+
name: "Pastel",
|
|
818
|
+
variantType: "PASTEL",
|
|
819
|
+
description: "",
|
|
820
|
+
imageURL: ""
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
id: "topo-v2-topographique",
|
|
824
|
+
name: "Topographique",
|
|
825
|
+
variantType: "TOPOGRAPHIQUE",
|
|
826
|
+
description: "",
|
|
827
|
+
imageURL: ""
|
|
828
|
+
}
|
|
829
|
+
]
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
referenceStyleID: "VOYAGER",
|
|
833
|
+
name: "Voyager",
|
|
834
|
+
description: "",
|
|
835
|
+
variants: [
|
|
836
|
+
{
|
|
837
|
+
id: "voyager-v2",
|
|
838
|
+
name: "Default",
|
|
839
|
+
variantType: "DEFAULT",
|
|
840
|
+
description: "",
|
|
841
|
+
imageURL: ""
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
id: "voyager-v2-darkmatter",
|
|
845
|
+
name: "Darkmatter",
|
|
846
|
+
variantType: "DARK",
|
|
847
|
+
description: "",
|
|
848
|
+
imageURL: ""
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
id: "voyager-v2-positron",
|
|
852
|
+
name: "Positron",
|
|
853
|
+
variantType: "LIGHT",
|
|
854
|
+
description: "",
|
|
855
|
+
imageURL: ""
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
id: "voyager-v2-vintage",
|
|
859
|
+
name: "Vintage",
|
|
860
|
+
variantType: "VINTAGE",
|
|
861
|
+
description: "",
|
|
862
|
+
imageURL: ""
|
|
863
|
+
}
|
|
864
|
+
]
|
|
865
|
+
},
|
|
866
|
+
{
|
|
867
|
+
referenceStyleID: "TONER",
|
|
868
|
+
name: "Toner",
|
|
869
|
+
description: "",
|
|
870
|
+
variants: [
|
|
871
|
+
{
|
|
872
|
+
id: "toner-v2",
|
|
873
|
+
name: "Default",
|
|
874
|
+
variantType: "DEFAULT",
|
|
875
|
+
description: "",
|
|
876
|
+
imageURL: ""
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
id: "toner-v2-background",
|
|
880
|
+
name: "Background",
|
|
881
|
+
variantType: "BACKGROUND",
|
|
882
|
+
description: "",
|
|
883
|
+
imageURL: ""
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
id: "toner-v2-lite",
|
|
887
|
+
name: "Lite",
|
|
888
|
+
variantType: "LITE",
|
|
889
|
+
description: "",
|
|
890
|
+
imageURL: ""
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
id: "toner-v2-lines",
|
|
894
|
+
name: "Lines",
|
|
895
|
+
variantType: "LINES",
|
|
896
|
+
description: "",
|
|
897
|
+
imageURL: ""
|
|
898
|
+
}
|
|
899
|
+
]
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
referenceStyleID: "STAGE",
|
|
903
|
+
name: "Stage",
|
|
904
|
+
description: "",
|
|
905
|
+
variants: [
|
|
906
|
+
{
|
|
907
|
+
id: "stage",
|
|
908
|
+
name: "Default",
|
|
909
|
+
variantType: "DEFAULT",
|
|
910
|
+
description: "",
|
|
911
|
+
imageURL: ""
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
id: "stage-dark",
|
|
915
|
+
name: "Dark",
|
|
916
|
+
variantType: "DARK",
|
|
917
|
+
description: "",
|
|
918
|
+
imageURL: ""
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
id: "stage-light",
|
|
922
|
+
name: "Light",
|
|
923
|
+
variantType: "LIGHT",
|
|
924
|
+
description: "",
|
|
925
|
+
imageURL: ""
|
|
926
|
+
}
|
|
927
|
+
]
|
|
928
|
+
},
|
|
929
|
+
{
|
|
930
|
+
referenceStyleID: "OCEAN",
|
|
931
|
+
name: "Ocean",
|
|
932
|
+
description: "",
|
|
933
|
+
variants: [
|
|
934
|
+
{
|
|
935
|
+
id: "ocean",
|
|
936
|
+
name: "Default",
|
|
937
|
+
variantType: "DEFAULT",
|
|
938
|
+
description: "",
|
|
939
|
+
imageURL: ""
|
|
940
|
+
}
|
|
941
|
+
]
|
|
942
|
+
}
|
|
943
|
+
];
|
|
944
|
+
function makeReferenceStyleProxy(referenceStyle) {
|
|
945
|
+
return new Proxy(referenceStyle, {
|
|
946
|
+
get(target, prop, receiver) {
|
|
947
|
+
if (target.hasVariant(prop)) {
|
|
948
|
+
return target.getVariant(prop);
|
|
949
|
+
}
|
|
950
|
+
if (prop.toString().toUpperCase() === prop) {
|
|
951
|
+
return referenceStyle.getDefaultVariant();
|
|
952
|
+
}
|
|
953
|
+
return Reflect.get(target, prop, receiver);
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
function buildMapStyles() {
|
|
958
|
+
const mapStyle = {};
|
|
959
|
+
for (let i = 0; i < mapStylePresetList.length; i += 1) {
|
|
960
|
+
const refStyleInfo = mapStylePresetList[i];
|
|
961
|
+
const refStyle = makeReferenceStyleProxy(
|
|
962
|
+
new ReferenceMapStyle(refStyleInfo.name, refStyleInfo.referenceStyleID)
|
|
963
|
+
);
|
|
964
|
+
for (let j = 0; j < refStyleInfo.variants.length; j += 1) {
|
|
965
|
+
const variantInfo = refStyleInfo.variants[j];
|
|
966
|
+
const variant = new MapStyleVariant(
|
|
967
|
+
variantInfo.name,
|
|
968
|
+
// name
|
|
969
|
+
variantInfo.variantType,
|
|
970
|
+
// variantType
|
|
971
|
+
variantInfo.id,
|
|
972
|
+
// id
|
|
973
|
+
refStyle,
|
|
974
|
+
// referenceStyle
|
|
975
|
+
variantInfo.description,
|
|
976
|
+
variantInfo.imageURL
|
|
977
|
+
// imageURL
|
|
978
|
+
);
|
|
979
|
+
refStyle.addVariant(variant);
|
|
980
|
+
}
|
|
981
|
+
mapStyle[refStyleInfo.referenceStyleID] = refStyle;
|
|
982
|
+
}
|
|
983
|
+
return mapStyle;
|
|
984
|
+
}
|
|
985
|
+
function styleToStyle(style) {
|
|
986
|
+
if (!style) {
|
|
987
|
+
return MapStyle[mapStylePresetList[0].referenceStyleID].getDefaultVariant().getId();
|
|
988
|
+
}
|
|
989
|
+
if (typeof style === "string" || style instanceof String) {
|
|
990
|
+
return style.trim().toLowerCase();
|
|
991
|
+
}
|
|
992
|
+
if (style instanceof MapStyleVariant) {
|
|
993
|
+
return style.getId();
|
|
994
|
+
}
|
|
995
|
+
if (style instanceof ReferenceMapStyle) {
|
|
996
|
+
return style.getDefaultVariant().getId();
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const MapStyle = buildMapStyles();
|
|
1000
|
+
|
|
441
1001
|
function getSqSegDist(p, p1, p2) {
|
|
442
1002
|
let x = p1[0], y = p1[1], dx = p2[0] - x, dy = p2[1] - y;
|
|
443
1003
|
if (dx !== 0 || dy !== 0) {
|
|
@@ -508,12 +1068,12 @@ function simplifyAndStringify(path, maxNbChar = 3e3) {
|
|
|
508
1068
|
return str;
|
|
509
1069
|
}
|
|
510
1070
|
function centered(center, zoom, options = {}) {
|
|
511
|
-
var _a, _b, _c, _d, _e
|
|
512
|
-
const style = (
|
|
1071
|
+
var _a, _b, _c, _d, _e;
|
|
1072
|
+
const style = styleToStyle(options.style);
|
|
513
1073
|
const scale = options.hiDPI ? "@2x" : "";
|
|
514
|
-
const format = (
|
|
515
|
-
let width = ~~((
|
|
516
|
-
let height = ~~((
|
|
1074
|
+
const format = (_a = options.format) != null ? _a : "png";
|
|
1075
|
+
let width = ~~((_b = options.width) != null ? _b : 1024);
|
|
1076
|
+
let height = ~~((_c = options.height) != null ? _c : 1024);
|
|
517
1077
|
if (options.hiDPI) {
|
|
518
1078
|
width = ~~(width / 2);
|
|
519
1079
|
height = ~~(height / 2);
|
|
@@ -543,7 +1103,7 @@ function centered(center, zoom, options = {}) {
|
|
|
543
1103
|
}
|
|
544
1104
|
if ("path" in options) {
|
|
545
1105
|
let pathStr = "";
|
|
546
|
-
pathStr += `fill:${(
|
|
1106
|
+
pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
|
|
547
1107
|
if ("pathStrokeColor" in options) {
|
|
548
1108
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
549
1109
|
}
|
|
@@ -554,16 +1114,16 @@ function centered(center, zoom, options = {}) {
|
|
|
554
1114
|
pathStr += simplifyAndStringify(options.path);
|
|
555
1115
|
endpoint.searchParams.set("path", pathStr);
|
|
556
1116
|
}
|
|
557
|
-
endpoint.searchParams.set("key", (
|
|
1117
|
+
endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
|
|
558
1118
|
return endpoint.toString();
|
|
559
1119
|
}
|
|
560
1120
|
function bounded(boundingBox, options = {}) {
|
|
561
|
-
var _a, _b, _c, _d, _e
|
|
562
|
-
const style = (
|
|
1121
|
+
var _a, _b, _c, _d, _e;
|
|
1122
|
+
const style = styleToStyle(options.style);
|
|
563
1123
|
const scale = options.hiDPI ? "@2x" : "";
|
|
564
|
-
const format = (
|
|
565
|
-
let width = ~~((
|
|
566
|
-
let height = ~~((
|
|
1124
|
+
const format = (_a = options.format) != null ? _a : "png";
|
|
1125
|
+
let width = ~~((_b = options.width) != null ? _b : 1024);
|
|
1126
|
+
let height = ~~((_c = options.height) != null ? _c : 1024);
|
|
567
1127
|
if (options.hiDPI) {
|
|
568
1128
|
width = ~~(width / 2);
|
|
569
1129
|
height = ~~(height / 2);
|
|
@@ -596,7 +1156,7 @@ function bounded(boundingBox, options = {}) {
|
|
|
596
1156
|
}
|
|
597
1157
|
if ("path" in options) {
|
|
598
1158
|
let pathStr = "";
|
|
599
|
-
pathStr += `fill:${(
|
|
1159
|
+
pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
|
|
600
1160
|
if ("pathStrokeColor" in options) {
|
|
601
1161
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
602
1162
|
}
|
|
@@ -607,21 +1167,21 @@ function bounded(boundingBox, options = {}) {
|
|
|
607
1167
|
pathStr += simplifyAndStringify(options.path);
|
|
608
1168
|
endpoint.searchParams.set("path", pathStr);
|
|
609
1169
|
}
|
|
610
|
-
endpoint.searchParams.set("key", (
|
|
1170
|
+
endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
|
|
611
1171
|
return endpoint.toString();
|
|
612
1172
|
}
|
|
613
1173
|
function automatic(options = {}) {
|
|
614
|
-
var _a, _b, _c, _d, _e
|
|
1174
|
+
var _a, _b, _c, _d, _e;
|
|
615
1175
|
if (!("markers" in options) && !("path" in options)) {
|
|
616
1176
|
throw new Error(
|
|
617
1177
|
"Automatic static maps require markers and/or path to be created."
|
|
618
1178
|
);
|
|
619
1179
|
}
|
|
620
|
-
const style = (
|
|
1180
|
+
const style = styleToStyle(options.style);
|
|
621
1181
|
const scale = options.hiDPI ? "@2x" : "";
|
|
622
|
-
const format = (
|
|
623
|
-
let width = ~~((
|
|
624
|
-
let height = ~~((
|
|
1182
|
+
const format = (_a = options.format) != null ? _a : "png";
|
|
1183
|
+
let width = ~~((_b = options.width) != null ? _b : 1024);
|
|
1184
|
+
let height = ~~((_c = options.height) != null ? _c : 1024);
|
|
625
1185
|
if (options.hiDPI) {
|
|
626
1186
|
width = ~~(width / 2);
|
|
627
1187
|
height = ~~(height / 2);
|
|
@@ -656,7 +1216,7 @@ function automatic(options = {}) {
|
|
|
656
1216
|
}
|
|
657
1217
|
if ("path" in options) {
|
|
658
1218
|
let pathStr = "";
|
|
659
|
-
pathStr += `fill:${(
|
|
1219
|
+
pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
|
|
660
1220
|
if ("pathStrokeColor" in options) {
|
|
661
1221
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
662
1222
|
}
|
|
@@ -667,7 +1227,7 @@ function automatic(options = {}) {
|
|
|
667
1227
|
pathStr += simplifyAndStringify(options.path);
|
|
668
1228
|
endpoint.searchParams.set("path", pathStr);
|
|
669
1229
|
}
|
|
670
|
-
endpoint.searchParams.set("key", (
|
|
1230
|
+
endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
|
|
671
1231
|
return endpoint.toString();
|
|
672
1232
|
}
|
|
673
1233
|
const staticMaps = {
|
|
@@ -676,5 +1236,5 @@ const staticMaps = {
|
|
|
676
1236
|
automatic
|
|
677
1237
|
};
|
|
678
1238
|
|
|
679
|
-
export { ClientConfig, LanguageGeocoding, ServiceError, config, coordinates, data, geocoding, geolocation, staticMaps };
|
|
1239
|
+
export { ClientConfig, LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, ServiceError, config, coordinates, data, expandMapStyle, geocoding, geolocation, mapStylePresetList, staticMaps };
|
|
680
1240
|
//# sourceMappingURL=maptiler-client.mjs.map
|