@maptiler/client 1.1.0 → 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 +122 -1
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +12 -2
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +122 -1
- package/dist/maptiler-client.mjs.map +1 -1
- package/dist/maptiler-client.umd.js +122 -1
- package/dist/maptiler-client.umd.js.map +1 -1
- package/dist/maptiler-client.umd.min.js +1 -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 +28 -35
- 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 +5 -5
- 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 +46 -44
- package/docsmd/classes/ClientConfig.md +5 -5
- package/docsmd/classes/MapStyleVariant.md +29 -12
- package/docsmd/classes/ReferenceMapStyle.md +9 -9
- package/docsmd/classes/ServiceError.md +3 -3
- package/package.json +1 -1
- package/readme.md +28 -28
- package/src/index.ts +2 -2
- package/src/mapstyle.ts +33 -0
|
@@ -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,20 @@
|
|
|
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
|
+
}
|
|
447
480
|
class MapStyleVariant {
|
|
448
481
|
constructor(name, variantType, id, referenceStyle, description, imageURL) {
|
|
449
482
|
this.name = name;
|
|
@@ -453,63 +486,146 @@
|
|
|
453
486
|
this.description = description;
|
|
454
487
|
this.imageURL = imageURL;
|
|
455
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Get the human-friendly name
|
|
491
|
+
* @returns
|
|
492
|
+
*/
|
|
456
493
|
getName() {
|
|
457
494
|
return this.name;
|
|
458
495
|
}
|
|
459
496
|
getFullName() {
|
|
460
497
|
return `${this.referenceStyle.getName()} ${this.name}`;
|
|
461
498
|
}
|
|
499
|
+
/**
|
|
500
|
+
* Get the variant type (eg. "DEFAULT", "DARK", "PASTEL", etc.)
|
|
501
|
+
* @returns
|
|
502
|
+
*/
|
|
462
503
|
getType() {
|
|
463
504
|
return this.variantType;
|
|
464
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Get the MapTiler Cloud id
|
|
508
|
+
* @returns
|
|
509
|
+
*/
|
|
465
510
|
getId() {
|
|
466
511
|
return this.id;
|
|
467
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* Get the human-friendly description
|
|
515
|
+
*/
|
|
468
516
|
getDescription() {
|
|
469
517
|
return this.description;
|
|
470
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Get the reference style this variant belongs to
|
|
521
|
+
* @returns
|
|
522
|
+
*/
|
|
471
523
|
getReferenceStyle() {
|
|
472
524
|
return this.referenceStyle;
|
|
473
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
|
+
*/
|
|
474
532
|
hasVariant(variantType) {
|
|
475
533
|
return this.referenceStyle.hasVariant(variantType);
|
|
476
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
|
+
*/
|
|
477
541
|
getVariant(variantType) {
|
|
478
542
|
return this.referenceStyle.getVariant(variantType);
|
|
479
543
|
}
|
|
544
|
+
/**
|
|
545
|
+
* Get all the variants for _this_ variants, except _this_ current one
|
|
546
|
+
* @returns
|
|
547
|
+
*/
|
|
480
548
|
getVariants() {
|
|
481
549
|
return this.referenceStyle.getVariants().filter((v) => v !== this);
|
|
482
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Get the image URL that represent _this_ variant
|
|
553
|
+
* @returns
|
|
554
|
+
*/
|
|
483
555
|
getImageURL() {
|
|
484
556
|
return this.imageURL;
|
|
485
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
|
+
}
|
|
486
565
|
}
|
|
487
566
|
class ReferenceMapStyle {
|
|
488
567
|
constructor(name, id) {
|
|
489
568
|
this.name = name;
|
|
490
569
|
this.id = id;
|
|
570
|
+
/**
|
|
571
|
+
* Variants that belong to this reference style, key being the reference type
|
|
572
|
+
*/
|
|
491
573
|
this.variants = {};
|
|
574
|
+
/**
|
|
575
|
+
* Variants that belong to this reference style, ordered by relevance
|
|
576
|
+
*/
|
|
492
577
|
this.orderedVariants = [];
|
|
493
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* Get the human-friendly name of this reference style
|
|
581
|
+
* @returns
|
|
582
|
+
*/
|
|
494
583
|
getName() {
|
|
495
584
|
return this.name;
|
|
496
585
|
}
|
|
586
|
+
/**
|
|
587
|
+
* Get the id of _this_ reference style
|
|
588
|
+
* @returns
|
|
589
|
+
*/
|
|
497
590
|
getId() {
|
|
498
591
|
return this.id;
|
|
499
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* Add a variant to _this_ reference style
|
|
595
|
+
* @param v
|
|
596
|
+
*/
|
|
500
597
|
addVariant(v) {
|
|
501
598
|
this.variants[v.getType()] = v;
|
|
502
599
|
this.orderedVariants.push(v);
|
|
503
600
|
}
|
|
601
|
+
/**
|
|
602
|
+
* Check if a given variant type exists for this reference style
|
|
603
|
+
* @param variantType
|
|
604
|
+
* @returns
|
|
605
|
+
*/
|
|
504
606
|
hasVariant(variantType) {
|
|
505
607
|
return variantType in this.variants;
|
|
506
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
|
+
*/
|
|
507
615
|
getVariant(variantType) {
|
|
508
616
|
return variantType in this.variants ? this.variants[variantType] : this.orderedVariants[0];
|
|
509
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* Get the list of variants for this reference style
|
|
620
|
+
* @returns
|
|
621
|
+
*/
|
|
510
622
|
getVariants() {
|
|
511
623
|
return Object.values(this.variants);
|
|
512
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Get the defualt variant for this reference style
|
|
627
|
+
* @returns
|
|
628
|
+
*/
|
|
513
629
|
getDefaultVariant() {
|
|
514
630
|
return this.orderedVariants[0];
|
|
515
631
|
}
|
|
@@ -855,11 +971,16 @@
|
|
|
855
971
|
const variantInfo = refStyleInfo.variants[j];
|
|
856
972
|
const variant = new MapStyleVariant(
|
|
857
973
|
variantInfo.name,
|
|
974
|
+
// name
|
|
858
975
|
variantInfo.variantType,
|
|
976
|
+
// variantType
|
|
859
977
|
variantInfo.id,
|
|
978
|
+
// id
|
|
860
979
|
refStyle,
|
|
980
|
+
// referenceStyle
|
|
861
981
|
variantInfo.description,
|
|
862
982
|
variantInfo.imageURL
|
|
983
|
+
// imageURL
|
|
863
984
|
);
|
|
864
985
|
refStyle.addVariant(variant);
|
|
865
986
|
}
|
|
@@ -1130,11 +1251,11 @@
|
|
|
1130
1251
|
exports.config = config;
|
|
1131
1252
|
exports.coordinates = coordinates;
|
|
1132
1253
|
exports.data = data;
|
|
1254
|
+
exports.expandMapStyle = expandMapStyle;
|
|
1133
1255
|
exports.geocoding = geocoding;
|
|
1134
1256
|
exports.geolocation = geolocation;
|
|
1135
1257
|
exports.mapStylePresetList = mapStylePresetList;
|
|
1136
1258
|
exports.staticMaps = staticMaps;
|
|
1137
|
-
exports.styleToStyle = styleToStyle;
|
|
1138
1259
|
|
|
1139
1260
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1140
1261
|
|