intro, map, layout, permissions
This commit is contained in:
1 parent
efdbbdfc76
commit
d9387f464f
16 files changed
+204
-131
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
||||
import * as maplibregl from 'maplibre-gl';
|
||||
import 'maplibre-gl/dist/maplibre-gl.css';
|
||||
import styles from '../css/MapView.module.css';
|
||||
import styles from '@/css/MapView.module.css';
|
||||
|
||||
export interface PlaceMarker {
|
||||
id: string;
|
||||
@@ -11,7 +11,6 @@ export interface PlaceMarker {
|
||||
lng: number;
|
||||
title: string;
|
||||
description?: string;
|
||||
category?: string;
|
||||
}
|
||||
|
||||
export interface MapViewProps {
|
||||
@@ -48,16 +47,15 @@ export default function MapView({
|
||||
const mapContainerRef = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<maplibregl.Map | null>(null);
|
||||
const activeMarkersRef = useRef<Map<string, maplibregl.Marker>>(new Map());
|
||||
const [ mapReady, setMapReady ] = useState(false);
|
||||
|
||||
const [isCaching, setIsCaching] = useState(false);
|
||||
const [cacheProgress, setCacheProgress] = useState<{ loaded: number; total: number } | null>(null);
|
||||
|
||||
// 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 = {
|
||||
version: 8,
|
||||
sources: {
|
||||
@@ -101,6 +99,7 @@ export default function MapView({
|
||||
map.addControl(new maplibregl.ScaleControl({ unit: 'metric' }), 'bottom-left');
|
||||
|
||||
map.on('load', async () => {
|
||||
setMapReady(true);
|
||||
navigator.geolocation.getCurrentPosition((pos) => {
|
||||
map.setCenter([pos.coords.longitude, pos.coords.latitude]);
|
||||
geolocate.trigger();
|
||||
@@ -114,18 +113,19 @@ export default function MapView({
|
||||
return () => {
|
||||
map.remove();
|
||||
mapRef.current = null;
|
||||
setMapReady(false);
|
||||
};
|
||||
}, [/*initialCenter, initialZoom, tileUrlTemplate Create your own listeners*/]);
|
||||
|
||||
// 2. Manage Markers Sync
|
||||
useEffect(() => {
|
||||
const map = mapRef.current;
|
||||
if (!map) return;
|
||||
if (!map || !mapReady) return;
|
||||
|
||||
const currentMarkers = activeMarkersRef.current;
|
||||
const incomingMarkerIds = new Set(markers.map((m) => m.id));
|
||||
|
||||
// Remove obsolete markers
|
||||
console.log(incomingMarkerIds);
|
||||
|
||||
currentMarkers.forEach((markerInstance, id) => {
|
||||
if (!incomingMarkerIds.has(id)) {
|
||||
markerInstance.remove();
|
||||
@@ -133,10 +133,9 @@ export default function MapView({
|
||||
}
|
||||
});
|
||||
|
||||
// Add / Update markers
|
||||
markers.forEach((markerData) => {
|
||||
if (!currentMarkers.has(markerData.id)) {
|
||||
const popup = new maplibregl.Popup({ offset: 25 }).setHTML(
|
||||
const popup = new maplibregl.Popup({ offset: 25, className: styles["marker"] }).setHTML(
|
||||
`<strong>${markerData.title}</strong>${
|
||||
markerData.description ? `<p style="margin:4px 0 0;font-size:12px;">${markerData.description}</p>` : ''
|
||||
}`
|
||||
@@ -154,9 +153,8 @@ export default function MapView({
|
||||
currentMarkers.set(markerData.id, newMarker);
|
||||
}
|
||||
});
|
||||
}, [markers, onMarkerClick]);
|
||||
}, [mapReady, markers, onMarkerClick]);
|
||||
|
||||
// 3. Region Precaching Logic for Offline Woods Usage
|
||||
const precacheCurrentRegion = useCallback(async () => {
|
||||
const map = mapRef.current;
|
||||
if (!map) return;
|
||||
|
||||
Reference in new issue
Block a user