@maptiler/client 1.0.3 → 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 (72) hide show
  1. package/dist/maptiler-client.cjs +465 -21
  2. package/dist/maptiler-client.cjs.map +1 -1
  3. package/dist/maptiler-client.d.ts +395 -2
  4. package/dist/maptiler-client.min.mjs +1 -1
  5. package/dist/maptiler-client.mjs +461 -22
  6. package/dist/maptiler-client.mjs.map +1 -1
  7. package/dist/maptiler-client.umd.js +465 -21
  8. package/dist/maptiler-client.umd.js.map +1 -1
  9. package/dist/maptiler-client.umd.min.js +1 -1
  10. package/docs/assets/custom.css +28 -1
  11. package/docs/classes/config.ClientConfig.html +9 -9
  12. package/docs/classes/services_ServiceError.ServiceError.html +7 -7
  13. package/docs/functions/language.getAutoLanguageGeocoding.html +5 -5
  14. package/docs/functions/services_simplify.default.html +5 -5
  15. package/docs/index.html +98 -10
  16. package/docs/modules/config.html +5 -5
  17. package/docs/modules/language.html +5 -5
  18. package/docs/modules/services_ServiceError.html +5 -5
  19. package/docs/modules/services_coordinates.html +5 -5
  20. package/docs/modules/services_data.html +5 -5
  21. package/docs/modules/services_geocoding.html +5 -5
  22. package/docs/modules/services_geolocation.html +5 -5
  23. package/docs/modules/services_simplify.html +5 -5
  24. package/docs/modules/services_staticMaps.html +5 -5
  25. package/docs/modules.html +4 -4
  26. package/docs/types/config.FetchFunction.html +5 -5
  27. package/docs/types/language.LanguageGeocodingString.html +5 -5
  28. package/docs/types/services_coordinates.CoordinateExport.html +5 -5
  29. package/docs/types/services_coordinates.CoordinateGrid.html +5 -5
  30. package/docs/types/services_coordinates.CoordinateId.html +5 -5
  31. package/docs/types/services_coordinates.CoordinateSearch.html +5 -5
  32. package/docs/types/services_coordinates.CoordinateSearchResult.html +5 -5
  33. package/docs/types/services_coordinates.CoordinateTransformResult.html +5 -5
  34. package/docs/types/services_coordinates.CoordinateTransformation.html +5 -5
  35. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +5 -5
  36. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +5 -5
  37. package/docs/types/services_coordinates.XYZ.html +5 -5
  38. package/docs/types/services_data.GetDataOptions.html +5 -5
  39. package/docs/types/services_geocoding.Coordinates.html +5 -5
  40. package/docs/types/services_geocoding.FeatureHierarchy.html +5 -5
  41. package/docs/types/services_geocoding.GeocodingFeature.html +5 -5
  42. package/docs/types/services_geocoding.GeocodingOptions.html +5 -5
  43. package/docs/types/services_geocoding.GeocodingSearchResult.html +5 -5
  44. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +5 -5
  45. package/docs/types/services_geolocation.GeolocationInfoOptions.html +5 -5
  46. package/docs/types/services_geolocation.GeolocationResult.html +5 -5
  47. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +5 -5
  48. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +5 -5
  49. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +5 -5
  50. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +7 -7
  51. package/docs/types/services_staticMaps.StaticMapMarker.html +5 -5
  52. package/docs/variables/config.config.html +5 -5
  53. package/docs/variables/language.LanguageGeocoding.html +5 -5
  54. package/docs/variables/services_coordinates.coordinates.html +5 -5
  55. package/docs/variables/services_data.data.html +5 -5
  56. package/docs/variables/services_geocoding.geocoding.html +5 -5
  57. package/docs/variables/services_geolocation.geolocation.html +5 -5
  58. package/docs/variables/services_staticMaps.staticMaps.html +5 -5
  59. package/docsmd/README.md +143 -36
  60. package/docsmd/assets/custom.css +28 -1
  61. package/docsmd/classes/ClientConfig.md +5 -5
  62. package/docsmd/classes/MapStyleVariant.md +217 -0
  63. package/docsmd/classes/ReferenceMapStyle.md +169 -0
  64. package/docsmd/classes/ServiceError.md +3 -3
  65. package/examples/test-browser-umd.html +1 -1
  66. package/package.json +1 -1
  67. package/readme.md +64 -5
  68. package/src/index.ts +17 -0
  69. package/src/mapstyle.ts +841 -0
  70. package/src/services/staticMaps.ts +5 -4
  71. package/tsconfig.json +0 -1
  72. package/typedoc.css +28 -1
@@ -444,6 +444,445 @@
444
444
  get
445
445
  };
446
446
 
447
+ class MapStyleVariant {
448
+ constructor(name, variantType, id, referenceStyle, description, imageURL) {
449
+ this.name = name;
450
+ this.variantType = variantType;
451
+ this.id = id;
452
+ this.referenceStyle = referenceStyle;
453
+ this.description = description;
454
+ this.imageURL = imageURL;
455
+ }
456
+ getName() {
457
+ return this.name;
458
+ }
459
+ getFullName() {
460
+ return `${this.referenceStyle.getName()} ${this.name}`;
461
+ }
462
+ getType() {
463
+ return this.variantType;
464
+ }
465
+ getId() {
466
+ return this.id;
467
+ }
468
+ getDescription() {
469
+ return this.description;
470
+ }
471
+ getReferenceStyle() {
472
+ return this.referenceStyle;
473
+ }
474
+ hasVariant(variantType) {
475
+ return this.referenceStyle.hasVariant(variantType);
476
+ }
477
+ getVariant(variantType) {
478
+ return this.referenceStyle.getVariant(variantType);
479
+ }
480
+ getVariants() {
481
+ return this.referenceStyle.getVariants().filter((v) => v !== this);
482
+ }
483
+ getImageURL() {
484
+ return this.imageURL;
485
+ }
486
+ }
487
+ class ReferenceMapStyle {
488
+ constructor(name, id) {
489
+ this.name = name;
490
+ this.id = id;
491
+ this.variants = {};
492
+ this.orderedVariants = [];
493
+ }
494
+ getName() {
495
+ return this.name;
496
+ }
497
+ getId() {
498
+ return this.id;
499
+ }
500
+ addVariant(v) {
501
+ this.variants[v.getType()] = v;
502
+ this.orderedVariants.push(v);
503
+ }
504
+ hasVariant(variantType) {
505
+ return variantType in this.variants;
506
+ }
507
+ getVariant(variantType) {
508
+ return variantType in this.variants ? this.variants[variantType] : this.orderedVariants[0];
509
+ }
510
+ getVariants() {
511
+ return Object.values(this.variants);
512
+ }
513
+ getDefaultVariant() {
514
+ return this.orderedVariants[0];
515
+ }
516
+ }
517
+ const mapStylePresetList = [
518
+ {
519
+ referenceStyleID: "STREETS",
520
+ name: "Streets",
521
+ description: "",
522
+ variants: [
523
+ {
524
+ id: "streets-v2",
525
+ name: "Default",
526
+ variantType: "DEFAULT",
527
+ description: "",
528
+ imageURL: ""
529
+ },
530
+ {
531
+ id: "streets-v2-dark",
532
+ name: "Dark",
533
+ variantType: "DARK",
534
+ description: "",
535
+ imageURL: ""
536
+ },
537
+ {
538
+ id: "streets-v2-light",
539
+ name: "Light",
540
+ variantType: "LIGHT",
541
+ description: "",
542
+ imageURL: ""
543
+ },
544
+ {
545
+ id: "streets-v2-pastel",
546
+ name: "Pastel",
547
+ variantType: "PASTEL",
548
+ description: "",
549
+ imageURL: ""
550
+ }
551
+ ]
552
+ },
553
+ {
554
+ referenceStyleID: "OUTDOOR",
555
+ name: "Outdoor",
556
+ description: "",
557
+ variants: [
558
+ {
559
+ id: "outdoor-v2",
560
+ name: "Default",
561
+ variantType: "DEFAULT",
562
+ description: "",
563
+ imageURL: ""
564
+ }
565
+ ]
566
+ },
567
+ {
568
+ referenceStyleID: "WINTER",
569
+ name: "Winter",
570
+ description: "",
571
+ variants: [
572
+ {
573
+ id: "winter-v2",
574
+ name: "Winter",
575
+ variantType: "DEFAULT",
576
+ description: "",
577
+ imageURL: ""
578
+ }
579
+ ]
580
+ },
581
+ {
582
+ referenceStyleID: "SATELLITE",
583
+ name: "Satellite",
584
+ description: "",
585
+ variants: [
586
+ {
587
+ id: "satellite",
588
+ name: "Default",
589
+ variantType: "DEFAULT",
590
+ description: "",
591
+ imageURL: ""
592
+ }
593
+ ]
594
+ },
595
+ {
596
+ referenceStyleID: "HYBRID",
597
+ name: "Hybrid",
598
+ description: "",
599
+ variants: [
600
+ {
601
+ id: "hybrid",
602
+ name: "Default",
603
+ variantType: "DEFAULT",
604
+ description: "",
605
+ imageURL: ""
606
+ }
607
+ ]
608
+ },
609
+ {
610
+ referenceStyleID: "BASIC",
611
+ name: "Basic",
612
+ description: "",
613
+ variants: [
614
+ {
615
+ id: "basic-v2",
616
+ name: "Default",
617
+ variantType: "DEFAULT",
618
+ description: "",
619
+ imageURL: ""
620
+ },
621
+ {
622
+ id: "basic-v2-dark",
623
+ name: "Dark",
624
+ variantType: "DARK",
625
+ description: "",
626
+ imageURL: ""
627
+ },
628
+ {
629
+ id: "basic-v2-light",
630
+ name: "Light",
631
+ variantType: "LIGHT",
632
+ description: "",
633
+ imageURL: ""
634
+ }
635
+ ]
636
+ },
637
+ {
638
+ referenceStyleID: "BRIGHT",
639
+ name: "Bright",
640
+ description: "",
641
+ variants: [
642
+ {
643
+ id: "bright-v2",
644
+ name: "Default",
645
+ variantType: "DEFAULT",
646
+ description: "",
647
+ imageURL: ""
648
+ },
649
+ {
650
+ id: "bright-v2-dark",
651
+ name: "Dark",
652
+ variantType: "DARK",
653
+ description: "",
654
+ imageURL: ""
655
+ },
656
+ {
657
+ id: "bright-v2-light",
658
+ name: "Light",
659
+ variantType: "LIGHT",
660
+ description: "",
661
+ imageURL: ""
662
+ },
663
+ {
664
+ id: "bright-v2-pastel",
665
+ name: "Pastel",
666
+ variantType: "PASTEL",
667
+ description: "",
668
+ imageURL: ""
669
+ }
670
+ ]
671
+ },
672
+ {
673
+ referenceStyleID: "OPENSTREETMAP",
674
+ name: "OpenStreetMap",
675
+ description: "",
676
+ variants: [
677
+ {
678
+ id: "openstreetmap",
679
+ name: "Default",
680
+ variantType: "DEFAULT",
681
+ description: "",
682
+ imageURL: ""
683
+ }
684
+ ]
685
+ },
686
+ {
687
+ referenceStyleID: "TOPO",
688
+ name: "Topo",
689
+ description: "",
690
+ variants: [
691
+ {
692
+ id: "topo-v2",
693
+ name: "Default",
694
+ variantType: "DEFAULT",
695
+ description: "",
696
+ imageURL: ""
697
+ },
698
+ {
699
+ id: "topo-v2-shiny",
700
+ name: "Shiny",
701
+ variantType: "SHINY",
702
+ description: "",
703
+ imageURL: ""
704
+ },
705
+ {
706
+ id: "topo-v2-pastel",
707
+ name: "Pastel",
708
+ variantType: "PASTEL",
709
+ description: "",
710
+ imageURL: ""
711
+ },
712
+ {
713
+ id: "topo-v2-topographique",
714
+ name: "Topographique",
715
+ variantType: "TOPOGRAPHIQUE",
716
+ description: "",
717
+ imageURL: ""
718
+ }
719
+ ]
720
+ },
721
+ {
722
+ referenceStyleID: "VOYAGER",
723
+ name: "Voyager",
724
+ description: "",
725
+ variants: [
726
+ {
727
+ id: "voyager-v2",
728
+ name: "Default",
729
+ variantType: "DEFAULT",
730
+ description: "",
731
+ imageURL: ""
732
+ },
733
+ {
734
+ id: "voyager-v2-darkmatter",
735
+ name: "Darkmatter",
736
+ variantType: "DARK",
737
+ description: "",
738
+ imageURL: ""
739
+ },
740
+ {
741
+ id: "voyager-v2-positron",
742
+ name: "Positron",
743
+ variantType: "LIGHT",
744
+ description: "",
745
+ imageURL: ""
746
+ },
747
+ {
748
+ id: "voyager-v2-vintage",
749
+ name: "Vintage",
750
+ variantType: "VINTAGE",
751
+ description: "",
752
+ imageURL: ""
753
+ }
754
+ ]
755
+ },
756
+ {
757
+ referenceStyleID: "TONER",
758
+ name: "Toner",
759
+ description: "",
760
+ variants: [
761
+ {
762
+ id: "toner-v2",
763
+ name: "Default",
764
+ variantType: "DEFAULT",
765
+ description: "",
766
+ imageURL: ""
767
+ },
768
+ {
769
+ id: "toner-v2-background",
770
+ name: "Background",
771
+ variantType: "BACKGROUND",
772
+ description: "",
773
+ imageURL: ""
774
+ },
775
+ {
776
+ id: "toner-v2-lite",
777
+ name: "Lite",
778
+ variantType: "LITE",
779
+ description: "",
780
+ imageURL: ""
781
+ },
782
+ {
783
+ id: "toner-v2-lines",
784
+ name: "Lines",
785
+ variantType: "LINES",
786
+ description: "",
787
+ imageURL: ""
788
+ }
789
+ ]
790
+ },
791
+ {
792
+ referenceStyleID: "STAGE",
793
+ name: "Stage",
794
+ description: "",
795
+ variants: [
796
+ {
797
+ id: "stage",
798
+ name: "Default",
799
+ variantType: "DEFAULT",
800
+ description: "",
801
+ imageURL: ""
802
+ },
803
+ {
804
+ id: "stage-dark",
805
+ name: "Dark",
806
+ variantType: "DARK",
807
+ description: "",
808
+ imageURL: ""
809
+ },
810
+ {
811
+ id: "stage-light",
812
+ name: "Light",
813
+ variantType: "LIGHT",
814
+ description: "",
815
+ imageURL: ""
816
+ }
817
+ ]
818
+ },
819
+ {
820
+ referenceStyleID: "OCEAN",
821
+ name: "Ocean",
822
+ description: "",
823
+ variants: [
824
+ {
825
+ id: "ocean",
826
+ name: "Default",
827
+ variantType: "DEFAULT",
828
+ description: "",
829
+ imageURL: ""
830
+ }
831
+ ]
832
+ }
833
+ ];
834
+ function makeReferenceStyleProxy(referenceStyle) {
835
+ return new Proxy(referenceStyle, {
836
+ get(target, prop, receiver) {
837
+ if (target.hasVariant(prop)) {
838
+ return target.getVariant(prop);
839
+ }
840
+ if (prop.toString().toUpperCase() === prop) {
841
+ return referenceStyle.getDefaultVariant();
842
+ }
843
+ return Reflect.get(target, prop, receiver);
844
+ }
845
+ });
846
+ }
847
+ function buildMapStyles() {
848
+ const mapStyle = {};
849
+ for (let i = 0; i < mapStylePresetList.length; i += 1) {
850
+ const refStyleInfo = mapStylePresetList[i];
851
+ const refStyle = makeReferenceStyleProxy(
852
+ new ReferenceMapStyle(refStyleInfo.name, refStyleInfo.referenceStyleID)
853
+ );
854
+ for (let j = 0; j < refStyleInfo.variants.length; j += 1) {
855
+ const variantInfo = refStyleInfo.variants[j];
856
+ const variant = new MapStyleVariant(
857
+ variantInfo.name,
858
+ variantInfo.variantType,
859
+ variantInfo.id,
860
+ refStyle,
861
+ variantInfo.description,
862
+ variantInfo.imageURL
863
+ );
864
+ refStyle.addVariant(variant);
865
+ }
866
+ mapStyle[refStyleInfo.referenceStyleID] = refStyle;
867
+ }
868
+ return mapStyle;
869
+ }
870
+ function styleToStyle(style) {
871
+ if (!style) {
872
+ return MapStyle[mapStylePresetList[0].referenceStyleID].getDefaultVariant().getId();
873
+ }
874
+ if (typeof style === "string" || style instanceof String) {
875
+ return style.trim().toLowerCase();
876
+ }
877
+ if (style instanceof MapStyleVariant) {
878
+ return style.getId();
879
+ }
880
+ if (style instanceof ReferenceMapStyle) {
881
+ return style.getDefaultVariant().getId();
882
+ }
883
+ }
884
+ const MapStyle = buildMapStyles();
885
+
447
886
  function getSqSegDist(p, p1, p2) {
448
887
  let x = p1[0], y = p1[1], dx = p2[0] - x, dy = p2[1] - y;
449
888
  if (dx !== 0 || dy !== 0) {
@@ -514,12 +953,12 @@
514
953
  return str;
515
954
  }
516
955
  function centered(center, zoom, options = {}) {
517
- var _a, _b, _c, _d, _e, _f;
518
- const style = (_a = options.style) != null ? _a : defaults.mapStyle;
956
+ var _a, _b, _c, _d, _e;
957
+ const style = styleToStyle(options.style);
519
958
  const scale = options.hiDPI ? "@2x" : "";
520
- const format = (_b = options.format) != null ? _b : "png";
521
- let width = ~~((_c = options.width) != null ? _c : 1024);
522
- let height = ~~((_d = options.height) != null ? _d : 1024);
959
+ const format = (_a = options.format) != null ? _a : "png";
960
+ let width = ~~((_b = options.width) != null ? _b : 1024);
961
+ let height = ~~((_c = options.height) != null ? _c : 1024);
523
962
  if (options.hiDPI) {
524
963
  width = ~~(width / 2);
525
964
  height = ~~(height / 2);
@@ -549,7 +988,7 @@
549
988
  }
550
989
  if ("path" in options) {
551
990
  let pathStr = "";
552
- pathStr += `fill:${(_e = options.pathFillColor) != null ? _e : "none"}|`;
991
+ pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
553
992
  if ("pathStrokeColor" in options) {
554
993
  pathStr += `stroke:${options.pathStrokeColor}|`;
555
994
  }
@@ -560,16 +999,16 @@
560
999
  pathStr += simplifyAndStringify(options.path);
561
1000
  endpoint.searchParams.set("path", pathStr);
562
1001
  }
563
- endpoint.searchParams.set("key", (_f = options.apiKey) != null ? _f : config.apiKey);
1002
+ endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
564
1003
  return endpoint.toString();
565
1004
  }
566
1005
  function bounded(boundingBox, options = {}) {
567
- var _a, _b, _c, _d, _e, _f;
568
- const style = (_a = options.style) != null ? _a : defaults.mapStyle;
1006
+ var _a, _b, _c, _d, _e;
1007
+ const style = styleToStyle(options.style);
569
1008
  const scale = options.hiDPI ? "@2x" : "";
570
- const format = (_b = options.format) != null ? _b : "png";
571
- let width = ~~((_c = options.width) != null ? _c : 1024);
572
- let height = ~~((_d = options.height) != null ? _d : 1024);
1009
+ const format = (_a = options.format) != null ? _a : "png";
1010
+ let width = ~~((_b = options.width) != null ? _b : 1024);
1011
+ let height = ~~((_c = options.height) != null ? _c : 1024);
573
1012
  if (options.hiDPI) {
574
1013
  width = ~~(width / 2);
575
1014
  height = ~~(height / 2);
@@ -602,7 +1041,7 @@
602
1041
  }
603
1042
  if ("path" in options) {
604
1043
  let pathStr = "";
605
- pathStr += `fill:${(_e = options.pathFillColor) != null ? _e : "none"}|`;
1044
+ pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
606
1045
  if ("pathStrokeColor" in options) {
607
1046
  pathStr += `stroke:${options.pathStrokeColor}|`;
608
1047
  }
@@ -613,21 +1052,21 @@
613
1052
  pathStr += simplifyAndStringify(options.path);
614
1053
  endpoint.searchParams.set("path", pathStr);
615
1054
  }
616
- endpoint.searchParams.set("key", (_f = options.apiKey) != null ? _f : config.apiKey);
1055
+ endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
617
1056
  return endpoint.toString();
618
1057
  }
619
1058
  function automatic(options = {}) {
620
- var _a, _b, _c, _d, _e, _f;
1059
+ var _a, _b, _c, _d, _e;
621
1060
  if (!("markers" in options) && !("path" in options)) {
622
1061
  throw new Error(
623
1062
  "Automatic static maps require markers and/or path to be created."
624
1063
  );
625
1064
  }
626
- const style = (_a = options.style) != null ? _a : defaults.mapStyle;
1065
+ const style = styleToStyle(options.style);
627
1066
  const scale = options.hiDPI ? "@2x" : "";
628
- const format = (_b = options.format) != null ? _b : "png";
629
- let width = ~~((_c = options.width) != null ? _c : 1024);
630
- let height = ~~((_d = options.height) != null ? _d : 1024);
1067
+ const format = (_a = options.format) != null ? _a : "png";
1068
+ let width = ~~((_b = options.width) != null ? _b : 1024);
1069
+ let height = ~~((_c = options.height) != null ? _c : 1024);
631
1070
  if (options.hiDPI) {
632
1071
  width = ~~(width / 2);
633
1072
  height = ~~(height / 2);
@@ -662,7 +1101,7 @@
662
1101
  }
663
1102
  if ("path" in options) {
664
1103
  let pathStr = "";
665
- pathStr += `fill:${(_e = options.pathFillColor) != null ? _e : "none"}|`;
1104
+ pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
666
1105
  if ("pathStrokeColor" in options) {
667
1106
  pathStr += `stroke:${options.pathStrokeColor}|`;
668
1107
  }
@@ -673,7 +1112,7 @@
673
1112
  pathStr += simplifyAndStringify(options.path);
674
1113
  endpoint.searchParams.set("path", pathStr);
675
1114
  }
676
- endpoint.searchParams.set("key", (_f = options.apiKey) != null ? _f : config.apiKey);
1115
+ endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
677
1116
  return endpoint.toString();
678
1117
  }
679
1118
  const staticMaps = {
@@ -684,13 +1123,18 @@
684
1123
 
685
1124
  exports.ClientConfig = ClientConfig;
686
1125
  exports.LanguageGeocoding = LanguageGeocoding;
1126
+ exports.MapStyle = MapStyle;
1127
+ exports.MapStyleVariant = MapStyleVariant;
1128
+ exports.ReferenceMapStyle = ReferenceMapStyle;
687
1129
  exports.ServiceError = ServiceError;
688
1130
  exports.config = config;
689
1131
  exports.coordinates = coordinates;
690
1132
  exports.data = data;
691
1133
  exports.geocoding = geocoding;
692
1134
  exports.geolocation = geolocation;
1135
+ exports.mapStylePresetList = mapStylePresetList;
693
1136
  exports.staticMaps = staticMaps;
1137
+ exports.styleToStyle = styleToStyle;
694
1138
 
695
1139
  Object.defineProperty(exports, '__esModule', { value: true });
696
1140