Skip to content

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

[feat] Vector Tile layer fixes (#2899)

Igor Dykhta2753321c5c6d
diff --git a/src/components/package.json b/src/components/package.json
index 3ac2f4092..b927bfad3 100644
--- a/src/components/package.json
+++ b/src/components/package.json
@@ -125,7 +125,7 @@
"react-virtualized": "^9.22.5",
"react-vis": "1.11.7",
"redux": "^4.2.1",
- "reselect": "^4.0.0",
+ "reselect": "^4.1.0",
"styled-components": "6.1.8",
"suncalc": "^1.9.0",
"viewport-mercator-project": "^6.0.0"
diff --git a/src/components/src/hooks/use-fetch-vector-tile-metadata.ts b/src/components/src/hooks/use-fetch-vector-tile-metadata.ts
index 574465649..ce671b7fc 100644
--- a/src/components/src/hooks/use-fetch-vector-tile-metadata.ts
+++ b/src/components/src/hooks/use-fetch-vector-tile-metadata.ts
@@ -3,10 +3,11 @@
import {useCallback, useEffect, useState} from 'react';
-import {MVTSource, TileJSON} from '@loaders.gl/mvt';
+import {/* MVTSource,*/ TileJSON} from '@loaders.gl/mvt';
import {PMTilesSource, PMTilesMetadata} from '@loaders.gl/pmtiles';
-import {VectorTileMetadata, VectorTileType} from '@kepler.gl/layers';
+import {VectorTileType} from '@kepler.gl/constants';
+import {getMVTMetadata, VectorTileMetadata} from '@kepler.gl/table';
type FetchVectorTileMetadataProps = {
url: string | null;
@@ -65,16 +66,25 @@ export default function useFetchVectorTileMetadata({
setLoading(true);
try {
- const tileSource =
- type === VectorTileType.MVT
- ? MVTSource.createDataSource('', {
- mvt: {
- metadataUrl: decodeURIComponent(url)
- }
- })
- : PMTilesSource.createDataSource(decodeURIComponent(url), {});
+ let metadata: PMTilesMetadata | TileJSON | null = null;
+ if (type === VectorTileType.MVT) {
+ metadata = await getMVTMetadata(url);
- const metadata = await tileSource.metadata;
+ // MVTSource returns messy partial metadata
+ // MVTSource.createDataSource('', {
+ // mvt: {
+ // metadataUrl: decodeURIComponent(url)
+ // }
+ // })
+ } else {
+ const tileSource = PMTilesSource.createDataSource(url, {});
+ metadata = await tileSource.metadata;
+ }
+
+ // Since we switched to Source.createDataSource detailed response errors aren't available here...
+ if (!metadata) {
+ throw new Error('Failed to fetch metadata');
+ }
setProcessedData(metadata);
} catch (metadataError) {
setError(metadataError as any);
diff --git a/src/components/src/kepler-gl.tsx b/src/components/src/kepler-gl.tsx
index 9e61bb545..0cb5c1905 100644
--- a/src/components/src/kepler-gl.tsx
+++ b/src/components/src/kepler-gl.tsx
@@ -11,7 +11,13 @@ import {connect as keplerGlConnect} from './connect/keplergl-connect';
import {IntlProvider} from 'react-intl';
import {messages} from '@kepler.gl/localization';
import {RootContext, FeatureFlagsContextProvider, FeatureFlags} from './context';
-import {OnErrorCallBack, OnSuccessCallBack, Viewport} from '@kepler.gl/types';
+import {
+ AttributionWithStyle,
+ DatasetAttribution,
+ OnErrorCallBack,
+ OnSuccessCallBack,
+ Viewport
+} from '@kepler.gl/types';
import {
MapStateActions,
@@ -157,6 +163,7 @@ export const mapFieldsSelector = (props: KeplerGLProps, index = 0) => ({
mapboxApiAccessToken: props.mapboxApiAccessToken,
mapboxApiUrl: props.mapboxApiUrl ? props.mapboxApiUrl : DEFAULT_KEPLER_GL_PROPS.mapboxApiUrl,
mapState: mapStateSelector(props, index),
+ datasetAttributions: attributionSelector(props).sources,
mapStyle: props.mapStyle,
onDeckInitialized: props.onDeckInitialized,
onViewStateChange: props.onViewStateChange,
@@ -282,6 +289,62 @@ export const geoCoderPanelSelector = (
appWidth: dimensions.width
});
+/**
+ * Returns array of unique dataset attributions, each with title and url properties.
+ */
+export const datasetAttributionSelector = createSelector(
+ [state => state.visState.datasets],
+ datasets => {
+ const uniqueAttributions: DatasetAttribution[] = [];
+ Object.keys(datasets).forEach(key => {
+ const ds = datasets[key];
+ const attributions = ds?.metadata?.attributions;
+ if (Array.isArray(attributions)) {
+ attributions.forEach(attribution => {
+ if (typeof attribution === 'string') {
+ // attribution can be a raw string or a string with link tags
+ const links = attribution.match(/<a[^]+?a>/g);
+ if (links) {
+ try {
+ links?.forEach(link => {
+ const href = link.match(/href="([^"]*)/)?.[1];
+ const title = link.match(/title="([^"]*)/)?.[1];
+ if (href && title) {
+ uniqueAttributions.push({
+ title: `${link.indexOf('&copy;') >= 0 ? '© ' : ''}${title}`,
+ url: href
+ });
+ }
+ });
+ } catch (error) {
+ // just ignore for now
+ }
+ } else {
+ uniqueAttributions.push({title: attribution, url: null});
+ }
+ }
+ });
+ }
+ });
+ return uniqueAttributions;
+ }
+);
+
+/**
+ * Deduplicated dataset and layer text attributions and logos.
+ * Returns text attributions and logos to display.
+ */
+export const attributionSelector = createSelector(
+ [datasetAttributionSelector],
+ datasetAttributions => {
+ // TODO collect attributions from layers, and merge with dataset attributions here
+ const uniqueTextAttributions = datasetAttributions;
+ const logos: AttributionWithStyle[] = [];
+
+ return {sources: uniqueTextAttributions, logos};
+ }
+);
+
export const notificationPanelSelector = (props: KeplerGLProps) => ({
removeNotification: props.uiStateActions.removeNotification,
notifications: props.uiState.notifications
@@ -506,6 +569,7 @@ function KeplerGlFactory(
const modalContainerFields = modalContainerSelector(this.props, this.root.current);
const geoCoderPanelFields = geoCoderPanelSelector(this.props, dimensions);
const notificationPanelFields = notificationPanelSelector(this.props);
+
const mapContainers = !isSplit
? [
<MapContainer
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 168925f60..93bb4575a 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -33,7 +33,14 @@ import {
EditorLayerUtils,
AggregatedBin
} from '@kepler.gl/layers';
-import {MapState, MapControls, Viewport, SplitMap, SplitMapLayers} from '@kepler.gl/types';
+import {
+ DatasetAttribution,
+ MapState,
+ MapControls,
+ Viewport,
+ SplitMap,
+ SplitMapLayers
+} from '@kepler.gl/types';
import {
errorNotification,
setLayerBlending,
@@ -71,7 +78,6 @@ import {
import {MapViewStateContext} from './map-view-state-context';
import ErrorBoundary from './common/error-boundary';
-import {DatasetAttribution} from './types';
import {LOCALE_CODES} from '@kepler.gl/localization';
import {MapView} from '@deck.gl/core';
import {
@@ -180,12 +186,13 @@ interface StyledDatasetAttributionsContainerProps {
}
const StyledDatasetAttributionsContainer = styled.div<StyledDatasetAttributionsContainerProps>`
- max-width: ${props => (props.isPalm ? '130px' : '180px')};
+ max-width: ${props => (props.isPalm ? '200px' : '300px')};
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
color: ${props => props.theme.labelColor};
margin-right: 2px;
+ margin-bottom: 1px;
line-height: ${props => (props.isPalm ? '1em' : '1.4em')};
&:hover {
diff --git a/src/components/src/modal-container.tsx b/src/components/src/modal-container.tsx
index 54ded6acb..c8b0c5bf9 100644
--- a/src/components/src/modal-container.tsx
+++ b/src/components/src/modal-container.tsx
@@ -191,7 +191,8 @@ export default function ModalContainerFactory(
...tileset.metadata
},
// vector tile layer only supports gpu filtering for now
- supportedFilterTypes: [ALL_FIELD_TYPES.real, ALL_FIELD_TYPES.integer]
+ supportedFilterTypes: [ALL_FIELD_TYPES.real, ALL_FIELD_TYPES.integer],
+ disableDataOperation: true
},
{
autoCreateLayers: true
diff --git a/src/components/src/modals/export-data-modal.tsx b/src/components/src/modals/export-data-modal.tsx
index 167cee317..7a36e3090 100644
--- a/src/components/src/modals/export-data-modal.tsx
+++ b/src/components/src/modals/export-data-modal.tsx
@@ -2,8 +2,12 @@
// Copyright contributors to the kepler.gl project
import React, {Component} from 'react';
+import {injectIntl, IntlShape} from 'react-intl';
+
+import {DatasetType, EXPORT_DATA_TYPE_OPTIONS} from '@kepler.gl/constants';
+import {FormattedMessage} from '@kepler.gl/localization';
+import {Datasets} from '@kepler.gl/table';
-import {EXPORT_DATA_TYPE_OPTIONS} from '@kepler.gl/constants';
import {FileType} from '../common/icons';
import {
StyledExportSection,
@@ -13,10 +17,6 @@ import {
CheckMark
} from '../common/styled-components';
import {StyledWarning} from './export-map-modal/components';
-import {injectIntl, IntlShape} from 'react-intl';
-import {DatasetType} from '@kepler.gl/layers';
-import {FormattedMessage} from '@kepler.gl/localization';
-import {Datasets} from '@kepler.gl/table';
const getDataRowCount = (
datasets: Datasets,
diff --git a/src/components/src/modals/tilesets-modals/common.tsx b/src/components/src/modals/tilesets-modals/common.tsx
index 10dca23de..c257a4239 100644
--- a/src/components/src/modals/tilesets-modals/common.tsx
+++ b/src/components/src/modals/tilesets-modals/common.tsx
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {VectorTileMetadata} from '@kepler.gl/layers';
+import {VectorTileMetadata} from '@kepler.gl/table';
export type DatasetCreationAttributes = {
name: string;
diff --git a/src/components/src/modals/tilesets-modals/load-data-footer.tsx b/src/components/src/modals/tilesets-modals/load-data-footer.tsx
index 11cb971b8..f58968ddd 100644
--- a/src/components/src/modals/tilesets-modals/load-data-footer.tsx
+++ b/src/components/src/modals/tilesets-modals/load-data-footer.tsx
@@ -2,9 +2,11 @@
// Copyright contributors to the kepler.gl project
import React from 'react';
+import {injectIntl, WrappedComponentProps} from 'react-intl';
import styled from 'styled-components';
import {Button} from '../../common';
+import LoadingSpinner from '../../common/loading-spinner';
const AddDataButton = styled(Button)<{isLoading?: boolean}>`
position: relative;
@@ -13,7 +15,7 @@ const AddDataButton = styled(Button)<{isLoading?: boolean}>`
opacity: ${props => (props.disabled ? 0.6 : 1)};
height: 40px;
padding: 9px 32px;
- width: auto;
+ width: ${props => props.width};
svg {
margin-right: ${props => (props.isLoading ? '0' : '6px')};
@@ -36,7 +38,8 @@ const LoadDataFooterContainer = styled.div.attrs({
const ErrorContainer = styled.div`
color: red;
- padding-right: 15px;
+ padding-left: 15px;
+ display: inline-block;
`;
type LoadDataFooterProps = {
@@ -45,34 +48,40 @@ type LoadDataFooterProps = {
onConfirm: () => void;
confirmText: string;
prependText?: string;
- errorText?: string;
+ errorText?: string | null;
};
-const LoadDataFooter: React.FC<LoadDataFooterProps> = ({
+const LoadDataFooter: React.FC<LoadDataFooterProps & WrappedComponentProps> = ({
disabled,
+ intl,
isLoading,
onConfirm,
confirmText,
prependText = '',
errorText = ''
-}) => {
+}: LoadDataFooterProps & WrappedComponentProps) => {
return (
<LoadDataFooterContainer>
<div>
- {errorText && <ErrorContainer>{errorText}</ErrorContainer>}
{prependText}
<AddDataButton
disabled={disabled}
isLoading={isLoading}
onClick={onConfirm}
- width="100px"
+ width="130px"
cta
>
- {confirmText}
+ {isLoading && <LoadingSpinner size={12} />}
+ {isLoading
+ ? null
+ : intl.formatMessage({
+ id: confirmText
+ })}
</AddDataButton>
+ {errorText && <ErrorContainer>{errorText}</ErrorContainer>}
</div>
</LoadDataFooterContainer>
);
};
-export default LoadDataFooter;
+export default injectIntl(LoadDataFooter) as React.FC<LoadDataFooterProps>;
diff --git a/src/components/src/modals/tilesets-modals/load-tileset.tsx b/src/components/src/modals/tilesets-modals/load-tileset.tsx
index b811b67bb..0583f9648 100644
--- a/src/components/src/modals/tilesets-modals/load-tileset.tsx
+++ b/src/components/src/modals/tilesets-modals/load-tileset.tsx
@@ -142,7 +142,9 @@ function LoadTilesetTabFactory() {
*/}
<div>
<CurrentForm setResponse={setResponse} />
+ {/**
{error && <div>{getError(error)}</div>}
+ */}
</div>
</div>
<MetaContainer>
@@ -161,7 +163,8 @@ function LoadTilesetTabFactory() {
disabled={Boolean(error) || !isReady(response)}
isLoading={loading || isAddingDatasets}
onConfirm={createTileDataset}
- confirmText="Add Tileset"
+ confirmText="tilesetSetup.addTilesetText"
+ errorText={error && getError(error)}
/>
</LoadTilesetTabContainer>
);
diff --git a/src/components/src/modals/tilesets-modals/tileset-vector-form.tsx b/src/components/src/modals/tilesets-modals/tileset-vector-form.tsx
index 3fc39a146..56a291b21 100644
--- a/src/components/src/modals/tilesets-modals/tileset-vector-form.tsx
+++ b/src/components/src/modals/tilesets-modals/tileset-vector-form.tsx
@@ -4,13 +4,8 @@
import React, {useCallback, useEffect, useState, useMemo} from 'react';
import styled from 'styled-components';
-import {
- getMetaUrl,
- parseVectorMetadata,
- VectorTileMetadata,
- DatasetType,
- VectorTileType
-} from '@kepler.gl/layers';
+import {DatasetType, VectorTileType} from '@kepler.gl/constants';
+import {getMetaUrl, parseVectorMetadata, VectorTileMetadata} from '@kepler.gl/table';
import {TileJSON} from '@loaders.gl/mvt';
import {PMTilesMetadata} from '@loaders.gl/pmtiles';
@@ -63,6 +58,7 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
const [tileName, setTileName] = useState<string>('');
const [tileUrl, setTileUrl] = useState<string>('');
const [metadataUrl, setMetadataUrl] = useState<string | null>('');
+ const [initialFetchError, setInitialFetchError] = useState<Error | null>(null);
const onTileNameChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
@@ -89,7 +85,16 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
if (!metadataUrl && potentialMetadataUrl) {
// check if URL exists before setting it as the metadata URL
const resp = await fetch(potentialMetadataUrl);
- if (resp.ok) setMetadataUrl(potentialMetadataUrl);
+ if (resp.ok) {
+ setInitialFetchError(null);
+ setMetadataUrl(potentialMetadataUrl);
+ } else {
+ setInitialFetchError(
+ new Error(`Metadata loading failed: ${resp.status} ${resp.statusText}`)
+ );
+ }
+ } else {
+ setInitialFetchError(null);
}
if (!tileName) {
setTileName(newTileUrl.split('/').pop() || newTileUrl);
@@ -97,6 +102,7 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
},
[setTileUrl, tileName, setMetadataUrl, metadataUrl]
);
+
const process = useMemo(() => {
return (value: PMTilesMetadata | TileJSON) =>
parseVectorMetadata(value, {tileUrl: metadataUrl});
@@ -123,17 +129,26 @@ const TilesetVectorForm: React.FC<TilesetVectorFormProps> = ({setResponse}) => {
metadata,
dataset,
loading,
- error: metaError
+ error: metaError || initialFetchError
});
} else {
setResponse({
metadata,
dataset: null,
loading,
- error: metaError
+ error: metaError || initialFetchError
});
}
- }, [setResponse, metadata, loading, metaError, tileUrl, tileName, metadataUrl]);
+ }, [
+ setResponse,
+ metadata,
+ loading,
+ metaError,
+ initialFetchError,
+ tileUrl,
+ tileName,
+ metadataUrl
+ ]);
useEffect(() => {
if (metadata) {
diff --git a/src/components/src/side-panel/common/dataset-info.tsx b/src/components/src/side-panel/common/dataset-info.tsx
index bb7e689b6..743a77c65 100644
--- a/src/components/src/side-panel/common/dataset-info.tsx
+++ b/src/components/src/side-panel/common/dataset-info.tsx
@@ -5,7 +5,7 @@ import React from 'react';
import styled from 'styled-components';
import {format} from 'd3-format';
-import {DatasetType} from '@kepler.gl/layers';
+import {DatasetType} from '@kepler.gl/constants';
import {FormattedMessage} from '@kepler.gl/localization';
import {DataContainerInterface} from '@kepler.gl/utils';
diff --git a/src/components/src/side-panel/common/dataset-title.tsx b/src/components/src/side-panel/common/dataset-title.tsx
index a4cdd66d2..185d9d8c0 100644
--- a/src/components/src/side-panel/common/dataset-title.tsx
+++ b/src/components/src/side-panel/common/dataset-title.tsx
@@ -52,6 +52,7 @@ type MiniDataset = {
id: string;
color: RGBColor;
label?: string;
+ disableDataOperation?: boolean;
};
export type DatasetTitleProps = {
@@ -137,10 +138,11 @@ export default function DatasetTitleFactory(
if (typeof onTitleClick === 'function') {
onTitleClick();
} else if (typeof showDatasetTable === 'function') {
+ if (dataset.disableDataOperation) return;
showDatasetTable(datasetId);
}
},
- [onTitleClick, showDatasetTable, datasetId]
+ [onTitleClick, showDatasetTable, datasetId, dataset.disableDataOperation]
);
return (
@@ -168,7 +170,7 @@ export default function DatasetTitleFactory(
<ArrowRight height="12px" />
</CenterFlexbox>
) : null}
- {showDatasetTable ? (
+ {showDatasetTable && !dataset.disableDataOperation ? (
<ShowDataTable id={datasetId} showDatasetTable={showDatasetTable} />
) : null}
{showDeleteDataset ? (
diff --git a/src/components/src/side-panel/layer-panel/custom-palette.tsx b/src/components/src/side-panel/layer-panel/custom-palette.tsx
index d234c8df3..b99a2b6b3 100644
--- a/src/components/src/side-panel/layer-panel/custom-palette.tsx
+++ b/src/components/src/side-panel/layer-panel/custom-palette.tsx
@@ -703,6 +703,7 @@ export type CategoricalCustomPaletteInputProps = {
onAdd: (index: number) => void;
onToggleSketcher: (index: number) => void;
allValues: string[] | number[];
+ disableDelete?: boolean;
};
export const CategoricalCustomPaletteInput: React.FC<CategoricalCustomPaletteInputProps> = ({
@@ -712,6 +713,7 @@ export const CategoricalCustomPaletteInput: React.FC<CategoricalCustomPaletteInp
colorMap,
actionIcons = defaultActionIcons,
onDelete,
+ disableDelete,
onAdd,
onToggleSketcher,
addColorMapValue,
@@ -721,7 +723,7 @@ export const CategoricalCustomPaletteInput: React.FC<CategoricalCustomPaletteInp
allValues
}: CategoricalCustomPaletteInputProps) => {
const selectedValues: (number | string | null)[] = useMemo(() => {
- if (!colorMap) return [];
+ if (!colorMap || !colorMap[index]) return [];
const value = colorMap[index][0];
const values = Array.isArray(value) ? value : value !== null ? [value] : [];
return values;
@@ -750,7 +752,9 @@ export const CategoricalCustomPaletteInput: React.FC<CategoricalCustomPaletteInp
)}
</div>
<div className="custom-palette-input__right">
- <DeleteColorStop onColorDelete={onColorDelete} IconComponent={actionIcons.delete} />
+ {!disableDelete ? (
+ <DeleteColorStop onColorDelete={onColorDelete} IconComponent={actionIcons.delete} />
+ ) : null}
</div>
</SortableItem>
);
@@ -1012,6 +1016,7 @@ function CustomPaletteFactory(): React.FC<CustomPaletteProps> {
actionIcons={actionIcons}
onAdd={onAdd}
onDelete={onDelete}
+ disableDelete={colors.length <= 2}
onToggleSketcher={onToggleSketcher}
addColorMapValue={addCategoricalColorMapValue}
removeColorMapValue={removeCategoricalColorMapValue}
diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
index eb6b97291..432c5cd43 100644
--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
@@ -27,20 +27,13 @@ import VisConfigSliderFactory from './vis-config-slider';
import VisConfigSwitchFactory from './vis-config-switch';
import VectorTileLayerConfiguratorFactory from './vector-tile-layer-configurator';
-import {capitalizeFirstLetter} from '@kepler.gl/utils';
-
+import {ActionHandler, toggleModal} from '@kepler.gl/actions';
import {AGGREGATION_TYPE_OPTIONS, LAYER_TYPES} from '@kepler.gl/constants';
-import {
- AggregationLayer,
- Layer,
- LayerBaseConfig,
- VisualChannel,
- matchDatasetType
-} from '@kepler.gl/layers';
+import {AggregationLayer, Layer, LayerBaseConfig, VisualChannel} from '@kepler.gl/layers';
-import {ActionHandler, toggleModal} from '@kepler.gl/actions';
-import {Datasets} from '@kepler.gl/table';
+import {matchDatasetType, Datasets} from '@kepler.gl/table';
import {ColorUI, LayerVisConfig, NestedPartial} from '@kepler.gl/types';
+import {capitalizeFirstLetter} from '@kepler.gl/utils';
type LayerConfiguratorProps = {
layer: Layer;
diff --git a/src/components/src/side-panel/layer-panel/vector-tile-layer-configurator.tsx b/src/components/src/side-panel/layer-panel/vector-tile-layer-configurator.tsx
index 08a4cefe8..209927837 100644
--- a/src/components/src/side-panel/layer-panel/vector-tile-layer-configurator.tsx
+++ b/src/components/src/side-panel/layer-panel/vector-tile-layer-configurator.tsx
@@ -162,7 +162,8 @@ function VectorTileLayerConfiguratorFactory(
<LayerConfigGroup
{...visConfiguratorProps}
label={'layer.radius'}
- description="Point radius in meters"
+ description="Point radius in pixels or meters"
+ collapsible
>
{layer.config.visConfig.radiusByZoom?.enabled && visConfiguratorProps.onChange ? (
<VisConfigByZoomInput
@@ -179,6 +180,16 @@ function VectorTileLayerConfiguratorFactory(
label={false}
/>
)}
+
+ <ConfigGroupCollapsibleContent>
+ {layerChannelConfigProps.fields ? (
+ <ChannelByValueSelector
+ {...layerChannelConfigProps}
+ channel={layer.visualChannels.radius}
+ />
+ ) : null}
+ <VisConfigSwitch {...layer.visConfigSettings.radiusUnits} {...visConfiguratorProps} />
+ </ConfigGroupCollapsibleContent>
</LayerConfigGroup>
</StyledLayerConfigurator>
);
diff --git a/src/components/src/types.ts b/src/components/src/types.ts
index 5202e6e87..2e55fd560 100644
--- a/src/components/src/types.ts
+++ b/src/components/src/types.ts
@@ -48,8 +48,3 @@ export type SidePanelProps = {
onSaveMap?: () => void;
version: string;
};
-
-export type DatasetAttribution = {
- title: string;
- url: string;
-};
diff --git a/src/constants/src/dataset.ts b/src/constants/src/dataset.ts
new file mode 100644
index 000000000..4af6da352
--- /dev/null
+++ b/src/constants/src/dataset.ts
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+export enum DatasetType {
+ LOCAL = 'local',
+ VECTOR_TILE = 'vectorTile'
+}
+
+export enum TileType {
+ VECTOR_TILE = 'vectorTile'
+}
+
+export enum VectorTileType {
+ MVT = 'mvt',
+ PMTILES = 'pmtiles'
+}
+
+export type VectorTileDatasetMetadata = {
+ type: VectorTileType;
+ tilesetDataUrl: string;
+ tilesetMetadataUrl?: string;
+};
diff --git a/src/constants/src/index.ts b/src/constants/src/index.ts
index 663dd8668..629b35a7d 100644
--- a/src/constants/src/index.ts
+++ b/src/constants/src/index.ts
@@ -7,6 +7,7 @@ export * from './colors-by-theme';
export * from './color-palettes';
export * from './default-settings';
export * from './layers';
+export * from './dataset';
export {default as KeyEvent} from './keyevent';
export * from './tooltip';
export * from './user-feedbacks';
diff --git a/src/layers/package.json b/src/layers/package.json
index 7d7f0375d..2e040bd98 100644
--- a/src/layers/package.json
+++ b/src/layers/package.json
@@ -79,7 +79,7 @@
"react": "^18.2.0",
"react-intl": "^6.3.0",
"react-markdown": "^6.0.3",
- "reselect": "^4.0.0",
+ "reselect": "^4.1.0",
"s2-geometry": "^1.2.10",
"styled-components": "6.1.8",
"type-analyzer": "0.4.0",
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index a5517e067..56c191fd7 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -178,7 +178,7 @@ function* generateColor(): Generator<RGBColor> {
if (index === layerColors.length) {
index = 0;
}
- yield layerColors[index++] as unknown as RGBColor;
+ yield layerColors[index++];
}
}
diff --git a/src/layers/src/index.ts b/src/layers/src/index.ts
index 9d5ab2c24..e25ff6fe4 100644
--- a/src/layers/src/index.ts
+++ b/src/layers/src/index.ts
@@ -40,21 +40,8 @@ import {default as S2GeometryLayer} from './s2-geometry-layer/s2-geometry-layer'
export {defaultElevation as s2DefaultElevation} from './s2-geometry-layer/s2-geometry-layer';
export {getS2Center} from './s2-geometry-layer/s2-utils';
export {default as AggregationLayer} from './aggregation-layer';
+//import {default as VectorTileLayer} from './vector-tile/vector-tile-layer';
-// import {default as VectorTileLayer} from './vector-tile/vector-tile-layer';
-
-export {
- getMetaUrl,
- parseVectorMetadata,
- matchDatasetType,
- DatasetType,
- TileType,
- VectorTileType
-} from './vector-tile/utils/vector-tile-utils';
-export type {
- VectorTileDatasetMetadata,
- VectorTileMetadata
-} from './vector-tile/utils/vector-tile-utils';
export {default as VectorTileIcon} from './vector-tile/vector-tile-icon';
export {default as VectorTileLayer} from './vector-tile/vector-tile-layer';
diff --git a/src/layers/src/vector-tile/abstract-tile-layer.ts b/src/layers/src/vector-tile/abstract-tile-layer.ts
index 367120edd..7bdf7078b 100644
--- a/src/layers/src/vector-tile/abstract-tile-layer.ts
+++ b/src/layers/src/vector-tile/abstract-tile-layer.ts
@@ -6,6 +6,7 @@ import throttle from 'lodash.throttle';
import {notNullorUndefined} from '@kepler.gl/common-utils';
import {SCALE_TYPES, ALL_FIELD_TYPES, LAYER_VIS_CONFIGS} from '@kepler.gl/constants';
import {
+ isTileDataset,
KeplerTable as KeplerDataset,
Datasets as KeplerDatasets,
GpuFilter
@@ -37,7 +38,6 @@ import {
VisualChannelDomain,
VisualChannelField
} from '../base-layer';
-import {isTileDataset} from './utils/vector-tile-utils';
import TileDataset from './common-tile/tile-dataset';
import {isIndexedField, isDomainQuantiles} from './common-tile/tile-utils';
@@ -47,7 +47,8 @@ export const DEFAULT_RADIUS = 1;
export type AbstractTileLayerVisConfigSettings = {
strokeColor: VisConfigColorSelect;
strokeOpacity: VisConfigNumber;
- radius: VisConfigRange;
+ radius: VisConfigNumber;
+ radiusUnits: VisConfigBoolean;
enable3d: VisConfigBoolean;
stroked: VisConfigBoolean;
transition: VisConfigBoolean;
@@ -84,12 +85,19 @@ export const commonTileVisConfigs = {
},
radius: {
...LAYER_VIS_CONFIGS.radius,
- isRanged: true,
- range: [0, 1000],
+ range: [0.1, 100],
step: 0.1,
- defaultValue: [50, 50],
+ defaultValue: DEFAULT_RADIUS,
allowCustomValue: false
- } as VisConfigRange,
+ } as VisConfigNumber,
+ radiusUnits: {
+ type: 'boolean',
+ defaultValue: true,
+ label: 'Radius in pixels',
+ group: '',
+ property: 'radiusUnits',
+ description: 'Radius in pixels or in meters'
+ } as VisConfigBoolean,
enable3d: 'enable3d' as const,
stroked: {
...LAYER_VIS_CONFIGS.stroked,
@@ -400,15 +408,12 @@ export default abstract class AbstractTileLayer<
indexKey
});
- const getPointRadius = () => DEFAULT_RADIUS;
-
const metadata = dataset?.metadata as LayerData | undefined;
return {
...(metadata ? {minZoom: metadata.minZoom} : {}),
...(metadata ? {maxZoom: metadata.maxZoom} : {}),
- ...accessors,
- getPointRadius
+ ...accessors
};
}
diff --git a/src/layers/src/vector-tile/common-tile/tile-dataset.ts b/src/layers/src/vector-tile/common-tile/tile-dataset.ts
index 6d7050748..b59592b76 100644
--- a/src/layers/src/vector-tile/common-tile/tile-dataset.ts
+++ b/src/layers/src/vector-tile/common-tile/tile-dataset.ts
@@ -5,7 +5,7 @@ import {Field as KeplerField} from '@kepler.gl/types';
import {quickInsertionSort} from '@kepler.gl/utils';
import IterableTileSet, {RowCountAccessor} from './iterable-tile-set';
-import {pruneQuantiles} from '../utils/vector-tile-utils';
+import {pruneQuantiles} from './tile-utils';
export type Datum = number | string | null;
diff --git a/src/layers/src/vector-tile/common-tile/tile-utils.ts b/src/layers/src/vector-tile/common-tile/tile-utils.ts
index 41276377e..3178c7033 100644
--- a/src/layers/src/vector-tile/common-tile/tile-utils.ts
+++ b/src/layers/src/vector-tile/common-tile/tile-utils.ts
@@ -48,3 +48,16 @@ export function getPropertyByZoom(
return stops[i - 1][1];
};
}
+
+/**
+ * Remove null/0 values from the bottom of the quantiles. If the column has many nulls
+ * or 0s at the bottom of the quantiles, it will wash out color scales and produce
+ * meaningless "no value" legend entries. We want to keep the first 0 and no others.
+ * Operates in place.
+ */
+export function pruneQuantiles(quantiles: number[]): void {
+ const firstNonZeroIdx = quantiles.findIndex(d => d !== null && d !== 0);
+ if (firstNonZeroIdx > 0) {
+ quantiles.splice(0, firstNonZeroIdx - 1);
+ }
+}
diff --git a/src/layers/src/vector-tile/vector-tile-layer.ts b/src/layers/src/vector-tile/vector-tile-layer.ts
index dcc601af7..def81db24 100644
--- a/src/layers/src/vector-tile/vector-tile-layer.ts
+++ b/src/layers/src/vector-tile/vector-tile-layer.ts
@@ -12,15 +12,22 @@ import GL from '@luma.gl/constants';
import {notNullorUndefined} from '@kepler.gl/common-utils';
import {
+ DatasetType,
+ TileType,
+ VectorTileType,
+ VectorTileDatasetMetadata,
SCALE_TYPES,
CHANNEL_SCALES,
DEFAULT_COLOR_UI,
LAYER_VIS_CONFIGS
} from '@kepler.gl/constants';
import {
+ getTileUrl,
+ getLoaderOptions,
KeplerTable as KeplerDataset,
Datasets as KeplerDatasets,
- GpuFilter
+ GpuFilter,
+ VectorTileMetadata
} from '@kepler.gl/table';
import {
AnimationConfig,
@@ -36,7 +43,6 @@ import {
} from '@kepler.gl/types';
import {DataContainerInterface} from '@kepler.gl/utils';
-import {getTileUrl} from './utils/vector-tile-utils';
import {MVTLayer as CustomMVTLayer} from './mvt-layer';
import VectorTileIcon from './vector-tile-icon';
import {
@@ -47,14 +53,6 @@ import {
VisualChannelDomain,
VisualChannelField
} from '../base-layer';
-import {
- VectorTileMetadata,
- getLoaderOptions,
- DatasetType,
- TileType,
- VectorTileType,
- VectorTileDatasetMetadata
-} from './utils/vector-tile-utils';
import AbstractTileLayer, {
LayerData as CommonLayerData,
@@ -70,7 +68,8 @@ import {
getPropertyByZoom
} from './common-tile/tile-utils';
-export const DEFAULT_HIGHLIGHT_COLOR = [252, 242, 26, 150];
+export const DEFAULT_HIGHLIGHT_FILL_COLOR = [252, 242, 26, 150];
+export const DEFAULT_HIGHLIGHT_STROKE_COLOR = [252, 242, 26, 255];
export const MAX_CACHE_SIZE_MOBILE = 1; // Minimize caching, visible tiles will always be loaded
export const DEFAULT_STROKE_WIDTH = 1;
@@ -138,7 +137,17 @@ export const vectorTileVisConfigs = {
property: 'strokeWidth',
defaultValue: 0.5,
allowCustomValue: false
- }
+ },
+
+ radiusScale: 'radiusScale' as any,
+ radiusRange: {
+ ...LAYER_VIS_CONFIGS.radiusRange,
+ type: 'number',
+ defaultValue: [0, 1],
+ isRanged: true,
+ range: [0, 1],
+ step: 0.01
+ } as VisConfigRange
};
export type VectorTileLayerConfig = Merge<
@@ -147,7 +156,13 @@ export type VectorTileLayerConfig = Merge<
sizeField?: VisualChannelField;
sizeScale?: string;
sizeDomain?: VisualChannelDomain;
+
strokeColorField: VisualChannelField;
+
+ radiusField?: VisualChannelField;
+ radiusScale?: string;
+ radiusDomain?: VisualChannelDomain;
+ radiusRange?: any;
}
>;
@@ -239,6 +254,21 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
accessor: 'getLineWidth',
condition: config => config.visConfig.stroked,
getAttributeValue: config => config.visConfig.strokeWidth || DEFAULT_STROKE_WIDTH
+ },
+ radius: {
+ property: 'radius',
+ field: 'radiusField',
+ scale: 'radiusScale',
+ domain: 'radiusDomain',
+ range: 'radiusRange',
+ key: 'radius',
+ channelScaleType: CHANNEL_SCALES.size,
+ nullValue: 0,
+ getAttributeValue: config => {
+ return config.visConfig.radius || config.radius;
+ },
+ accessor: 'getPointRadius',
+ defaultValue: config => config.radius
}
};
}
@@ -258,7 +288,11 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
...defaultLayerConfig.colorUI,
// @ts-expect-error LayerConfig
strokeColorRange: DEFAULT_COLOR_UI
- }
+ },
+
+ radiusField: null,
+ radiusDomain: [0, 1],
+ radiusScale: SCALE_TYPES.linear
};
}
@@ -432,7 +466,10 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
data,
getFillColor: props.getFillColorByZoom ? props.getFillColor(zoom) : props.getFillColor,
getElevation: props.getElevationByZoom ? props.getElevation(zoom) : props.getElevation,
- pointRadiusScale: props.getPointRadiusScaleByZoom(zoom),
+ // radius for points
+ pointRadiusScale: props.pointRadiusScale, // props.getPointRadiusScaleByZoom(zoom),
+ pointRadiusUnits: props.pointRadiusUnits,
+ getPointRadius: props.getPointRadius,
// For some reason tile Layer reset autoHighlight to false
pickable: true,
autoHighlight: true,
@@ -467,6 +504,7 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
const heightField = this.config.heightField as KeplerField;
const strokeColorField = this.config.strokeColorField as KeplerField;
const sizeField = this.config.sizeField as KeplerField;
+ const radiusField = this.config.radiusField as KeplerField;
if (data.tileSource) {
const hoveredObject = this.hasHoveredObject(objectHovered);
@@ -482,6 +520,7 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
getFilterValue: this.getGpuFilterValueAccessor(opts),
filterRange: gpuFilter.filterRange,
lineWidthUnits: 'pixels',
+
binary: false,
elevationScale: visConfig.elevationScale * eleZoomFactor,
extruded: visConfig.enable3d,
@@ -492,11 +531,12 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
renderSubLayers: this.renderSubLayers,
// when radiusUnits is meter
getPointRadiusScaleByZoom: getPropertyByZoom(visConfig.radiusByZoom, visConfig.radius),
- pointRadiusScale: 1,
+ pointRadiusUnits: visConfig.radiusUnits ? 'pixels' : 'meters',
+ pointRadiusScale: radiusField ? visConfig.radius : 1,
pointRadiusMinPixels: 1,
autoHighlight: true,
- highlightColor: DEFAULT_HIGHLIGHT_COLOR,
+ highlightColor: DEFAULT_HIGHLIGHT_FILL_COLOR,
pickable: true,
transitions,
updateTriggers: {
@@ -544,6 +584,14 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
sizeScale: this.config.sizeScale,
sizeDomain: this.config.sizeDomain,
currentTime: isIndexedField(sizeField) ? animationConfig.currentTime : null
+ },
+ getPointRadius: {
+ radius: visConfig.radius,
+ radiusField: this.config.radiusField,
+ radiusScale: this.config.radiusScale,
+ radiusDomain: this.config.radiusDomain,
+ radiusRange: this.config.radiusRange,
+ currentTime: isIndexedField(radiusField) ? animationConfig.currentTime : null
}
},
_subLayerProps: {
@@ -562,17 +610,18 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, Featu
...(hoveredObject
? [
new GeoJsonLayer({
- // @ts-expect-error not typed
+ // @ts-expect-error props not typed?
...objectHovered.sourceLayer?.props,
...(this.getDefaultHoverLayerProps() as any),
visible: true,
wrapLongitude: false,
data: [hoveredObject],
- getLineColor: this.config.highlightColor,
- getFillColor: this.config.highlightColor,
- // always draw outline
+ getLineColor: DEFAULT_HIGHLIGHT_STROKE_COLOR,
+ getFillColor: DEFAULT_HIGHLIGHT_FILL_COLOR,
+ getLineWidth: visConfig.strokeWidth + 1,
+ lineWidthUnits: 'pixels',
stroked: true,
- filled: false
+ filled: true
})
]
: [])
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index e15d760b1..be58e7348 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -603,7 +603,8 @@ ${'```'}
or: 'or'
},
tilesetSetup: {
- header: 'Setup Vector Tiles'
+ header: 'Setup Vector Tiles',
+ addTilesetText: 'Add Tileset'
},
geocoder: {
title: 'Enter an address or coordinates, ex 37.79,-122.40'
diff --git a/src/reducers/package.json b/src/reducers/package.json
index 525b78fdf..cc8d005a5 100644
--- a/src/reducers/package.json
+++ b/src/reducers/package.json
@@ -74,7 +74,7 @@
"react-palm": "^3.3.8",
"redux": "^4.2.1",
"redux-actions": "^2.2.1",
- "reselect": "^4.0.0"
+ "reselect": "^4.1.0"
},
"overrides": {
"@types/lodash": "4.17.5"
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index 5bd596f7f..c5f86f1b3 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -14,7 +14,7 @@ import {
aggregate
} from '@kepler.gl/utils';
-import {Layer, VisualChannel} from '@kepler.gl/layers';
+import {Layer} from '@kepler.gl/layers';
import {createEffect} from '@kepler.gl/effects';
import {notNullorUndefined} from '@kepler.gl/common-utils';
import {AGGREGATION_TYPES, LAYER_BLENDINGS, OVERLAY_BLENDINGS} from '@kepler.gl/constants';
@@ -822,7 +822,7 @@ export function validateSavedVisualChannels(
savedLayer: ParsedLayer,
options: {throwOnError?: boolean} = {}
): null | Layer {
- (Object.values(newLayer.visualChannels) as VisualChannel[]).forEach(({field, scale, key}) => {
+ Object.values(newLayer.visualChannels).forEach(({field, scale, key}) => {
let foundField;
if (savedLayer.config) {
if (savedLayer.config[field]) {
diff --git a/src/schemas/src/dataset-schema.ts b/src/schemas/src/dataset-schema.ts
index 9141a899a..83245ac91 100644
--- a/src/schemas/src/dataset-schema.ts
+++ b/src/schemas/src/dataset-schema.ts
@@ -34,6 +34,7 @@ export type SavedDatasetV1 = {
fields: SavedField[];
type?: string;
metadata?: JsonObject;
+ disableDataOperation?: boolean;
};
};
@@ -94,7 +95,8 @@ export const propertiesV1 = {
properties: fieldPropertiesV1
}),
type: null,
- metadata: null
+ metadata: null,
+ disableDataOperation: null
};
export class DatasetSchema extends Schema {
@@ -149,7 +151,8 @@ export class DatasetSchema extends Schema {
return {
data: {fields: updatedFields, rows: dataset.allData},
info: pick(dataset, ['id', 'label', 'color', 'type']),
- ...(dataset.metadata ? {metadata: dataset.metadata} : {})
+ ...(dataset.metadata ? {metadata: dataset.metadata} : {}),
+ ...(dataset.disableDataOperation ? {disableDataOperation: dataset.disableDataOperation} : {})
};
}
}
diff --git a/src/table/package.json b/src/table/package.json
index b6d6fa94b..d1ef0b5e6 100644
--- a/src/table/package.json
+++ b/src/table/package.json
@@ -34,13 +34,16 @@
"@kepler.gl/constants": "3.1.0-alpha.3",
"@kepler.gl/types": "3.1.0-alpha.3",
"@kepler.gl/utils": "3.1.0-alpha.3",
+ "@loaders.gl/mvt": "^4.3.2",
+ "@loaders.gl/pmtiles": "^4.3.2",
"@types/d3-array": "^2.8.0",
"@types/lodash.uniq": "^4.5.7",
"d3-array": "^2.8.0",
"global": "^4.3.0",
"lodash.uniq": "^4.0.1",
"moment": "^2.10.6",
- "react-palm": "^3.3.8"
+ "react-palm": "^3.3.8",
+ "type-analyzer": "0.4.0"
},
"nyc": {
"sourceMap": false,
diff --git a/src/table/src/dataset-utils.ts b/src/table/src/dataset-utils.ts
index f73cfb975..e7a20188a 100644
--- a/src/table/src/dataset-utils.ts
+++ b/src/table/src/dataset-utils.ts
@@ -6,12 +6,18 @@ import KeplerTable, {Datasets} from './kepler-table';
import {ProtoDataset, RGBColor} from '@kepler.gl/types';
import Task from 'react-palm/tasks';
+import {DatasetType, VectorTileType} from '@kepler.gl/constants';
import {
hexToRgb,
validateInputData,
datasetColorMaker,
getApplicationConfig
} from '@kepler.gl/utils';
+import {PMTilesSource, PMTilesMetadata} from '@loaders.gl/pmtiles';
+import {/* MVTSource,*/ TileJSON} from '@loaders.gl/mvt';
+
+import {getMVTMetadata} from './tileset/tileset-utils';
+import {parseVectorMetadata} from './tileset/vector-tile-utils';
// apply a color for each dataset
// to use as label colors
@@ -80,12 +86,71 @@ async function updateTable({table, data}) {
return updated;
}
-async function createTable({info, color, opts, data}) {
+type CreateTableProps = {
+ info: any;
+ color: RGBColor;
+ opts: {
+ metadata?: Record<string, unknown>;
+ };
+ data: any;
+};
+
+async function createTable(dataasetInfo: CreateTableProps) {
+ const {info, color, opts, data} = dataasetInfo;
+
+ // update metadata for remote tiled datasets
+ const refreshedMetadata = await refreshMetadata(dataasetInfo);
+ const metadata = refreshedMetadata ? {...opts.metadata, ...refreshedMetadata} : opts.metadata;
+
const TableClass = getApplicationConfig().table ?? KeplerTable;
- const table = new TableClass({info, color, ...opts});
+ const table = new TableClass({
+ info,
+ color,
+ ...opts,
+ metadata
+ });
await table.importData({data});
return table;
}
const UPDATE_TABLE_TASK = Task.fromPromise(updateTable, 'UPDATE_TABLE_TASK');
const CREATE_TABLE_TASK = Task.fromPromise(createTable, 'CREATE_TABLE_TASK');
+
+/**
+ * Fetch metadata for vector tile layers using tilesetMetadataUrl from metadata
+ * @param datasetInfo
+ * @returns
+ */
+async function refreshMetadata(datasetInfo: CreateTableProps) {
+ // so far only vector tile layers should refresh metadata
+ if (datasetInfo.info.type !== DatasetType.VECTOR_TILE) {
+ return null;
+ }
+
+ const {type, tilesetMetadataUrl} = datasetInfo.opts.metadata || {};
+
+ if (
+ !(type === VectorTileType.PMTILES || type === VectorTileType.MVT) ||
+ typeof tilesetMetadataUrl !== 'string'
+ ) {
+ return null;
+ }
+
+ try {
+ let rawMetadata: PMTilesMetadata | TileJSON | null = null;
+ if (type === VectorTileType.MVT) {
+ rawMetadata = await getMVTMetadata(tilesetMetadataUrl);
+ } else {
+ const tileSource = PMTilesSource.createDataSource(tilesetMetadataUrl, {});
+ rawMetadata = await tileSource.metadata;
+ }
+
+ if (rawMetadata) {
+ return parseVectorMetadata(rawMetadata);
+ }
+ } catch (err) {
+ // ignore for now, and use old metadata?
+ }
+
+ return null;
+}
diff --git a/src/table/src/index.ts b/src/table/src/index.ts
index 25e855cf1..dfffca942 100644
--- a/src/table/src/index.ts
+++ b/src/table/src/index.ts
@@ -23,3 +23,5 @@ export type {
} from './kepler-table';
export * from './gpu-filter-utils';
export * from './dataset-utils';
+export * from './tileset/tileset-utils';
+export * from './tileset/vector-tile-utils';
diff --git a/src/table/src/tileset/tileset-utils.ts b/src/table/src/tileset/tileset-utils.ts
new file mode 100644
index 000000000..83b42e29d
--- /dev/null
+++ b/src/table/src/tileset/tileset-utils.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import {TileJSONLoader, TileJSON} from '@loaders.gl/mvt';
+
+/**
+ * MVTSource in current loaders ignores attribution
+ * TODO: remove once MVTSource is ready
+ */
+export async function getMVTMetadata(metadataURL: string | null): Promise<TileJSON | null> {
+ if (!metadataURL) return null;
+
+ let response: Response;
+ try {
+ // Annoyingly, on CORS errors, fetch doesn't use the response status/ok mechanism but instead throws
+ // CORS errors are common when requesting an unavailable sub resource such as a metadata file or an unavailable tile)
+ response = await fetch(metadataURL);
+ } catch (error: unknown) {
+ // eslint-disable-next-line no-console
+ console.error((error as TypeError).message);
+ return null;
+ }
+ if (!response.ok) {
+ // eslint-disable-next-line no-console
+ console.error(response.statusText);
+ return null;
+ }
+ const tileJSON = await response.text();
+ const metadata = TileJSONLoader.parseTextSync?.(tileJSON) || null;
+
+ const rawMetadata = JSON.parse(tileJSON);
+ if (rawMetadata?.attribution) {
+ metadata.attributions = [rawMetadata.attribution];
+ }
+
+ return metadata;
+}
diff --git a/src/layers/src/vector-tile/utils/vector-tile-utils.spec.ts b/src/table/src/tileset/vector-tile-utils.spec.ts
similarity index 97%
rename from src/layers/src/vector-tile/utils/vector-tile-utils.spec.ts
rename to src/table/src/tileset/vector-tile-utils.spec.ts
index 67ae2d266..6de089733 100644
--- a/src/layers/src/vector-tile/utils/vector-tile-utils.spec.ts
+++ b/src/table/src/tileset/vector-tile-utils.spec.ts
@@ -6,7 +6,7 @@ import {DATA_TYPES} from 'type-analyzer';
import {ALL_FIELD_TYPES, FILTER_TYPES} from '@kepler.gl/constants';
import {getTileUrl, getMetaUrl, parseVectorMetadata as parseMetadata} from './vector-tile-utils';
-import {PMTILES_METADATA, MVT_METADATA} from '../../../../../test/fixtures/tile-metadata';
+import {PMTILES_METADATA, MVT_METADATA} from '../../../../test/fixtures/tile-metadata';
describe('getTileUrl', () => {
[
@@ -86,6 +86,7 @@ test('parseMetadata, metadata from MVTSource and Mapbox URL', () => {
expect(
parseMetadata(MVT_METADATA, {tileUrl: 'https://api.mapbox.com/v4/spam/{z}/{x}/{y}.mvt'})
).toEqual({
+ attributions: [],
metaJson: null,
bounds: [-180, -85, 180, 85],
center: [0, 0, 0],
@@ -118,6 +119,7 @@ test('parseMetadata, PMTiles from PMTileSource', () => {
'https://4sq-studio-data-staging.s3.us-west-2.amazonaws.com/some_path/some_file.pmtiles'
})
).toEqual({
+ attributions: [],
name: 'My Custom Tiles',
description: 'My Custom Tiles Description',
metaJson: null,
@@ -160,6 +162,7 @@ test('parseMetadata, PMTiles from PMTileSource', () => {
test('parseMetadata, empty input', () => {
expect(parseMetadata({})).toEqual({
+ attributions: [],
name: '',
description: '',
metaJson: null,
@@ -173,6 +176,7 @@ test('parseMetadata, empty input', () => {
expect(
parseMetadata({}, {tileUrl: 'http://xyz.api.here.com/some_id/tile/web/{z}_{x}_{y}.pbf'})
).toEqual({
+ attributions: [],
name: '',
description: '',
metaJson: null,
@@ -184,6 +188,7 @@ test('parseMetadata, empty input', () => {
});
expect(parseMetadata({}, {tileUrl: 'https://api.mapbox.com/v4/spam/{z}/{x}/{y}.mvt'})).toEqual({
+ attributions: [],
name: '',
description: '',
metaJson: null,
diff --git a/src/layers/src/vector-tile/utils/vector-tile-utils.ts b/src/table/src/tileset/vector-tile-utils.ts
similarity index 94%
rename from src/layers/src/vector-tile/utils/vector-tile-utils.ts
rename to src/table/src/tileset/vector-tile-utils.ts
index 5928480bf..6c92bbeb7 100644
--- a/src/layers/src/vector-tile/utils/vector-tile-utils.ts
+++ b/src/table/src/tileset/vector-tile-utils.ts
@@ -15,7 +15,7 @@ import {
notNullorUndefined as notNullOrUndefined,
parseUri
} from '@kepler.gl/common-utils';
-import {ALL_FIELD_TYPES, FILTER_TYPES} from '@kepler.gl/constants';
+import {DatasetType, ALL_FIELD_TYPES, FILTER_TYPES} from '@kepler.gl/constants';
import {
FilterProps,
NumericFieldFilterProps,
@@ -23,31 +23,9 @@ import {
StringFieldFilterProps,
KeplerTable as KeplerDataset
} from '@kepler.gl/table';
-import {Field as KeplerField} from '@kepler.gl/types';
+import {Field as KeplerField, KeplerLayer} from '@kepler.gl/types';
import {clamp, formatNumberByStep, getNumericStepSize, timeToUnixMilli} from '@kepler.gl/utils';
-import {default as BaseLayer} from '../../base-layer';
-
-export enum DatasetType {
- LOCAL = 'local',
- VECTOR_TILE = 'vectorTile'
-}
-
-export enum TileType {
- VECTOR_TILE = 'vectorTile'
-}
-
-export enum VectorTileType {
- MVT = 'mvt',
- PMTILES = 'pmtiles'
-}
-
-export type VectorTileDatasetMetadata = {
- type: VectorTileType;
- tilesetDataUrl: string;
- tilesetMetadataUrl?: string;
-};
-
export const getLoaderOptions = () => {
return {
mvt: {
@@ -70,6 +48,7 @@ type VectorTileField = {
};
export type VectorTileMetadata = {
+ attributions?: unknown[];
metaJson: any | null;
bounds: number[] | null;
center: number[] | null;
@@ -269,6 +248,7 @@ function parseMetadataTippecanoeFromDataSource(
}
let result: TilesetMetadata = {
+ attributions: [],
metaJson: null,
bounds: null,
center: null,
@@ -317,6 +297,10 @@ function parseMetadataTippecanoeFromDataSource(
result = {
...result,
+ attributions:
+ pmTileMetadata.attributions ||
+ (mvtMetadata.htmlAttribution ? [mvtMetadata.htmlAttribution] : undefined) ||
+ [],
...parseMetaJson(result.metaJson)
};
@@ -664,7 +648,7 @@ function attributeTypeToFieldType(aType?: string): {type: string; analyzerType:
* @param layer A layer.
* @returns Returns true if a dataset can be used as source data for a layer.
*/
-export function matchDatasetType(dataset: KeplerDataset, layer: BaseLayer): boolean {
+export function matchDatasetType(dataset: KeplerDataset, layer: KeplerLayer): boolean {
// allow selection if type is not assigned yet
if (!layer.type) {
return true;
@@ -683,16 +667,3 @@ export function matchDatasetType(dataset: KeplerDataset, layer: BaseLayer): bool
layer.supportedDatasetTypes.includes(dataset.type || '')
);
}
-
-/**
- * Remove null/0 values from the bottom of the quantiles. If the column has many nulls
- * or 0s at the bottom of the quantiles, it will wash out color scales and produce
- * meaningless "no value" legend entries. We want to keep the first 0 and no others.
- * Operates in place.
- */
-export function pruneQuantiles(quantiles: number[]): void {
- const firstNonZeroIdx = quantiles.findIndex(d => d !== null && d !== 0);
- if (firstNonZeroIdx > 0) {
- quantiles.splice(0, firstNonZeroIdx - 1);
- }
-}
diff --git a/src/types/datasets.d.ts b/src/types/datasets.d.ts
index 12b8f774d..034da69a6 100644
--- a/src/types/datasets.d.ts
+++ b/src/types/datasets.d.ts
@@ -13,3 +13,14 @@ export type ZoomStopsConfig = {
enabled?: boolean;
stops: ZoomStops | null;
};
+
+export type DatasetAttribution = {
+ title: string;
+ url: string | null;
+};
+
+export type AttributionWithStyle = DatasetAttribution & {
+ logoUrl: string;
+ height?: number;
+ bottom?: number;
+};
diff --git a/src/types/layers.d.ts b/src/types/layers.d.ts
index bbdf112d5..9c6cfa06a 100644
--- a/src/types/layers.d.ts
+++ b/src/types/layers.d.ts
@@ -451,6 +451,9 @@ export interface KeplerLayer {
};
config: LayerBaseConfig;
+ get type(): string | null;
+ get supportedDatasetTypes(): string[] | null;
+
getColorScale(
colorScale: string,
colorDomain: VisualChannelDomain,
diff --git a/yarn.lock b/yarn.lock
index 1eff3461a..5256aa866 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3315,7 +3315,7 @@ __metadata:
react-virtualized: "npm:^9.22.5"
react-vis: "npm:1.11.7"
redux: "npm:^4.2.1"
- reselect: "npm:^4.0.0"
+ reselect: "npm:^4.1.0"
styled-components: "npm:6.1.8"
suncalc: "npm:^1.9.0"
viewport-mercator-project: "npm:^6.0.0"
@@ -3461,7 +3461,7 @@ __metadata:
react: "npm:^18.2.0"
react-intl: "npm:^6.3.0"
react-markdown: "npm:^6.0.3"
- reselect: "npm:^4.0.0"
+ reselect: "npm:^4.1.0"
s2-geometry: "npm:^1.2.10"
styled-components: "npm:6.1.8"
type-analyzer: "npm:0.4.0"
@@ -3555,7 +3555,7 @@ __metadata:
react-palm: "npm:^3.3.8"
redux: "npm:^4.2.1"
redux-actions: "npm:^2.2.1"
- reselect: "npm:^4.0.0"
+ reselect: "npm:^4.1.0"
languageName: unknown
linkType: soft
@@ -3598,6 +3598,8 @@ __metadata:
"@kepler.gl/constants": "npm:3.1.0-alpha.3"
"@kepler.gl/types": "npm:3.1.0-alpha.3"
"@kepler.gl/utils": "npm:3.1.0-alpha.3"
+ "@loaders.gl/mvt": "npm:^4.3.2"
+ "@loaders.gl/pmtiles": "npm:^4.3.2"
"@types/d3-array": "npm:^2.8.0"
"@types/lodash.uniq": "npm:^4.5.7"
d3-array: "npm:^2.8.0"
@@ -3605,6 +3607,7 @@ __metadata:
lodash.uniq: "npm:^4.0.1"
moment: "npm:^2.10.6"
react-palm: "npm:^3.3.8"
+ type-analyzer: "npm:0.4.0"
languageName: unknown
linkType: soft
@@ -26256,7 +26259,7 @@ __metadata:
languageName: node
linkType: hard
-"reselect@npm:^4.0.0, reselect@npm:^4.1.8":
+"reselect@npm:^4.0.0, reselect@npm:^4.1.0, reselect@npm:^4.1.8":
version: 4.1.8
resolution: "reselect@npm:4.1.8"
checksum: 10c0/06a305a504affcbb67dd0561ddc8306b35796199c7e15b38934c80606938a021eadcf68cfd58e7bb5e17786601c37602a3362a4665c7bf0a96c1041ceee9d0b7