Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Bug] fix bug map loaded with custom map style not save correctly (#993)
Shan He4bc73ab1a41e
diff --git a/examples/demo-app/src/data/sample-geojson-config.js b/examples/demo-app/src/data/sample-geojson-config.jsindex f6b724ec0..e44ba0330 100644--- a/examples/demo-app/src/data/sample-geojson-config.js+++ b/examples/demo-app/src/data/sample-geojson-config.js@@ -174,6 +174,21 @@ const config = {}},layerBlending: 'normal'+ },++ mapStyle: {+ styleType: 'b9tnac',+ mapStyles: {+ b9tnac: {+ accessToken: null,+ custom: true,+ icon:+ 'https://api.mapbox.com/styles/v1/heshan0131/cjg0ks54x300a2squ8fr9vhvq/static/-122.3391,37.7922,9,0,0/400x300?access_token=pk.eyJ1IjoidWJlcmRhdGEiLCJhIjoiY2pmc3hhd21uMzE3azJxczJhOWc4czBpYyJ9.HiDptGv2C0Bkcv_TGr_kJw&logo=false&attribution=false',+ id: 'b9tnac',+ label: 'label maker',+ url: 'mapbox://styles/heshan0131/cjg0ks54x300a2squ8fr9vhvq'+ }+ }}}};diff --git a/src/components/common/logo.js b/src/components/common/logo.jsindex bc1219817..2be53f063 100644--- a/src/components/common/logo.js+++ b/src/components/common/logo.js@@ -68,12 +68,7 @@ const KeplerGlLogo = ({appName, appWebsite = KEPLER_GL_WEBSITE, version}) => (</LogoSvgWrapper><LogoTitle className="logo__title"><LogoName className="logo__name">- <a- className="logo__link"- target="_blank"- rel="noopener noreferrer"- href={appWebsite}- >+ <a className="logo__link" target="_blank" rel="noopener noreferrer" href={appWebsite}>{appName}</a></LogoName>diff --git a/src/components/side-panel/panel-header.js b/src/components/side-panel/panel-header.jsindex e20e47820..eeeff8adc 100644--- a/src/components/side-panel/panel-header.js+++ b/src/components/side-panel/panel-header.js@@ -282,7 +282,7 @@ function PanelHeaderFactory(SaveExportDropdown, CloudStorageDropdown) {return (<StyledPanelHeader className="side-panel__panel-header"><StyledPanelHeaderTop className="side-panel__panel-header__top">- <this.props.logoComponent appName={appName} version={version} appWebsite={appWebsite}/>+ <this.props.logoComponent appName={appName} version={version} appWebsite={appWebsite} /><StyledPanelTopActions>{items.map(item => (<divdiff --git a/src/schemas/map-style-schema.js b/src/schemas/map-style-schema.jsindex 05c7ed0b5..efbc2ff53 100644--- a/src/schemas/map-style-schema.js+++ b/src/schemas/map-style-schema.js@@ -43,6 +43,7 @@ class MapStyleSchemaV1 extends Schema {// save all custom stylesconst saveCustomStyle = Object.keys(mapStyles).reduce((accu, key) => ({+ ...accu,...(mapStyles[key].custom? {[key]: CustomMapStyleSchema.save(mapStyles[key]).customStyle}: {})diff --git a/src/schemas/schema-manager.js b/src/schemas/schema-manager.jsindex 2dbea6277..a8ea0cec4 100644--- a/src/schemas/schema-manager.js+++ b/src/schemas/schema-manager.js@@ -141,7 +141,7 @@ class KeplerGLSchema {const config = Object.keys(this._reducerSchemas).reduce((accu, key) => ({...accu,- ...this._reducerSchemas[key][this._version].save(state[key])+ ...(state[key] ? this._reducerSchemas[key][this._version].save(state[key]) : {})}),{});diff --git a/src/schemas/vis-state-schema.js b/src/schemas/vis-state-schema.jsindex 9fc30be51..edda37a76 100644--- a/src/schemas/vis-state-schema.js+++ b/src/schemas/vis-state-schema.js@@ -403,13 +403,14 @@ const visConfigModificationV1 = {const modified = {};const [layer] = parents.slice(-2, -1);const isOld =+ layer.visualChannels &&!layer.visualChannels.hasOwnProperty('strokeColorField') &&!visConfig.strokeColor &&!visConfig.strokeColorRange;// make our best guess if this geojson layer contains pointconst isPoint =- layer.visualChannels.radiusField ||- visConfig.radius !== LAYER_VIS_CONFIGS.radius.defaultValue;+ (layer.visualChannels && layer.visualChannels.radiusField) ||+ (visConfig && visConfig.radius !== LAYER_VIS_CONFIGS.radius.defaultValue);if (isOld) {// color color & color range to stroke colordiff --git a/test/browser/layer-tests/hexagon-layer-specs.js b/test/browser/layer-tests/hexagon-layer-specs.jsindex 91a9ed666..576409f00 100644--- a/test/browser/layer-tests/hexagon-layer-specs.js+++ b/test/browser/layer-tests/hexagon-layer-specs.js@@ -327,7 +327,11 @@ test('#HexagonLayer -> renderLayer', t => {const expectedProps = {coverage: layer.config.visConfig.coverage,radius: layer.config.visConfig.worldUnitSize * 1000,- colorRange: [[8, 8, 8], [9, 9, 9], [7, 7, 7]],+ colorRange: [+ [8, 8, 8],+ [9, 9, 9],+ [7, 7, 7]+ ],colorScaleType: layer.config.colorScale,elevationScaleType: layer.config.sizeScale,elevationScale: layer.config.visConfig.elevationScale,@@ -335,8 +339,14 @@ test('#HexagonLayer -> renderLayer', t => {lowerPercentile: layer.config.visConfig.percentile[0]};- const expectedColorBins = [{i: 2, value: 1, counts: 1}, {i: 1, value: 2, counts: 2}];- const expectedElevationBins = [{i: 2, value: 1, counts: 1}, {i: 1, value: 2, counts: 2}];+ const expectedColorBins = [+ {i: 2, value: 1, counts: 1},+ {i: 1, value: 2, counts: 2}+ ];+ const expectedElevationBins = [+ {i: 2, value: 1, counts: 1},+ {i: 1, value: 2, counts: 2}+ ];t.deepEqual(hexCellLayer.props.data,diff --git a/test/node/reducers/map-style-test.js b/test/node/reducers/map-style-test.jsindex 111527100..a61061571 100644--- a/test/node/reducers/map-style-test.js+++ b/test/node/reducers/map-style-test.js@@ -237,5 +237,39 @@ test('#mapStyleReducer -> RECEIVE_MAP_CONFIG', t => {);});+ const savedConfig = SchemaManager.getConfigToSave({mapStyle: resultState1});+ const expectedSaved = {+ version: 'v1',+ config: {+ mapStyle: {+ styleType: 'smoothie_the_cat',+ topLayerGroups: {},+ visibleLayerGroups: {},+ threeDBuildingColor: [1, 2, 3],+ mapStyles: {+ smoothie_the_cat: {+ accessToken: 'secret_token',+ custom: true,+ icon:+ 'https://api.mapbox.com/styles/v1/shanhe/smoothie.the.cat/static/-122.3391,37.7922,9,0,0/400x300?access_token=secret_token&logo=false&attribution=false',+ id: 'smoothie_the_cat',+ label: 'Smoothie the Cat',+ url: 'mapbox://styles/shanhe/smoothie.the.cat'+ }+ }+ }+ }+ };++ t.deepEqual(+ Object.keys(savedConfig).sort(),+ Object.keys(expectedSaved).sort(),+ 'mapStyle state saved should have same keys'+ );++ Object.keys(savedConfig).forEach(key => {+ t.deepEqual(savedConfig[key], expectedSaved[key], `should save state.${key} with correctly`);+ });+t.end();});diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.jsindex ba6183107..c89169468 100644--- a/test/node/reducers/vis-state-test.js+++ b/test/node/reducers/vis-state-test.js@@ -1383,7 +1383,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {];const expectedFilterProps = {- domain: [12.249990000000002,12.290000000000001],+ domain: [12.249990000000002, 12.290000000000001],step: 0.00001,histogram: [1], // test not emptyenlargedHistogram: [2], // test not empty@@ -1391,7 +1391,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {type: mockFilter.type,gpu: true,typeOptions: ['range'],- value: [12.249990000000002,12.290000000000001]+ value: [12.249990000000002, 12.290000000000001]};const expectedFilter = {diff --git a/test/node/utils/filter-utils-test.js b/test/node/utils/filter-utils-test.jsindex 04a2dc0e1..0e53cce45 100644--- a/test/node/utils/filter-utils-test.js+++ b/test/node/utils/filter-utils-test.js@@ -20,10 +20,7 @@import test from 'tape';import moment from 'moment';-import testData, {- numericRangesCsv,- testFields-} from 'test/fixtures/test-csv-data';+import testData, {numericRangesCsv, testFields} from 'test/fixtures/test-csv-data';import {adjustValueToFilterDomain,@@ -42,7 +39,6 @@ import {import {preciseRound} from 'utils/data-utils';import {getDatasetFieldIndexForFilter} from 'utils/gpu-filter-utils';-import {FILTER_TYPES} from 'constants/default-settings';import {processCsvData} from 'processors/data-processor';import {mockPolygonFeature, mockPolygonData} from '../../fixtures/polygon';@@ -124,7 +120,7 @@ function testGetNumericFieldStep(rows, allFields, t) {name: 'large',input: getFieldDomain(rows, allFields[4]).step,output: 1- },+ }];test_cases.forEach(tc =>