22import "mapbox-gl/dist/mapbox-gl.css" ;
33
44import { Building } from "@common/types" ;
5- import mbxDirections from "@mapbox/mapbox-sdk/services/directions" ;
65import Box from "@mui/material/Box" ;
76import { DarkModeContext } from "app/clientLayout" ;
8- import { useSearchParams } from "next/navigation" ;
97import React , { useContext , useEffect , useRef , useState } from "react" ;
10- import {
11- Layer ,
12- LngLatBoundsLike ,
13- Map ,
14- MapRef ,
15- Marker ,
16- Source ,
17- } from "react-map-gl/mapbox" ;
8+ import { LngLatBoundsLike , Map , MapRef , Marker } from "react-map-gl/mapbox" ;
189import { useDebounceValue } from "usehooks-ts" ;
19- import BuildingDrawer from "views/BuildingDrawer" ;
2010
2111import { MAPBOX_ACCESS_TOKEN } from "../config" ;
2212import useBuildings from "../hooks/useBuildings" ;
@@ -66,25 +56,6 @@ if (!MAPBOX_ACCESS_TOKEN) {
6656 throw new Error ( "Missing Mapbox access token" ) ;
6757}
6858
69- const directionsClient = mbxDirections ( { accessToken : MAPBOX_ACCESS_TOKEN } ) ;
70-
71- const fetchRoute = async ( start : [ number , number ] , end : [ number , number ] ) => {
72- try {
73- const response = await directionsClient
74- . getDirections ( {
75- profile : "walking" , // or 'driving', 'cycling'
76- geometries : "geojson" ,
77- waypoints : [ { coordinates : start } , { coordinates : end } ] ,
78- } )
79- . send ( ) ;
80-
81- return response . body . routes [ 0 ] . geometry ;
82- } catch ( error : any ) {
83- console . error ( "Route fetch error:" , error . response ?. body || error . message ) ;
84- throw error ;
85- }
86- } ;
87-
8859export const MapComponent = ( ) => {
8960 const { buildings } = useBuildings ( ) ;
9061 const { isDarkMode } = useContext ( DarkModeContext ) ;
@@ -100,20 +71,12 @@ export const MapComponent = () => {
10071 setRoomIdToFocus ( params . get ( "roomId" ) ?? undefined ) ;
10172 } , [ ] ) ;
10273
103- // useEffect(() => {
104- // // Run only on client side, no Suspense issues
105- // const params = new URLSearchParams(window.location.search);
106- // setRoomIdToFocus(params.get("roomId") ?? undefined);
107- // }, []);
108- // const roomIdToFocus = useSearchParams().get("roomId") ?? undefined;
10974 const mapRef = useRef < MapRef > ( null ) ;
11075
11176 // Use debounce to allow moving from marker to popup without popup hiding
11277 const [ currentHover , setCurrentHover ] = useState < Building | null > ( null ) ;
11378 const [ debouncedCurrentHover ] = useDebounceValue ( currentHover , 50 ) ;
11479
115- const [ routeGeoJSON , setRouteGeoJSON ] = useState < any | null > ( null ) ;
116-
11780 const style = isDarkMode
11881 ? "mapbox://styles/bengodw/cmcimql2101qo01sp7dricgzq"
11982 : "mapbox://styles/bengodw/cmcimp1tz002p01rcfzbd8btn" ;
@@ -130,21 +93,6 @@ export const MapComponent = () => {
13093 }
13194 } , [ buildings , userLat , userLng ] ) ;
13295
133- const handleMarkerClick = async ( building : Building ) => {
134- if ( ! userLat || ! userLng ) return ;
135-
136- const geometry = await fetchRoute (
137- [ userLng , userLat ] ,
138- [ building . long , building . lat ]
139- ) ;
140-
141- setRouteGeoJSON ( {
142- type : "Feature" ,
143- properties : { } ,
144- geometry,
145- } ) ;
146- } ;
147-
14896 return (
14997 < div style = { { height : "100%" , position : "relative" } } >
15098 < Map
@@ -160,7 +108,6 @@ export const MapComponent = () => {
160108 key = { building . id }
161109 latitude = { building . lat }
162110 longitude = { building . long }
163- onClick = { ( ) => handleMarkerClick ( building ) }
164111 >
165112 < MapMarker
166113 buildingId = { building . id }
@@ -177,34 +124,17 @@ export const MapComponent = () => {
177124 </ Marker >
178125 ) }
179126
180- < RoomMapMarker
181- roomId = { roomIdToFocus }
182- roomLocation = { ( lat , long ) => {
183- mapRef . current ?. flyTo ( {
184- center : [ long , lat ] ,
185- zoom : 19.5 ,
186- duration : 1000 ,
187- } ) ;
188- } }
189- />
190-
191- { routeGeoJSON && (
192- < >
193- < Source id = "route" type = "geojson" data = { routeGeoJSON } />
194- < Layer
195- id = "route-line"
196- type = "line"
197- source = "route"
198- layout = { {
199- "line-cap" : "round" ,
200- "line-join" : "round" ,
201- } }
202- paint = { {
203- "line-color" : "#1DB954" ,
204- "line-width" : 4 ,
205- } }
206- />
207- </ >
127+ { roomIdToFocus && (
128+ < RoomMapMarker
129+ roomId = { roomIdToFocus }
130+ roomLocation = { ( lat , long ) => {
131+ mapRef . current ?. flyTo ( {
132+ center : [ long , lat ] ,
133+ zoom : 19.5 ,
134+ duration : 1000 ,
135+ } ) ;
136+ } }
137+ />
208138 ) }
209139 </ Map >
210140 </ div >
0 commit comments