Small preact-based (like React.js) project
https://inga-lovinde.github.io/static/komoot-demo/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
923 B
34 lines
923 B
10 months ago
|
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;
|
||
|
});
|
||
|
|
||
10 months ago
|
return <div ref={mapContainerRef} class="map-container" />;
|
||
10 months ago
|
};
|