maplibre-gl-basemap-control 0.14.0 → 0.14.3
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/README.md +3 -0
- package/dist/{BasemapControl-CKgYscxI.js → BasemapControl-CSw9YZ4S.js} +64 -26
- package/dist/BasemapControl-CSw9YZ4S.js.map +1 -0
- package/dist/{BasemapControl-DgR3c4ci.cjs → BasemapControl-nc1awj6S.cjs} +64 -26
- package/dist/BasemapControl-nc1awj6S.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +1 -1
- package/dist/types/lib/core/BasemapControl.d.ts +3 -0
- package/dist/types/lib/core/BasemapControl.d.ts.map +1 -1
- package/dist/types/lib/core/types.d.ts +2 -0
- package/dist/types/lib/core/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/BasemapControl-CKgYscxI.js.map +0 -1
- package/dist/BasemapControl-DgR3c4ci.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -152,6 +152,7 @@ destructive style change, so the missing key can be entered and the basemap retr
|
|
|
152
152
|
const control = new BasemapControl({
|
|
153
153
|
defaultBasemapId: 'maptiler-streets',
|
|
154
154
|
mapTilerApiKey: 'YOUR_MAPTILER_API_KEY',
|
|
155
|
+
cartoApiKey: 'YOUR_CARTO_API_KEY',
|
|
155
156
|
amazonApiKey: 'YOUR_AMAZON_LOCATION_API_KEY',
|
|
156
157
|
awsRegion: 'us-east-1',
|
|
157
158
|
mapboxAccessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
|
|
@@ -354,6 +355,7 @@ API key and load straight from `https://styles.maptoolkit.org/{styleId}.json`:
|
|
|
354
355
|
| `panelWidth` | `number` | `340` | Floating panel width in pixels |
|
|
355
356
|
| `className` | `string` | `''` | Extra class for the control button container |
|
|
356
357
|
| `mapTilerApiKey` | `string` | `undefined` | Initial MapTiler API key for built-in MapTiler styles |
|
|
358
|
+
| `cartoApiKey` | `string` | `undefined` | Initial CARTO API key for built-in CARTO raster basemaps |
|
|
357
359
|
| `amazonApiKey` | `string` | `undefined` | Initial Amazon Location API key for built-in Amazon styles |
|
|
358
360
|
| `awsRegion` | `string` | `'us-east-1'` | AWS region for built-in Amazon Location styles |
|
|
359
361
|
| `mapboxAccessToken` | `string` | `undefined` | Initial Mapbox access token for built-in Mapbox styles and the Mapbox Traffic overlay |
|
|
@@ -424,6 +426,7 @@ const control = new BasemapControl({
|
|
|
424
426
|
- `toggleBasemap(id)` - Add the raster basemap if inactive, otherwise remove it
|
|
425
427
|
- `isBasemapActive(id)` - Whether the basemap is currently active
|
|
426
428
|
- `setMapTilerApiKey(apiKey)` - Set or update the MapTiler API key used by MapTiler styles
|
|
429
|
+
- `setCartoApiKey(apiKey)` - Set or update the CARTO API key used by CARTO raster basemaps
|
|
427
430
|
- `setAmazonCredentials(apiKey, awsRegion)` - Set or update Amazon Location credentials
|
|
428
431
|
- `setMapboxAccessToken(accessToken)` - Set or update the Mapbox access token
|
|
429
432
|
- `setProtomapsApiKey(apiKey)` - Set or update the Protomaps API key used by Protomaps styles
|
|
@@ -661,10 +661,10 @@ const DEFAULT_BASEMAPS = [
|
|
|
661
661
|
description: "Light basemap for data overlays.",
|
|
662
662
|
attribution: CARTO_ATTRIBUTION,
|
|
663
663
|
tiles: [
|
|
664
|
-
"https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
|
|
665
|
-
"https://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
|
|
666
|
-
"https://c.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
|
|
667
|
-
"https://d.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
|
|
664
|
+
"https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png?key={api-key}",
|
|
665
|
+
"https://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png?key={api-key}",
|
|
666
|
+
"https://c.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png?key={api-key}",
|
|
667
|
+
"https://d.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png?key={api-key}"
|
|
668
668
|
],
|
|
669
669
|
maxzoom: 20,
|
|
670
670
|
tags: ["carto", "light", "positron"]
|
|
@@ -676,7 +676,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
676
676
|
category: "Light",
|
|
677
677
|
description: "Light basemap without labels.",
|
|
678
678
|
attribution: CARTO_ATTRIBUTION,
|
|
679
|
-
tiles: ["https://a.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png"],
|
|
679
|
+
tiles: ["https://a.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png?key={api-key}"],
|
|
680
680
|
maxzoom: 20,
|
|
681
681
|
tags: ["carto", "light", "no labels"]
|
|
682
682
|
}),
|
|
@@ -688,7 +688,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
688
688
|
description: "Carto Positron labels layer.",
|
|
689
689
|
attribution: CARTO_ATTRIBUTION,
|
|
690
690
|
tiles: [
|
|
691
|
-
"https://a.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png"
|
|
691
|
+
"https://a.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png?key={api-key}"
|
|
692
692
|
],
|
|
693
693
|
maxzoom: 20,
|
|
694
694
|
tags: ["carto", "labels"]
|
|
@@ -701,10 +701,10 @@ const DEFAULT_BASEMAPS = [
|
|
|
701
701
|
description: "Dark basemap for high-contrast overlays.",
|
|
702
702
|
attribution: CARTO_ATTRIBUTION,
|
|
703
703
|
tiles: [
|
|
704
|
-
"https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
|
|
705
|
-
"https://b.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
|
|
706
|
-
"https://c.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
|
|
707
|
-
"https://d.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"
|
|
704
|
+
"https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png?key={api-key}",
|
|
705
|
+
"https://b.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png?key={api-key}",
|
|
706
|
+
"https://c.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png?key={api-key}",
|
|
707
|
+
"https://d.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png?key={api-key}"
|
|
708
708
|
],
|
|
709
709
|
maxzoom: 20,
|
|
710
710
|
tags: ["carto", "dark", "matter"]
|
|
@@ -716,7 +716,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
716
716
|
category: "Dark",
|
|
717
717
|
description: "Dark basemap without labels.",
|
|
718
718
|
attribution: CARTO_ATTRIBUTION,
|
|
719
|
-
tiles: ["https://a.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png"],
|
|
719
|
+
tiles: ["https://a.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png?key={api-key}"],
|
|
720
720
|
maxzoom: 20,
|
|
721
721
|
tags: ["carto", "dark", "no labels"]
|
|
722
722
|
}),
|
|
@@ -727,7 +727,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
727
727
|
category: "Labels",
|
|
728
728
|
description: "Carto Dark Matter labels layer.",
|
|
729
729
|
attribution: CARTO_ATTRIBUTION,
|
|
730
|
-
tiles: ["https://a.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}.png"],
|
|
730
|
+
tiles: ["https://a.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}.png?key={api-key}"],
|
|
731
731
|
maxzoom: 20,
|
|
732
732
|
tags: ["carto", "dark", "labels"]
|
|
733
733
|
}),
|
|
@@ -739,10 +739,10 @@ const DEFAULT_BASEMAPS = [
|
|
|
739
739
|
description: "Detailed street basemap with subtle styling.",
|
|
740
740
|
attribution: CARTO_ATTRIBUTION,
|
|
741
741
|
tiles: [
|
|
742
|
-
"https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",
|
|
743
|
-
"https://b.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",
|
|
744
|
-
"https://c.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",
|
|
745
|
-
"https://d.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png"
|
|
742
|
+
"https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png?key={api-key}",
|
|
743
|
+
"https://b.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png?key={api-key}",
|
|
744
|
+
"https://c.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png?key={api-key}",
|
|
745
|
+
"https://d.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png?key={api-key}"
|
|
746
746
|
],
|
|
747
747
|
maxzoom: 20,
|
|
748
748
|
tags: ["carto", "street", "voyager"]
|
|
@@ -755,7 +755,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
755
755
|
description: "Carto Voyager without labels.",
|
|
756
756
|
attribution: CARTO_ATTRIBUTION,
|
|
757
757
|
tiles: [
|
|
758
|
-
"https://a.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png"
|
|
758
|
+
"https://a.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png?key={api-key}"
|
|
759
759
|
],
|
|
760
760
|
maxzoom: 20,
|
|
761
761
|
tags: ["carto", "voyager", "no labels"]
|
|
@@ -768,7 +768,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
768
768
|
description: "Carto Voyager labels layer.",
|
|
769
769
|
attribution: CARTO_ATTRIBUTION,
|
|
770
770
|
tiles: [
|
|
771
|
-
"https://a.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}.png"
|
|
771
|
+
"https://a.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}.png?key={api-key}"
|
|
772
772
|
],
|
|
773
773
|
maxzoom: 20,
|
|
774
774
|
tags: ["carto", "voyager", "labels"]
|
|
@@ -781,7 +781,7 @@ const DEFAULT_BASEMAPS = [
|
|
|
781
781
|
description: "Carto Voyager labels-under variant.",
|
|
782
782
|
attribution: CARTO_ATTRIBUTION,
|
|
783
783
|
tiles: [
|
|
784
|
-
"https://a.basemaps.cartocdn.com/rastertiles/voyager_labels_under/{z}/{x}/{y}.png"
|
|
784
|
+
"https://a.basemaps.cartocdn.com/rastertiles/voyager_labels_under/{z}/{x}/{y}.png?key={api-key}"
|
|
785
785
|
],
|
|
786
786
|
maxzoom: 20,
|
|
787
787
|
tags: ["carto", "voyager", "labels"]
|
|
@@ -1888,6 +1888,10 @@ const MAPTILER_API_KEY_QUERY = "?key";
|
|
|
1888
1888
|
const MAPTILER_API_KEY_EMPTY_QUERY = "?key=";
|
|
1889
1889
|
const AWS_REGION_PLACEHOLDER = "{aws-region}";
|
|
1890
1890
|
const PROVIDER_CREDENTIAL_HELP = {
|
|
1891
|
+
carto: {
|
|
1892
|
+
url: "https://carto.com/basemaps/apikey/",
|
|
1893
|
+
label: "Get a CARTO API key"
|
|
1894
|
+
},
|
|
1891
1895
|
amazon: {
|
|
1892
1896
|
url: "https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html",
|
|
1893
1897
|
label: "Get an Amazon API key"
|
|
@@ -1926,6 +1930,7 @@ const PROVIDER_CREDENTIAL_HELP = {
|
|
|
1926
1930
|
}
|
|
1927
1931
|
};
|
|
1928
1932
|
const RASTER_KEY_LABELS = {
|
|
1933
|
+
carto: "CARTO API key",
|
|
1929
1934
|
google: "Google Maps API key",
|
|
1930
1935
|
here: "HERE API key",
|
|
1931
1936
|
stadia: "Stadia Maps API key",
|
|
@@ -1985,6 +1990,7 @@ class BasemapControl {
|
|
|
1985
1990
|
// stacked raster overlay so each can be added or removed independently.
|
|
1986
1991
|
__publicField(this, "_managedRasters", new globalThis.Map());
|
|
1987
1992
|
__publicField(this, "_mapTilerApiKey", "");
|
|
1993
|
+
__publicField(this, "_cartoApiKey", "");
|
|
1988
1994
|
__publicField(this, "_amazonApiKey", "");
|
|
1989
1995
|
__publicField(this, "_awsRegion", "");
|
|
1990
1996
|
__publicField(this, "_mapboxAccessToken", "");
|
|
@@ -2050,6 +2056,7 @@ class BasemapControl {
|
|
|
2050
2056
|
});
|
|
2051
2057
|
this._options = { ...DEFAULT_OPTIONS, ...options };
|
|
2052
2058
|
this._mapTilerApiKey = (options == null ? void 0 : options.mapTilerApiKey) ?? "";
|
|
2059
|
+
this._cartoApiKey = (options == null ? void 0 : options.cartoApiKey) ?? "";
|
|
2053
2060
|
this._amazonApiKey = (options == null ? void 0 : options.amazonApiKey) ?? "";
|
|
2054
2061
|
this._awsRegion = (options == null ? void 0 : options.awsRegion) ?? "us-east-1";
|
|
2055
2062
|
this._mapboxAccessToken = (options == null ? void 0 : options.mapboxAccessToken) ?? "";
|
|
@@ -2174,6 +2181,12 @@ class BasemapControl {
|
|
|
2174
2181
|
this._renderContent();
|
|
2175
2182
|
this._emit({ type: "statechange", state: this.getState() });
|
|
2176
2183
|
}
|
|
2184
|
+
setCartoApiKey(apiKey) {
|
|
2185
|
+
this._cartoApiKey = apiKey;
|
|
2186
|
+
this._clearError();
|
|
2187
|
+
this._renderContent();
|
|
2188
|
+
this._emit({ type: "statechange", state: this.getState() });
|
|
2189
|
+
}
|
|
2177
2190
|
setAmazonCredentials(apiKey, awsRegion = this._awsRegion) {
|
|
2178
2191
|
this._amazonApiKey = apiKey;
|
|
2179
2192
|
this._awsRegion = awsRegion;
|
|
@@ -2317,12 +2330,16 @@ class BasemapControl {
|
|
|
2317
2330
|
let resolvedStyleUrl;
|
|
2318
2331
|
if (isOverlay) {
|
|
2319
2332
|
await this._waitForStyleReady();
|
|
2333
|
+
const resolvedRasterTiles = basemap.source.type === "raster" ? await this._resolveRasterTiles(basemap) : void 0;
|
|
2334
|
+
if (basemap.source.type === "vector-overlay") {
|
|
2335
|
+
this._resolveVectorOverlaySource(basemap, basemap.source);
|
|
2336
|
+
}
|
|
2320
2337
|
if (effectiveMode === "replace") {
|
|
2321
2338
|
this._removeManagedBasemap();
|
|
2322
2339
|
} else {
|
|
2323
2340
|
this._removeManagedRaster(basemap.id);
|
|
2324
2341
|
}
|
|
2325
|
-
managedRaster = await this._addOverlay(basemap);
|
|
2342
|
+
managedRaster = await this._addOverlay(basemap, resolvedRasterTiles);
|
|
2326
2343
|
} else {
|
|
2327
2344
|
const styleUrl = this._resolveStyleUrl(basemap);
|
|
2328
2345
|
resolvedStyleUrl = styleUrl;
|
|
@@ -2779,6 +2796,23 @@ class BasemapControl {
|
|
|
2779
2796
|
// missing-credential error, so the two never drift (#837).
|
|
2780
2797
|
_providerFieldDefs() {
|
|
2781
2798
|
return [
|
|
2799
|
+
{
|
|
2800
|
+
provider: "carto",
|
|
2801
|
+
label: "CARTO",
|
|
2802
|
+
has: this._hasCartoBasemaps(),
|
|
2803
|
+
fields: [
|
|
2804
|
+
{
|
|
2805
|
+
className: "basemap-control-carto-key",
|
|
2806
|
+
type: "password",
|
|
2807
|
+
placeholder: "CARTO API key",
|
|
2808
|
+
ariaLabel: "CARTO API key",
|
|
2809
|
+
value: this._cartoApiKey,
|
|
2810
|
+
onInput: (value) => {
|
|
2811
|
+
this._cartoApiKey = value;
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
]
|
|
2815
|
+
},
|
|
2782
2816
|
{
|
|
2783
2817
|
provider: "maptiler",
|
|
2784
2818
|
label: "MapTiler",
|
|
@@ -3280,6 +3314,9 @@ class BasemapControl {
|
|
|
3280
3314
|
_hasProtomapsBasemaps() {
|
|
3281
3315
|
return this._basemaps.some((basemap) => basemap.provider === "protomaps");
|
|
3282
3316
|
}
|
|
3317
|
+
_hasCartoBasemaps() {
|
|
3318
|
+
return this._basemaps.some((basemap) => basemap.provider === "carto");
|
|
3319
|
+
}
|
|
3283
3320
|
_hasStadiaBasemaps() {
|
|
3284
3321
|
return this._basemaps.some((basemap) => basemap.provider === "stadia");
|
|
3285
3322
|
}
|
|
@@ -3302,7 +3339,7 @@ class BasemapControl {
|
|
|
3302
3339
|
);
|
|
3303
3340
|
}
|
|
3304
3341
|
_hasProviderSettings() {
|
|
3305
|
-
return this._hasMapTilerBasemaps() || this._hasAmazonBasemaps() || this._hasMapboxBasemaps() || this._hasProtomapsBasemaps() || this._hasStadiaBasemaps() || this._hasTiandituBasemaps() || this._hasTomTomBasemaps() || this._hasHereBasemaps() || this._hasGoogleApiKeyBasemaps();
|
|
3342
|
+
return this._hasMapTilerBasemaps() || this._hasCartoBasemaps() || this._hasAmazonBasemaps() || this._hasMapboxBasemaps() || this._hasProtomapsBasemaps() || this._hasStadiaBasemaps() || this._hasTiandituBasemaps() || this._hasTomTomBasemaps() || this._hasHereBasemaps() || this._hasGoogleApiKeyBasemaps();
|
|
3306
3343
|
}
|
|
3307
3344
|
_resolveStyleUrl(basemap) {
|
|
3308
3345
|
if (basemap.source.type !== "style" && basemap.source.type !== "vector-style") {
|
|
@@ -3449,15 +3486,15 @@ class BasemapControl {
|
|
|
3449
3486
|
}
|
|
3450
3487
|
// Add a stackable overlay (raster tiles or a vector overlay) to the map,
|
|
3451
3488
|
// resolving any provider credentials first.
|
|
3452
|
-
async _addOverlay(basemap) {
|
|
3489
|
+
async _addOverlay(basemap, resolvedRasterTiles) {
|
|
3453
3490
|
if (basemap.source.type === "vector-overlay") {
|
|
3454
3491
|
return this._addVectorOverlay(basemap, basemap.source);
|
|
3455
3492
|
}
|
|
3456
|
-
return this._addRasterBasemap(basemap);
|
|
3493
|
+
return this._addRasterBasemap(basemap, resolvedRasterTiles);
|
|
3457
3494
|
}
|
|
3458
|
-
async _addRasterBasemap(basemap) {
|
|
3495
|
+
async _addRasterBasemap(basemap, resolvedTiles) {
|
|
3459
3496
|
if (!this._map || basemap.source.type !== "raster") return void 0;
|
|
3460
|
-
const tiles = await this._resolveRasterTiles(basemap);
|
|
3497
|
+
const tiles = resolvedTiles ?? await this._resolveRasterTiles(basemap);
|
|
3461
3498
|
const sourceId = `${CONTROL_SOURCE_PREFIX}-${basemap.id}`;
|
|
3462
3499
|
const layerId = [CONTROL_LAYER_PREFIX, basemap.id].filter(Boolean).join("-");
|
|
3463
3500
|
const beforeId = this._getBasemapInsertBeforeId();
|
|
@@ -3559,6 +3596,7 @@ class BasemapControl {
|
|
|
3559
3596
|
return tiles.map((tile) => tile.split(API_KEY_PLACEHOLDER).join(encoded));
|
|
3560
3597
|
}
|
|
3561
3598
|
_rasterApiKeyFor(provider) {
|
|
3599
|
+
if (provider === "carto") return this._cartoApiKey.trim();
|
|
3562
3600
|
if (provider === "tomtom") return this._tomtomApiKey.trim();
|
|
3563
3601
|
if (provider === "here") return this._hereApiKey.trim();
|
|
3564
3602
|
if (provider === "stadia") return this._stadiaApiKey.trim();
|
|
@@ -3826,4 +3864,4 @@ export {
|
|
|
3826
3864
|
getBasemapCategories as g,
|
|
3827
3865
|
resolveBasemapProviders as r
|
|
3828
3866
|
};
|
|
3829
|
-
//# sourceMappingURL=BasemapControl-
|
|
3867
|
+
//# sourceMappingURL=BasemapControl-CSw9YZ4S.js.map
|