Skip to content

Commit cf93e1a

Browse files
committed
update
1 parent ad47b77 commit cf93e1a

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/app/components/Map/TWLSample.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ export const TWLSample = (props: any) => {
7474

7575
const setCurrYear = (yr, mode = 'forecast') => {
7676
const date = new Date();
77-
if (getCY() !== yr.toString()) {
78-
console.log('setting current year from Leaflet Timedmension:', yr);
79-
77+
if (getCY() !== (yr + (mode === 'forecast' ? 0 : 1)).toString()) {
8078
setTimeout(() => {
79+
console.log('setting current year from Leaflet Timedmension:', yr);
8180
date.setFullYear(yr + (mode === 'forecast' ? 0 : 1));
8281
setCurrentYear(yr);
8382
setCY(yr);
@@ -101,7 +100,7 @@ export const TWLSample = (props: any) => {
101100
const y = url.searchParams.get('year');
102101
if (y) {
103102
setTimeout(() => {
104-
setCurrYear(parseInt(y));
103+
setCurrYear(parseInt(y), mode);
105104
}, 1250);
106105
}
107106
}
@@ -118,7 +117,7 @@ export const TWLSample = (props: any) => {
118117
} else {
119118
if (!yearSet) {
120119
let dt = new Date(+data.time).getFullYear();
121-
setCurrYear(dt);
120+
setCurrYear(dt, mode);
122121
}
123122
//setTimeout(() => {
124123
// let layers = document.getElementsByClassName('leaflet-layer');

src/app/components/MapSearch/index.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -439,26 +439,24 @@ export const MapPopup: React.FunctionComponent<MapPopupProps> = props => {
439439
}
440440
}, [timeserie, baseYear]);
441441

442-
useEffect(() => {
443-
// @ts-ignore
444-
map.timeDimension.on('timeloading', data => {
445-
if (baseYear) {
446-
let dt = new Date(+data.time).getFullYear();
447-
console.log(dt);
448-
setOTsIndex(tsIndex);
449-
const index = dt - baseYear;
450-
setTsIndex(index);
442+
//@ts-ignore
443+
map.timeDimension.on('timeloading', data => {
444+
if (baseYear) {
445+
let dt = new Date(+data.time).getFullYear();
446+
console.log(dt);
447+
setOTsIndex(tsIndex);
448+
const index = dt - baseYear;
449+
setTsIndex(index);
451450

452-
let url = new URL(window.location.href);
453-
if (url.searchParams.has('year')) {
454-
url.searchParams.set('year', dt.toString());
455-
} else {
456-
url.searchParams.append('year', dt.toString());
457-
}
458-
window.history.pushState(null, '', url.toString());
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());
459456
}
460-
});
461-
}, [baseYear]);
457+
window.history.pushState(null, '', url.toString());
458+
}
459+
});
462460

463461
useEffect(() => {
464462
let ctt = timeserie[tsIndex]?.datetime;

0 commit comments

Comments
 (0)