Skip to content

Commit

Permalink
fix: removing the 'SearchMap' file and adding 'index.tsx'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugahnstn committed Oct 2, 2023
1 parent cb087d0 commit cb95c9a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/components/SearchMap/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { SearchMapProps, ViewPort } from "../../types";
import { useState, useEffect } from "react";
import Map from "react-map-gl";

export const SearchMap = ({ longitude, latitude }: SearchMapProps) => {
const [viewPort, setViewPort] = useState<ViewPort>({
attributionControl: false,
longitude: longitude,
latitude: latitude,
zoom: 5,
});

const [screenWidth, setScreenWidth] = useState<number>();

useEffect(() => {
setScreenWidth(() => {
let width = window.innerWidth;
const getWidth = width >= 768 ? 1280 : 420;

return getWidth;
})
});

useEffect(() => {
setViewPort({
attributionControl: false,
longitude: longitude,
latitude: latitude,
zoom: viewPort.zoom,
});
}, [longitude, latitude]);

return (
<Map
mapLib={import("mapbox-gl")}
initialViewState={{ ...viewPort }}
style={{ width: screenWidth, height: 420}}
mapStyle="mapbox://styles/mapbox/streets-v10"
mapboxAccessToken={import.meta.env.VITE_MAPBOX_TOKEN} />
);
};

0 comments on commit cb95c9a

Please sign in to comment.