Working stuff!
This commit is contained in:
1 parent
9d69d13aa5
commit
5b73127836
9 files changed
+168
-38
No files matched your search
@@ -39,7 +39,7 @@ const TILE_CACHE_NAME = 'excalibur-offline-map-tiles-v1';
|
||||
const DEFAULT_TILE_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
||||
|
||||
export default function MapView({
|
||||
initialCenter = [11.5761, 48.1371], // Munich default [lng, lat]
|
||||
initialCenter = [9.281477, 49.088795],
|
||||
initialZoom = 13,
|
||||
markers = [],
|
||||
onMarkerClick,
|
||||
@@ -55,6 +55,7 @@ export default function MapView({
|
||||
// 1. Initialize Map instance
|
||||
useEffect(() => {
|
||||
if (!mapContainerRef.current) return;
|
||||
if (mapRef.current) return;
|
||||
|
||||
// Standard OpenStreetMap raster style (can be swapped for MapTiler / custom PBF vector style)
|
||||
const mapStyle: maplibregl.StyleSpecification = {
|
||||
@@ -85,10 +86,8 @@ export default function MapView({
|
||||
zoom: initialZoom,
|
||||
});
|
||||
|
||||
// Default Controls
|
||||
map.addControl(new maplibregl.NavigationControl({ visualizePitch: true }), 'top-right');
|
||||
map.addControl(new maplibregl.NavigationControl({ visualizePitch: true }), 'bottom-right');
|
||||
|
||||
// Offline Geolocation Control (Uses Native Device GPS)
|
||||
const geolocate = new maplibregl.GeolocateControl({
|
||||
positionOptions: {
|
||||
enableHighAccuracy: true,
|
||||
@@ -97,17 +96,26 @@ export default function MapView({
|
||||
showUserLocation: true,
|
||||
showAccuracyCircle: true,
|
||||
});
|
||||
map.addControl(geolocate, 'top-right');
|
||||
map.addControl(geolocate, 'bottom-right');
|
||||
|
||||
map.addControl(new maplibregl.ScaleControl({ unit: 'metric' }), 'bottom-left');
|
||||
|
||||
map.on('load', async () => {
|
||||
navigator.geolocation.getCurrentPosition((pos) => {
|
||||
map.setCenter([pos.coords.longitude, pos.coords.latitude]);
|
||||
geolocate.trigger();
|
||||
}, () => {
|
||||
geolocate.trigger();
|
||||
});
|
||||
});
|
||||
|
||||
mapRef.current = map;
|
||||
|
||||
return () => {
|
||||
map.remove();
|
||||
mapRef.current = null;
|
||||
};
|
||||
}, [initialCenter, initialZoom, tileUrlTemplate]);
|
||||
}, [/*initialCenter, initialZoom, tileUrlTemplate Create your own listeners*/]);
|
||||
|
||||
// 2. Manage Markers Sync
|
||||
useEffect(() => {
|
||||
@@ -217,7 +225,7 @@ export default function MapView({
|
||||
|
||||
return (
|
||||
<div className={styles.mapWrapper}>
|
||||
<div className={styles.controlOverlay}>
|
||||
{/*<div className={styles.controlOverlay}>
|
||||
<button
|
||||
className={styles.precacheButton}
|
||||
onClick={precacheCurrentRegion}
|
||||
@@ -241,7 +249,7 @@ export default function MapView({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>*/}
|
||||
|
||||
<div ref={mapContainerRef} className={styles.mapContainer} />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user