parent
f567ce0c74
commit
9a5cfaa650
@ -0,0 +1,33 @@ |
||||
import 'leaflet/dist/leaflet.css'; |
||||
import leaflet from 'leaflet'; |
||||
import { useEffect, useRef } from 'preact/hooks'; |
||||
|
||||
export const MapComponent = () => { |
||||
const mapContainerRef = useRef<HTMLDivElement>(null); |
||||
const mapRef = useRef<leaflet.Map | undefined>(undefined); |
||||
|
||||
useEffect(() => { |
||||
if (mapRef.current) { |
||||
return; |
||||
} |
||||
|
||||
if (!mapContainerRef.current) { |
||||
return; |
||||
} |
||||
|
||||
const map = leaflet.map(mapContainerRef.current); |
||||
map.setView([51.505, -0.09], 13); |
||||
|
||||
leaflet |
||||
.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { |
||||
maxZoom: 19, |
||||
attribution: |
||||
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', |
||||
}) |
||||
.addTo(map); |
||||
|
||||
mapRef.current = map; |
||||
}); |
||||
|
||||
return <div ref={mapContainerRef} style="height: 500px" />; |
||||
}; |
Loading…
Reference in new issue