diff --git a/app/src/api.js b/app/src/api.js index f6e69e75..6130bfbb 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -1679,14 +1679,28 @@ export async function getMapFiles() { } } -export async function deleteMapFile(filename) { - const response = await apiDelete(`${API_URI}/map/files/${encodeURIComponent(filename)}`); +// A map file is named by its path within the map directory; it may be in a sub-directory. +function encodeMapPath(mapPath) { + return String(mapPath).split('/').map(encodeURIComponent).join('/'); +} + +export async function deleteMapFile(mapPath) { + const response = await apiDelete(`${API_URI}/map/files/${encodeMapPath(mapPath)}`); if (!response.ok) { const message = await getErrorMessage(response, 'Could not delete map file'); toast({type: 'error', title: 'Map Error', description: message, time: 5000}); } } +// Show a map file on the map, or ignore it. +export async function setMapFileVisible(mapPath, visible) { + const response = await apiPost(`${API_URI}/map/files/visible`, {map_path: mapPath, visible}); + if (!response.ok) { + const message = await getErrorMessage(response, 'Could not change the map file'); + toast({type: 'error', title: 'Map Error', description: message, time: 5000}); + } +} + export async function fetchMapSubscriptions() { const response = await apiGet(`${API_URI}/map/subscribe`); if (response.ok) { @@ -1793,8 +1807,8 @@ export async function searchEstimateMap(search_str) { return {mapPlaces: data.map_places || 0}; } -export async function rebuildMapSearchIndex(filename) { - const response = await apiPost(`${API_URI}/map/search/rebuild/${encodeURIComponent(filename)}`); +export async function rebuildMapSearchIndex(mapPath) { + const response = await apiPost(`${API_URI}/map/search/rebuild/${encodeMapPath(mapPath)}`); if (!response.ok) { const message = await getErrorMessage(response, 'Could not rebuild search index'); toast({type: 'error', title: 'Map Error', description: message, time: 5000}); diff --git a/app/src/components/Map.js b/app/src/components/Map.js index 46b2554d..6a730d5f 100644 --- a/app/src/components/Map.js +++ b/app/src/components/Map.js @@ -12,9 +12,9 @@ import { import {Route, Routes, useNavigate} from "react-router"; import { deleteMapFile, deleteMapPin, fetchMapSubscriptions, getMapFiles, getMapPins, - mapSubscribe, mapUnsubscribe, rebuildMapSearchIndex, updateMapPin + mapSubscribe, mapUnsubscribe, rebuildMapSearchIndex, setMapFileVisible, updateMapPin } from "../api"; -import {Button, Divider, Group, Header, Icon, Modal, Table, TextInput} from "./ui"; +import {Button, Divider, Group, Header, Icon, Modal, Table, TextInput, Toggle} from "./ui"; import {SortableTable} from "./SortableTable"; import {Media, StatusContext} from "../contexts/contexts"; import {MAP_VIEWER_URI} from "./Vars"; @@ -24,29 +24,29 @@ import {solarCalculatorPath} from "./calculators/solar"; import maplibregl from "maplibre-gl"; import {Protocol} from "pmtiles"; import layers from "protomaps-themes-base"; +import {planMapFiles, pmtilesUrl} from "./mapOverlays"; // Ensure PMTiles protocol is registered (may already be registered by MapViewer). try { maplibregl.addProtocol("pmtiles", new Protocol().tile); } catch (e) { /* already registered */ } const MAP_OVERVIEW_URL = "/blobs/map-overview.pmtiles"; -// Detect full planet files: "planet-20260329.pmtiles" or bare date like "20260329.pmtiles". -function isPlanetFile(name) { - if (name.startsWith("planet-")) return true; - return /^\d{8}\.pmtiles$/.test(name); -} +// How the map draws a file (the API's `kind`). +const MAP_FILE_KINDS = { + basemap: 'Basemap', + overlay: 'Overlay', + terrain: 'Terrain', + unknown: 'Unreadable', +}; // Resolve the best available base map source for preview maps. // Checks for a user's planet file first, falls back to the overview blob. async function getPreviewMapSource() { try { const data = await getMapFiles(); - if (data?.files) { - for (const f of data.files) { - if (isPlanetFile(f.name)) { - return {type: 'vector', url: `pmtiles:///media/map/${f.name}`}; - } - } + const {planet} = planMapFiles(data?.files); + if (planet) { + return {type: 'vector', url: pmtilesUrl(planet.path)}; } } catch (e) { /* ignore */ } return {type: 'vector', url: `pmtiles://${MAP_OVERVIEW_URL}`}; @@ -343,30 +343,47 @@ function ManageMap() { // --- Files table --- const fileHeaders = [ - {key: 'name', text: 'File', sortBy: i => i.name.toLowerCase()}, + {key: 'name', text: 'File', sortBy: i => i.map_path.toLowerCase()}, + {key: 'kind', text: 'Type', sortBy: i => i.kind || ''}, {key: 'size', text: 'Size', sortBy: i => i.size || 0}, {key: 'search', text: 'Search', sortBy: null}, {key: 'actions', text: '', sortBy: null}, + {key: 'visible', text: 'Visible', sortBy: i => (i.visible === false ? 0 : 1)}, ]; - const handleBuildSearch = async (filename) => { - await rebuildMapSearchIndex(filename); + const handleBuildSearch = async (mapPath) => { + await rebuildMapSearchIndex(mapPath); await fetchFiles(); }; + const handleVisible = async (file, visible) => { + try { + await setMapFileVisible(file.map_path, visible); + } finally { + await fetchFiles(); + } + }; + const fileRowFunc = (file) => { - return