-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
682 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.modalOverlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
z-index: 20; | ||
} | ||
|
||
.modalContent { | ||
display: flex; | ||
width: 80%; | ||
max-width: 900px; | ||
background-color: white; | ||
border-radius: 8px; | ||
overflow: hidden; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
.leftColumn { | ||
width: 90%; | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
} | ||
|
||
.mapContainer { | ||
width: 100%; | ||
height: 100%; /* Ensures the map fills the entire left column */ | ||
min-height: 400px; /* A minimum height to prevent collapsing */ | ||
position: relative; | ||
} | ||
|
||
.rightColumn { | ||
width: fit-content; | ||
padding: 16px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
} | ||
.rightColumn h2{ | ||
white-space: nowrap; | ||
} | ||
|
||
.subTitle{ | ||
white-space: nowrap; | ||
width: fit-content; | ||
} | ||
|
||
.imageSection { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 8px; | ||
margin-top: 8px; | ||
width: fit-content; | ||
} | ||
|
||
.imageSection img { | ||
width: 250px; | ||
height: auto; | ||
border-radius: 4px; | ||
object-fit: cover; | ||
} | ||
|
||
.closeButton { | ||
margin-top: 16px; | ||
padding: 8px 16px; | ||
background-color: #333; | ||
color: white; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// components/MapModal.tsx | ||
import React, { useRef, useEffect } from 'react'; | ||
import mapboxgl from 'mapbox-gl'; | ||
import styles from './MapModal.module.css'; | ||
import 'mapbox-gl/dist/mapbox-gl.css'; | ||
|
||
// Ensure Mapbox token is defined | ||
if (!process.env.NEXT_PUBLIC_MAPBOX_TOKEN) { | ||
throw new Error("Mapbox access token is not defined. Please set NEXT_PUBLIC_MAPBOX_TOKEN in your environment variables."); | ||
} | ||
|
||
mapboxgl.accessToken = process.env.NEXT_PUBLIC_MAPBOX_TOKEN; | ||
|
||
// Define the TrekDetails type with image as an array of strings | ||
import { TrekDetails } from '../ui/TrekCard'; | ||
|
||
// Define the props interface, including `info` as a prop of type TrekDetails | ||
interface MapModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
center?: number[]; | ||
zoom?: number; | ||
markerLocation?: number[]; | ||
info: TrekDetails; | ||
subTitle : string; | ||
} | ||
|
||
const MapModal: React.FC<MapModalProps> = ({ | ||
isOpen, | ||
onClose, | ||
center = [78.9629, 20.5937], | ||
zoom = 5, | ||
markerLocation = [78.9629, 20.5937], | ||
info, | ||
subTitle | ||
}) => { | ||
const mapContainerRef = useRef<HTMLDivElement | null>(null); | ||
const mapRef = useRef<mapboxgl.Map | null>(null); | ||
|
||
useEffect(() => { | ||
if (isOpen && mapContainerRef.current) { | ||
mapRef.current = new mapboxgl.Map({ | ||
container: mapContainerRef.current, | ||
style: 'mapbox://styles/mapbox/streets-v11', | ||
center: [center[1],center[0]], | ||
zoom: zoom, | ||
}); | ||
|
||
// Add the marker to the specified location | ||
new mapboxgl.Marker() | ||
.setLngLat([markerLocation[1],markerLocation[0]]) | ||
.addTo(mapRef.current); | ||
|
||
return () => mapRef.current?.remove(); | ||
} | ||
}, [isOpen, center, zoom, markerLocation]); | ||
|
||
if (!isOpen) return null; | ||
|
||
return ( | ||
<div className={styles.modalOverlay} onClick={onClose}> | ||
<div className={styles.modalContent} onClick={(e) => e.stopPropagation()}> | ||
<div className={styles.leftColumn}> | ||
<div ref={mapContainerRef} className={styles.mapContainer} /> | ||
</div> | ||
<div className={styles.rightColumn}> | ||
<h2>{info.title}</h2> | ||
<p className={styles.subTitle}>{subTitle}</p> | ||
<h3>Address </h3> | ||
<p>{info.address}</p> | ||
<p></p> | ||
<div className={styles.imageSection}> | ||
<img src={info.image} alt={`Image`} /> | ||
</div> | ||
<button className={styles.closeButton} onClick={onClose}> | ||
Close | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MapModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters