Skip to content

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

[Chore]: Technical: Translate deckgl-layers/layer-utils (#1789)

Maksim Suslov843123849d0c
diff --git a/src/deckgl-layers/layer-utils/cluster-utils.js b/src/deckgl-layers/layer-utils/cluster-utils.ts
similarity index 99%
rename from src/deckgl-layers/layer-utils/cluster-utils.js
rename to src/deckgl-layers/layer-utils/cluster-utils.ts
index 9170f93a1..628988bd6 100644
--- a/src/deckgl-layers/layer-utils/cluster-utils.js
+++ b/src/deckgl-layers/layer-utils/cluster-utils.ts
@@ -53,6 +53,8 @@ const getClusterer = ({clusterRadius, geoJSON}) =>
}).load(geoJSON);
export default class ClusterBuilder {
+ clusterer: any;
+
constructor() {
this.clusterer = memoize(getClusterer, clusterResolver);
}
diff --git a/src/deckgl-layers/layer-utils/cpu-aggregator.js b/src/deckgl-layers/layer-utils/cpu-aggregator.ts
similarity index 91%
rename from src/deckgl-layers/layer-utils/cpu-aggregator.js
rename to src/deckgl-layers/layer-utils/cpu-aggregator.ts
index 2572b96fc..c4c603eb8 100644
--- a/src/deckgl-layers/layer-utils/cpu-aggregator.js
+++ b/src/deckgl-layers/layer-utils/cpu-aggregator.ts
@@ -22,8 +22,34 @@
import {AGGREGATION_OPERATION, _BinSorter as BinSorter} from '@deck.gl/aggregation-layers';
import {console as Console} from 'global/window';
-import {aggregate} from 'utils/aggregate-utils';
-import {AGGREGATION_TYPES, SCALE_FUNC} from 'constants/default-settings';
+import {aggregate} from '../../utils/aggregate-utils';
+import {AGGREGATION_TYPES, SCALE_FUNC} from '../../constants/default-settings';
+import {RGBAColor} from '../../reducers';
+
+export type UpdaterType = (step, props, dimensionUpdater) => void;
+
+export type UpdateStepsType = {
+ key: string;
+ triggers: {
+ [key: string]: {
+ prop?: string;
+ updateTrigger?: string;
+ };
+ };
+ onSet?: {
+ props: string;
+ };
+ updater: UpdaterType;
+};
+
+export type DimensionType<ValueType> = {
+ key: string;
+ accessor: string;
+ getPickingInfo: (dimensionState, cell) => any;
+ nullValue: ValueType;
+ updateSteps: UpdateStepsType[];
+ getSubLayerAccessor;
+};
export const DECK_AGGREGATION_MAP = {
[AGGREGATION_OPERATION.SUM]: AGGREGATION_TYPES.sum,
@@ -122,7 +148,7 @@ export function getDimensionScale(step, props, dimensionUpdater) {
this._setDimensionState(key, {scaleFunc});
}
-function normalizeResult(result = {}) {
+function normalizeResult(result: {hexagons?; layerData?} = {}) {
// support previous hexagonAggregator API
if (result.hexagons) {
return Object.assign({data: result.hexagons}, result);
@@ -189,7 +215,7 @@ function getSubLayerAccessor(dimensionState, dimension, layerProps) {
};
}
-export const defaultColorDimension = {
+export const defaultColorDimension: DimensionType<RGBAColor> = {
key: 'fillColor',
accessor: 'getFillColor',
getPickingInfo: (dimensionState, cell) => {
@@ -255,7 +281,7 @@ export const defaultColorDimension = {
getSubLayerAccessor
};
-export const defaultElevationDimension = {
+export const defaultElevationDimension: DimensionType<number> = {
key: 'elevation',
accessor: 'getElevation',
getPickingInfo: (dimensionState, cell) => {
@@ -323,8 +349,22 @@ export const defaultElevationDimension = {
export const defaultDimensions = [defaultColorDimension, defaultElevationDimension];
+export type CPUAggregatorState = {layerData: {data}; dimensions: {}};
+
export default class CPUAggregator {
- constructor(opts = {}) {
+ static getDimensionScale: any;
+ state: CPUAggregatorState;
+ dimensionUpdaters: {
+ [key: string]: {
+ updateSteps: UpdateStepsType[];
+ accessor: string;
+ getPickingInfo;
+ getSubLayerAccessor;
+ };
+ };
+ aggregationUpdater: {};
+
+ constructor(opts: {initialState?: CPUAggregatorState; dimensions?; aggregation?} = {}) {
this.state = {
layerData: {},
dimensions: {
@@ -422,7 +462,7 @@ export default class CPUAggregator {
});
}
- _needUpdateStep(dimensionStep, oldProps, props, changeFlags) {
+ _needUpdateStep(dimensionStep: UpdateStepsType, oldProps, props, changeFlags) {
// whether need to update current dimension step
// dimension step is the value, domain, scaleFunction of each dimension
// each step is an object with properties links to layer prop and whether the prop is
@@ -491,7 +531,10 @@ export default class CPUAggregator {
const updateTriggers = {};
for (const key in this.dimensionUpdaters) {
- const {accessor, updateSteps} = this.dimensionUpdaters[key];
+ const {
+ accessor,
+ updateSteps
+ }: {accessor; updateSteps: UpdateStepsType[]} = this.dimensionUpdaters[key];
// fold dimension triggers into each accessor
updateTriggers[accessor] = {};
diff --git a/src/deckgl-layers/layer-utils/shader-utils.js b/src/deckgl-layers/layer-utils/shader-utils.ts
similarity index 94%
rename from src/deckgl-layers/layer-utils/shader-utils.js
rename to src/deckgl-layers/layer-utils/shader-utils.ts
index 955c0cdd9..4ea831a1f 100644
--- a/src/deckgl-layers/layer-utils/shader-utils.js
+++ b/src/deckgl-layers/layer-utils/shader-utils.ts
@@ -29,7 +29,7 @@ import {console as Console} from 'global/window';
* @return {string} output shader
*
*/
-export function editShader(vs, type, originalText, testToReplace) {
+export function editShader(vs: string, type: string, originalText: string, testToReplace: string) {
if (!vs.includes(originalText)) {
// Here we call Console.error when we fail to edit deck.gl shader
// This should be caught by layer test