From acb81a538d4f2c04d12f5398fe16f384bdf92c45 Mon Sep 17 00:00:00 2001 From: Mayur Marakana Date: Fri, 16 Feb 2024 00:10:28 -0800 Subject: [PATCH] add time dimension config in custom config json --- ...ckage-time-slider2-config-time-slider.json | 42 +++++++++---------- .../time-slider-state.ts | 39 ----------------- .../geoview-layers/abstract-geoview-layers.ts | 11 +++++ .../geoview-time-slider/src/time-slider.tsx | 7 +--- 4 files changed, 34 insertions(+), 65 deletions(-) diff --git a/packages/geoview-core/public/configs/package-time-slider2-config-time-slider.json b/packages/geoview-core/public/configs/package-time-slider2-config-time-slider.json index 5d4a30fb9e7..c8c1033a0dd 100644 --- a/packages/geoview-core/public/configs/package-time-slider2-config-time-slider.json +++ b/packages/geoview-core/public/configs/package-time-slider2-config-time-slider.json @@ -15,27 +15,27 @@ "defaultValue": "", "temporalDimension": { "field": "datetime", - "default": "1696-01-01T05:00:00Z", + "default": ["1950-01-01T05:00:00Z", "1970-01-01T05:00:00Z"], "unitSymbol": "", "range": [ - "1696-01-01T05:00:00Z", - "1704-01-01T05:00:00Z", - "1712-01-01T05:00:00Z", - "1720-01-01T05:00:00Z", - "1728-01-01T05:00:00Z", - "1736-01-01T05:00:00Z", - "1744-01-01T05:00:00Z", - "1752-01-01T05:00:00Z", - "1760-01-01T05:00:00Z", - "1768-01-01T05:00:00Z", - "1776-01-01T05:00:00Z", - "1784-01-01T05:00:00Z", - "1792-01-01T05:00:00Z", - "1800-01-01T05:00:00Z", - "1808-01-01T05:00:00Z", - "1816-01-01T05:00:00Z", - "1824-01-01T05:00:00Z", - "1832-01-01T05:00:00Z", + "1900-01-01T05:00:00Z", + "1905-01-01T05:00:00Z", + "1910-01-01T05:00:00Z", + "1915-01-01T05:00:00Z", + "1920-01-01T05:00:00Z", + "1930-01-01T05:00:00Z", + "1940-01-01T05:00:00Z", + "1945-01-01T05:00:00Z", + "1950-01-01T05:00:00Z", + "1955-01-01T05:00:00Z", + "1960-01-01T05:00:00Z", + "1965-01-01T05:00:00Z", + "1970-01-01T05:00:00Z", + "1975-01-01T05:00:00Z", + "1980-01-01T05:00:00Z", + "1985-01-01T05:00:00Z", + "1990-01-01T05:00:00Z", + "1995-01-01T05:00:00Z", "1840-01-01T05:00:00Z", "1848-01-01T05:00:00Z", "1856-01-01T05:00:00Z", @@ -58,9 +58,9 @@ "1992-01-01T04:47:32Z", "2000-01-01T04:47:32Z", "2008-01-01T04:47:32Z", - "2016-01-01T04:47:32Z" + "2000-01-01T04:47:32Z" ], - "nearestValues": "discrete", + "nearestValues": "absolute", "singleHandle": true } }, diff --git a/packages/geoview-core/src/core/stores/store-interface-and-intial-values/time-slider-state.ts b/packages/geoview-core/src/core/stores/store-interface-and-intial-values/time-slider-state.ts index 0241e621ed3..c6cb4a92cc7 100644 --- a/packages/geoview-core/src/core/stores/store-interface-and-intial-values/time-slider-state.ts +++ b/packages/geoview-core/src/core/stores/store-interface-and-intial-values/time-slider-state.ts @@ -8,15 +8,6 @@ export type TimeSliderLayerSet = { [layerPath: string]: TypeTimeSliderValues; }; -export type TemporalDimensionProps = { - field: string; - default: string; - unitSymbol: string; - range: string[]; - nearestValues: string; - singleHandle: boolean; -}; - // #region INTERFACES export interface TypeTimeSliderValues { title?: string; @@ -35,7 +26,6 @@ export interface TypeTimeSliderValues { reversed?: boolean; nearestValues?: string; unitSymbol?: string; - temporalDimension?: TemporalDimensionProps | null; } export interface ITimeSliderState { @@ -54,7 +44,6 @@ export interface ITimeSliderState { setDefaultValue: (layerPath: string, defaultValue: string) => void; setValues: (layerPath: string, values: number[]) => void; setVisibleTimeSliderLayers: (visibleLayerPaths: string[]) => void; - setTemporalDimension: (layerPath: string, temporalDimension: TemporalDimensionProps | null) => void; }; } // #endregion INTERFACES @@ -171,34 +160,6 @@ export function initializeTimeSliderState(set: TypeSetStore, get: TypeGetStore): get().timeSliderState.actions.applyFilters(layerPath, values); }, // #endregion ACTIONS - setTemporalDimension(layerPath: string, temporalDimension: TemporalDimensionProps | null): void { - const sliderLayers = get().timeSliderState.timeSliderLayers; - if (temporalDimension?.field) { - sliderLayers[layerPath].field = temporalDimension.field; - } - if (temporalDimension?.default) { - sliderLayers[layerPath].defaultValue = temporalDimension.default; - } - if (temporalDimension?.singleHandle) { - sliderLayers[layerPath].singleHandle = temporalDimension.singleHandle; - } - if (temporalDimension?.nearestValues) { - sliderLayers[layerPath].nearestValues = temporalDimension.nearestValues; - } - if (temporalDimension?.unitSymbol) { - sliderLayers[layerPath].unitSymbol = temporalDimension.unitSymbol; - } - if (temporalDimension?.range) { - sliderLayers[layerPath].range = temporalDimension.range; - } - sliderLayers[layerPath].temporalDimension = temporalDimension; - set({ - timeSliderState: { - ...get().timeSliderState, - timeSliderLayers: { ...sliderLayers }, - }, - }); - }, }, } as ITimeSliderState; diff --git a/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts b/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts index ac9f73b04ca..8a192b02053 100644 --- a/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts +++ b/packages/geoview-core/src/geo/layer/geoview-layers/abstract-geoview-layers.ts @@ -437,6 +437,17 @@ export abstract class AbstractGeoViewLayer { if (layerStatus === 'processed') this.setLayerPhase('processed', layerPath); } + /** *************************************************************************************************************************** + * Change the layer temporal dimension property and emit an event to update existing layer sets. + * + * @param {TimeDimension} timeDimension The value to assign to the layer temporal dimension property. + * @param {string} layerPath The layer path to the layer's configuration affected by the change. + */ + setLayerTemporalDimension(timeDimension: TimeDimension, layerPath?: string) { + layerPath = layerPath || this.layerPathAssociatedToTheGeoviewLayer; + this.layerTemporalDimension[layerPath] = timeDimension; + } + /** *************************************************************************************************************************** * Process recursively the list of layer entries to see if all of them are processed. * diff --git a/packages/geoview-time-slider/src/time-slider.tsx b/packages/geoview-time-slider/src/time-slider.tsx index 81add28114c..271261e3b2c 100644 --- a/packages/geoview-time-slider/src/time-slider.tsx +++ b/packages/geoview-time-slider/src/time-slider.tsx @@ -51,7 +51,7 @@ export function TimeSlider(TimeSliderPanelProps: TimeSliderPanelProps) { // Get actions and states from store // TODO: evaluate best option to set value by layer path.... trough a getter? - const { setTitle, setDescription, setDefaultValue, setValues, setLocked, setReversed, setDelay, setFiltering, setTemporalDimension } = + const { setTitle, setDescription, setDefaultValue, setValues, setLocked, setReversed, setDelay, setFiltering } = useTimeSliderStoreActions(); // TODO: check performance as we should technically have one selector by constant @@ -69,8 +69,7 @@ export function TimeSlider(TimeSliderPanelProps: TimeSliderPanelProps) { values, delay, locked, - reversed, - temporalDimension, + reversed } = useTimeSliderLayers()[layerPath]; // slider config @@ -82,8 +81,6 @@ export function TimeSlider(TimeSliderPanelProps: TimeSliderPanelProps) { if (defaultValue === undefined) setDefaultValue(layerPath, sliderConfig?.defaultValue || ''); if (locked === undefined) setLocked(layerPath, sliderConfig?.locked !== undefined ? sliderConfig?.locked : false); if (reversed === undefined) setReversed(layerPath, sliderConfig?.reversed !== undefined ? sliderConfig?.reversed : false); - if (temporalDimension === undefined) - setTemporalDimension(layerPath, sliderConfig?.temporalDimension !== undefined ? sliderConfig?.temporalDimension : null); // eslint-disable-next-line react-hooks/exhaustive-deps }, []);