22<script lang="ts">
33import {
44 computed , defineComponent ,
5+ watch ,
56} from ' vue' ;
67import { throttle } from ' lodash' ;
8+ import GlobalTime from ' ./GlobalTime.vue' ;
79import {
810 AnnotationTypes ,
911 NetCDFLayer ,
@@ -13,12 +15,15 @@ import {
1315 VectorMapLayer ,
1416} from ' ../../types' ; // Import your defined types
1517import MapStore from ' ../../MapStore' ;
16- import { updateNetCDFLayer , visibleNetCDFLayers } from ' ../../map/mapNetCDFLayer' ;
18+ import { updateNetCDFLayer } from ' ../../map/mapNetCDFLayer' ;
1719import { getRasterLayerDisplayConfig , getVectorLayerDisplayConfig } from ' ../../utils' ;
1820import { updateLayer } from ' ../../map/mapLayers' ;
1921
2022export default defineComponent ({
2123 name: ' ControlsKey' ,
24+ components: {
25+ GlobalTime ,
26+ },
2227 props: {
2328 vectorLayers: {
2429 type: Array as () => VectorMapLayer [],
@@ -73,7 +78,7 @@ export default defineComponent({
7378 // Compute NetCDF Layer Keys
7479 const stepIndexMap: Record <string , { length: number , currentIndex: number }> = {};
7580 const resamplingMap: Record <string , ' linear' | ' nearest' > = {};
76- visibleNetCDFLayers .value .forEach ((item ) => {
81+ MapStore . visibleNetCDFLayers .value .forEach ((item ) => {
7782 const found = props .netcdfLayers .find ((layer ) => layer .id === item .netCDFLayer );
7883 if (found ) {
7984 const { opacity } = item ;
@@ -123,7 +128,7 @@ export default defineComponent({
123128
124129 const stepMapping = computed (() => {
125130 const mappedStepMapping: Record <string , Record <number , string | number >> = {};
126- visibleNetCDFLayers .value .forEach ((item ) => {
131+ MapStore . visibleNetCDFLayers .value .forEach ((item ) => {
127132 const foundLayer = props .netcdfLayers .find ((layer ) => layer .id === item .netCDFLayer );
128133 mappedStepMapping [` netcdf_${foundLayer ?.id } ` ] = {};
129134 const mapSlicer: Record <number , string | number > = {};
@@ -174,7 +179,7 @@ export default defineComponent({
174179 });
175180 }
176181 if (item .type === ' netcdf' ) {
177- const found = visibleNetCDFLayers .value .find ((layer ) => item .id === layer .netCDFLayer );
182+ const found = MapStore . visibleNetCDFLayers .value .find ((layer ) => item .id === layer .netCDFLayer );
178183 if (found ) {
179184 found .opacity = val ;
180185 updateNetCDFLayer (item .id , { opacity: val });
@@ -194,26 +199,59 @@ export default defineComponent({
194199 };
195200
196201 const toggleResampling = (id : number ) => {
197- const found = visibleNetCDFLayers .value .find ((layer ) => id === layer .netCDFLayer );
202+ const found = MapStore . visibleNetCDFLayers .value .find ((layer ) => id === layer .netCDFLayer );
198203 if (found ) {
199204 const val = found .resampling === ' linear' ? ' nearest' : ' linear' ;
200205 found .resampling = val ;
201206 updateNetCDFLayer (id , { resampling: val });
202207 }
203208 };
209+
210+ watch (MapStore .globalTime , (newVal ) => {
211+ if (! MapStore .timeLinked .value ) {
212+ return ;
213+ }
214+ props .netcdfLayers .forEach ((netcdfLayer ) => {
215+ const found = MapStore .visibleNetCDFLayers .value .find ((layer ) => layer .netCDFLayer === netcdfLayer .id );
216+ if (found ) {
217+ // now we need to find the closest index to the current time
218+ const { min } = found .sliding ;
219+ const stepSize = found .sliding .step ;
220+ const currentIndex = Math .round ((newVal - min ) / stepSize );
221+ if (currentIndex >= 0 && currentIndex < found .images .length ) {
222+ found .currentIndex = currentIndex ;
223+ throttledUpdateNetCDFLayer (netcdfLayer .id , currentIndex );
224+ }
225+ }
226+ });
227+ });
228+
229+ const globalTimeEnabled = computed (() => {
230+ let enabled = false ;
231+ if (props .netcdfLayers .length > 0 ) {
232+ enabled = true ;
233+ }
234+ return enabled ;
235+ });
204236 return {
205237 processedLayers ,
206238 iconMapper ,
207239 updateOpacity ,
208240 throttledUpdateNetCDFLayer ,
209241 stepMapping ,
210242 toggleResampling ,
243+ globalTimeEnabled ,
211244 };
212245 },
213246});
214247 </script >
215248
216249<template >
250+ <v-card v-if =" globalTimeEnabled" class =" pa-0 ma-0 mb-2" >
251+ <v-card-text class =" pa-0 ma-0" >
252+ <global-time />
253+ </v-card-text >
254+ </v-card >
217255 <v-card
218256 v-for =" (item, index) in processedLayers"
219257 :key =" `opacity_${index}`"
0 commit comments