Skip to content

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

[Enhancement] add options.autoCreateLayers to addDataToMap (#1215)

Shan He53f98013f28b
diff --git a/src/actions/actions.d.ts b/src/actions/actions.d.ts
index b5fa0f032..ccc1df519 100644
--- a/src/actions/actions.d.ts
+++ b/src/actions/actions.d.ts
@@ -52,6 +52,7 @@ export type AddDataToMapOptions = {
centerMap?: boolean;
readOnly?: boolean;
keepExistingConfig?: boolean;
+ autoCreateLayers?: boolean;
};
export type AddDataToMapPayload = {
diff --git a/src/actions/actions.js b/src/actions/actions.js
index 6c5a7a612..beb7683e6 100644
--- a/src/actions/actions.js
+++ b/src/actions/actions.js
@@ -133,6 +133,7 @@ export const resetMapConfig = createAction(ActionTypes.RESET_MAP_CONFIG);
* @param {boolean} options.readOnly `default: false` if `readOnly` is set to `true`
* the left setting panel will be hidden
* @param {boolean} options.keepExistingConfig whether to keep exiting layer filter and interaction config `default: false`.
+ * @param {boolean} options.autoCreateLayers whether to automatically create layers based on dataset columns `default: true`.
* @public
* @example
* import {receiveMapConfig} from 'kepler.gl/actions';
diff --git a/src/reducers/combined-updaters.js b/src/reducers/combined-updaters.js
index bf47a0241..48077b382 100644
--- a/src/reducers/combined-updaters.js
+++ b/src/reducers/combined-updaters.js
@@ -88,7 +88,8 @@ export const isValidConfig = config =>
export const defaultAddDataToMapOptions = {
centerMap: true,
- keepExistingConfig: false
+ keepExistingConfig: false,
+ autoCreateLayers: true
};
/**
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 0dbaf21b3..58bf891db 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -1168,7 +1168,7 @@ export const updateVisDataUpdater = (state, action) => {
let newLayers = mergedState.layers.filter(l => l.config.dataId in newDataEntries);
- if (!newLayers.length) {
+ if (!newLayers.length && (options || {}).autoCreateLayers !== false) {
// no layer merged, find defaults
const result = addDefaultLayers(mergedState, newDataEntries);
mergedState = result.state;
diff --git a/test/node/reducers/composer-state-test.js b/test/node/reducers/composer-state-test.js
index da8f88ea4..57bfcc296 100644
--- a/test/node/reducers/composer-state-test.js
+++ b/test/node/reducers/composer-state-test.js
@@ -338,3 +338,26 @@ test('#composerStateReducer - addDataToMapUpdater: readOnly', t => {
t.equal(nextState2.uiState.readOnly, false, 'should set readonly to be false');
t.end();
});
+
+test('#composerStateReducer - addDataToMapUpdater: autoCreateLayers', t => {
+ const datasets = {
+ data: processCsvData(testCsvData),
+ info: {
+ id: sampleConfig.dataId
+ }
+ };
+ const state = keplerGlReducer({}, registerEntry({id: 'test'})).test;
+
+ // old state contain splitMaps
+ const nextState = addDataToMapUpdater(state, {
+ payload: {
+ datasets,
+ options: {
+ autoCreateLayers: false
+ }
+ }
+ });
+ t.equal(nextState.visState.layers.length, 0, 'should not create layers');
+
+ t.end();
+});