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,13 +199,32 @@ 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+ });
204228 return {
205229 processedLayers ,
206230 iconMapper ,
@@ -214,6 +238,11 @@ export default defineComponent({
214238 </script >
215239
216240<template >
241+ <v-card class =" pa-0 ma-0 mb-2" >
242+ <v-card-text class =" pa-0 ma-0" >
243+ <global-time />
244+ </v-card-text >
245+ </v-card >
217246 <v-card
218247 v-for =" (item, index) in processedLayers"
219248 :key =" `opacity_${index}`"
0 commit comments