Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[feat] mapbox and maplibre simultaneous support (#2897)

Igor Dykhta6e425972eea1
diff --git a/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js b/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js
index fcef7ec80..281abe195 100644
--- a/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js
+++ b/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js
@@ -84,6 +84,10 @@ function App() {
rel="stylesheet"
href="http://d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css"
/>
+ <link
+ rel="stylesheet"
+ href="http://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css"
+ />
<link
rel="stylesheet"
href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css"
diff --git a/bindings/kepler.gl-jupyter/js/webpack/build-html.js b/bindings/kepler.gl-jupyter/js/webpack/build-html.js
index 504fc096d..1e790323f 100644
--- a/bindings/kepler.gl-jupyter/js/webpack/build-html.js
+++ b/bindings/kepler.gl-jupyter/js/webpack/build-html.js
@@ -75,6 +75,7 @@ module.exports = (rules, plugins) => ({
inject: true,
links: [
'https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css',
+ 'https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css',
'https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css'
],
scripts: [
diff --git a/examples/custom-map-style/index.html b/examples/custom-map-style/index.html
index 75839a0a9..92aa7d84f 100644
--- a/examples/custom-map-style/index.html
+++ b/examples/custom-map-style/index.html
@@ -4,6 +4,7 @@
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
<link rel="stylesheet" href="//d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<style type="text/css">
body {margin: 0; padding: 0; overflow: hidden;}
diff --git a/examples/custom-reducer/index.html b/examples/custom-reducer/index.html
index 3b7fcd281..20159859e 100644
--- a/examples/custom-reducer/index.html
+++ b/examples/custom-reducer/index.html
@@ -4,6 +4,7 @@
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
<link href="//d1a3f4spazzrp4.cloudfront.net/uber-fonts/4.0.0/superfine.css" rel="stylesheet">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<style type="text/css">
body {margin: 0; padding: 0; overflow: hidden;}
diff --git a/examples/custom-theme/index.html b/examples/custom-theme/index.html
index 6a31c8c2b..02e69fb3f 100644
--- a/examples/custom-theme/index.html
+++ b/examples/custom-theme/index.html
@@ -4,6 +4,7 @@
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
<link rel="stylesheet" href="//d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<style type="text/css">
body {margin: 0; padding: 0; overflow: hidden;}
diff --git a/examples/demo-app/dist/index.html b/examples/demo-app/dist/index.html
index 8a73d4124..fa90e43ae 100644
--- a/examples/demo-app/dist/index.html
+++ b/examples/demo-app/dist/index.html
@@ -4,6 +4,7 @@
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
<link rel="stylesheet" href="//d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<link rel="stylesheet" href="/bundle.css">
<style type="text/css">
diff --git a/examples/node-app/index.html b/examples/node-app/index.html
index 65815b442..82685a80d 100644
--- a/examples/node-app/index.html
+++ b/examples/node-app/index.html
@@ -4,6 +4,7 @@
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
<link rel="stylesheet" href="//d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<style type="text/css">
body {margin: 0; padding: 0; overflow: hidden;}
diff --git a/examples/open-modal/index.html b/examples/open-modal/index.html
index 75839a0a9..92aa7d84f 100644
--- a/examples/open-modal/index.html
+++ b/examples/open-modal/index.html
@@ -4,6 +4,7 @@
<meta charset='UTF-8' />
<title>kepler.gl demo</title>
<link rel="stylesheet" href="//d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
+ <link href="//api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<style type="text/css">
body {margin: 0; padding: 0; overflow: hidden;}
diff --git a/examples/umd-client/index.html b/examples/umd-client/index.html
index 3f32df2ad..9c1a646f8 100644
--- a/examples/umd-client/index.html
+++ b/examples/umd-client/index.html
@@ -11,6 +11,7 @@
/>
<!--MapBox css-->
+ <link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet" />
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet" />
<!-- Load React/Redux -->
@@ -88,8 +89,8 @@
/** END STORE **/
/** COMPONENTS **/
- const KeplerElement = (function(react, keplerGl, mapboxToken) {
- return function(props) {
+ const KeplerElement = (function (react, keplerGl, mapboxToken) {
+ return function (props) {
return react.createElement(
'div',
{style: {position: 'absolute', left: 0, width: '100vw', height: '100vh'}},
diff --git a/package.json b/package.json
index 0a8b7ddff..53ae91509 100644
--- a/package.json
+++ b/package.json
@@ -183,6 +183,7 @@
"jest-environment-jsdom": "^29.5.0",
"jsdom": "^24.1.1",
"json-loader": "^0.5.4",
+ "mapbox-gl": "1.13.1",
"maplibre-gl": "^3.6.2",
"minimist": "^1.2.6",
"nyc": "^15.1.0",
diff --git a/src/components/src/common/styled-components.tsx b/src/components/src/common/styled-components.tsx
index c6b3a325f..f236ac0a2 100644
--- a/src/components/src/common/styled-components.tsx
+++ b/src/components/src/common/styled-components.tsx
@@ -533,11 +533,24 @@ export const StyledMapContainer = styled.div`
display: none;
}
}
+ .mapboxgl-map {
+ .mapboxgl-missing-css {
+ display: none;
+ }
+ .mapboxgl-ctrl-attrib {
+ display: none;
+ }
+ }
`;
-export const StyledAttrbution = styled.div.attrs({
- className: 'maplibre-attribution-container'
-})`
+export type StyledAttrbutionProps = {
+ mapLibCssClass: string;
+ mapLibAttributionCssClass: string;
+};
+
+export const StyledAttrbution = styled.div.attrs<StyledAttrbutionProps>(props => ({
+ className: props.mapLibAttributionCssClass
+}))<StyledAttrbutionProps>`
bottom: 0;
right: 0;
position: absolute;
@@ -567,7 +580,7 @@ export const StyledAttrbution = styled.div.attrs({
align-items: center;
color: ${props => props.theme.labelColor};
- a.maplibregl-ctrl-logo {
+ a.${props => props.mapLibCssClass}-ctrl-logo {
width: 72px;
margin-left: 4px;
background-size: contain;
diff --git a/src/components/src/kepler-gl.tsx b/src/components/src/kepler-gl.tsx
index 7cc03f5d7..9e61bb545 100644
--- a/src/components/src/kepler-gl.tsx
+++ b/src/components/src/kepler-gl.tsx
@@ -109,6 +109,10 @@ const GlobalStyle = styled.div`
.maplibregl-ctrl .maplibregl-ctrl-logo {
display: none;
}
+
+ .mapboxgl-ctrl .mapboxgl-ctrl-logo {
+ display: none;
+ }
`;
type BottomWidgetOuterProps = {
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index b2c314de0..168925f60 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -38,6 +38,9 @@ import {
errorNotification,
setLayerBlending,
isStyleUsingMapboxTiles,
+ isStyleUsingOpenStreetMapTiles,
+ getBaseMapLibrary,
+ BaseMapLibraryConfig,
transformRequest,
observeDimensions,
unobserveDimensions,
@@ -48,7 +51,8 @@ import {
normalizeEvent,
rgbToHex,
computeDeckEffects,
- getApplicationConfig
+ getApplicationConfig,
+ GetMapRef
} from '@kepler.gl/utils';
import {breakPointValues} from '@kepler.gl/styles';
@@ -87,7 +91,6 @@ import {VisState} from '@kepler.gl/schemas';
const DEBOUNCE_VIEWPORT_PROPAGATE = 10;
const DEBOUNCE_MOUSE_MOVE_PROPAGATE = 10;
-/** @type {{[key: string]: React.CSSProperties}} */
const MAP_STYLE: {[key: string]: React.CSSProperties} = {
container: {
display: 'inline-block',
@@ -108,14 +111,15 @@ const LOCALE_CODES_ARRAY = Object.keys(LOCALE_CODES);
interface StyledMapContainerProps {
mixBlendMode?: string;
+ mapLibCssClass: string;
}
const StyledMap = styled(StyledMapContainer)<StyledMapContainerProps>(
- ({mixBlendMode = 'normal'}) => `
+ ({mixBlendMode = 'normal', mapLibCssClass}) => `
#default-deckgl-overlay {
mix-blend-mode: ${mixBlendMode};
};
- *[${getApplicationConfig().mapLibCssClass}-children] {
+ *[${mapLibCssClass}-children] {
position: absolute;
}
`
@@ -127,16 +131,20 @@ const nop = () => {
return;
};
-const MapLibLogo = () => (
+type MapLibLogoProps = {
+ baseMapLibraryConfig: BaseMapLibraryConfig;
+};
+
+const MapLibLogo = ({baseMapLibraryConfig}: MapLibLogoProps) => (
<div className="attrition-logo">
Basemap by:
<a
style={{marginLeft: '5px'}}
- className={`${getApplicationConfig().mapLibCssClass}-ctrl-logo`}
+ className={`${baseMapLibraryConfig.mapLibCssClass}-ctrl-logo`}
target="_blank"
rel="noopener noreferrer"
- href={getApplicationConfig().mapLibUrl}
- aria-label={`${getApplicationConfig().mapLibName} logo`}
+ href={baseMapLibraryConfig.mapLibUrl}
+ aria-label={`${baseMapLibraryConfig.mapLibName} logo`}
/>
</div>
);
@@ -211,17 +219,28 @@ const DatasetAttributions = ({
</>
);
-export const Attribution: React.FC<{
- showMapboxLogo: boolean;
+type AttributionProps = {
+ showBaseMapLibLogo: boolean;
showOsmBasemapAttribution: boolean;
datasetAttributions: DatasetAttribution[];
-}> = ({showMapboxLogo = true, showOsmBasemapAttribution = false, datasetAttributions}) => {
+ baseMapLibraryConfig: BaseMapLibraryConfig;
+};
+
+export const Attribution: React.FC<AttributionProps> = ({
+ showBaseMapLibLogo = true,
+ showOsmBasemapAttribution = false,
+ datasetAttributions,
+ baseMapLibraryConfig
+}: AttributionProps) => {
const isPalm = hasMobileWidth(breakPointValues);
const memoizedComponents = useMemo(() => {
- if (!showMapboxLogo) {
+ if (!showBaseMapLibLogo) {
return (
- <StyledAttrbution>
+ <StyledAttrbution
+ mapLibCssClass={baseMapLibraryConfig.mapLibCssClass}
+ mapLibAttributionCssClass={baseMapLibraryConfig.mapLibAttributionCssClass}
+ >
<EndHorizontalFlexbox>
<DatasetAttributions datasetAttributions={datasetAttributions} isPalm={isPalm} />
{showOsmBasemapAttribution ? (
@@ -242,21 +261,30 @@ export const Attribution: React.FC<{
}
return (
- <StyledAttrbution>
+ <StyledAttrbution
+ mapLibCssClass={baseMapLibraryConfig.mapLibCssClass}
+ mapLibAttributionCssClass={baseMapLibraryConfig.mapLibAttributionCssClass}
+ >
<EndHorizontalFlexbox>
<DatasetAttributions datasetAttributions={datasetAttributions} isPalm={isPalm} />
<div className="attrition-link">
{datasetAttributions?.length ? <span className="pipe-separator">|</span> : null}
- {isPalm ? <MapLibLogo /> : null}
+ {isPalm ? <MapLibLogo baseMapLibraryConfig={baseMapLibraryConfig} /> : null}
<a href="https://kepler.gl/policy/" target="_blank" rel="noopener noreferrer">
© kepler.gl |{' '}
</a>
- {!isPalm ? <MapLibLogo /> : null}
+ {!isPalm ? <MapLibLogo baseMapLibraryConfig={baseMapLibraryConfig} /> : null}
</div>
</EndHorizontalFlexbox>
</StyledAttrbution>
);
- }, [showMapboxLogo, showOsmBasemapAttribution, datasetAttributions, isPalm]);
+ }, [
+ showBaseMapLibLogo,
+ showOsmBasemapAttribution,
+ datasetAttributions,
+ isPalm,
+ baseMapLibraryConfig
+ ]);
return memoizedComponents;
};
@@ -266,8 +294,6 @@ MapContainerFactory.deps = [MapPopoverFactory, MapControlFactory, EditorFactory]
type MapboxStyle = string | object | undefined;
type PropSelector<R> = Selector<MapContainerProps, R>;
-type GetMapRef = ReturnType<ReturnType<typeof getApplicationConfig>['getMap']>;
-
export interface MapContainerProps {
visState: VisState;
mapState: MapState;
@@ -301,7 +327,7 @@ export interface MapContainerProps {
topMapContainerProps: any;
bottomMapContainerProps: any;
- transformRequest?: any;
+ transformRequest?: (url: string, resourceType?: string) => {url: string};
datasetAttributions?: DatasetAttribution[];
@@ -343,7 +369,7 @@ export default function MapContainerFactory(
state = {
// Determines whether attribution should be visible based the result of loading the map style
- showMapboxAttribution: true
+ showBaseMapAttribution: true
};
componentDidMount() {
@@ -493,7 +519,10 @@ export default function MapContainerFactory(
if (update && update.style) {
// No attributions are needed if the style doesn't reference Mapbox sources
- this.setState({showMapboxAttribution: isStyleUsingMapboxTiles(update.style)});
+ this.setState({
+ showBaseMapAttribution:
+ isStyleUsingMapboxTiles(update.style) || !isStyleUsingOpenStreetMapTiles(update.style)
+ });
}
if (typeof this.props.onMapStyleLoaded === 'function') {
@@ -502,8 +531,18 @@ export default function MapContainerFactory(
};
_setMapRef = mapRef => {
+ // Handle change of the map library
+ if (this._map && mapRef) {
+ const map = mapRef.getMap();
+ if (map && this._map !== map) {
+ this._map?.off(MAPBOXGL_STYLE_UPDATE, nop);
+ this._map?.off(MAPBOXGL_RENDER, nop);
+ this._map = null;
+ }
+ }
+
if (!this._map && mapRef) {
- this._map = getApplicationConfig().getMap(mapRef);
+ this._map = mapRef.getMap();
// i noticed in certain context we don't access the actual map element
if (!this._map) {
return;
@@ -964,7 +1003,7 @@ export default function MapContainerFactory(
mapStateActions,
MapComponent = Map,
mapboxApiAccessToken,
- mapboxApiUrl,
+ // mapboxApiUrl,
mapControls,
isExport,
locale,
@@ -986,13 +1025,17 @@ export default function MapContainerFactory(
// Current style can be a custom style, from which we pull the mapbox API acccess token
const currentStyle = mapStyle.mapStyles?.[mapStyle.styleType];
+ const baseMapLibraryName = getBaseMapLibrary(currentStyle);
+ const baseMapLibraryConfig =
+ getApplicationConfig().baseMapLibraryConfig?.[baseMapLibraryName];
+
const internalViewState = this.context?.getInternalViewState(index);
const mapProps = {
...internalViewState,
preserveDrawingBuffer: true,
mapboxAccessToken: currentStyle?.accessToken || mapboxApiAccessToken,
- baseApiUrl: mapboxApiUrl,
- mapLib: getApplicationConfig().getMapLib(),
+ // baseApiUrl: mapboxApiUrl,
+ mapLib: baseMapLibraryConfig.getMapLib(),
transformRequest:
this.props.transformRequest ||
transformRequest(currentStyle?.accessToken || mapboxApiAccessToken)
@@ -1006,7 +1049,7 @@ export default function MapContainerFactory(
isInteractive: true,
children: (
<MapComponent
- key="bottom"
+ key={`bottom-${baseMapLibraryName}`}
{...mapProps}
mapStyle={mapStyle.bottomMapStyle ?? EMPTY_MAPBOX_STYLE}
{...bottomMapContainerProps}
@@ -1076,13 +1119,13 @@ export default function MapContainerFactory(
{this.props.children}
{mapStyle.topMapStyle ? (
<MapComponent
- key="top"
+ key={`top-${baseMapLibraryName}`}
viewState={internalViewState}
mapStyle={mapStyle.topMapStyle}
style={MAP_STYLE.top}
mapboxAccessToken={mapProps.mapboxAccessToken}
- baseApiUrl={mapProps.baseApiUrl}
- mapLib={getApplicationConfig().getMapLib()}
+ transformRequest={mapProps.transformRequest}
+ mapLib={baseMapLibraryConfig.getMapLib()}
{...topMapContainerProps}
/>
) : null}
@@ -1096,9 +1139,10 @@ export default function MapContainerFactory(
{this._renderMapPopover()}
{this.props.primary ? (
<Attribution
- showMapboxLogo={this.state.showMapboxAttribution}
+ showBaseMapLibLogo={this.state.showBaseMapAttribution}
showOsmBasemapAttribution={true}
datasetAttributions={datasetAttributions}
+ baseMapLibraryConfig={baseMapLibraryConfig}
/>
) : null}
</>
@@ -1106,19 +1150,26 @@ export default function MapContainerFactory(
}
render() {
- const {visState} = this.props;
+ const {visState, mapStyle} = this.props;
const mapContent = this._renderMap();
if (!mapContent) {
// mapContent can be null if onDeckRender returns null
// in this case we don't want to render the map
return null;
}
+
+ const currentStyle = mapStyle.mapStyles?.[mapStyle.styleType];
+ const baseMapLibraryName = getBaseMapLibrary(currentStyle);
+ const baseMapLibraryConfig =
+ getApplicationConfig().baseMapLibraryConfig?.[baseMapLibraryName];
+
return (
<StyledMap
ref={this._ref}
style={this.styleSelector(this.props)}
onContextMenu={event => event.preventDefault()}
mixBlendMode={visState.overlayBlending}
+ mapLibCssClass={baseMapLibraryConfig.mapLibCssClass}
>
{mapContent}
</StyledMap>
diff --git a/src/components/src/modal-container.tsx b/src/components/src/modal-container.tsx
index 4c32c96bb..54ded6acb 100644
--- a/src/components/src/modal-container.tsx
+++ b/src/components/src/modal-container.tsx
@@ -465,7 +465,7 @@ export default function ModalContainerFactory(
onConfirm: this._onAddCustomMapStyle,
confirmButton: {
large: true,
- disabled: !mapStyle.inputStyle.url,
+ disabled: !mapStyle.inputStyle.url || !mapStyle.inputStyle.label,
children: 'modal.button.addStyle'
}
};
diff --git a/src/components/src/modals/add-map-style-modal.tsx b/src/components/src/modals/add-map-style-modal.tsx
index 0d78e6016..89e2f0119 100644
--- a/src/components/src/modals/add-map-style-modal.tsx
+++ b/src/components/src/modals/add-map-style-modal.tsx
@@ -16,7 +16,7 @@ import {
import {media} from '@kepler.gl/styles';
// Utils
-import {getApplicationConfig, transformRequest} from '@kepler.gl/utils';
+import {getApplicationConfig, getBaseMapLibrary, transformRequest} from '@kepler.gl/utils';
import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from '@kepler.gl/localization';
import {NO_BASEMAP_ICON} from '@kepler.gl/constants';
@@ -95,6 +95,12 @@ interface AddMapStyleModalProps {
loadCustomMapStyle: ActionHandler<typeof loadCustomMapStyle>;
mapboxApiAccessToken: string;
mapboxApiUrl?: string;
+ transformRequest?: (mapboxKey: string) => (
+ url: string,
+ resourceType: string
+ ) => {
+ url: string;
+ };
mapState: MapState;
intl: IntlShape;
}
@@ -153,16 +159,22 @@ function AddMapStyleModalFactory() {
};
render() {
- const {inputStyle, mapState, mapboxApiUrl, intl} = this.props;
+ const {inputStyle, mapState, intl} = this.props;
+
+ const baseMapLibraryName = getBaseMapLibrary(inputStyle);
+ const baseMapLibraryConfig = getApplicationConfig().baseMapLibraryConfig[baseMapLibraryName];
const mapboxApiAccessToken = inputStyle.accessToken || this.props.mapboxApiAccessToken;
const mapProps = {
...mapState,
- baseApiUrl: mapboxApiUrl,
+ // TODO baseApiUrl should be taken into account in transformRequest as we use dynamic mapLib import
+ // baseApiUrl: mapboxApiUrl,
mapboxAccessToken: mapboxApiAccessToken,
- mapLib: getApplicationConfig().getMapLib(),
+ mapLib: baseMapLibraryConfig.getMapLib(),
preserveDrawingBuffer: true,
- transformRequest: transformRequest(mapboxApiAccessToken)
+ transformRequest:
+ this.props.transformRequest?.(mapboxApiAccessToken) ||
+ transformRequest(mapboxApiAccessToken)
};
return (
@@ -205,7 +217,7 @@ function AddMapStyleModalFactory() {
/>
</StyledModalSection>
- {/* <StyledModalSection>
+ <StyledModalSection>
<div className="modal-section-title">
<FormattedMessage id={'modal.addStyle.publishTitle'} />
</div>
@@ -243,7 +255,7 @@ function AddMapStyleModalFactory() {
onChange={({target: {value}}) => this.props.inputMapStyle({accessToken: value})}
placeholder={intl.formatMessage({id: 'modal.addStyle.exampleToken'})}
/>
- </StyledModalSection> */}
+ </StyledModalSection>
<StyledModalSection>
<div className="modal-section-title">
@@ -253,6 +265,7 @@ function AddMapStyleModalFactory() {
type="text"
value={inputStyle.label || ''}
onChange={({target: {value}}) => this.props.inputMapStyle({label: value})}
+ placeholder="Name your style"
/>
</StyledModalSection>
</StyledModalVerticalPanel>
diff --git a/src/components/src/plot-container.tsx b/src/components/src/plot-container.tsx
index fd67fa05d..ce6591087 100644
--- a/src/components/src/plot-container.tsx
+++ b/src/components/src/plot-container.tsx
@@ -32,6 +32,7 @@ import {mapFieldsSelector} from './kepler-gl';
const CLASS_FILTER = [
'maplibregl-control-container',
+ 'mapboxgl-control-container',
'attrition-link',
'attrition-logo',
'map-control__panel-split-viewport-tools'
@@ -47,6 +48,9 @@ const StyledPlotContainer = styled.div`
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right,
.maplibre-attribution-container,
+ .mapboxgl-ctrl-bottom-left,
+ .mapboxgl-ctrl-bottom-right,
+ .mapbox-attribution-container,
.map-control__panel-split-viewport-tools {
display: none;
}
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index ff69895cb..124fb5ac2 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -3,7 +3,14 @@
import keyMirror from 'keymirror';
-import {BaseMapStyle, EffectDescription, RGBAColor, SyncTimelineMode} from '@kepler.gl/types';
+import {
+ BaseMapStyle,
+ EffectDescription,
+ RGBAColor,
+ SyncTimelineMode,
+ BaseMapColorModes,
+ Merge
+} from '@kepler.gl/types';
import {
scaleLinear,
scaleLog,
@@ -203,7 +210,7 @@ export const BACKGROUND_LAYER_GROUP: DEFAULT_LAYER_GROUP = {
export const DEFAULT_LAYER_GROUPS: DEFAULT_LAYER_GROUP[] = [
{
slug: 'label',
- filter: ({id}) => id.match(/(?=(label|place-|poi-))/),
+ filter: ({id, type}) => id.match(/(?=(label|place-|poi-))/) || type?.match(/(?=(symbol))/),
defaultVisibility: true,
isVisibilityToggleAvailable: true,
isMoveToTopAvailable: true,
@@ -275,18 +282,85 @@ export const EMPTY_MAPBOX_STYLE = {
layers: []
};
+export const MAP_LIB_OPTIONS = {
+ MAPBOX: 'mapbox' as const,
+ MAPLIBRE: 'maplibre' as const
+};
+
+export type BaseMapLibraryType = 'mapbox' | 'maplibre';
+
export const NO_BASEMAP_ICON = `${BASEMAP_ICON_PREFIX}/NO_BASEMAP.png`;
-export const DEFAULT_MAP_STYLES: BaseMapStyle[] = [
+export const DEFAULT_BASE_MAP_STYLE = 'dark-matter';
+
+type DefaultBaseMapStyle = Merge<
+ BaseMapStyle,
+ {
+ colorMode: BaseMapColorModes;
+ }
+>;
+
+export const DEFAULT_NO_BASEMAP_STYLE: DefaultBaseMapStyle = {
+ id: NO_MAP_ID,
+ label: 'No Basemap',
+ url: '',
+ icon: NO_BASEMAP_ICON,
+ layerGroups: [BACKGROUND_LAYER_GROUP],
+ colorMode: BASE_MAP_COLOR_MODES.NONE,
+ style: EMPTY_MAPBOX_STYLE
+};
+
+export const DEFAULT_MAPBOX_STYLES: DefaultBaseMapStyle[] = [
+ {
+ id: 'dark',
+ label: 'Dark',
+ url: 'mapbox://styles/uberdata/cjoqbbf6l9k302sl96tyvka09',
+ icon: `${BASEMAP_ICON_PREFIX}/UBER_DARK_V2.png`,
+ layerGroups: DEFAULT_LAYER_GROUPS,
+ colorMode: BASE_MAP_COLOR_MODES.DARK,
+ complimentaryStyleId: 'light'
+ },
{
- id: NO_MAP_ID,
- label: 'No Basemap',
- url: '',
- icon: NO_BASEMAP_ICON,
- layerGroups: [BACKGROUND_LAYER_GROUP],
- colorMode: BASE_MAP_COLOR_MODES.NONE,
- style: EMPTY_MAPBOX_STYLE
+ id: 'light',
+ label: 'Light',
+ url: 'mapbox://styles/uberdata/cjoqb9j339k1f2sl9t5ic5bn4',
+ icon: `${BASEMAP_ICON_PREFIX}/UBER_LIGHT_V2.png`,
+ layerGroups: DEFAULT_LAYER_GROUPS,
+ colorMode: BASE_MAP_COLOR_MODES.LIGHT,
+ complimentaryStyleId: 'dark'
},
+ {
+ id: 'muted',
+ label: 'Muted Light',
+ url: 'mapbox://styles/uberdata/cjfyl03kp1tul2smf5v2tbdd4',
+ icon: `${BASEMAP_ICON_PREFIX}/UBER_MUTED_LIGHT.png`,
+ layerGroups: DEFAULT_LAYER_GROUPS,
+ colorMode: BASE_MAP_COLOR_MODES.LIGHT,
+ complimentaryStyleId: 'muted_night'
+ },
+ {
+ id: 'muted_night',
+ label: 'Muted Night',
+ url: 'mapbox://styles/uberdata/cjfxhlikmaj1b2soyzevnywgs',
+ icon: `${BASEMAP_ICON_PREFIX}/UBER_MUTED_NIGHT.png`,
+ layerGroups: DEFAULT_LAYER_GROUPS,
+ colorMode: BASE_MAP_COLOR_MODES.DARK,
+ complimentaryStyleId: 'muted'
+ }
+];
+
+export const DEFAULT_MAPBOX_SATELITE_STYLES: DefaultBaseMapStyle[] = [
+ {
+ id: 'satellite',
+ label: 'Satellite with streets',
+ url: `mapbox://styles/mapbox/satellite-streets-v11`,
+ icon: `${BASEMAP_ICON_PREFIX}/UBER_SATELLITE.png`,
+ layerGroups: DEFAULT_LAYER_GROUPS,
+ colorMode: BASE_MAP_COLOR_MODES.NONE
+ }
+];
+
+export const DEFAULT_MAPLIBRE_STYLES: DefaultBaseMapStyle[] = [
{
id: 'dark-matter',
label: 'DarkMatter',
@@ -296,15 +370,6 @@ export const DEFAULT_MAP_STYLES: BaseMapStyle[] = [
colorMode: BASE_MAP_COLOR_MODES.DARK,
complimentaryStyleId: 'positron'
},
- {
- id: 'dark-matter-nolabels',
- label: 'DarkMatterNoLabels',
- url: 'https://basemaps.cartocdn.com/gl/dark-matter-nolabels-gl-style/style.json',
- icon: `${BASEMAP_ICON_PREFIX}/DARKMATTER_NOLABELS.png`,
- layerGroups: DEFAULT_LAYER_GROUPS,
- colorMode: BASE_MAP_COLOR_MODES.DARK,
- complimentaryStyleId: 'positron-nolabels'
- },
{
id: 'positron',
label: 'Positron',
@@ -314,15 +379,6 @@ export const DEFAULT_MAP_STYLES: BaseMapStyle[] = [
colorMode: BASE_MAP_COLOR_MODES.LIGHT,
complimentaryStyleId: 'dark-matter'
},
- {
- id: 'positron-nolabels',
- label: 'PositronNoLabels',
- url: 'https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json',
- icon: `${BASEMAP_ICON_PREFIX}/POSITRON_NOLABELS.png`,
- layerGroups: DEFAULT_LAYER_GROUPS,
- colorMode: BASE_MAP_COLOR_MODES.LIGHT,
- complimentaryStyleId: 'dark-matter-nolabels'
- },
{
id: 'voyager',
label: 'Voyager',
@@ -331,18 +387,16 @@ export const DEFAULT_MAP_STYLES: BaseMapStyle[] = [
layerGroups: DEFAULT_LAYER_GROUPS,
colorMode: BASE_MAP_COLOR_MODES.LIGHT,
complimentaryStyleId: 'dark-matter'
- },
- {
- id: 'voyager-nolabels',
- label: 'VoyagerNoLabels',
- url: 'https://basemaps.cartocdn.com/gl/voyager-nolabels-gl-style/style.json',
- icon: `${BASEMAP_ICON_PREFIX}/VOYAGER_NOLABELS.png`,
- layerGroups: DEFAULT_LAYER_GROUPS,
- colorMode: BASE_MAP_COLOR_MODES.LIGHT,
- complimentaryStyleId: 'dark-matter-nolabels'
}
];
+export const DEFAULT_MAP_STYLES = [
+ DEFAULT_NO_BASEMAP_STYLE,
+ ...DEFAULT_MAPLIBRE_STYLES,
+ ...DEFAULT_MAPBOX_SATELITE_STYLES,
+ ...DEFAULT_MAPBOX_STYLES
+];
+
export const GEOJSON_FIELDS = {
geojson: ['_geojson', 'all_points', 'geojson']
};
diff --git a/src/reducers/src/map-style-updaters.ts b/src/reducers/src/map-style-updaters.ts
index 0f488a3a9..e35820e49 100644
--- a/src/reducers/src/map-style-updaters.ts
+++ b/src/reducers/src/map-style-updaters.ts
@@ -25,7 +25,8 @@ import {
NO_MAP_ID,
DEFAULT_BLDG_COLOR,
DEFAULT_BACKGROUND_COLOR,
- BASE_MAP_BACKGROUND_LAYER_IDS
+ BASE_MAP_BACKGROUND_LAYER_IDS,
+ DEFAULT_BASE_MAP_STYLE
} from '@kepler.gl/constants';
import {ACTION_TASK, LOAD_MAP_STYLE_TASK} from '@kepler.gl/tasks';
import {rgb} from 'd3-color';
@@ -72,11 +73,10 @@ export type MapStyle = {
const getDefaultState = (): MapStyle => {
const visibleLayerGroups = {};
- const styleType = 'dark-matter';
const topLayerGroups = {};
return {
- styleType,
+ styleType: DEFAULT_BASE_MAP_STYLE,
visibleLayerGroups,
topLayerGroups,
mapStyles: DEFAULT_MAP_STYLES.reduce(
@@ -703,7 +703,8 @@ export const inputMapStyleUpdater = (
const icon =
!isUpdatedIconDataUri && isMapboxStyleUrl
- ? getStyleImageIcon({
+ ? // Get image icon urls only for mapbox map lib.
+ getStyleImageIcon({
mapState,
styleUrl: updated.url || '',
mapboxApiAccessToken: updated.accessToken || state.mapboxApiAccessToken || '',
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
index 2a3338b6c..0d1dd34ca 100644
--- a/src/types/reducers.d.ts
+++ b/src/types/reducers.d.ts
@@ -355,6 +355,8 @@ export type CustomStyleType =
// boolean for backwards compatability with previous map configs
| boolean;
+export type BaseMapColorModes = 'NONE' | 'DARK' | 'LIGHT';
+
export type BaseMapStyle = {
id: string;
label: string;
@@ -364,7 +366,7 @@ export type BaseMapStyle = {
layerGroups: LayerGroup[];
accessToken?: string;
custom?: CustomStyleType;
- colorMode?: BASE_MAP_COLOR_MODES;
+ colorMode?: BaseMapColorModes;
complimentaryStyleId?: string;
};
diff --git a/src/utils/src/application-config.ts b/src/utils/src/application-config.ts
index f4640af57..53dca38a0 100644
--- a/src/utils/src/application-config.ts
+++ b/src/utils/src/application-config.ts
@@ -3,7 +3,18 @@
import {MapLib, MapRef} from 'react-map-gl';
+import type {BaseMapLibraryType} from '@kepler.gl/constants';
+
export type MapLibInstance = MapLib<any>;
+export type GetMapRef = ReturnType<MapRef['getMap']>;
+
+export type BaseMapLibraryConfig = {
+ getMapLib: () => Promise<MapLibInstance>;
+ mapLibAttributionCssClass: string;
+ mapLibCssClass: string;
+ mapLibName: string;
+ mapLibUrl: string;
+};
/**
* A mechanism to override default Kepler values/settings so that we
@@ -18,11 +29,7 @@ export type KeplerApplicationConfig<Map> = {
defaultExportJsonSettings?: {
hasData?: boolean;
};
- getMapLib?: () => Promise<MapLibInstance>;
- getMap?: (ref: any) => Map;
- mapLibCssClass?: string;
- mapLibName?: string;
- mapLibUrl?: string;
+ baseMapLibraryConfig?: Record<BaseMapLibraryType, BaseMapLibraryConfig>;
plugins?: any[];
// KeplerTable alternative
// TODO improve typing by exporting KeplerTable interface to @kepler.gl/types
@@ -37,11 +44,24 @@ const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig<mapboxgl.Map>
defaultExportJsonSettings: {
hasData: true
},
- getMapLib: () => import('maplibre-gl'),
- getMap: (mapRef: MapRef): mapboxgl.Map => mapRef?.getMap(),
- mapLibCssClass: 'maplibregl',
- mapLibName: 'MapLibre',
- mapLibUrl: 'https://www.maplibre.org/',
+
+ baseMapLibraryConfig: {
+ maplibre: {
+ getMapLib: () => import('maplibre-gl'),
+ mapLibCssClass: 'maplibregl',
+ mapLibAttributionCssClass: 'maplibre-attribution-container',
+ mapLibName: 'MapLibre',
+ mapLibUrl: 'https://www.maplibre.org/'
+ },
+ mapbox: {
+ getMapLib: () => import('mapbox-gl'),
+ mapLibCssClass: 'mapboxgl',
+ mapLibAttributionCssClass: 'mapbox-attribution-container',
+ mapLibName: 'Mapbox',
+ mapLibUrl: 'https://www.mapbox.com/'
+ }
+ },
+
plugins: [],
// The default table class is KeplerTable.
// TODO include KeplerTable here when the circular dependency with @kepler.gl/table and @kepler.gl/utils are resolved.
diff --git a/src/utils/src/export-map-html.ts b/src/utils/src/export-map-html.ts
index c1a01ffd1..4d831f04e 100644
--- a/src/utils/src/export-map-html.ts
+++ b/src/utils/src/export-map-html.ts
@@ -24,6 +24,7 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
<link rel="stylesheet" href="https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
<!--MapBox css-->
+ <link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<!-— facebook open graph tags -->
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index d791a8d5e..887ed6364 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -114,7 +114,12 @@ export {
} from './effect-utils';
// Mapbox
-export {isStyleUsingMapboxTiles, transformRequest} from './map-style-utils/mapbox-utils';
+export {
+ isStyleUsingMapboxTiles,
+ isStyleUsingOpenStreetMapTiles,
+ getBaseMapLibrary,
+ transformRequest
+} from './map-style-utils/mapbox-utils';
// Map
export * from './map-utils';
@@ -169,7 +174,12 @@ export {DataRow} from './data-row';
// Application config
export {getApplicationConfig, initApplicationConfig} from './application-config';
-export type {KeplerApplicationConfig, MapLibInstance} from './application-config';
+export type {
+ KeplerApplicationConfig,
+ BaseMapLibraryConfig,
+ MapLibInstance,
+ GetMapRef
+} from './application-config';
export {default as quickInsertionSort} from './quick-insertion-sort';
diff --git a/src/utils/src/map-style-utils/mapbox-utils.ts b/src/utils/src/map-style-utils/mapbox-utils.ts
index dc9052a60..d09bdf9de 100644
--- a/src/utils/src/map-style-utils/mapbox-utils.ts
+++ b/src/utils/src/map-style-utils/mapbox-utils.ts
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
+// import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
+
+import {MAP_LIB_OPTIONS, BaseMapLibraryType} from '@kepler.gl/constants';
/**
* Determines whether a Map Style is using Mapbox Tiles
@@ -26,6 +28,17 @@ export function isStyleUsingMapboxTiles(mapStyle) {
});
}
+export function isStyleUsingOpenStreetMapTiles(mapStyle: any) {
+ const sources = mapStyle?.stylesheet?.sources || {};
+ return Object.keys(sources).some(sourceId => {
+ const {attribution} = sources[sourceId] || {};
+ if (typeof attribution?.attribution === 'string') {
+ return attribution.attribution.includes('openstreetmap.org');
+ }
+ return false;
+ });
+}
+
/**
* Transform mapbox protocol so can be used with maplibre
* @param mapboxKey mapbox api key
@@ -35,10 +48,33 @@ export const transformRequest = (
mapboxKey: string
): ((url: string, resourceType: string) => {url: string}) => {
return (url: string, resourceType: string) => {
+ /*
if (isMapboxURL(url)) {
+ // ! TODO - use MapBox directly?
return transformMapboxUrl(url, resourceType, mapboxKey);
}
+ */
return {url};
};
};
+
+type StyleWithSources = {
+ sources?: Record<string, any>;
+};
+
+export const getBaseMapLibrary = (baseMapStyle?: {
+ url?: string | null;
+ style?: any;
+}): BaseMapLibraryType => {
+ if (baseMapStyle) {
+ if (baseMapStyle.url?.startsWith('mapbox://') || baseMapStyle.url?.includes('mapbox.com')) {
+ return MAP_LIB_OPTIONS.MAPBOX;
+ }
+
+ if ((baseMapStyle.style as StyleWithSources)?.sources?.['mapbox'])
+ return MAP_LIB_OPTIONS.MAPBOX;
+ }
+
+ return MAP_LIB_OPTIONS.MAPLIBRE;
+};
diff --git a/test/helpers/mock-map-styles.js b/test/helpers/mock-map-styles.js
index 7c67ff450..c308c4988 100644
--- a/test/helpers/mock-map-styles.js
+++ b/test/helpers/mock-map-styles.js
@@ -31,7 +31,6 @@ export const MOCK_MAP_STYLE = {
layout: {visibility: 'visible'},
paint: {'background-color': '#0e0e0e', 'background-opacity': 1}
},
-
{
id: 'road_path',
type: 'line',
diff --git a/test/node/reducers/map-style-test.js b/test/node/reducers/map-style-test.js
index 44ac82514..ad58ca6ab 100644
--- a/test/node/reducers/map-style-test.js
+++ b/test/node/reducers/map-style-test.js
@@ -690,15 +690,21 @@ test('#mapStyleReducer -> MAP_STYLE_CHANGE', t => {
...MOCK_MAP_STYLE.style,
layers: [
{
+ id: 'roadname_minor',
+ minzoom: 13,
+ source: 'carto',
type: 'symbol',
- source: 'composite',
- id: 'country-label-sm',
- 'source-layer': 'country_label'
- }
+ 'source-layer': 'transportation_name'
+ },
+ {type: 'symbol', source: 'composite', id: 'country-label-sm', 'source-layer': 'country_label'}
]
};
- t.deepEqual(nextState2.topMapStyle, expectedTopStyle2, 'topMapStyle should be set correctly');
+ t.deepEqual(
+ nextState2.topMapStyle,
+ expectedTopStyle2,
+ 'topMapStyle should be set correctly - road: false'
+ );
// set style type to light
const nextState3 = reducer(nextState2, mapStyleChange('positron'));
@@ -740,6 +746,13 @@ test('#mapStyleReducer -> MAP_STYLE_CHANGE', t => {
const expectedTopStyle3 = {
...MOCK_MAP_STYLE_LIGHT.style,
layers: [
+ {
+ id: 'roadname_minor',
+ minzoom: 13,
+ source: 'carto',
+ type: 'symbol',
+ 'source-layer': 'transportation_name'
+ },
{
type: 'symbol',
source: 'composite',
diff --git a/website/src/static/index.html b/website/src/static/index.html
index a6bfd130d..42c5a1a54 100644
--- a/website/src/static/index.html
+++ b/website/src/static/index.html
@@ -8,6 +8,7 @@
<link rel="shortcut icon" href="/favicon.png">
<link rel="stylesheet" href="https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/uber-fonts/4.0.0/superfine.css">
+ <link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css" rel="stylesheet">
<link href="https://unpkg.com/maplibre-gl@^3/dist/maplibre-gl.css" rel="stylesheet">
<!-— facebook open graph tags -->
diff --git a/yarn.lock b/yarn.lock
index a2cf9f7ee..1eff3461a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -20539,6 +20539,7 @@ __metadata:
jest-environment-jsdom: "npm:^29.5.0"
jsdom: "npm:^24.1.1"
json-loader: "npm:^0.5.4"
+ mapbox-gl: "npm:1.13.1"
maplibre-gl: "npm:^3.6.2"
minimist: "npm:^1.2.6"
nyc: "npm:^15.1.0"