Skip to content

Commit 4353246

Browse files
Merge pull request #60 from OCA-UFCG/feat/search
Create a Search Feature
2 parents 26279f1 + 2457c39 commit 4353246

File tree

10 files changed

+485
-108
lines changed

10 files changed

+485
-108
lines changed

package-lock.json

Lines changed: 105 additions & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/close-icon.svg

Lines changed: 3 additions & 0 deletions
Loading

public/follow-icon.svg

Lines changed: 4 additions & 0 deletions
Loading

public/search-icon.svg

Lines changed: 4 additions & 0 deletions
Loading

src/app/map/page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import { useSearchParams } from "next/navigation";
44
import { Suspense, useCallback, useContext, useEffect, useState } from "react";
5-
import { IEEInfo, IMapInfo } from "@/utils/interfaces";
5+
import { IEEInfo, IMapInfo, ILocationData } from "@/utils/interfaces";
66
import MapTiff from "@/components/MapTiff/MapTiff";
7+
import Search from "@/components/Search/Search";
78
import MapTemplate from "@/templates/mapTemplate";
89
import MapsMenu from "@/components/MapsMenu/MapsMenu";
910
import { defaultEEInfo } from "@/utils/constants";
@@ -35,6 +36,7 @@ const DEFAULT_TIFF = "spei";
3536
const MapPage = () => {
3637
const searchParams = useSearchParams();
3738

39+
const [boundingBox, setBoundingBox] = useState<number[]>([]);
3840
const [loadingMap, setLoadingMap] = useState<boolean>(false);
3941
const [imageData, setImageData] = useState<IMapInfo>({
4042
name: "",
@@ -97,6 +99,14 @@ const MapPage = () => {
9799
// eslint-disable-next-line react-hooks/exhaustive-deps
98100
}, [mapsData]);
99101

102+
const getBoundingBox = (searchResults: ILocationData) => {
103+
const boundingBox = searchResults.boundingbox;
104+
const [south, north, west, east] = boundingBox.map((coordinate: string) =>
105+
parseFloat(coordinate),
106+
);
107+
setBoundingBox([west, north, east, south]);
108+
};
109+
100110
return (
101111
<MapTemplate>
102112
<MapContainer>
@@ -105,6 +115,7 @@ const MapPage = () => {
105115
onClick={handleMapClick}
106116
loading={loadingMap}
107117
setLoading={setLoadingMap}
118+
boundingBox={boundingBox}
108119
/>
109120
</MapContainer>
110121
<MapDescription
@@ -125,6 +136,7 @@ const MapPage = () => {
125136
<Link href="/">
126137
<HomeImage id="home" size={16} />
127138
</Link>
139+
<Search onClick={getBoundingBox} />
128140
</MenuWrapper>
129141
{imageData.name && (
130142
<NameContainer>

src/app/map/styles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const NameContainer = styled.div`
4343
display: flex;
4444
pointer-events: auto;
4545
gap: 1rem;
46-
z-index: 1;
46+
z-index: 0;
4747
4848
max-width: 18rem;
4949
border-radius: 4px;

src/components/MapTiff/MapTiff.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import maplibregl from "maplibre-gl";
3+
import maplibregl, { LngLatBoundsLike } from "maplibre-gl";
44
import "maplibre-gl/dist/maplibre-gl.css";
55
import { useCallback, useContext, useEffect, useRef, useState } from "react";
66
import { MapContainer, Loading, LoadingText } from "./MapTiff.styles";
@@ -18,13 +18,15 @@ const MapTiff = ({
1818
data,
1919
loading,
2020
setLoading,
21+
boundingBox,
2122
onClick,
2223
...props
2324
}: {
2425
data: IMapInfo;
2526
loading: boolean;
2627
setLoading: (e: boolean) => void;
2728
onClick?: (e: any) => void;
29+
boundingBox: number[];
2830
}) => {
2931
const { name, year } = data;
3032
const mapContainer = useRef<HTMLDivElement>(null);
@@ -151,6 +153,12 @@ const MapTiff = ({
151153
}
152154
}, [name, year, map, loadLayer, loadMap]);
153155

156+
useEffect(() => {
157+
if (map && boundingBox.length > 0) {
158+
map.fitBounds(boundingBox as LngLatBoundsLike);
159+
}
160+
}, [map, boundingBox]);
161+
154162
return (
155163
<MapContainer
156164
loading={loading.toString()}

0 commit comments

Comments
 (0)