Skip to content

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

[Bug] Fix geojson layer duplicated index (#1530)

Shan He72354560eca7
diff --git a/src/layers/geojson-layer/geojson-utils.js b/src/layers/geojson-layer/geojson-utils.js
index cdcdbc881..e5327ec0f 100644
--- a/src/layers/geojson-layer/geojson-utils.js
+++ b/src/layers/geojson-layer/geojson-utils.js
@@ -74,13 +74,16 @@ export function getGeojsonDataMaps(allData, getFeature) {
const feature = parseGeoJsonRawFeature(getFeature(allData[index]));
if (feature && feature.geometry && acceptableTypes.includes(feature.geometry.type)) {
- // store index of the data in feature properties
- feature.properties = {
- ...(feature.properties || {}),
- index
+ const cleaned = {
+ ...feature,
+ // store index of the data in feature properties
+ properties: {
+ ...feature.properties,
+ index
+ }
};
- dataToFeature[index] = feature;
+ dataToFeature[index] = cleaned;
} else {
dataToFeature[index] = null;
}
diff --git a/test/browser/reducers/index.js b/test/browser/reducers/index.js
index 9a939fe24..35d5c3e3d 100644
--- a/test/browser/reducers/index.js
+++ b/test/browser/reducers/index.js
@@ -38,11 +38,11 @@ test('#visStateReducer -> COPY_TABLE_COLUMN', t => {
reducer(nextState, VisStateActions.copyTableColumn(testGeoJsonDataId, '_geojson'));
const expectedCopy2 =
- `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.40115971858505,37.78202426695214],[-122.40037436684331,37.78264451554517],[-122.40001902006377,37.782925153640136],[-122.39989147796784,37.783025880124256],[-122.398930331093,37.783784933304034]]]},"properties":{"OBJECTID":1,"ZIP_CODE":94107,"ID":94107,"TRIPS":11,"RATE":"a","OBJ":{"id":1},"index":0}}\n` +
- `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39189026034138,37.79427854456892],[-122.39166672864975,37.794132425256194],[-122.39172303426619,37.79410061945832],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":2,"ZIP_CODE":94105,"ID":94105,"TRIPS":4,"RATE":"b","OBJ":{"id":2},"index":1}}\n` +
- `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39189026034138,37.79427854456892],[-122.39198201510793,37.79387190612868],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":3,"ZIP_CODE":94109,"ID":94109,"TRIPS":20,"RATE":null,"OBJ":{"id":3},"index":2}}\n` +
- `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39166672864975,37.794132425256194],[-122.39172303426619,37.79410061945832],[-122.3916732283519,37.7940478541246],[-122.39198201510793,37.79387190612868],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":4,"ZIP_CODE":94111,"ID":94111,"RATE":"c","OBJ":{"id":4},"TRIPS":null,"index":3}}\n` +
- `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39189026034138,37.79427854456892],[-122.39178886557242,37.794170982455135],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":5,"ZIP_CODE":94107,"ID":9409,"RATE":"c","OBJ":{"id":5},"TRIPS":null,"index":4}}`;
+ `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.40115971858505,37.78202426695214],[-122.40037436684331,37.78264451554517],[-122.40001902006377,37.782925153640136],[-122.39989147796784,37.783025880124256],[-122.398930331093,37.783784933304034]]]},"properties":{"OBJECTID":1,"ZIP_CODE":94107,"ID":94107,"TRIPS":11,"RATE":"a","OBJ":{"id":1}}}\n` +
+ `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39189026034138,37.79427854456892],[-122.39166672864975,37.794132425256194],[-122.39172303426619,37.79410061945832],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":2,"ZIP_CODE":94105,"ID":94105,"TRIPS":4,"RATE":"b","OBJ":{"id":2}}}\n` +
+ `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39189026034138,37.79427854456892],[-122.39198201510793,37.79387190612868],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":3,"ZIP_CODE":94109,"ID":94109,"TRIPS":20,"RATE":null,"OBJ":{"id":3}}}\n` +
+ `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39166672864975,37.794132425256194],[-122.39172303426619,37.79410061945832],[-122.3916732283519,37.7940478541246],[-122.39198201510793,37.79387190612868],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":4,"ZIP_CODE":94111,"ID":94111,"RATE":"c","OBJ":{"id":4},"TRIPS":null}}\n` +
+ `{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-122.39249932896719,37.79376881413398],[-122.39189026034138,37.79427854456892],[-122.39178886557242,37.794170982455135],[-122.39249932896719,37.79376881413398]]]},"properties":{"OBJECTID":5,"ZIP_CODE":94107,"ID":9409,"RATE":"c","OBJ":{"id":5},"TRIPS":null}}`;
t.equal(window.clipboardData.data().text, expectedCopy2, 'should copy to clipboard');
t.end();
diff --git a/test/fixtures/geojson.js b/test/fixtures/geojson.js
index 1d7ed593f..74bc0b467 100644
--- a/test/fixtures/geojson.js
+++ b/test/fixtures/geojson.js
@@ -273,19 +273,7 @@ export const rows = [
];
// add index to properties
-export const datasetAllData = rows.map((row, index) =>
- row.map((cell, i) =>
- i === 0
- ? {
- ...cell,
- properties: {
- ...cell.properties,
- index
- }
- }
- : cell
- )
-);
+export const datasetAllData = rows;
export const geoJsonTripHistogram = [
{count: 1, x0: 4, x1: 4.5},