2026-03-29 18:58:31 -06:00
|
|
|
import React, {useEffect, useState} from "react";
|
2023-08-23 20:14:23 -06:00
|
|
|
import {
|
|
|
|
|
APIButton,
|
2023-09-07 20:13:36 -06:00
|
|
|
ErrorMessage,
|
2024-04-17 11:25:26 -06:00
|
|
|
HandPointMessage,
|
2023-08-23 20:14:23 -06:00
|
|
|
humanFileSize,
|
|
|
|
|
InfoMessage,
|
|
|
|
|
PageContainer,
|
|
|
|
|
TabLinks,
|
|
|
|
|
useTitle,
|
|
|
|
|
WROLModeMessage
|
|
|
|
|
} from "./Common";
|
2026-03-29 18:58:31 -06:00
|
|
|
import {Route, Routes, useNavigate} from "react-router";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {
|
2026-03-29 18:58:31 -06:00
|
|
|
deleteMapFile, deleteMapPin, fetchMapSubscriptions, getMapFiles, getMapPins,
|
|
|
|
|
mapSubscribe, mapUnsubscribe, updateMapPin
|
|
|
|
|
} from "../api";
|
|
|
|
|
import {
|
|
|
|
|
Button,
|
2022-11-05 14:38:51 -06:00
|
|
|
Divider,
|
2026-03-29 18:58:31 -06:00
|
|
|
Input,
|
2022-08-06 05:22:07 +00:00
|
|
|
TableCell,
|
|
|
|
|
TableRow
|
|
|
|
|
} from "semantic-ui-react";
|
2026-02-15 14:16:35 -07:00
|
|
|
import {SortableTable} from "./SortableTable";
|
2022-03-08 13:26:03 -07:00
|
|
|
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
2026-03-29 18:58:31 -06:00
|
|
|
import {Header} from "./Theme";
|
|
|
|
|
import {Media} from "../contexts/contexts";
|
2024-11-02 15:14:02 -06:00
|
|
|
import {MAP_VIEWER_URI} from "./Vars";
|
2026-03-29 18:58:31 -06:00
|
|
|
import {Modal} from "./Theme";
|
|
|
|
|
import MapViewer from "./MapViewer";
|
|
|
|
|
import maplibregl from "maplibre-gl";
|
|
|
|
|
import {Protocol} from "pmtiles";
|
|
|
|
|
import layers from "protomaps-themes-base";
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
// Ensure PMTiles protocol is registered (may already be registered by MapViewer).
|
|
|
|
|
try { maplibregl.addProtocol("pmtiles", new Protocol().tile); } catch (e) { /* already registered */ }
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const MAP_OVERVIEW_URL = "/blobs/map-overview.pmtiles";
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
// 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);
|
|
|
|
|
}
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
// 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}`};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { /* ignore */ }
|
|
|
|
|
return {type: 'vector', url: `pmtiles://${MAP_OVERVIEW_URL}`};
|
|
|
|
|
}
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
function RegionPreviewModal({bbox, name, open, onClose}) {
|
|
|
|
|
const mapContainer = React.useRef(null);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (!open || !mapContainer.current || !bbox) return;
|
|
|
|
|
|
|
|
|
|
const [minLon, minLat, maxLon, maxLat] = bbox.split(',').map(Number);
|
|
|
|
|
const centerLon = (minLon + maxLon) / 2;
|
|
|
|
|
const centerLat = (minLat + maxLat) / 2;
|
|
|
|
|
|
|
|
|
|
let map;
|
|
|
|
|
getPreviewMapSource().then(source => {
|
|
|
|
|
if (!mapContainer.current) return;
|
|
|
|
|
map = new maplibregl.Map({
|
|
|
|
|
container: mapContainer.current,
|
|
|
|
|
style: {
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {'basemap': source},
|
|
|
|
|
layers: layers('basemap', 'light'),
|
|
|
|
|
glyphs: '/map-assets/fonts/{fontstack}/{range}.pbf',
|
|
|
|
|
sprite: `${window.location.origin}/map-assets/sprites/light`,
|
|
|
|
|
},
|
|
|
|
|
center: [centerLon, centerLat],
|
|
|
|
|
zoom: 1,
|
|
|
|
|
attributionControl: false,
|
|
|
|
|
});
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
map.on('load', () => {
|
|
|
|
|
map.addSource('bbox', {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Polygon',
|
|
|
|
|
coordinates: [[
|
|
|
|
|
[minLon, minLat],
|
|
|
|
|
[maxLon, minLat],
|
|
|
|
|
[maxLon, maxLat],
|
|
|
|
|
[minLon, maxLat],
|
|
|
|
|
[minLon, minLat],
|
|
|
|
|
]],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
map.addLayer({
|
|
|
|
|
id: 'bbox-fill',
|
|
|
|
|
type: 'fill',
|
|
|
|
|
source: 'bbox',
|
|
|
|
|
paint: {'fill-color': '#6435c9', 'fill-opacity': 0.2},
|
|
|
|
|
});
|
|
|
|
|
map.addLayer({
|
|
|
|
|
id: 'bbox-outline',
|
|
|
|
|
type: 'line',
|
|
|
|
|
source: 'bbox',
|
|
|
|
|
paint: {'line-color': '#6435c9', 'line-width': 2},
|
|
|
|
|
});
|
|
|
|
|
map.fitBounds([[minLon, minLat], [maxLon, maxLat]], {padding: 40});
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-11-05 14:38:51 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
return () => { if (map) map.remove(); };
|
|
|
|
|
}, [open, bbox]);
|
2022-11-05 14:38:51 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
return <Modal open={open} onClose={onClose} size='large' closeIcon>
|
|
|
|
|
<Modal.Header>{name}</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<div ref={mapContainer} style={{width: '100%', height: '50vh'}}/>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
</Modal>;
|
2022-11-04 09:03:13 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
// Random-ish distinct colors for region boxes.
|
|
|
|
|
const REGION_COLORS = [
|
|
|
|
|
'#6435c9', '#e03997', '#00b5ad', '#2185d0', '#f2711c', '#b5cc18',
|
|
|
|
|
'#a333c8', '#21ba45', '#db2828', '#fbbd08', '#a5673f', '#767676',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function AllRegionsPreviewModal({catalog, open, onClose}) {
|
|
|
|
|
const mapContainer = React.useRef(null);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (!open || !mapContainer.current) return;
|
|
|
|
|
|
|
|
|
|
let map;
|
|
|
|
|
getPreviewMapSource().then(source => {
|
|
|
|
|
if (!mapContainer.current) return;
|
|
|
|
|
map = new maplibregl.Map({
|
|
|
|
|
container: mapContainer.current,
|
|
|
|
|
style: {
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {'basemap': source},
|
|
|
|
|
layers: layers('basemap', 'light'),
|
|
|
|
|
glyphs: '/map-assets/fonts/{fontstack}/{range}.pbf',
|
|
|
|
|
sprite: `${window.location.origin}/map-assets/sprites/light`,
|
|
|
|
|
},
|
|
|
|
|
center: [0, 20],
|
|
|
|
|
zoom: 1,
|
|
|
|
|
attributionControl: false,
|
|
|
|
|
});
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
map.on('load', () => {
|
|
|
|
|
const regions = catalog.filter(r => r.bbox);
|
|
|
|
|
regions.forEach((region, i) => {
|
|
|
|
|
const [minLon, minLat, maxLon, maxLat] = region.bbox.split(',').map(Number);
|
|
|
|
|
const color = REGION_COLORS[i % REGION_COLORS.length];
|
|
|
|
|
const id = `region-${i}`;
|
|
|
|
|
|
|
|
|
|
map.addSource(id, {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Polygon',
|
|
|
|
|
coordinates: [[
|
|
|
|
|
[minLon, minLat], [maxLon, minLat],
|
|
|
|
|
[maxLon, maxLat], [minLon, maxLat],
|
|
|
|
|
[minLon, minLat],
|
|
|
|
|
]],
|
|
|
|
|
},
|
|
|
|
|
properties: {name: region.name},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
map.addLayer({
|
|
|
|
|
id: `${id}-fill`, type: 'fill', source: id,
|
|
|
|
|
paint: {'fill-color': color, 'fill-opacity': 0.15},
|
|
|
|
|
});
|
|
|
|
|
map.addLayer({
|
|
|
|
|
id: `${id}-outline`, type: 'line', source: id,
|
|
|
|
|
paint: {'line-color': color, 'line-width': 1.5},
|
|
|
|
|
});
|
|
|
|
|
map.addLayer({
|
|
|
|
|
id: `${id}-label`, type: 'symbol', source: id,
|
|
|
|
|
layout: {
|
|
|
|
|
'text-field': ['get', 'name'],
|
|
|
|
|
'text-size': 11,
|
|
|
|
|
'text-allow-overlap': true,
|
|
|
|
|
},
|
|
|
|
|
paint: {
|
|
|
|
|
'text-color': color,
|
|
|
|
|
'text-halo-color': 'white',
|
|
|
|
|
'text-halo-width': 1,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
return () => { if (map) map.remove(); };
|
|
|
|
|
}, [open, catalog]);
|
2022-11-04 09:03:13 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
return <Modal open={open} onClose={onClose} size='fullscreen' closeIcon>
|
|
|
|
|
<Modal.Header>All Map Regions</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<div ref={mapContainer} style={{width: '100%', height: '75vh'}}/>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
</Modal>;
|
2022-11-04 09:03:13 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
function MapCatalogRow({item, subscribedRegions, fetchData}) {
|
|
|
|
|
const {name, region, size_estimate, bbox} = item;
|
|
|
|
|
const isSubscribed = subscribedRegions.has(region);
|
|
|
|
|
const [previewOpen, setPreviewOpen] = useState(false);
|
2024-04-17 11:25:26 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const handleButton = async () => {
|
|
|
|
|
if (isSubscribed) {
|
|
|
|
|
await mapUnsubscribe(region);
|
|
|
|
|
} else {
|
|
|
|
|
await mapSubscribe(name, region);
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
2026-03-29 18:58:31 -06:00
|
|
|
if (fetchData) {
|
|
|
|
|
await fetchData();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return <TableRow>
|
|
|
|
|
<TableCell>{name}</TableCell>
|
|
|
|
|
<TableCell>{humanFileSize(size_estimate)}</TableCell>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
{bbox && <Button
|
|
|
|
|
size='tiny'
|
|
|
|
|
icon='eye'
|
|
|
|
|
onClick={() => setPreviewOpen(true)}
|
|
|
|
|
/>}
|
|
|
|
|
<Button
|
|
|
|
|
color={isSubscribed ? 'red' : 'violet'}
|
|
|
|
|
size='tiny'
|
|
|
|
|
onClick={handleButton}
|
|
|
|
|
>
|
|
|
|
|
{isSubscribed ? 'Unsubscribe' : 'Subscribe'}
|
|
|
|
|
</Button>
|
|
|
|
|
</TableCell>
|
|
|
|
|
{previewOpen && <RegionPreviewModal
|
|
|
|
|
bbox={bbox}
|
|
|
|
|
name={name}
|
|
|
|
|
open={previewOpen}
|
|
|
|
|
onClose={() => setPreviewOpen(false)}
|
|
|
|
|
/>}
|
|
|
|
|
</TableRow>;
|
|
|
|
|
}
|
2022-03-08 13:26:03 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
function ManageMap() {
|
|
|
|
|
const [files, setFiles] = useState(null);
|
|
|
|
|
const [catalog, setCatalog] = useState([]);
|
|
|
|
|
const [subscriptions, setSubscriptions] = useState([]);
|
|
|
|
|
const [allRegionsOpen, setAllRegionsOpen] = useState(false);
|
2022-03-08 13:26:03 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const fetchFiles = async () => {
|
2022-05-01 21:03:30 -06:00
|
|
|
try {
|
2026-03-29 18:58:31 -06:00
|
|
|
const data = await getMapFiles();
|
|
|
|
|
if (data) {
|
|
|
|
|
setFiles(data.files || []);
|
|
|
|
|
}
|
2022-05-01 21:03:30 -06:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
2026-03-29 18:58:31 -06:00
|
|
|
setFiles(undefined);
|
2023-08-15 15:12:45 -06:00
|
|
|
}
|
2026-03-29 18:58:31 -06:00
|
|
|
};
|
2022-03-08 13:26:03 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const fetchSubscriptionData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await fetchMapSubscriptions();
|
|
|
|
|
if (data) {
|
|
|
|
|
setCatalog(data.catalog || []);
|
|
|
|
|
setSubscriptions(data.subscriptions || []);
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
2026-03-29 18:58:31 -06:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
2026-03-29 18:58:31 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchFiles();
|
|
|
|
|
fetchSubscriptionData();
|
|
|
|
|
const interval = setInterval(fetchFiles, 30000);
|
|
|
|
|
return () => clearInterval(interval);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleDelete = async (filename) => {
|
|
|
|
|
await deleteMapFile(filename);
|
|
|
|
|
await fetchFiles();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// --- Files table ---
|
|
|
|
|
const fileHeaders = [
|
|
|
|
|
{key: 'name', text: 'File', sortBy: i => i.name.toLowerCase()},
|
|
|
|
|
{key: 'size', text: 'Size', sortBy: i => i.size || 0},
|
|
|
|
|
{key: 'actions', text: '', sortBy: null},
|
|
|
|
|
];
|
2022-03-08 13:26:03 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const fileRowFunc = (file) => {
|
|
|
|
|
return <TableRow key={file.name}>
|
|
|
|
|
<TableCell>{file.name}</TableCell>
|
|
|
|
|
<TableCell>{humanFileSize(file.size)}</TableCell>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<APIButton
|
|
|
|
|
color='red'
|
|
|
|
|
size='tiny'
|
|
|
|
|
confirmContent='Delete this map file?'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onClick={() => handleDelete(file.name)}
|
|
|
|
|
>
|
|
|
|
|
Delete
|
|
|
|
|
</APIButton>
|
|
|
|
|
</TableCell>
|
2026-02-15 14:16:35 -07:00
|
|
|
</TableRow>;
|
2026-03-29 18:58:31 -06:00
|
|
|
};
|
2026-02-15 14:16:35 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const emptyRow = <TableRow>
|
|
|
|
|
<TableCell colSpan={3}>No PMTiles map files were found in <b>map/</b></TableCell>
|
|
|
|
|
</TableRow>;
|
2026-02-15 14:16:35 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
// --- Catalog table ---
|
|
|
|
|
const catalogHeaders = [
|
|
|
|
|
{key: 'name', text: 'Region', sortBy: i => i.name.toLowerCase()},
|
|
|
|
|
{key: 'size', text: 'Estimated Size', sortBy: i => i.size_estimate || 0},
|
|
|
|
|
{key: 'actions', text: '', sortBy: null},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const catalogRowFunc = (item) => {
|
|
|
|
|
return <MapCatalogRow
|
|
|
|
|
key={item.region}
|
|
|
|
|
item={item}
|
|
|
|
|
subscribedRegions={new Set(subscriptions.map(s => s.region))}
|
|
|
|
|
fetchData={fetchSubscriptionData}
|
|
|
|
|
/>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (files === undefined) {
|
2022-08-06 05:22:07 +00:00
|
|
|
return <PageContainer>
|
|
|
|
|
<WROLModeMessage content='Cannot modify Map'/>
|
2026-03-29 18:58:31 -06:00
|
|
|
<ErrorMessage>Could not fetch map files</ErrorMessage>
|
|
|
|
|
</PageContainer>;
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
2026-03-29 18:58:31 -06:00
|
|
|
|
|
|
|
|
return <PageContainer>
|
|
|
|
|
<WROLModeMessage content='Cannot modify Map'/>
|
|
|
|
|
|
|
|
|
|
<Header as='h3'>Map Files</Header>
|
|
|
|
|
<SortableTable
|
|
|
|
|
tableHeaders={fileHeaders}
|
|
|
|
|
data={files}
|
|
|
|
|
rowFunc={fileRowFunc}
|
|
|
|
|
rowKey='name'
|
|
|
|
|
defaultSortColumn='name'
|
|
|
|
|
emptyRow={emptyRow}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Divider/>
|
|
|
|
|
|
|
|
|
|
<div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '0.5em'}}>
|
|
|
|
|
<Header as='h3'>Map Subscriptions</Header>
|
|
|
|
|
<Button size='tiny' icon='globe' content='View All Regions' onClick={() => setAllRegionsOpen(true)}/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<AllRegionsPreviewModal catalog={catalog} open={allRegionsOpen} onClose={() => setAllRegionsOpen(false)}/>
|
|
|
|
|
|
|
|
|
|
<SortableTable
|
|
|
|
|
tableHeaders={catalogHeaders}
|
|
|
|
|
data={catalog}
|
|
|
|
|
rowFunc={catalogRowFunc}
|
|
|
|
|
rowKey='region'
|
|
|
|
|
defaultSortColumn='name'
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<InfoMessage storageName='hint_map_subscribe'>
|
|
|
|
|
<Message.Header>How to get map files</Message.Header>
|
|
|
|
|
<p>Subscribe to a map region to automatically download it. Subscriptions will
|
|
|
|
|
periodically check for updated maps. Downloads may take a long time depending on
|
|
|
|
|
the region size and your internet speed. You can monitor progress on
|
|
|
|
|
the <b>Downloads</b> page.</p>
|
|
|
|
|
<p>You can also manually extract a region using the <b>pmtiles</b> command-line tool
|
|
|
|
|
and place the resulting file into the <b>map/</b> directory:</p>
|
|
|
|
|
<pre> pmtiles extract https://build.protomaps.com/YYYYMMDD.pmtiles region.pmtiles \{'\n'} --bbox="-125.0,24.4,-66.9,49.4"</pre>
|
|
|
|
|
<p>Find the latest build date at
|
|
|
|
|
<a href='https://maps.protomaps.com/builds/' rel='noopener noreferrer'
|
|
|
|
|
target='_blank'>maps.protomaps.com/builds</a>
|
|
|
|
|
</p>
|
|
|
|
|
</InfoMessage>
|
|
|
|
|
|
|
|
|
|
<HandPointMessage>
|
|
|
|
|
<p>You can also view the map at <a href={MAP_VIEWER_URI}>{MAP_VIEWER_URI}</a></p>
|
|
|
|
|
</HandPointMessage>
|
|
|
|
|
</PageContainer>
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const PIN_COLORS = ["red", "blue", "green", "yellow", "orange", "purple"];
|
|
|
|
|
|
|
|
|
|
function PinEditRow({pin, onSave, onCancel}) {
|
|
|
|
|
const [label, setLabel] = useState(pin.label);
|
|
|
|
|
const [color, setColor] = useState(pin.color);
|
|
|
|
|
|
|
|
|
|
return <TableRow>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<div style={{display: "flex", gap: 4}}>
|
|
|
|
|
{PIN_COLORS.map(c =>
|
|
|
|
|
<div
|
|
|
|
|
key={c}
|
|
|
|
|
onClick={() => setColor(c)}
|
|
|
|
|
style={{
|
|
|
|
|
width: 20, height: 20, borderRadius: "50%", background: c, cursor: "pointer",
|
|
|
|
|
border: color === c ? "3px solid #333" : "2px solid #ccc",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Input
|
|
|
|
|
size='small'
|
|
|
|
|
value={label}
|
|
|
|
|
onChange={(e) => setLabel(e.target.value)}
|
|
|
|
|
onKeyDown={(e) => e.key === 'Enter' && label.trim() && onSave(pin.id, label.trim(), color)}
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>{pin.lat.toFixed(4)}, {pin.lon.toFixed(4)}</TableCell>
|
|
|
|
|
<Media greaterThan='mobile'><TableCell>{pin.created}</TableCell></Media>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<Button size='tiny' color='green' onClick={() => label.trim() && onSave(pin.id, label.trim(), color)}>Save</Button>
|
|
|
|
|
<Button size='tiny' onClick={onCancel}>Cancel</Button>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>;
|
|
|
|
|
}
|
2024-06-17 10:40:30 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
function MapPins() {
|
|
|
|
|
const [pins, setPins] = useState([]);
|
|
|
|
|
const [filter, setFilter] = useState('');
|
|
|
|
|
const [editingId, setEditingId] = useState(null);
|
|
|
|
|
const navigate = useNavigate();
|
2024-07-30 17:14:08 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const fetchPins = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await getMapPins();
|
|
|
|
|
if (data) setPins(data.pins || []);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchPins();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleDelete = async (pinId) => {
|
|
|
|
|
await deleteMapPin(pinId);
|
|
|
|
|
setEditingId(null);
|
|
|
|
|
await fetchPins();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSave = async (pinId, label, color) => {
|
|
|
|
|
await updateMapPin(pinId, label, color);
|
|
|
|
|
setEditingId(null);
|
|
|
|
|
await fetchPins();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleNavigate = (pin) => {
|
|
|
|
|
navigate(`/map?lat=${pin.lat}&lon=${pin.lon}&z=14`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// --- Desktop headers and row ---
|
|
|
|
|
const fullHeaders = [
|
|
|
|
|
{key: 'color', text: '', sortBy: i => i.color},
|
|
|
|
|
{key: 'label', text: 'Label', sortBy: i => i.label.toLowerCase()},
|
|
|
|
|
{key: 'coords', text: 'Coordinates', sortBy: i => i.lat},
|
|
|
|
|
{key: 'created', text: 'Created', sortBy: i => i.created},
|
|
|
|
|
{key: 'actions', text: '', sortBy: null},
|
|
|
|
|
];
|
2024-06-17 10:40:30 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
const fullRowFunc = (pin) => {
|
|
|
|
|
if (editingId === pin.id) {
|
|
|
|
|
return <PinEditRow
|
|
|
|
|
key={pin.id}
|
|
|
|
|
pin={pin}
|
|
|
|
|
onSave={handleSave}
|
|
|
|
|
onCancel={() => setEditingId(null)}
|
|
|
|
|
/>;
|
|
|
|
|
}
|
|
|
|
|
return <TableRow key={pin.id}>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<div style={{
|
|
|
|
|
width: 16, height: 16, borderRadius: "50%",
|
|
|
|
|
background: pin.color || "red", border: "1px solid #ccc",
|
|
|
|
|
}}/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>{pin.label}</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<a href="#" onClick={(e) => {e.preventDefault(); handleNavigate(pin);}}>
|
|
|
|
|
{pin.lat.toFixed(4)}, {pin.lon.toFixed(4)}
|
|
|
|
|
</a>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>{pin.created}</TableCell>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<Button size='tiny' icon='edit' onClick={() => setEditingId(pin.id)}/>
|
|
|
|
|
<APIButton
|
|
|
|
|
size='tiny'
|
|
|
|
|
color='red'
|
|
|
|
|
icon='trash'
|
|
|
|
|
confirmContent='Delete this pin?'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onClick={() => handleDelete(pin.id)}
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>;
|
|
|
|
|
};
|
2024-06-17 10:40:30 -06:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
// --- Mobile headers and row ---
|
|
|
|
|
const mobileHeaders = [
|
|
|
|
|
{key: 'color', text: '', sortBy: i => i.color},
|
|
|
|
|
{key: 'label', text: 'Label', sortBy: i => i.label.toLowerCase()},
|
|
|
|
|
{key: 'actions', text: '', sortBy: null},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const mobileRowFunc = (pin) => {
|
|
|
|
|
return <TableRow key={pin.id}>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<div style={{
|
|
|
|
|
width: 16, height: 16, borderRadius: "50%",
|
|
|
|
|
background: pin.color || "red", border: "1px solid #ccc",
|
|
|
|
|
}}/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<a href="#" onClick={(e) => {e.preventDefault(); handleNavigate(pin);}}>
|
|
|
|
|
{pin.label}
|
|
|
|
|
</a>
|
|
|
|
|
<div style={{fontSize: 11, color: '#888'}}>{pin.lat.toFixed(4)}, {pin.lon.toFixed(4)}</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<APIButton
|
|
|
|
|
size='tiny'
|
|
|
|
|
color='red'
|
|
|
|
|
icon='trash'
|
|
|
|
|
confirmContent='Delete this pin?'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onClick={() => handleDelete(pin.id)}
|
|
|
|
|
/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const emptyRow = <TableRow>
|
|
|
|
|
<TableCell colSpan={5}>No pins. Right-click on the map to add one.</TableCell>
|
|
|
|
|
</TableRow>;
|
|
|
|
|
|
|
|
|
|
const lowerFilter = filter.toLowerCase();
|
|
|
|
|
const filteredPins = lowerFilter
|
|
|
|
|
? pins.filter(p =>
|
|
|
|
|
(p.label || '').toLowerCase().includes(lowerFilter) ||
|
|
|
|
|
`${p.lat.toFixed(4)}, ${p.lon.toFixed(4)}`.includes(lowerFilter)
|
|
|
|
|
)
|
|
|
|
|
: pins;
|
|
|
|
|
|
|
|
|
|
return <PageContainer>
|
|
|
|
|
<Input
|
|
|
|
|
icon='search'
|
|
|
|
|
placeholder='Filter by label or coordinates...'
|
|
|
|
|
value={filter}
|
|
|
|
|
onChange={(e) => setFilter(e.target.value)}
|
|
|
|
|
style={{marginBottom: '1em', width: '100%'}}
|
|
|
|
|
/>
|
|
|
|
|
<Media at='mobile'>
|
|
|
|
|
<SortableTable
|
|
|
|
|
tableProps={{unstackable: true}}
|
|
|
|
|
tableHeaders={mobileHeaders}
|
|
|
|
|
data={filteredPins}
|
|
|
|
|
rowFunc={mobileRowFunc}
|
|
|
|
|
rowKey='label'
|
|
|
|
|
defaultSortColumn='label'
|
|
|
|
|
emptyRow={emptyRow}
|
|
|
|
|
/>
|
|
|
|
|
</Media>
|
|
|
|
|
<Media greaterThanOrEqual='tablet'>
|
|
|
|
|
<SortableTable
|
|
|
|
|
tableProps={{unstackable: true}}
|
|
|
|
|
tableHeaders={fullHeaders}
|
|
|
|
|
data={filteredPins}
|
|
|
|
|
rowFunc={fullRowFunc}
|
|
|
|
|
rowKey='label'
|
|
|
|
|
defaultSortColumn='label'
|
|
|
|
|
emptyRow={emptyRow}
|
|
|
|
|
/>
|
|
|
|
|
</Media>
|
|
|
|
|
</PageContainer>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MapPage() {
|
|
|
|
|
return <MapViewer/>;
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function MapRoute() {
|
2022-10-25 15:57:44 -06:00
|
|
|
useTitle('Map');
|
|
|
|
|
|
2022-03-08 13:26:03 -07:00
|
|
|
const links = [
|
2022-08-06 05:22:07 +00:00
|
|
|
{text: 'Map', to: '/map', key: 'map', end: true},
|
2026-03-29 18:58:31 -06:00
|
|
|
{text: 'Pins', to: '/map/pins', key: 'pins'},
|
2022-08-06 05:22:07 +00:00
|
|
|
{text: 'Manage', to: '/map/manage', key: 'manage'},
|
2022-03-08 13:26:03 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return <div style={{marginTop: '2em'}}>
|
|
|
|
|
<TabLinks links={links}/>
|
2022-08-06 05:22:07 +00:00
|
|
|
<Routes>
|
2023-07-21 15:14:09 -06:00
|
|
|
<Route path='/' exact element={<MapPage/>}/>
|
2026-03-29 18:58:31 -06:00
|
|
|
<Route path='pins' exact element={<MapPins/>}/>
|
2022-08-06 05:22:07 +00:00
|
|
|
<Route path='manage' exact element={<ManageMap/>}/>
|
|
|
|
|
</Routes>
|
2022-03-08 13:26:03 -07:00
|
|
|
</div>
|
2026-03-29 18:58:31 -06:00
|
|
|
}
|