diff --git a/src/actions/externalLayers.js b/src/actions/externalLayers.js
index 2748b7e06..e5eeff0e8 100644
--- a/src/actions/externalLayers.js
+++ b/src/actions/externalLayers.js
@@ -3,12 +3,8 @@ import * as types from '../constants/actionTypes.js'
import { createExternalLayer } from '../util/external.js'
import { fetchExternalLayers } from '../util/requests.js'
import { addBasemaps } from './basemap.js'
-import { EARTH_ENGINE_LAYER } from '../constants/layers.js'
-export const EXTERNAL_LAYERS_NAMESPACE = 'EXTERNAL_LAYERS'
-
-// const isBasemap = (layer) => layer.mapLayerPosition === 'BASEMAP'
-const isBasemap = (layer) => layer.position === 'basemap'
+const isBasemap = (layer) => layer.mapLayerPosition === 'BASEMAP'
const isOverlay = (layer) => !isBasemap(layer)
// Add external overlay
@@ -18,79 +14,18 @@ export const addExternalLayer = (layer) => ({
})
export const tSetExternalLayers = (engine) => async (dispatch) => {
- engine
- .query({
- dataStore: {
- resource: 'dataStore',
- },
- })
- .then(({ dataStore }) => {
- if (dataStore.includes(EXTERNAL_LAYERS_NAMESPACE)) {
- engine
- .query({
- layerIds: {
- resource: `dataStore/${EXTERNAL_LAYERS_NAMESPACE}`,
- },
- })
- .then(({ layerIds }) => {
- // TODO: Possible to load all layers at once?
- Promise.all(
- layerIds.map((layerId) =>
- engine
- .query({
- layer: {
- resource: `dataStore/${EXTERNAL_LAYERS_NAMESPACE}/${layerId}`,
- },
- })
- .then(({ layer }) => layer)
- )
- ).then((layers) => {
- layers.sort((a, b) => a.name.localeCompare(b.name))
-
- const basemaps = layers
- .filter(isBasemap)
- .map(createExternalLayer)
-
- if (basemaps.length) {
- dispatch(addBasemaps(basemaps))
- }
-
- // console.log('basemaps', basemaps)
-
- layers.filter(isOverlay).forEach((layer) => {
- const layerId = layer.id // TODO
- delete layer.id // TODO
-
- dispatch(
- addExternalLayer({
- ...layer,
- layer: EARTH_ENGINE_LAYER, // TODO
- layerId, // TODO
- })
- )
- })
- })
- })
- }
- })
-
try {
const externalLayers = await fetchExternalLayers(engine)
const externalBasemaps = externalLayers.externalLayers.externalMapLayers
- .filter((layer) => layer.mapLayerPosition === 'BASEMAP')
+ .filter(isBasemap)
.map(createExternalLayer)
- // console.log('externalBasemaps', externalBasemaps)
-
- /*
dispatch(addBasemaps(externalBasemaps))
-
externalLayers.externalLayers.externalMapLayers
.filter(isOverlay)
.map(createExternalLayer)
.map((layer) => dispatch(addExternalLayer(layer)))
- */
} catch (e) {
log.error('Could not load external map layers')
return e
diff --git a/src/components/edit/earthEngine/EarthEngineDialog.js b/src/components/edit/earthEngine/EarthEngineDialog.js
index ab85f8c97..6be648166 100644
--- a/src/components/edit/earthEngine/EarthEngineDialog.js
+++ b/src/components/edit/earthEngine/EarthEngineDialog.js
@@ -8,7 +8,7 @@ import {
setFilter,
setBufferRadius,
} from '../../../actions/layerEdit.js'
-import { getEarthEngineLayer } from '../../../constants/earthEngine.js'
+// import { getEarthEngineLayer } from '../../../constants/earthEngine.js'
import {
DEFAULT_ORG_UNIT_LEVEL,
EE_BUFFER,
@@ -35,7 +35,7 @@ const EarthEngineDialog = (props) => {
const [error, setError] = useState()
const {
- layerId,
+ // layerId,
datasetId,
band,
rows,
@@ -59,11 +59,12 @@ const EarthEngineDialog = (props) => {
periodType,
periodReducer,
bands,
- filters = defaultFilters,
+ filters, // = defaultFilters,
unit,
source,
sourceUrl,
aggregations,
+ defaultAggregations,
} = props // dataset
const period = getPeriodFromFilter(filter)
@@ -121,6 +122,7 @@ const EarthEngineDialog = (props) => {
const noBandSelected = Array.isArray(bands) && (!band || !band.length)
+ const hasAggregations = !!(aggregations || defaultAggregations)
const hasMultipleAggregations = !aggregations || aggregations.length > 1
const hasOrgUnitField = !!orgUnitField && orgUnitField !== NONE
@@ -182,6 +184,12 @@ const EarthEngineDialog = (props) => {
}
}, [hasOrgUnitField, areaRadius, setBufferRadius])
+ useEffect(() => {
+ if (!periodType && filters) {
+ setFilter(filters)
+ }
+ }, [periodType, filters, setFilter])
+
useEffect(() => {
if (validateLayer) {
const isValid = !noBandSelected && (!periodType || period)
@@ -258,7 +266,7 @@ const EarthEngineDialog = (props) => {
}
/>
)}
-