Skip to content

Commit 545ac81

Browse files
committed
Fix: Fix tif serial time change
1 parent 871a271 commit 545ac81

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/components/MapTiff/MapTiff.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ const MapTiff = ({
112112
}
113113
}
114114
let firstSymbolId;
115-
const layers = map?.getStyle()?.layers || [];
116115

117-
if (layers.length) {
116+
if (map && map.getStyle()) {
117+
const layers = map?.getStyle().layers || [];
118+
118119
for (let i = 0; i < layers.length; i++) {
119120
if (layers[i].type === "symbol") {
120121
firstSymbolId = layers[i].id;
@@ -130,8 +131,8 @@ const MapTiff = ({
130131
},
131132
firstSymbolId,
132133
);
134+
setLoading(false);
133135
}
134-
setLoading(false);
135136
},
136137
[map, mapsData, setLoading],
137138
);
@@ -143,6 +144,7 @@ const MapTiff = ({
143144

144145
if (name) {
145146
const yearStr = year || "general";
147+
146148
loadLayer(name, yearStr);
147149

148150
return () => {

src/components/MapTiff/Section/MapSection.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ const MapPageWrapper = ({ mapsData }: { mapsData: any }) => (
3333

3434
const MapSection = ({ mapsData }: { mapsData: { fields: IEEInfo }[] }) => {
3535
const searchParams = useSearchParams();
36-
37-
const [loadingMap, setLoadingMap] = useState<boolean>(false);
3836
const [imageData, setImageData] = useState<IMapInfo>({
3937
name: "",
4038
year: "",
4139
});
4240

41+
const [loadingMap, setLoadingMap] = useState<boolean>(false);
4342
const [descriptionInfo, setDescriptionInfo] =
4443
useState<IEEInfo>(defaultEEInfo);
4544
const [isDescRetracted, setIsDescRetracted] = useState<boolean>(true);
45+
const [isMenuRetracted, setIsmenuRetracted] = useState<boolean>(false);
4646

4747
const handleDescUpdate = useCallback(
4848
(name: string, retract: boolean = true) => {
@@ -62,41 +62,40 @@ const MapSection = ({ mapsData }: { mapsData: { fields: IEEInfo }[] }) => {
6262
[descriptionInfo.id, isDescRetracted, mapsData],
6363
);
6464

65-
const [isMenuRetracted, setIsmenuRetracted] = useState<boolean>(false);
66-
6765
const handleMapClick = useCallback(() => {
6866
setIsmenuRetracted(true);
6967
setIsDescRetracted(true);
7068
}, [setIsmenuRetracted, setIsDescRetracted]);
7169

7270
useEffect(() => {
73-
if (mapsData.length === 0) return;
71+
if (!mapsData || mapsData.length === 0) return;
7472

75-
let name = searchParams?.get("name") ?? "spei";
73+
let name = searchParams?.get("name") ?? DEFAULT_TIFF;
7674
let year = searchParams?.get("year") ?? "general";
7775

78-
const filteredData = mapsData.filter(
76+
const filteredData = mapsData.find(
7977
(data: { fields: { id: string } }) => data.fields.id === name,
8078
);
81-
if (filteredData.length === 0) {
79+
80+
if (!filteredData) {
8281
name = DEFAULT_TIFF;
8382
}
8483

8584
if (
86-
mapsData &&
87-
mapsData.filter(
85+
filteredData &&
86+
!mapsData.find(
8887
(data: { fields: { id: string; imageData: {} } }) =>
8988
name === data.fields.id && year in Object.keys(data.fields.imageData),
90-
).length == 0
89+
)
9190
) {
92-
year = Object.keys(filteredData[0].fields.imageData)[0];
91+
year = Object.keys(filteredData?.fields?.imageData)[0];
9392
}
9493

9594
setImageData({ name, year });
96-
setDescriptionInfo(filteredData[0].fields);
95+
filteredData && setDescriptionInfo(filteredData?.fields);
9796

9897
// eslint-disable-next-line react-hooks/exhaustive-deps
99-
}, [mapsData]);
98+
}, []);
10099

101100
return (
102101
<MapTemplate>

0 commit comments

Comments
 (0)