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:
Roland 2026-10-04 17:09:33 -06:00
parent 4f06dfe9c8
commit b5ea2054c1
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
9 changed files with 203 additions and 22 deletions

View file

@ -0,0 +1,45 @@
import React from 'react';
import {renderWithProviders as render} from '../test-utils';
import MapViewer from './MapViewer';
// MapLibre needs WebGL, which jsdom lacks; these tests only cover what the viewer does to the URL.
jest.mock('maplibre-gl', () => ({
__esModule: true,
default: {Map: class {
}, addProtocol: jest.fn(), Marker: class {
}, Popup: class {
}},
}));
jest.mock('maplibre-gl/dist/maplibre-gl.css', () => ({}));
jest.mock('pmtiles', () => ({
__esModule: true, Protocol: class {
tile = jest.fn();
},
}));
jest.mock('protomaps-themes-base', () => ({__esModule: true, default: () => []}));
jest.mock('@acalcutt/maplibre-contour-pmtiles', () => ({__esModule: true, default: {}}));
jest.mock('../api', () => ({
...jest.requireActual('../api'),
// Never resolves: the map never initializes, which these tests do not need.
getMapFiles: jest.fn(() => new Promise(() => {
})),
getMapPins: jest.fn(() => new Promise(() => {
})),
}));
describe('the map position in the URL', () => {
test('is removed when the map closes', () => {
const {unmount} = render(<MapViewer/>, {route: '/map?lat=40&lon=-105&z=8&layer=a'});
unmount();
expect(window.location.pathname).toBe('/map');
expect(window.location.search).toBe('?layer=a');
});
test('is not removed from the page the map navigated to', () => {
// "Calculate Solar Performance" navigates to a page whose own lat/lon must survive the map closing.
const {unmount} = render(<MapViewer/>, {route: '/map?lat=40&lon=-105&z=8'});
window.history.pushState({}, '', '/more/calculators?calc=solar&lat=40.0154&lon=-105.2705');
unmount();
expect(window.location.search).toBe('?calc=solar&lat=40.0154&lon=-105.2705');
});
});