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