Skip to content

Commit b09d7eb

Browse files
authored
[Enhancement] support mapbox url protocol (#2693)
Signed-off-by: Sahit Tuntas Sadono <[email protected]>
1 parent 2153836 commit b09d7eb

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

src/components/src/map-container.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,9 @@ export default function MapContainerFactory(
987987
mapboxAccessToken: currentStyle?.accessToken || mapboxApiAccessToken,
988988
baseApiUrl: mapboxApiUrl,
989989
mapLib: getApplicationConfig().getMapLib(),
990-
transformRequest: this.props.transformRequest || transformRequest
990+
transformRequest:
991+
this.props.transformRequest ||
992+
transformRequest(currentStyle?.accessToken || mapboxApiAccessToken)
991993
};
992994

993995
const hasGeocoderLayer = Boolean(layers.find(l => l.id === GEOCODER_LAYER_ID));

src/components/src/modals/add-map-style-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function AddMapStyleModalFactory() {
162162
mapboxAccessToken: mapboxApiAccessToken,
163163
mapLib: getApplicationConfig().getMapLib(),
164164
preserveDrawingBuffer: true,
165-
transformRequest
165+
transformRequest: transformRequest(mapboxApiAccessToken)
166166
};
167167

168168
return (

src/utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"lodash.isequal": "^4.5.0",
5959
"lodash.memoize": "^4.1.2",
6060
"lodash.throttle": "^4.1.1",
61+
"maplibregl-mapbox-request-transformer": "^0.0.2",
6162
"mini-svg-data-uri": "^1.0.3",
6263
"moment-timezone": "^0.5.35",
6364
"react": "^18.2.0",

src/utils/src/map-style-utils/mapbox-utils.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright contributors to the kepler.gl project
33

4+
import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
5+
46
/**
57
* Determines whether a Map Style is using Mapbox Tiles
68
* @param {any} mapStyle the mapStyle to check
@@ -24,8 +26,19 @@ export function isStyleUsingMapboxTiles(mapStyle) {
2426
});
2527
}
2628

27-
export const transformRequest = (url: string): {url: string} => {
28-
return {
29-
url
29+
/**
30+
* Transform mapbox protocol so can be used with maplibre
31+
* @param mapboxKey mapbox api key
32+
* @returns transformed url
33+
*/
34+
export const transformRequest = (
35+
mapboxKey: string
36+
): ((url: string, resourceType: string) => {url: string}) => {
37+
return (url: string, resourceType: string) => {
38+
if (isMapboxURL(url)) {
39+
return transformMapboxUrl(url, resourceType, mapboxKey);
40+
}
41+
42+
return {url};
3043
};
3144
};

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,6 +3623,7 @@ __metadata:
36233623
lodash.isequal: "npm:^4.5.0"
36243624
lodash.memoize: "npm:^4.1.2"
36253625
lodash.throttle: "npm:^4.1.1"
3626+
maplibregl-mapbox-request-transformer: "npm:^0.0.2"
36263627
mini-svg-data-uri: "npm:^1.0.3"
36273628
moment-timezone: "npm:^0.5.35"
36283629
react: "npm:^18.2.0"
@@ -21443,6 +21444,13 @@ __metadata:
2144321444
languageName: node
2144421445
linkType: hard
2144521446

21447+
"maplibregl-mapbox-request-transformer@npm:^0.0.2":
21448+
version: 0.0.2
21449+
resolution: "maplibregl-mapbox-request-transformer@npm:0.0.2"
21450+
checksum: 10c0/fb73e476a94039a884982e831060feae70977edba7963249bb8b924cdc72fdee29e1968710e026a45dcd4079b5c11477689f54d528ea0bd481aba47cc0ac924d
21451+
languageName: node
21452+
linkType: hard
21453+
2144621454
"markdown-escapes@npm:^1.0.0":
2144721455
version: 1.0.4
2144821456
resolution: "markdown-escapes@npm:1.0.4"

0 commit comments

Comments
 (0)