File tree Expand file tree Collapse file tree 1 file changed +25
-10
lines changed
src/app/components/MapSearch Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -386,6 +386,19 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
386386 }
387387 } , [ currentTimeserie ] ) ;
388388
389+ const setCY = yr => {
390+ localStorage . setItem ( 'currentYear' , yr . toString ( ) ) ;
391+ } ;
392+
393+ const getCY = ( ) => {
394+ const cy = localStorage . getItem ( 'currentYear' ) ;
395+ if ( cy ) {
396+ return cy ;
397+ } else {
398+ return 0 ;
399+ }
400+ } ;
401+
389402 useEffect ( ( ) => {
390403 let att = yr ;
391404 let atv = 0 ;
@@ -443,18 +456,20 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
443456 map . timeDimension . on ( 'timeloading' , data => {
444457 if ( baseYear ) {
445458 let dt = new Date ( + data . time ) . getFullYear ( ) ;
446- console . log ( dt ) ;
447- setOTsIndex ( tsIndex ) ;
448- const index = dt - baseYear ;
449- setTsIndex ( index ) ;
459+ if ( getCY ( ) !== dt . toString ( ) ) {
460+ console . log ( dt ) ;
461+ setOTsIndex ( tsIndex ) ;
462+ const index = dt - baseYear ;
463+ setTsIndex ( index ) ;
450464
451- let url = new URL ( window . location . href ) ;
452- if ( url . searchParams . has ( 'year' ) ) {
453- url . searchParams . set ( 'year' , dt . toString ( ) ) ;
454- } else {
455- url . searchParams . append ( 'year' , dt . toString ( ) ) ;
465+ let url = new URL ( window . location . href ) ;
466+ if ( url . searchParams . has ( 'year' ) ) {
467+ url . searchParams . set ( 'year' , dt . toString ( ) ) ;
468+ } else {
469+ url . searchParams . append ( 'year' , dt . toString ( ) ) ;
470+ }
471+ window . history . pushState ( null , '' , url . toString ( ) ) ;
456472 }
457- window . history . pushState ( null , '' , url . toString ( ) ) ;
458473 }
459474 } ) ;
460475
You can’t perform that action at this time.
0 commit comments