@@ -373,16 +373,33 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
373373 let oyr = 0 ;
374374 let otsindex = 0 ;
375375
376+ const [ isObservation , setObservation ] = useState < boolean > ( false ) ;
377+
378+ const doSetBaseYear = yr => {
379+ localStorage . setItem ( 'baseYear' , yr . toString ( ) ) ;
380+ setBaseYear ( yr ) ;
381+ } ;
382+
383+ const getBaseYear = ( ) => {
384+ const by = localStorage . getItem ( 'baseYear' ) ;
385+ if ( by ) {
386+ return parseInt ( by ) ;
387+ } else {
388+ return data === 'forecast' ? 1976 : 1984 ;
389+ }
390+ } ;
391+
376392 useEffect ( ( ) => {
377393 if ( currentTimeserie && currentTimeserie . values ) {
394+ setObservation ( currentTimeserie . info . dataset_type === 'observation' ) ;
378395 setTimeSerie ( [ ...currentTimeserie . values ] ) ;
379396 let fy = parseInt ( currentTimeserie . values [ 0 ] . datetime . split ( '-' ) [ 0 ] ) ;
380- setBaseYear ( fy ) ;
397+ doSetBaseYear ( fy ) ;
381398 } else {
382399 setTimeSerie ( [ ] ) ;
383400 setTt ( NaN ) ;
384401 setTv ( 0 ) ;
385- setBaseYear ( data === 'forecast' ? 1976 : 1984 ) ;
402+ doSetBaseYear ( data === 'forecast' ? 1976 : 1984 ) ;
386403 }
387404 } , [ currentTimeserie ] ) ;
388405
@@ -427,7 +444,7 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
427444
428445 if ( timeserie ) {
429446 if ( timeserie . length > 0 ) {
430- setBaseYear ( parseInt ( timeserie [ 0 ] . datetime . split ( '-' ) [ 0 ] , 10 ) ) ;
447+ doSetBaseYear ( parseInt ( timeserie [ 0 ] . datetime . split ( '-' ) [ 0 ] , 10 ) ) ;
431448 if ( timeserie . length > 1 ) {
432449 let found_year = timeserie . filter (
433450 x => x . datetime . split ( '-' ) [ 0 ] === yr . toString ( ) ,
@@ -436,9 +453,9 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
436453 ctsindex = timeserie . indexOf ( found_year [ 0 ] ) ;
437454
438455 //@ts -ignore
439- map . timeDimension . setCurrentTime (
440- new Date ( found_year [ 0 ] . datetime ) . getTime ( ) ,
441- ) ;
456+ // map.timeDimension.setCurrentTime(
457+ // new Date(found_year[0].datetime).getTime(),
458+ // );
442459 } else {
443460 ctsindex = 0 ;
444461 }
@@ -455,23 +472,20 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
455472 useEffect ( ( ) => {
456473 //@ts -ignore
457474 map . timeDimension . on ( 'timeloading' , data => {
458- if ( baseYear ) {
459- let dt = new Date ( + data . time ) . getFullYear ( ) ;
460- if ( getCY ( ) !== dt . toString ( ) ) {
461- console . log ( dt ) ;
462- setOTsIndex ( tsIndex ) ;
463- const index = dt - baseYear ;
464- setTsIndex ( index ) ;
465-
466- let url = new URL ( window . location . href ) ;
467- if ( url . searchParams . has ( 'year' ) ) {
468- url . searchParams . set ( 'year' , dt . toString ( ) ) ;
469- } else {
470- url . searchParams . append ( 'year' , dt . toString ( ) ) ;
471- }
472- window . history . pushState ( null , '' , url . toString ( ) ) ;
473- }
475+ console . log ( 'timeloading' , data ) ;
476+ let dt = new Date ( + data . time ) . getFullYear ( ) + ( isObservation ? 1 : 0 ) ;
477+ console . log ( dt ) ;
478+ setOTsIndex ( tsIndex ) ;
479+ const index = dt - getBaseYear ( ) ;
480+ setTsIndex ( index ) ;
481+
482+ let url = new URL ( window . location . href ) ;
483+ if ( url . searchParams . has ( 'year' ) ) {
484+ url . searchParams . set ( 'year' , dt . toString ( ) ) ;
485+ } else {
486+ url . searchParams . append ( 'year' , dt . toString ( ) ) ;
474487 }
488+ window . history . pushState ( null , '' , url . toString ( ) ) ;
475489 } ) ;
476490 } , [ ] ) ;
477491
0 commit comments