diff --git a/src/loaders/earthEngineLoader.js b/src/loaders/earthEngineLoader.js index 703f82ea3..d41410e37 100644 --- a/src/loaders/earthEngineLoader.js +++ b/src/loaders/earthEngineLoader.js @@ -84,48 +84,37 @@ const earthEngineLoader = async (config) => { // From database as favorite layerConfig = JSON.parse(config.config) - const { filter, params } = layerConfig - - // Backward compability for layers saved before 2.41 - if (filter) { - layerConfig.period = getPeriodFromFilter(filter, layerConfig.id) - delete layerConfig.filter - } - - // Backward compability for layers saved before 2.41 - if (params) { - layerConfig.style = params - if (params.palette) { - layerConfig.style.palette = params.palette.split(',') - } - delete layerConfig.params - } - - // Backward compability for layers with periods saved before 2.36 - // (could also be fixed in a db update script) if (layerConfig.image) { + // Backward compability for layers with periods saved before 2.36 const filter = layerConfig.filter?.[0] if (filter) { - const period = filter.arguments?.[1] - let name = String(layerConfig.image) - - if (typeof period === 'string' && period.length > 4) { - const year = period.substring(0, 4) - filter.year = parseInt(year, 10) + const id = filter.arguments?.[1] + const name = String(layerConfig.image) + const year = + typeof id === 'string' && id.length > 4 + ? parseInt(id.substring(0, 4), 10) + : undefined - if (name.slice(-4) === year) { - name = name.slice(0, -4) - } - } + layerConfig.period = { id, name, year } - filter.name = name + delete layerConfig.filter } + delete layerConfig.image + } else if (layerConfig.filter) { + // Backward compability for layers saved before v100.6.0 + layerConfig.period = getPeriodFromFilter(filter, layerConfig.id) + delete layerConfig.filter } - // Backward compability for layers saved before 2.40 - if (typeof layerConfig.params?.palette === 'string') { - layerConfig.params.palette = layerConfig.params.palette.split(',') + if (layerConfig.params) { + // Backward compability for layers saved before v100.6.0 + layerConfig.style = layerConfig.params + if (typeof layerConfig.params.palette === 'string') { + layerConfig.style.palette = + layerConfig.params.palette.split(',') + } + delete layerConfig.params } dataset = getEarthEngineLayer(layerConfig.id) @@ -135,7 +124,9 @@ const earthEngineLoader = async (config) => { } delete config.config - delete config.filters // Backend returns empty filters array + // Remove the always empty filters array from saved map layer object + // so as not to overwrite the filters array from the layer config + delete config.filters } else { dataset = getEarthEngineLayer(layerConfig.id) } diff --git a/src/util/__tests__/pluginHelper.spec.js b/src/util/__tests__/pluginHelper.spec.js index 182698154..07d7e9cb2 100644 --- a/src/util/__tests__/pluginHelper.spec.js +++ b/src/util/__tests__/pluginHelper.spec.js @@ -76,4 +76,16 @@ describe('didViewsChange', () => { ] expect(didViewsChange(oldViews, newViews)).toEqual(false) }) + + it('should always return false for earth engine layer', () => { + const oldViews = [{ layer: 'earthEngine', rows: [] }] + const newViews = [ + { + layer: 'earthEngine', + filters: [], + rows: [], + }, + ] + expect(didViewsChange(oldViews, newViews)).toEqual(false) + }) }) diff --git a/src/util/pluginHelper.js b/src/util/pluginHelper.js index 2054118ab..0741ca7da 100644 --- a/src/util/pluginHelper.js +++ b/src/util/pluginHelper.js @@ -1,7 +1,14 @@ +import { EARTH_ENGINE_LAYER } from '../constants/layers.js' + const didViewsChange = (oldViews, newViews) => { return newViews.some((newView, i) => { const oldView = oldViews[i] + // EE layers don't have filters + if (oldView.layer === EARTH_ENGINE_LAYER) { + return false + } + if ( oldView.filters.length !== newView.filters.length || oldView.rows.length !== newView.rows.length