diff --git a/app/scripts/components/common/blocks/scrollytelling/index.tsx b/app/scripts/components/common/blocks/scrollytelling/index.tsx index 79051a32c..e81793484 100644 --- a/app/scripts/components/common/blocks/scrollytelling/index.tsx +++ b/app/scripts/components/common/blocks/scrollytelling/index.tsx @@ -378,16 +378,14 @@ function Scrollytelling(props) { ); @@ -468,16 +466,14 @@ function Scrollytelling(props) { ); diff --git a/app/scripts/components/common/mapbox/index.tsx b/app/scripts/components/common/mapbox/index.tsx index 87124d8e1..9a35241bb 100644 --- a/app/scripts/components/common/mapbox/index.tsx +++ b/app/scripts/components/common/mapbox/index.tsx @@ -398,12 +398,9 @@ function MapboxMapComponent(props: MapboxMapProps, ref) { {isMapLoaded && baseLayerResolvedData && BaseLayerComponent && ( )} @@ -448,11 +445,9 @@ function MapboxMapComponent(props: MapboxMapProps, ref) { CompareLayerComponent && ( )} diff --git a/app/scripts/components/common/mapbox/layers/raster-timeseries.tsx b/app/scripts/components/common/mapbox/layers/raster-timeseries.tsx index 1da88e46b..dff4795af 100644 --- a/app/scripts/components/common/mapbox/layers/raster-timeseries.tsx +++ b/app/scripts/components/common/mapbox/layers/raster-timeseries.tsx @@ -36,15 +36,17 @@ const LOG = true; const FIT_BOUNDS_PADDING = 32; -interface MapLayerRasterTimeseriesProps { +export interface MapLayerRasterTimeseriesProps { id: string; - stacCol: string; date?: Date; mapInstance: MapboxMap; - sourceParams: object; - zoomExtent?: [number, number]; onStatusChange?: (result: { status: ActionStatus; id: string }) => void; - isHidden: boolean; + isHidden?: boolean; + layerData: { + sourceParams?: object; + zoomExtent?: number[]; + stacCol: string; + }; } export interface StacFeature { @@ -64,16 +66,8 @@ interface Statuses { } export function MapLayerRasterTimeseries(props: MapLayerRasterTimeseriesProps) { - const { - id, - stacCol, - date, - mapInstance, - sourceParams, - zoomExtent, - onStatusChange, - isHidden - } = props; + const { id, date, mapInstance, onStatusChange, isHidden } = props; + const { sourceParams, zoomExtent, stacCol } = props.layerData; const theme = useTheme(); const { updateStyle } = useMapStyle(); diff --git a/app/scripts/components/common/mapbox/layers/utils.ts b/app/scripts/components/common/mapbox/layers/utils.ts index 651f546fa..4656890fc 100644 --- a/app/scripts/components/common/mapbox/layers/utils.ts +++ b/app/scripts/components/common/mapbox/layers/utils.ts @@ -19,9 +19,19 @@ import { DatasetDatumReturnType, DatasetLayerCompareNormalized } from 'veda'; -import { MapLayerRasterTimeseries, StacFeature } from './raster-timeseries'; -import { MapLayerVectorTimeseries } from './vector-timeseries'; -import { MapLayerZarrTimeseries } from './zarr-timeseries'; +import { + MapLayerRasterTimeseries, + MapLayerRasterTimeseriesProps, + StacFeature +} from './raster-timeseries'; +import { + MapLayerVectorTimeseries, + MapLayerVectorTimeseriesProps +} from './vector-timeseries'; +import { + MapLayerZarrTimeseries, + MapLayerZarrTimeseriesProps +} from './zarr-timeseries'; import { userTzDate2utcString, utcString2userTzDate } from '$utils/date'; import { AsyncDatasetLayer } from '$context/layer-data'; @@ -31,7 +41,11 @@ import { HintedError } from '$utils/hinted-error'; export const getLayerComponent = ( isTimeseries: boolean, layerType: 'raster' | 'vector' | 'zarr' -): FunctionComponent | null => { +): FunctionComponent< + | MapLayerRasterTimeseriesProps + | MapLayerVectorTimeseriesProps + | MapLayerZarrTimeseriesProps +> | null => { if (isTimeseries) { if (layerType === 'raster') return MapLayerRasterTimeseries; if (layerType === 'vector') return MapLayerVectorTimeseries; @@ -71,7 +85,6 @@ export const getCompareLayerData = ( id: stacCol, stacCol, type: type || layerData.type, - assetUrl: layerData.assetUrl, zoomExtent: zoomExtent || layerData.zoomExtent, sourceParams: defaultsDeep({}, sourceParams, layerData.sourceParams), ...passThroughProps diff --git a/app/scripts/components/common/mapbox/layers/vector-timeseries.tsx b/app/scripts/components/common/mapbox/layers/vector-timeseries.tsx index 3763a4bec..766fca30c 100644 --- a/app/scripts/components/common/mapbox/layers/vector-timeseries.tsx +++ b/app/scripts/components/common/mapbox/layers/vector-timeseries.tsx @@ -19,28 +19,22 @@ import { useCustomMarker } from './custom-marker'; import { ActionStatus, S_FAILED, S_LOADING, S_SUCCEEDED } from '$utils/status'; import { userTzDate2utcString } from '$utils/date'; -interface MapLayerVectorTimeseriesProps { +export interface MapLayerVectorTimeseriesProps { id: string; - stacCol: string; date?: Date; mapInstance: MapboxMap; - sourceParams: object; - zoomExtent?: [number, number]; onStatusChange?: (result: { status: ActionStatus; id: string }) => void; - isHidden: boolean; + isHidden?: boolean; + layerData: { + sourceParams?: object; + zoomExtent?: number[]; + stacCol: string; + }; } export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) { - const { - id, - stacCol, - date, - mapInstance, - sourceParams, - zoomExtent, - onStatusChange, - isHidden - } = props; + const { id, date, mapInstance, onStatusChange, isHidden } = props; + const { sourceParams, zoomExtent, stacCol } = props.layerData; const theme = useTheme(); const { updateStyle } = useMapStyle(); @@ -81,7 +75,6 @@ export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) { }; }, [mapInstance, id, stacCol, date, onStatusChange]); - const markerLayout = useCustomMarker(mapInstance); // @@ -188,7 +181,7 @@ export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) { 'source-layer': 'default', layout: { ...(markerLayout as any), - visibility: isHidden ? 'none' : 'visible', + visibility: isHidden ? 'none' : 'visible' }, paint: { 'icon-color': theme.color?.infographicB, diff --git a/app/scripts/components/common/mapbox/layers/zarr-timeseries.tsx b/app/scripts/components/common/mapbox/layers/zarr-timeseries.tsx index 1339012d4..9a56df5eb 100644 --- a/app/scripts/components/common/mapbox/layers/zarr-timeseries.tsx +++ b/app/scripts/components/common/mapbox/layers/zarr-timeseries.tsx @@ -1,37 +1,29 @@ import { useEffect, useMemo } from 'react'; import qs from 'qs'; -import { - AnyLayer, - AnySourceImpl, - RasterLayer, - RasterSource, -} from 'mapbox-gl'; +import { AnyLayer, AnySourceImpl, RasterLayer, RasterSource } from 'mapbox-gl'; import { useMapStyle } from './styles'; -interface MapLayerZarrTimeseriesProps { +export interface MapLayerZarrTimeseriesProps { id: string; date?: Date; - sourceParams: object; - zoomExtent?: [number, number]; - assetUrl?: string; - isHidden: boolean; + isHidden?: boolean; + layerData: { + sourceParams?: object; + zoomExtent?: number[]; + assetUrl: string; + }; } export function MapLayerZarrTimeseries(props: MapLayerZarrTimeseriesProps) { - const { - id, - date, - sourceParams, - zoomExtent, - assetUrl, - isHidden - } = props; + const { id, date, isHidden } = props; + const { sourceParams = {}, zoomExtent, assetUrl } = props.layerData; const { updateStyle } = useMapStyle(); const minZoom = zoomExtent?.[0] ?? 0; - const tilesUrl = process.env.API_XARRAY_ENDPOINT; + const tilerUrl = process.env.API_XARRAY_ENDPOINT; + // // Generate Mapbox GL layers and sources for raster timeseries // @@ -39,23 +31,22 @@ export function MapLayerZarrTimeseries(props: MapLayerZarrTimeseriesProps) { () => JSON.stringify(sourceParams), [sourceParams] ); + useEffect( () => { let layers: AnyLayer[] = []; let sources: Record = {}; - if (tilesUrl) { - const tileParams = qs.stringify( - { - url: assetUrl, - time_slice: date, - ...sourceParams - } - ); + if (tilerUrl) { + const tileParams = qs.stringify({ + url: assetUrl, + time_slice: date, + ...sourceParams + }); const zarrSource: RasterSource = { type: 'raster', - url: `${tilesUrl}?${tileParams}` + url: `${tilerUrl}?${tileParams}` }; const zarrLayer: RasterLayer = { @@ -78,10 +69,9 @@ export function MapLayerZarrTimeseries(props: MapLayerZarrTimeseriesProps) { }; sources = { - ...sources, [id]: zarrSource }; - layers = [...layers, zarrLayer]; + layers = [zarrLayer]; } updateStyle({ @@ -95,7 +85,8 @@ export function MapLayerZarrTimeseries(props: MapLayerZarrTimeseriesProps) { updateStyle, id, date, - tilesUrl, + assetUrl, + tilerUrl, minZoom, haveSourceParamsChanged, isHidden diff --git a/app/scripts/context/layer-data.tsx b/app/scripts/context/layer-data.tsx index 6e0363872..1ae0d111c 100644 --- a/app/scripts/context/layer-data.tsx +++ b/app/scripts/context/layer-data.tsx @@ -42,9 +42,7 @@ const fetchLayerById = async ( isPeriodic: data['dashboard:is_periodic'], timeDensity: data['dashboard:time_density'] }; - // TODO: Normalize API data structure - // For the time being the vector and raster sources have different api - // endpoints, and different properties to get data from. + if (type === 'vector') { const featuresApiEndpoint = data.links.find((l) => l.rel === 'child').href; const { data: featuresApiData } = await axios.get(featuresApiEndpoint); @@ -55,23 +53,23 @@ const fetchLayerById = async ( domain: featuresApiData.extent.temporal.interval[0] } }; - } - - const defaultData = { - timeseries: { - ...commonTimeseriesParams, - domain: data.summaries ? data.summaries.datetime : data.extent.temporal.interval[0] - } - }; - - if (type === 'zarr') { - return { - ...defaultData, - assetUrl: data.assets.zarr.href + } else { + const defaultData = { + timeseries: { + ...commonTimeseriesParams, + domain: data.summaries ? data.summaries.datetime : data.extent.temporal.interval[0] + } }; + + if (type === 'zarr') { + return { + ...defaultData, + assetUrl: data.assets.zarr.href + }; + } else { + return defaultData; + } } - - return defaultData; }; // Create a query object for react query. diff --git a/parcel-resolver-veda/index.d.ts b/parcel-resolver-veda/index.d.ts index 81d60ae0d..261ebf05f 100644 --- a/parcel-resolver-veda/index.d.ts +++ b/parcel-resolver-veda/index.d.ts @@ -54,8 +54,6 @@ declare module 'veda' { initialDatetime?: 'newest' | 'oldest' | string; projection?: ProjectionOptions; type: DatasetLayerType; - assetUrl?: string; - stacApiOverride?: string; compare: DatasetLayerCompareSTAC | DatasetLayerCompareInternal | null; legend?: LayerLegendCategorical | LayerLegendGradient; } @@ -68,7 +66,6 @@ declare module 'veda' { extends DatasetLayerCommonCompareProps { id: string; stacCol: string; - assetUrl?: string; type: DatasetLayerType; }