+
+
${hospitalName}
- ${
- distanceLabel
- ? `
- ${distanceLabel}
-
`
- : ''
- }
-
+
+ Itinéraire
+
`
}
@@ -324,7 +249,7 @@ function MapContent({ fullScreen = false }: MapContentProps) {
})
if (marker) {
- const newPopupContent = createPopupHTML(hospital, lat, lng)
+ const newPopupContent = createPopupHTML(hospital.fields.name, lat, lng)
marker.setPopupContent(newPopupContent)
}
})
@@ -344,7 +269,8 @@ function MapContent({ fullScreen = false }: MapContentProps) {
return
}
- let markersAdded = 0
+ let focusMarker: LeafletMarker | null = null
+ let focusCoords: [number, number] | null = null
hospitalsDataRef.current = []
@@ -357,27 +283,17 @@ function MapContent({ fullScreen = false }: MapContentProps) {
const [lat, lng] = coords
hospitalsDataRef.current.push({ hospital, coords })
- const popupContent = createPopupHTML(hospital, lat, lng)
+ const popupContent = createPopupHTML(hospital.fields.name, lat, lng)
if (!mapInstanceRef.current) return
- const marker = L.marker([lat, lng], {
- icon: redIcon
- })
+ const marker = L.marker([lat, lng], { icon: redIcon })
.bindPopup(popupContent, {
className: 'hospital-popup',
closeButton: true,
autoClose: false,
closeOnClick: false,
})
- .on('popupopen', () => {
- setTimeout(() => {
- const closeButton = document.querySelector('.leaflet-popup-close-button') as HTMLElement
- if (closeButton) {
- closeButton.setAttribute('tabindex', '-1')
- }
- }, 0)
- })
const handleMouseOver = () => {
marker.openPopup()
@@ -390,8 +306,19 @@ function MapContent({ fullScreen = false }: MapContentProps) {
}
markersRef.current.push(marker)
- markersAdded++
+
+ if (focusRecordId && hospital.recordid === focusRecordId) {
+ focusMarker = marker
+ focusCoords = [lat, lng]
+ }
})
+
+ if (focusMarker && focusCoords && mapInstanceRef.current) {
+ const zoomToUse = initialZoom ?? 16
+ mapInstanceRef.current.setView(focusCoords, zoomToUse)
+ mapInitializedRef.current = true
+ ;(focusMarker as LeafletMarker).openPopup()
+ }
} catch (error) {
console.error('Error loading hospitals:', error)
}
@@ -416,7 +343,15 @@ function MapContent({ fullScreen = false }: MapContentProps) {
}
}
- if ("geolocation" in navigator) {
+ if (initialCenter && isValidCoordinates(initialCenter[0], initialCenter[1])) {
+ userPositionRef.current = null
+ if (!focusRecordId) {
+ const zoomToUse = initialZoom ?? DEFAULT_ZOOM
+ centerMapOnCoords(initialCenter, zoomToUse)
+ }
+ await loadHospitals(initialCenter[0], initialCenter[1])
+ updatePopups()
+ } else if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(
async (position) => {
const { latitude, longitude } = position.coords
@@ -436,8 +371,7 @@ function MapContent({ fullScreen = false }: MapContentProps) {
}
userMarkerRef.current = L.marker(PARIS_COORDS, {
icon: userIcon,
- zIndexOffset: 1000,
- keyboard: false
+ zIndexOffset: 1000
})
.addTo(map)
.bindPopup('Votre position (approximative)', { closeButton: false })
@@ -454,8 +388,7 @@ function MapContent({ fullScreen = false }: MapContentProps) {
}
userMarkerRef.current = L.marker([latitude, longitude], {
icon: userIcon,
- zIndexOffset: 1000,
- keyboard: false
+ zIndexOffset: 1000
})
.addTo(map)
.bindPopup('Votre position', { closeButton: false })
@@ -588,6 +521,10 @@ function MapContent({ fullScreen = false }: MapContentProps) {
)
}
+interface MapComponentProps {
+ fullScreen?: boolean
+}
+
const MapComponent = dynamic(() => Promise.resolve(MapContent), {
ssr: false,
loading: () => (
@@ -595,6 +532,6 @@ const MapComponent = dynamic(() => Promise.resolve(MapContent), {
Chargement de la carte...