Skip to content

Commit

Permalink
fix: backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Dec 22, 2023
1 parent 44c77e5 commit bb00775
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/earthEngine/layers/landcover_MCD12Q1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
format: 'ImageCollection',
layerId: 'MODIS/006/MCD12Q1', // Layer id kept for backward compability for saved maps
datasetId: 'MODIS/061/MCD12Q1', // No longer in use: 'MODIS/006/MCD12Q1' / 'MODIS/051/MCD12Q1',
name: i18n.t('Landcover NASA'),
name: i18n.t('Landcover'),
description: i18n.t('Distinct landcover types collected from satellites.'),
img: 'images/landcover.png',
source: 'NASA LP DAAC / Google Earth Engine',
Expand Down
7 changes: 5 additions & 2 deletions src/components/edit/earthEngine/EarthEngineDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,12 @@ EarthEngineDialog.propTypes = {
onLayerValidation: PropTypes.func.isRequired,
aggregations: PropTypes.array,
areaRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
band: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), // TODO: Why array?
band: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
bands: PropTypes.array,
defaultAggregations: PropTypes.array,
defaultAggregations: PropTypes.oneOfType([
PropTypes.array,
PropTypes.string,
]),
description: PropTypes.string,
filters: PropTypes.array,
legend: PropTypes.object,
Expand Down
27 changes: 26 additions & 1 deletion src/loaders/earthEngineLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getInstance as getD2 } from 'd2'
import { precisionFixed, formatLocale } from 'd3-format'
import { getEarthEngineLayer } from '../constants/earthEngine.js'
import { getOrgUnitsFromRows } from '../util/analytics.js'
import { hasClasses, getFilterFromPeriod } from '../util/earthEngine.js'
import {
hasClasses,
getFilterFromPeriod,
getPeriodFromFilter,
} from '../util/earthEngine.js'
import { getDisplayProperty } from '../util/helpers.js'
import { toGeoJson } from '../util/map.js'
import {
Expand All @@ -24,6 +28,8 @@ const earthEngineLoader = async (config) => {
let dataset
let features

console.log('earthEngineLoader', config)

if (orgUnits && orgUnits.length) {
const d2 = await getD2()
const displayProperty = getDisplayProperty(d2).toUpperCase()
Expand Down Expand Up @@ -87,6 +93,25 @@ const earthEngineLoader = async (config) => {
// From database as favorite
layerConfig = JSON.parse(config.config)

console.log('layerConfig', layerConfig)

const { filter, params } = layerConfig

// Backward compability for layers saved before 2.41
if (filter) {
layerConfig.period = getPeriodFromFilter(filter)
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) {
Expand Down

0 comments on commit bb00775

Please sign in to comment.