@maptiler/client 1.1.0 → 1.1.2

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 (69) hide show
  1. package/dist/maptiler-client.cjs +122 -1
  2. package/dist/maptiler-client.cjs.map +1 -1
  3. package/dist/maptiler-client.d.ts +12 -2
  4. package/dist/maptiler-client.min.mjs +1 -1
  5. package/dist/maptiler-client.mjs +122 -1
  6. package/dist/maptiler-client.mjs.map +1 -1
  7. package/dist/maptiler-client.umd.js +123 -2
  8. package/dist/maptiler-client.umd.js.map +1 -1
  9. package/dist/maptiler-client.umd.min.js +1 -1
  10. package/docs/classes/config.ClientConfig.html +9 -9
  11. package/docs/classes/services_ServiceError.ServiceError.html +7 -7
  12. package/docs/functions/language.getAutoLanguageGeocoding.html +5 -5
  13. package/docs/functions/services_simplify.default.html +5 -5
  14. package/docs/index.html +28 -35
  15. package/docs/modules/config.html +5 -5
  16. package/docs/modules/language.html +5 -5
  17. package/docs/modules/services_ServiceError.html +5 -5
  18. package/docs/modules/services_coordinates.html +5 -5
  19. package/docs/modules/services_data.html +5 -5
  20. package/docs/modules/services_geocoding.html +5 -5
  21. package/docs/modules/services_geolocation.html +5 -5
  22. package/docs/modules/services_simplify.html +5 -5
  23. package/docs/modules/services_staticMaps.html +5 -5
  24. package/docs/modules.html +4 -4
  25. package/docs/types/config.FetchFunction.html +5 -5
  26. package/docs/types/language.LanguageGeocodingString.html +5 -5
  27. package/docs/types/services_coordinates.CoordinateExport.html +5 -5
  28. package/docs/types/services_coordinates.CoordinateGrid.html +5 -5
  29. package/docs/types/services_coordinates.CoordinateId.html +5 -5
  30. package/docs/types/services_coordinates.CoordinateSearch.html +5 -5
  31. package/docs/types/services_coordinates.CoordinateSearchResult.html +5 -5
  32. package/docs/types/services_coordinates.CoordinateTransformResult.html +5 -5
  33. package/docs/types/services_coordinates.CoordinateTransformation.html +5 -5
  34. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +5 -5
  35. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +5 -5
  36. package/docs/types/services_coordinates.XYZ.html +5 -5
  37. package/docs/types/services_data.GetDataOptions.html +5 -5
  38. package/docs/types/services_geocoding.Coordinates.html +5 -5
  39. package/docs/types/services_geocoding.FeatureHierarchy.html +5 -5
  40. package/docs/types/services_geocoding.GeocodingFeature.html +5 -5
  41. package/docs/types/services_geocoding.GeocodingOptions.html +5 -5
  42. package/docs/types/services_geocoding.GeocodingSearchResult.html +5 -5
  43. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +5 -5
  44. package/docs/types/services_geolocation.GeolocationInfoOptions.html +5 -5
  45. package/docs/types/services_geolocation.GeolocationResult.html +5 -5
  46. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +5 -5
  47. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +5 -5
  48. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +5 -5
  49. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +5 -5
  50. package/docs/types/services_staticMaps.StaticMapMarker.html +5 -5
  51. package/docs/variables/config.config.html +5 -5
  52. package/docs/variables/language.LanguageGeocoding.html +5 -5
  53. package/docs/variables/services_coordinates.coordinates.html +5 -5
  54. package/docs/variables/services_data.data.html +5 -5
  55. package/docs/variables/services_geocoding.geocoding.html +5 -5
  56. package/docs/variables/services_geolocation.geolocation.html +5 -5
  57. package/docs/variables/services_staticMaps.staticMaps.html +5 -5
  58. package/docsmd/README.md +46 -44
  59. package/docsmd/classes/ClientConfig.md +5 -5
  60. package/docsmd/classes/MapStyleVariant.md +29 -12
  61. package/docsmd/classes/ReferenceMapStyle.md +9 -9
  62. package/docsmd/classes/ServiceError.md +3 -3
  63. package/examples/test-browser-es.html +2 -1
  64. package/examples/test-browser-umd.html +17 -16
  65. package/package.json +1 -1
  66. package/readme.md +28 -28
  67. package/rollup.config.js +2 -2
  68. package/src/index.ts +2 -2
  69. package/src/mapstyle.ts +33 -0
@@ -13,18 +13,37 @@ function tryGettingFetch() {
13
13
  }
14
14
  class ClientConfig {
15
15
  constructor() {
16
+ /**
17
+ * MapTiler Cloud API key
18
+ */
16
19
  this._apiKey = "";
20
+ /**
21
+ * The fetch function. To be set if in Node < 18, otherwise
22
+ * will be automatically resolved.
23
+ */
17
24
  this._fetch = tryGettingFetch();
18
25
  }
26
+ /**
27
+ * Set the MapTiler Cloud API key
28
+ */
19
29
  set apiKey(k) {
20
30
  this._apiKey = k;
21
31
  }
32
+ /**
33
+ * Get the MapTiler Cloud API key
34
+ */
22
35
  get apiKey() {
23
36
  return this._apiKey;
24
37
  }
38
+ /**
39
+ * Set a the custom fetch function to replace the default one
40
+ */
25
41
  set fetch(f) {
26
42
  this._fetch = f;
27
43
  }
44
+ /**
45
+ * Get the fetch fucntion
46
+ */
28
47
  get fetch() {
29
48
  return this._fetch;
30
49
  }
@@ -442,6 +461,20 @@ const data = {
442
461
  get
443
462
  };
444
463
 
464
+ function expandMapStyle(style) {
465
+ const maptilerDomainRegex = /^maptiler:\/\/(.*)/;
466
+ let match;
467
+ const trimmed = style.trim();
468
+ let expandedStyle;
469
+ if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
470
+ expandedStyle = trimmed;
471
+ } else if ((match = maptilerDomainRegex.exec(trimmed)) !== null) {
472
+ expandedStyle = `https://api.maptiler.com/maps/${match[1]}/style.json`;
473
+ } else {
474
+ expandedStyle = `https://api.maptiler.com/maps/${trimmed}/style.json`;
475
+ }
476
+ return expandedStyle;
477
+ }
445
478
  class MapStyleVariant {
446
479
  constructor(name, variantType, id, referenceStyle, description, imageURL) {
447
480
  this.name = name;
@@ -451,63 +484,146 @@ class MapStyleVariant {
451
484
  this.description = description;
452
485
  this.imageURL = imageURL;
453
486
  }
487
+ /**
488
+ * Get the human-friendly name
489
+ * @returns
490
+ */
454
491
  getName() {
455
492
  return this.name;
456
493
  }
457
494
  getFullName() {
458
495
  return `${this.referenceStyle.getName()} ${this.name}`;
459
496
  }
497
+ /**
498
+ * Get the variant type (eg. "DEFAULT", "DARK", "PASTEL", etc.)
499
+ * @returns
500
+ */
460
501
  getType() {
461
502
  return this.variantType;
462
503
  }
504
+ /**
505
+ * Get the MapTiler Cloud id
506
+ * @returns
507
+ */
463
508
  getId() {
464
509
  return this.id;
465
510
  }
511
+ /**
512
+ * Get the human-friendly description
513
+ */
466
514
  getDescription() {
467
515
  return this.description;
468
516
  }
517
+ /**
518
+ * Get the reference style this variant belongs to
519
+ * @returns
520
+ */
469
521
  getReferenceStyle() {
470
522
  return this.referenceStyle;
471
523
  }
524
+ /**
525
+ * Check if a variant of a given type exists for _this_ variants
526
+ * (eg. if this is a "DARK", then we can check if there is a "LIGHT" variant of it)
527
+ * @param variantType
528
+ * @returns
529
+ */
472
530
  hasVariant(variantType) {
473
531
  return this.referenceStyle.hasVariant(variantType);
474
532
  }
533
+ /**
534
+ * Retrieve the variant of a given type. If not found, will return the "DEFAULT" variant.
535
+ * (eg. _this_ "DARK" variant does not have any "PASTEL" variant, then the "DEFAULT" is returned)
536
+ * @param variantType
537
+ * @returns
538
+ */
475
539
  getVariant(variantType) {
476
540
  return this.referenceStyle.getVariant(variantType);
477
541
  }
542
+ /**
543
+ * Get all the variants for _this_ variants, except _this_ current one
544
+ * @returns
545
+ */
478
546
  getVariants() {
479
547
  return this.referenceStyle.getVariants().filter((v) => v !== this);
480
548
  }
549
+ /**
550
+ * Get the image URL that represent _this_ variant
551
+ * @returns
552
+ */
481
553
  getImageURL() {
482
554
  return this.imageURL;
483
555
  }
556
+ /**
557
+ * Get the style as usable by MapLibre, a string (URL) or a plain style description (StyleSpecification)
558
+ * @returns
559
+ */
560
+ getExpandedStyleURL() {
561
+ return expandMapStyle(this.getId());
562
+ }
484
563
  }
485
564
  class ReferenceMapStyle {
486
565
  constructor(name, id) {
487
566
  this.name = name;
488
567
  this.id = id;
568
+ /**
569
+ * Variants that belong to this reference style, key being the reference type
570
+ */
489
571
  this.variants = {};
572
+ /**
573
+ * Variants that belong to this reference style, ordered by relevance
574
+ */
490
575
  this.orderedVariants = [];
491
576
  }
577
+ /**
578
+ * Get the human-friendly name of this reference style
579
+ * @returns
580
+ */
492
581
  getName() {
493
582
  return this.name;
494
583
  }
584
+ /**
585
+ * Get the id of _this_ reference style
586
+ * @returns
587
+ */
495
588
  getId() {
496
589
  return this.id;
497
590
  }
591
+ /**
592
+ * Add a variant to _this_ reference style
593
+ * @param v
594
+ */
498
595
  addVariant(v) {
499
596
  this.variants[v.getType()] = v;
500
597
  this.orderedVariants.push(v);
501
598
  }
599
+ /**
600
+ * Check if a given variant type exists for this reference style
601
+ * @param variantType
602
+ * @returns
603
+ */
502
604
  hasVariant(variantType) {
503
605
  return variantType in this.variants;
504
606
  }
607
+ /**
608
+ * Get a given variant. If the given type of variant does not exist for this reference style,
609
+ * then the most relevant default variant is returned instead
610
+ * @param variantType
611
+ * @returns
612
+ */
505
613
  getVariant(variantType) {
506
614
  return variantType in this.variants ? this.variants[variantType] : this.orderedVariants[0];
507
615
  }
616
+ /**
617
+ * Get the list of variants for this reference style
618
+ * @returns
619
+ */
508
620
  getVariants() {
509
621
  return Object.values(this.variants);
510
622
  }
623
+ /**
624
+ * Get the defualt variant for this reference style
625
+ * @returns
626
+ */
511
627
  getDefaultVariant() {
512
628
  return this.orderedVariants[0];
513
629
  }
@@ -853,11 +969,16 @@ function buildMapStyles() {
853
969
  const variantInfo = refStyleInfo.variants[j];
854
970
  const variant = new MapStyleVariant(
855
971
  variantInfo.name,
972
+ // name
856
973
  variantInfo.variantType,
974
+ // variantType
857
975
  variantInfo.id,
976
+ // id
858
977
  refStyle,
978
+ // referenceStyle
859
979
  variantInfo.description,
860
980
  variantInfo.imageURL
981
+ // imageURL
861
982
  );
862
983
  refStyle.addVariant(variant);
863
984
  }
@@ -1128,9 +1249,9 @@ exports.ServiceError = ServiceError;
1128
1249
  exports.config = config;
1129
1250
  exports.coordinates = coordinates;
1130
1251
  exports.data = data;
1252
+ exports.expandMapStyle = expandMapStyle;
1131
1253
  exports.geocoding = geocoding;
1132
1254
  exports.geolocation = geolocation;
1133
1255
  exports.mapStylePresetList = mapStylePresetList;
1134
1256
  exports.staticMaps = staticMaps;
1135
- exports.styleToStyle = styleToStyle;
1136
1257
  //# sourceMappingURL=maptiler-client.cjs.map