mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 16:06:19 -05:00
Open the Solar calculator from the map, pins and current location
The map's right-click (or long-press) menu gains "Calculate Solar Performance", and each saved pin a sun button; both open the calculator at that location. A button beside Latitude fills in the browser's current location. Locations are rounded to 4 decimals, and longitudes from a map panned around the world are wrapped back to -180..180. The map removed lat/lon/z from the URL when it closed, even after navigating to another page, which stripped the calculator's location from its URL (and from links shared with the Share button). It now only cleans up while the URL is still a map page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4f06dfe9c8
commit
b5ea2054c1
9 changed files with 203 additions and 22 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import React, {useCallback, useContext, useEffect, useRef, useState} from "react";
|
||||
import {useSearchParams} from "react-router";
|
||||
import {useNavigate, useSearchParams} from "react-router";
|
||||
import maplibregl from "maplibre-gl";
|
||||
import "maplibre-gl/dist/maplibre-gl.css";
|
||||
import {Protocol} from "pmtiles";
|
||||
|
|
@ -11,6 +11,7 @@ import {Button, Checkbox, Header, Icon, Panel, TextInput, Toggle} from "./ui";
|
|||
import {SettingsContext, ThemeContext} from "../contexts/contexts";
|
||||
import {mapFlavor, mapSprite} from "../themes/names";
|
||||
import {poiPopupHtml} from "./mapPoiPopup";
|
||||
import {solarCalculatorPath} from "./calculators/solar";
|
||||
|
||||
// Terrain DEM file prefix for hillshade and contours.
|
||||
const TERRAIN_PREFIX = "terrain-";
|
||||
|
|
@ -531,6 +532,7 @@ export default function MapViewer() {
|
|||
const [mapReady, setMapReady] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const [contextMenu, setContextMenu] = useState(null);
|
||||
const navigate = useNavigate();
|
||||
const [addingPin, setAddingPin] = useState(null); // {lat, lon} when pin dialog is open
|
||||
const markersRef = useRef([]);
|
||||
const pinsVisibleRef = useRef(true);
|
||||
|
|
@ -772,12 +774,16 @@ export default function MapViewer() {
|
|||
}
|
||||
mapRef.current = null;
|
||||
setMapReady(false);
|
||||
// Clean up map params from URL so they don't leak to other pages.
|
||||
// Clean up map params from URL so they don't leak to other pages. Only while the URL is
|
||||
// still a map page: after navigating away, lat/lon belong to the new page (the Solar
|
||||
// calculator, for one).
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.delete("lat");
|
||||
url.searchParams.delete("lon");
|
||||
url.searchParams.delete("z");
|
||||
window.history.replaceState(null, '', url.pathname + url.search);
|
||||
if (url.pathname.startsWith("/map")) {
|
||||
url.searchParams.delete("lat");
|
||||
url.searchParams.delete("lon");
|
||||
url.searchParams.delete("z");
|
||||
window.history.replaceState(null, '', url.pathname + url.search);
|
||||
}
|
||||
};
|
||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
|
|
@ -923,6 +929,12 @@ export default function MapViewer() {
|
|||
setContextMenu(null);
|
||||
}, [contextMenu]);
|
||||
|
||||
const handleSolar = useCallback(() => {
|
||||
if (!contextMenu) return;
|
||||
setContextMenu(null);
|
||||
navigate(solarCalculatorPath(contextMenu.lat, contextMenu.lon));
|
||||
}, [contextMenu, navigate]);
|
||||
|
||||
const handleSetDefaultLocation = useCallback(async () => {
|
||||
const map = mapRef.current;
|
||||
if (!map) return;
|
||||
|
|
@ -999,6 +1011,14 @@ export default function MapViewer() {
|
|||
>
|
||||
Add Pin Here
|
||||
</div>
|
||||
<div
|
||||
style={{padding: "0.5rem 0.75rem", cursor: "pointer", userSelect: "none"}}
|
||||
onMouseEnter={e => e.target.style.background = "#f0f0f0"}
|
||||
onMouseLeave={e => e.target.style.background = "transparent"}
|
||||
onClick={handleSolar}
|
||||
>
|
||||
Calculate Solar Performance
|
||||
</div>
|
||||
<div
|
||||
style={{padding: "0.5rem 0.75rem", cursor: "pointer", userSelect: "none"}}
|
||||
onMouseEnter={e => e.target.style.background = "#f0f0f0"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue