Skip to content

Commit 6a888ed

Browse files
committed
update
1 parent 2c4ae4d commit 6a888ed

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

src/app/Services/API/Requests/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ export class RequestApi extends Http {
138138
}
139139

140140
//labels['forecast'][1] = 'Predizioni';
141+
} else {
142+
if (!labels['historical']) {
143+
labels['historical'] = ['archive', 'Historical data'];
144+
} else {
145+
labels['historical'][1] = 'Historical data';
146+
}
147+
148+
if (!labels['forecast']) {
149+
labels['forecast'] = ['archive', 'Projecions'];
150+
} else {
151+
labels['forecast'][1] = 'Projecions';
152+
}
141153
}
142154
const innerConf = {
143155
...configuration,

src/app/components/Map/TWLSample.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export const TWLSample = (props: any) => {
7575
const setCurrYear = (yr, data = 'forecast') => {
7676
const date = new Date();
7777
if (
78-
getCY() !== (yr + (data === 'forecast' ? 0 : 1)).toString() &&
79-
getCY() != yr.toString()
78+
getCY() !== (yr + (data === 'forecast' ? 0 : 1)).toString() ||
79+
getCY() !== yr.toString()
8080
) {
8181
setTimeout(() => {
8282
console.log('setting current year from Leaflet Timedmension:', yr);
@@ -85,7 +85,7 @@ export const TWLSample = (props: any) => {
8585
setCY(yr);
8686
setYearSet(true);
8787
//@ts-ignore
88-
context.map.timeDimension.setCurrentTime(date.getTime());
88+
//context.map.timeDimension.setCurrentTime(date.getTime());
8989
}, 50);
9090
}
9191
};

src/app/components/MapSearch/index.tsx

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)