Skip to content

Commit

Permalink
feat(map): level filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Me1e committed Aug 1, 2023
1 parent 7ce52bd commit 64975bb
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions packages/nextjs/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,54 @@ const Map: NextPage = () => {
});
};

// console.log(useScaffoldContractRead);
// console.log(totalReports); // 이게 중요한 데이터
useEffect(() => {
if (map.current === null) return;

// const { data, isError, isLoading } = useContractRead({
// address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
// abi: wagmigotchiABI,
// functionName: 'getHunger',
// })
map.current.removeLayer("information");
map.current.removeLayer("caution");
map.current.removeLayer("alert");

// console.log(totalReports); // 이게 중요한 데이터
if (filter.level.includes(0) === true || filter.level.length === 0) {
map.current.addLayer({
id: "information",
type: "circle",
source: "information",
paint: {
"circle-color": "#4992FF",
"circle-radius": 10,
"circle-stroke-width": 1,
"circle-stroke-color": "rgba(255, 255, 255, 0.30)",
},
});
}
if (filter.level.includes(1) === true || filter.level.length === 0) {
map.current.addLayer({
id: "caution",
type: "circle",
source: "caution",
paint: {
"circle-color": "#F3B06C",
"circle-radius": 10,
"circle-stroke-width": 1,
"circle-stroke-color": "rgba(255, 255, 255, 0.30)",
},
});
}
if (filter.level.includes(2) === true || filter.level.length === 0) {
map.current.addLayer({
id: "alert",
type: "circle",
source: "alert",
paint: {
"circle-color": "#FF4958",
"circle-radius": 10,
"circle-stroke-width": 1,
"circle-stroke-color": "rgba(255, 255, 255, 0.30)",
},
});
}
}, [map, filter]);

useEffect(() => {
if (totalReports === undefined) return;
Expand Down Expand Up @@ -109,7 +148,9 @@ const Map: NextPage = () => {
zoom: 11,
});

console.log("1");
map.current.on("load", () => {
console.log("2");
map.current.addSource("information", {
type: "geojson",
data: {
Expand Down Expand Up @@ -139,6 +180,7 @@ const Map: NextPage = () => {
}),
},
});

map.current.addSource("caution", {
type: "geojson",
data: {
Expand Down Expand Up @@ -168,6 +210,7 @@ const Map: NextPage = () => {
}),
},
});

map.current.addSource("alert", {
type: "geojson",
data: {
Expand Down Expand Up @@ -261,7 +304,7 @@ const Map: NextPage = () => {
map.current.getCanvas().style.cursor = "";
});
});
}, [datas, map.current]);
}, [datas, filter]);

return (
<MapWrapper>
Expand Down Expand Up @@ -382,7 +425,7 @@ const MapWrapper = styled.div`
align-items: center;
justify-content: center;
flex-direction: column;
a {
.enter_button {
display: block;
max-width: 158px;
display: flex;
Expand Down

0 comments on commit 64975bb

Please sign in to comment.