@mailwoman/react 9.4.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -16
- package/fonts.css +97 -22
- package/lib/common/About.tsx +87 -71
- package/lib/common/ClientOnly.tsx +2 -14
- package/lib/common/CopyButton.tsx +3 -1
- package/lib/common/LoadingIndicator.tsx +4 -2
- package/lib/common/PresetChips.tsx +9 -8
- package/lib/common/confidence-tiers.ts +7 -6
- package/lib/common/cx.ts +3 -1
- package/lib/common/text-tokens.ts +7 -4
- package/lib/common/useBuildInfo.ts +54 -0
- package/lib/common/useClipboard.ts +2 -11
- package/lib/common.ts +22 -0
- package/lib/index.ts +27 -112
- package/lib/map/AppIdentity.tsx +85 -0
- package/lib/map/BackendControl.tsx +16 -13
- package/lib/map/CompareToggle.tsx +11 -33
- package/lib/map/DebugInfo.tsx +88 -0
- package/lib/map/Geocoder.tsx +92 -58
- package/lib/map/GeocoderControls.tsx +582 -127
- package/lib/map/GraticuleLayer.tsx +54 -0
- package/lib/map/MapCanvas.tsx +23 -12
- package/lib/map/MapChipRow.tsx +73 -0
- package/lib/map/MapCompass.tsx +68 -0
- package/lib/map/MapControlStack.tsx +97 -0
- package/lib/map/MapFooter.tsx +101 -0
- package/lib/map/MapProgressBar.tsx +55 -0
- package/lib/map/MapSearchBar.tsx +82 -0
- package/lib/map/MapSheet.tsx +71 -0
- package/lib/map/OverlayLayers.tsx +1 -1
- package/lib/map/PlaceAutocomplete.tsx +10 -21
- package/lib/map/PlaceMarker.tsx +4 -2
- package/lib/map/ResolvedPlaceLayers.tsx +5 -14
- package/lib/map/ResultCamera.tsx +8 -31
- package/lib/map/ResultOverlay.tsx +2 -12
- package/lib/map/ResultPanel.tsx +1 -20
- package/lib/map/VersionPicker.tsx +10 -19
- package/lib/map/fake-runtime.ts +10 -12
- package/lib/map/geometry.ts +14 -47
- package/lib/map/graticule.ts +80 -0
- package/lib/map/map-debug.ts +1 -1
- package/lib/map/place-render.ts +28 -60
- package/lib/map/types.ts +65 -97
- package/lib/map/useCompareState.ts +5 -4
- package/lib/map/useGeocode.ts +7 -5
- package/lib/map/useMapBearing.ts +56 -0
- package/lib/map/useMapLabelPick.ts +114 -0
- package/lib/map/useMapPlaceRender.ts +2 -6
- package/lib/map/usePlaceAutocomplete.ts +44 -50
- package/lib/map.ts +95 -0
- package/lib/pipeline/CandidatePicker.tsx +13 -5
- package/lib/pipeline/ConfidenceCell.tsx +1 -1
- package/lib/pipeline/FailureDiagnostic.tsx +8 -2
- package/lib/pipeline/QueryForm.tsx +5 -2
- package/lib/pipeline/ResolvedPlace.tsx +1 -1
- package/lib/pipeline/SpanHighlight.tsx +7 -5
- package/lib/pipeline/TimingPanel.tsx +1 -1
- package/lib/pipeline/TreeView.tsx +1 -1
- package/lib/pipeline/copy.ts +22 -25
- package/lib/pipeline/presets.ts +15 -13
- package/lib/pipeline/types.ts +21 -14
- package/lib/pipeline/useParsePipeline.ts +38 -24
- package/lib/pipeline.ts +36 -0
- package/lib/poi/AbstainPanel.tsx +1 -1
- package/lib/poi/LiveResultsBlock.tsx +2 -1
- package/lib/poi/POIExplorer.tsx +24 -15
- package/lib/poi/QueryInput.tsx +1 -1
- package/lib/poi/SubjectPanel.tsx +4 -3
- package/lib/poi/runtime.ts +5 -16
- package/lib/poi/types.ts +39 -27
- package/lib/poi/usePOISearch.ts +39 -44
- package/lib/poi.ts +39 -0
- package/lib/runtime/useReleaseRuntime.ts +125 -74
- package/lib/runtime.ts +16 -0
- package/lib/search/SearchModal.tsx +317 -0
- package/lib/search/search.css +144 -0
- package/lib/search/types.ts +67 -0
- package/lib/search.ts +11 -0
- package/out/common/About.d.ts +13 -4
- package/out/common/About.d.ts.map +1 -1
- package/out/common/About.js +5 -2
- package/out/common/About.js.map +1 -1
- package/out/common/ClientOnly.d.ts +2 -11
- package/out/common/ClientOnly.d.ts.map +1 -1
- package/out/common/ClientOnly.js +1 -13
- package/out/common/ClientOnly.js.map +1 -1
- package/out/common/CopyButton.d.ts +3 -1
- package/out/common/CopyButton.d.ts.map +1 -1
- package/out/common/CopyButton.js.map +1 -1
- package/out/common/LoadingIndicator.d.ts +4 -2
- package/out/common/LoadingIndicator.d.ts.map +1 -1
- package/out/common/LoadingIndicator.js.map +1 -1
- package/out/common/PresetChips.d.ts +9 -8
- package/out/common/PresetChips.d.ts.map +1 -1
- package/out/common/PresetChips.js.map +1 -1
- package/out/common/confidence-tiers.d.ts +7 -6
- package/out/common/confidence-tiers.d.ts.map +1 -1
- package/out/common/confidence-tiers.js +7 -6
- package/out/common/confidence-tiers.js.map +1 -1
- package/out/common/cx.d.ts +3 -1
- package/out/common/cx.d.ts.map +1 -1
- package/out/common/cx.js +3 -1
- package/out/common/cx.js.map +1 -1
- package/out/common/text-tokens.d.ts +4 -3
- package/out/common/text-tokens.d.ts.map +1 -1
- package/out/common/text-tokens.js +6 -3
- package/out/common/text-tokens.js.map +1 -1
- package/out/common/useBuildInfo.d.ts +27 -0
- package/out/common/useBuildInfo.d.ts.map +1 -0
- package/out/common/useBuildInfo.js +32 -0
- package/out/common/useBuildInfo.js.map +1 -0
- package/out/common/useClipboard.d.ts +1 -3
- package/out/common/useClipboard.d.ts.map +1 -1
- package/out/common/useClipboard.js +2 -11
- package/out/common/useClipboard.js.map +1 -1
- package/out/common.d.ts +22 -0
- package/out/common.d.ts.map +1 -0
- package/out/common.js +15 -0
- package/out/common.js.map +1 -0
- package/out/index.d.ts +26 -71
- package/out/index.d.ts.map +1 -1
- package/out/index.js +21 -47
- package/out/index.js.map +1 -1
- package/out/map/AppIdentity.d.ts +42 -0
- package/out/map/AppIdentity.d.ts.map +1 -0
- package/out/map/AppIdentity.js +16 -0
- package/out/map/AppIdentity.js.map +1 -0
- package/out/map/BackendControl.d.ts +9 -10
- package/out/map/BackendControl.d.ts.map +1 -1
- package/out/map/BackendControl.js +2 -2
- package/out/map/BackendControl.js.map +1 -1
- package/out/map/CompareToggle.d.ts +8 -31
- package/out/map/CompareToggle.d.ts.map +1 -1
- package/out/map/CompareToggle.js +5 -2
- package/out/map/CompareToggle.js.map +1 -1
- package/out/map/DebugInfo.d.ts +34 -0
- package/out/map/DebugInfo.d.ts.map +1 -0
- package/out/map/DebugInfo.js +39 -0
- package/out/map/DebugInfo.js.map +1 -0
- package/out/map/Geocoder.d.ts +47 -26
- package/out/map/Geocoder.d.ts.map +1 -1
- package/out/map/Geocoder.js +34 -50
- package/out/map/Geocoder.js.map +1 -1
- package/out/map/GeocoderControls.d.ts +23 -33
- package/out/map/GeocoderControls.d.ts.map +1 -1
- package/out/map/GeocoderControls.js +277 -16
- package/out/map/GeocoderControls.js.map +1 -1
- package/out/map/GraticuleLayer.d.ts +28 -0
- package/out/map/GraticuleLayer.d.ts.map +1 -0
- package/out/map/GraticuleLayer.js +25 -0
- package/out/map/GraticuleLayer.js.map +1 -0
- package/out/map/MapCanvas.d.ts +23 -12
- package/out/map/MapCanvas.d.ts.map +1 -1
- package/out/map/MapCanvas.js +5 -2
- package/out/map/MapCanvas.js.map +1 -1
- package/out/map/MapChipRow.d.ts +43 -0
- package/out/map/MapChipRow.d.ts.map +1 -0
- package/out/map/MapChipRow.js +12 -0
- package/out/map/MapChipRow.js.map +1 -0
- package/out/map/MapCompass.d.ts +33 -0
- package/out/map/MapCompass.d.ts.map +1 -0
- package/out/map/MapCompass.js +15 -0
- package/out/map/MapCompass.js.map +1 -0
- package/out/map/MapControlStack.d.ts +56 -0
- package/out/map/MapControlStack.d.ts.map +1 -0
- package/out/map/MapControlStack.js +18 -0
- package/out/map/MapControlStack.js.map +1 -0
- package/out/map/MapFooter.d.ts +27 -0
- package/out/map/MapFooter.d.ts.map +1 -0
- package/out/map/MapFooter.js +37 -0
- package/out/map/MapFooter.js.map +1 -0
- package/out/map/MapProgressBar.d.ts +31 -0
- package/out/map/MapProgressBar.d.ts.map +1 -0
- package/out/map/MapProgressBar.js +8 -0
- package/out/map/MapProgressBar.js.map +1 -0
- package/out/map/MapSearchBar.d.ts +48 -0
- package/out/map/MapSearchBar.d.ts.map +1 -0
- package/out/map/MapSearchBar.js +12 -0
- package/out/map/MapSearchBar.js.map +1 -0
- package/out/map/MapSheet.d.ts +35 -0
- package/out/map/MapSheet.d.ts.map +1 -0
- package/out/map/MapSheet.js +29 -0
- package/out/map/MapSheet.js.map +1 -0
- package/out/map/OverlayLayers.d.ts +1 -1
- package/out/map/OverlayLayers.js +2 -2
- package/out/map/PlaceAutocomplete.d.ts +10 -21
- package/out/map/PlaceAutocomplete.d.ts.map +1 -1
- package/out/map/PlaceAutocomplete.js +2 -1
- package/out/map/PlaceAutocomplete.js.map +1 -1
- package/out/map/PlaceMarker.d.ts +4 -2
- package/out/map/PlaceMarker.d.ts.map +1 -1
- package/out/map/PlaceMarker.js +3 -1
- package/out/map/PlaceMarker.js.map +1 -1
- package/out/map/ResolvedPlaceLayers.d.ts +5 -14
- package/out/map/ResolvedPlaceLayers.d.ts.map +1 -1
- package/out/map/ResolvedPlaceLayers.js +2 -2
- package/out/map/ResolvedPlaceLayers.js.map +1 -1
- package/out/map/ResultCamera.d.ts +8 -31
- package/out/map/ResultCamera.d.ts.map +1 -1
- package/out/map/ResultCamera.js +3 -28
- package/out/map/ResultCamera.js.map +1 -1
- package/out/map/ResultOverlay.d.ts +2 -12
- package/out/map/ResultOverlay.d.ts.map +1 -1
- package/out/map/ResultOverlay.js +1 -2
- package/out/map/ResultOverlay.js.map +1 -1
- package/out/map/ResultPanel.d.ts +1 -20
- package/out/map/ResultPanel.d.ts.map +1 -1
- package/out/map/ResultPanel.js +1 -1
- package/out/map/ResultPanel.js.map +1 -1
- package/out/map/VersionPicker.d.ts +7 -19
- package/out/map/VersionPicker.d.ts.map +1 -1
- package/out/map/VersionPicker.js +5 -2
- package/out/map/VersionPicker.js.map +1 -1
- package/out/map/fake-runtime.d.ts +9 -11
- package/out/map/fake-runtime.d.ts.map +1 -1
- package/out/map/fake-runtime.js +9 -12
- package/out/map/fake-runtime.js.map +1 -1
- package/out/map/geometry.d.ts +13 -34
- package/out/map/geometry.d.ts.map +1 -1
- package/out/map/geometry.js +9 -34
- package/out/map/geometry.js.map +1 -1
- package/out/map/graticule.d.ts +17 -0
- package/out/map/graticule.d.ts.map +1 -0
- package/out/map/graticule.js +67 -0
- package/out/map/graticule.js.map +1 -0
- package/out/map/map-debug.d.ts +1 -1
- package/out/map/map-debug.d.ts.map +1 -1
- package/out/map/map-debug.js +1 -1
- package/out/map/map-debug.js.map +1 -1
- package/out/map/place-render.d.ts +23 -43
- package/out/map/place-render.d.ts.map +1 -1
- package/out/map/place-render.js +4 -39
- package/out/map/place-render.js.map +1 -1
- package/out/map/types.d.ts +67 -95
- package/out/map/types.d.ts.map +1 -1
- package/out/map/types.js +1 -10
- package/out/map/types.js.map +1 -1
- package/out/map/useCompareState.d.ts +5 -4
- package/out/map/useCompareState.d.ts.map +1 -1
- package/out/map/useCompareState.js +3 -3
- package/out/map/useCompareState.js.map +1 -1
- package/out/map/useGeocode.d.ts +5 -3
- package/out/map/useGeocode.d.ts.map +1 -1
- package/out/map/useGeocode.js +4 -4
- package/out/map/useGeocode.js.map +1 -1
- package/out/map/useMapBearing.d.ts +28 -0
- package/out/map/useMapBearing.d.ts.map +1 -0
- package/out/map/useMapBearing.js +30 -0
- package/out/map/useMapBearing.js.map +1 -0
- package/out/map/useMapLabelPick.d.ts +13 -0
- package/out/map/useMapLabelPick.d.ts.map +1 -0
- package/out/map/useMapLabelPick.js +95 -0
- package/out/map/useMapLabelPick.js.map +1 -0
- package/out/map/useMapPlaceRender.d.ts +2 -6
- package/out/map/useMapPlaceRender.d.ts.map +1 -1
- package/out/map/useMapPlaceRender.js +2 -6
- package/out/map/useMapPlaceRender.js.map +1 -1
- package/out/map/usePlaceAutocomplete.d.ts +30 -28
- package/out/map/usePlaceAutocomplete.d.ts.map +1 -1
- package/out/map/usePlaceAutocomplete.js +6 -33
- package/out/map/usePlaceAutocomplete.js.map +1 -1
- package/out/map.d.ts +69 -0
- package/out/map.d.ts.map +1 -0
- package/out/map.js +46 -0
- package/out/map.js.map +1 -0
- package/out/pipeline/CandidatePicker.d.ts +12 -2
- package/out/pipeline/CandidatePicker.d.ts.map +1 -1
- package/out/pipeline/CandidatePicker.js +2 -2
- package/out/pipeline/CandidatePicker.js.map +1 -1
- package/out/pipeline/ConfidenceCell.d.ts +1 -1
- package/out/pipeline/ConfidenceCell.js +1 -1
- package/out/pipeline/FailureDiagnostic.d.ts +8 -2
- package/out/pipeline/FailureDiagnostic.d.ts.map +1 -1
- package/out/pipeline/FailureDiagnostic.js +3 -0
- package/out/pipeline/FailureDiagnostic.js.map +1 -1
- package/out/pipeline/PipelineExplorer.js +1 -1
- package/out/pipeline/QueryForm.d.ts +5 -2
- package/out/pipeline/QueryForm.d.ts.map +1 -1
- package/out/pipeline/QueryForm.js +1 -1
- package/out/pipeline/QueryForm.js.map +1 -1
- package/out/pipeline/ResolvedPlace.js +1 -1
- package/out/pipeline/SpanHighlight.d.ts +4 -3
- package/out/pipeline/SpanHighlight.d.ts.map +1 -1
- package/out/pipeline/SpanHighlight.js +3 -2
- package/out/pipeline/SpanHighlight.js.map +1 -1
- package/out/pipeline/TimingPanel.d.ts +1 -1
- package/out/pipeline/TimingPanel.js +1 -1
- package/out/pipeline/TreeView.d.ts +1 -1
- package/out/pipeline/copy.d.ts +1 -1
- package/out/pipeline/copy.d.ts.map +1 -1
- package/out/pipeline/copy.js +4 -3
- package/out/pipeline/copy.js.map +1 -1
- package/out/pipeline/presets.d.ts +5 -4
- package/out/pipeline/presets.d.ts.map +1 -1
- package/out/pipeline/presets.js +15 -13
- package/out/pipeline/presets.js.map +1 -1
- package/out/pipeline/types.d.ts +21 -14
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +2 -4
- package/out/pipeline/types.js.map +1 -1
- package/out/pipeline/useParsePipeline.d.ts +15 -7
- package/out/pipeline/useParsePipeline.d.ts.map +1 -1
- package/out/pipeline/useParsePipeline.js +10 -7
- package/out/pipeline/useParsePipeline.js.map +1 -1
- package/out/pipeline.d.ts +33 -0
- package/out/pipeline.d.ts.map +1 -0
- package/out/pipeline.js +21 -0
- package/out/pipeline.js.map +1 -0
- package/out/poi/AbstainPanel.d.ts +1 -1
- package/out/poi/LiveResultsBlock.d.ts +2 -1
- package/out/poi/LiveResultsBlock.d.ts.map +1 -1
- package/out/poi/LiveResultsBlock.js +1 -1
- package/out/poi/LiveResultsBlock.js.map +1 -1
- package/out/poi/POIExplorer.d.ts +22 -12
- package/out/poi/POIExplorer.d.ts.map +1 -1
- package/out/poi/POIExplorer.js +10 -9
- package/out/poi/POIExplorer.js.map +1 -1
- package/out/poi/QueryInput.d.ts +1 -1
- package/out/poi/SubjectPanel.d.ts +2 -2
- package/out/poi/SubjectPanel.d.ts.map +1 -1
- package/out/poi/SubjectPanel.js +3 -2
- package/out/poi/SubjectPanel.js.map +1 -1
- package/out/poi/runtime.d.ts +5 -14
- package/out/poi/runtime.d.ts.map +1 -1
- package/out/poi/runtime.js +5 -16
- package/out/poi/runtime.js.map +1 -1
- package/out/poi/types.d.ts +39 -27
- package/out/poi/types.d.ts.map +1 -1
- package/out/poi/types.js +2 -4
- package/out/poi/types.js.map +1 -1
- package/out/poi/usePOISearch.d.ts +28 -17
- package/out/poi/usePOISearch.d.ts.map +1 -1
- package/out/poi/usePOISearch.js +6 -32
- package/out/poi/usePOISearch.js.map +1 -1
- package/out/poi.d.ts +23 -0
- package/out/poi.d.ts.map +1 -0
- package/out/poi.js +15 -0
- package/out/poi.js.map +1 -0
- package/out/runtime/useReleaseRuntime.d.ts +64 -65
- package/out/runtime/useReleaseRuntime.d.ts.map +1 -1
- package/out/runtime/useReleaseRuntime.js +31 -26
- package/out/runtime/useReleaseRuntime.js.map +1 -1
- package/out/runtime.d.ts +9 -0
- package/out/runtime.d.ts.map +1 -0
- package/out/runtime.js +8 -0
- package/out/runtime.js.map +1 -0
- package/out/search/SearchModal.d.ts +33 -0
- package/out/search/SearchModal.d.ts.map +1 -0
- package/out/search/SearchModal.js +187 -0
- package/out/search/SearchModal.js.map +1 -0
- package/out/search/types.d.ts +64 -0
- package/out/search/types.d.ts.map +1 -0
- package/out/search/types.js +13 -0
- package/out/search/types.js.map +1 -0
- package/out/search.d.ts +11 -0
- package/out/search.d.ts.map +1 -0
- package/out/search.js +9 -0
- package/out/search.js.map +1 -0
- package/package.json +132 -133
- package/styles.css +1340 -202
- package/tokens/index.css +26 -7
- package/tokens/tokens.json +121 -6
- package/tokens/tokens.resolver.json +1 -1
- package/lib/map/index.ts +0 -76
- package/out/map/index.d.ts +0 -52
- package/out/map/index.d.ts.map +0 -1
- package/out/map/index.js +0 -36
- package/out/map/index.js.map +0 -1
- package/styleframe.config.ts +0 -321
- package/vitest.node.config.ts +0 -20
package/lib/map/place-render.ts
CHANGED
|
@@ -2,93 +2,78 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* `computeMapPlaceRenderSpec` — the PURE core that replaces the docs demo's ~100-line imperative
|
|
7
|
-
* marker/bbox/camera redraw effect (`_app.tsx:601-705`). It takes an ALREADY-RESOLVED place (the async
|
|
8
|
-
* polygon-DB fetch is a host/runtime concern — a later phase — so a crisp polygon arrives pre-fetched
|
|
9
|
-
* as `place.geometry`) and returns a declarative render spec: the marker position(s), the outline
|
|
10
|
-
* geometry to draw, and the camera target. No map instance, no DOM, no `react-map-gl` — so it is
|
|
11
|
-
* node-testable (see `place-render.node.test.ts`). The declarative components in this folder render
|
|
12
|
-
* the spec; a controlled-viewport consumer applies the camera.
|
|
13
|
-
*
|
|
14
|
-
* The decision cascade is a faithful, side-effect-free transcription of the imperative effect:
|
|
15
|
-
* 1. street tier (situs / interp) → exact-radius circle, fly to a tight zoom
|
|
16
|
-
* 2. crisp admin polygon (pre-fetched) → draw the polygon, fit its bounds
|
|
17
|
-
* 3. anchor-centroid postcode (no bbox) → ~3 km "around here" circle, fly to zoom 11
|
|
18
|
-
* 4. bbox with real extent → bbox-sized approximate circle, fit the bbox
|
|
19
|
-
* 5. bare point → no outline, fly to zoom 12
|
|
20
5
|
*/
|
|
21
6
|
|
|
22
7
|
import type { ResolvedPlaceView } from "@mailwoman/core/pipeline/client-result"
|
|
8
|
+
import type { LatLonBounds } from "@mailwoman/spatial"
|
|
23
9
|
|
|
24
10
|
import { approxCircleGeometry, bboxToBounds, geomBounds, radiusCircleGeometry } from "#map/geometry"
|
|
25
|
-
import type { BoundsTuple,
|
|
11
|
+
import type { BoundsTuple, PlaceGeometry } from "#map/geometry"
|
|
26
12
|
|
|
27
13
|
/**
|
|
28
|
-
* `[longitude, latitude]`.
|
|
14
|
+
* A coordinate pair as `[longitude, latitude]`.
|
|
29
15
|
*/
|
|
30
16
|
export type LngLat = [number, number]
|
|
31
17
|
|
|
32
18
|
/**
|
|
33
|
-
*
|
|
19
|
+
* How a street-level result was located: `address_point` is an exact building point
|
|
20
|
+
* and `interpolated` an estimate from a TIGER address range.
|
|
34
21
|
*/
|
|
35
22
|
export type PlaceTier = "address_point" | "interpolated"
|
|
36
23
|
|
|
37
24
|
/**
|
|
38
|
-
*
|
|
39
|
-
* demo's `ResolvedHit` carries (bbox, street tier + uncertainty), and an optional PRE-FETCHED crisp polygon. Extending
|
|
40
|
-
* `ResolvedPlaceView` keeps the map render aligned with the shared parse result; the extras are additive.
|
|
25
|
+
* A resolved place with the extra fields the map uses to draw it.
|
|
41
26
|
*/
|
|
42
27
|
export interface ResolvedMapPlace extends ResolvedPlaceView {
|
|
43
28
|
/**
|
|
44
|
-
* The place's bounding box
|
|
29
|
+
* The place's bounding box.
|
|
30
|
+
* Postcodes located by an anchor centroid have none.
|
|
45
31
|
*/
|
|
46
|
-
bbox?:
|
|
32
|
+
bbox?: LatLonBounds
|
|
33
|
+
|
|
47
34
|
/**
|
|
48
|
-
*
|
|
35
|
+
* The street-level tier, set only for results from address points or interpolation.
|
|
49
36
|
*/
|
|
50
37
|
tier?: PlaceTier
|
|
38
|
+
|
|
51
39
|
/**
|
|
52
|
-
*
|
|
40
|
+
* The uncertainty radius in meters of a street-level result, drawn as a circle when `tier` is set.
|
|
53
41
|
*/
|
|
54
42
|
uncertaintyM?: number
|
|
43
|
+
|
|
55
44
|
/**
|
|
56
|
-
* The
|
|
57
|
-
*
|
|
45
|
+
* The admin polygon, if the host has already fetched it.
|
|
46
|
+
* When present the outline and camera follow it.
|
|
58
47
|
*/
|
|
59
48
|
geometry?: PlaceGeometry
|
|
60
49
|
}
|
|
61
50
|
|
|
62
51
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* NOT — `fitBounds` needs the map's pixel dimensions, so it is applied imperatively by `<ResultCamera>`.
|
|
52
|
+
* Only a `center` target can be applied declaratively through {@link cameraToViewState};
|
|
53
|
+
* fitting bounds needs the map's pixel size, so `<ResultCamera>` applies it imperatively.
|
|
66
54
|
*/
|
|
67
55
|
export type MapCameraTarget =
|
|
68
56
|
| { kind: "center"; center: LngLat; zoom: number }
|
|
69
57
|
| { kind: "bounds"; bounds: BoundsTuple; padding: number }
|
|
70
58
|
|
|
71
59
|
/**
|
|
72
|
-
* The
|
|
60
|
+
* The markers, outline and camera target for one resolved place, as returned
|
|
61
|
+
* by {@link computeMapPlaceRenderSpec}.
|
|
73
62
|
*/
|
|
74
63
|
export interface MapPlaceRenderSpec {
|
|
75
64
|
/**
|
|
76
|
-
*
|
|
65
|
+
* The marker positions as `[lon, lat]`; there is always exactly one marker.
|
|
77
66
|
*/
|
|
78
67
|
markers: LngLat[]
|
|
68
|
+
|
|
79
69
|
/**
|
|
80
|
-
* The
|
|
70
|
+
* The polygon or circle outline to draw, or `null` when the place renders as a bare point.
|
|
81
71
|
*/
|
|
82
72
|
outline: PlaceGeometry | null
|
|
83
|
-
|
|
84
|
-
* The camera target — animate or fit to this.
|
|
85
|
-
*/
|
|
73
|
+
|
|
86
74
|
camera: MapCameraTarget
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
/**
|
|
90
|
-
* Zoom levels the imperative effect flew to, kept named so the cascade reads as intent, not magic numbers.
|
|
91
|
-
*/
|
|
92
77
|
const ZOOM = {
|
|
93
78
|
addressPoint: 17,
|
|
94
79
|
interpolated: 15,
|
|
@@ -96,26 +81,17 @@ const ZOOM = {
|
|
|
96
81
|
point: 12,
|
|
97
82
|
} as const
|
|
98
83
|
|
|
99
|
-
/**
|
|
100
|
-
* Padding (px) `fitBounds` insets a fitted box by, matching the ported effect.
|
|
101
|
-
*/
|
|
102
84
|
const FIT_PADDING = 40
|
|
103
85
|
|
|
104
|
-
/**
|
|
105
|
-
* The minimum lat/lon span (degrees) a bbox must exceed to be treated as a real extent rather than a point.
|
|
106
|
-
*/
|
|
107
86
|
const MIN_EXTENT_DEG = 0.001
|
|
108
87
|
|
|
109
88
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* inverse of the old redraw effect with the imperative map mutation and the async DB load removed.
|
|
89
|
+
* Computes the markers, outline and camera target for a resolved place without loading data,
|
|
90
|
+
* so the caller must put any fetched polygon in `place.geometry` first.
|
|
113
91
|
*/
|
|
114
92
|
export function computeMapPlaceRenderSpec(place: ResolvedMapPlace): MapPlaceRenderSpec {
|
|
115
93
|
const markers: LngLat[] = [[place.lon, place.lat]]
|
|
116
94
|
|
|
117
|
-
// 1. Street tier (#377): the honest uncertainty circle (exact meter radius) + a tight zoom. Takes precedence over
|
|
118
|
-
// the admin polygon/bbox paths — a precise point gets no admin boundary.
|
|
119
95
|
if (place.tier && place.uncertaintyM != null) {
|
|
120
96
|
return {
|
|
121
97
|
markers,
|
|
@@ -128,7 +104,6 @@ export function computeMapPlaceRenderSpec(place: ResolvedMapPlace): MapPlaceRend
|
|
|
128
104
|
}
|
|
129
105
|
}
|
|
130
106
|
|
|
131
|
-
// 2. Crisp admin polygon (host pre-fetched it from the polygon DB) — draw the real boundary and fit it.
|
|
132
107
|
if (place.geometry) {
|
|
133
108
|
return {
|
|
134
109
|
markers,
|
|
@@ -137,8 +112,6 @@ export function computeMapPlaceRenderSpec(place: ResolvedMapPlace): MapPlaceRend
|
|
|
137
112
|
}
|
|
138
113
|
}
|
|
139
114
|
|
|
140
|
-
// 3. Anchor-centroid postcode: no bbox, no polygon — a default ~3 km circle says "approximately here" without
|
|
141
|
-
// inventing a boundary.
|
|
142
115
|
if (!place.bbox && place.placetype === "postcode") {
|
|
143
116
|
return {
|
|
144
117
|
markers,
|
|
@@ -147,8 +120,6 @@ export function computeMapPlaceRenderSpec(place: ResolvedMapPlace): MapPlaceRend
|
|
|
147
120
|
}
|
|
148
121
|
}
|
|
149
122
|
|
|
150
|
-
// 4. A bbox with real extent — draw an approximate CIRCLE sized from the bbox (a rectangle would read as a wrong,
|
|
151
|
-
// real boundary) and fit the bbox.
|
|
152
123
|
const bbox = place.bbox
|
|
153
124
|
|
|
154
125
|
if (bbox && Math.max(bbox.maxLat - bbox.minLat, bbox.maxLon - bbox.minLon) > MIN_EXTENT_DEG) {
|
|
@@ -159,7 +130,6 @@ export function computeMapPlaceRenderSpec(place: ResolvedMapPlace): MapPlaceRend
|
|
|
159
130
|
}
|
|
160
131
|
}
|
|
161
132
|
|
|
162
|
-
// 5. A bare point (no tier, no polygon, no meaningful bbox) — just a marker and a mid zoom.
|
|
163
133
|
return {
|
|
164
134
|
markers,
|
|
165
135
|
outline: null,
|
|
@@ -168,10 +138,8 @@ export function computeMapPlaceRenderSpec(place: ResolvedMapPlace): MapPlaceRend
|
|
|
168
138
|
}
|
|
169
139
|
|
|
170
140
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* needs the map's pixel dimensions, which only the live map has, so that case is applied imperatively by
|
|
174
|
-
* `<ResultCamera>`. Pure + node-testable.
|
|
141
|
+
* Converts a `center` camera target into a `viewState` patch for a controlled `<MapCanvas>`,
|
|
142
|
+
* returning `null` for a `bounds` target that `<ResultCamera>` must fit imperatively.
|
|
175
143
|
*/
|
|
176
144
|
export function cameraToViewState(
|
|
177
145
|
camera: MapCameraTarget
|
package/lib/map/types.ts
CHANGED
|
@@ -3,21 +3,12 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Types for the geocoder map surface.
|
|
7
|
-
* machine + the declarative map, while the host injects a {@link GeocoderRuntime} that owns ONNX / httpvfs
|
|
8
|
-
* / R2 and the composed map style. {@link GeocoderRuntime} EXTENDS {@link PipelineRuntime} so the shared
|
|
9
|
-
* `runParse` / `parseStageLabels` / `loading` contract is reused, and adds the map-specific surface
|
|
10
|
-
* (style, overlays, initial center, viewport bias, backend/version selection). Phase 4 adds the
|
|
11
|
-
* `resolveMapPlace` enricher, the {@link GeocoderPanels} injection bag, and the {@link CompareContext}.
|
|
12
|
-
*
|
|
13
|
-
* The map-spec types are imported type-only from `react-map-gl/maplibre`; nothing here loads maplibre at
|
|
14
|
-
* runtime, so this module stays node-safe (its concrete-value CONSUMERS — `MapCanvas`, `Geocoder` —
|
|
15
|
-
* are the ones behind the `@mailwoman/react/map` subpath).
|
|
6
|
+
* Types for the geocoder map surface. Its `react-map-gl/maplibre` imports are type-only, so the module stays node-safe.
|
|
16
7
|
*/
|
|
17
8
|
|
|
18
9
|
import type { ParseResult, ResolvedPlaceView } from "@mailwoman/core/pipeline/client-result"
|
|
19
10
|
import type { ReactNode } from "react"
|
|
20
|
-
import type { LayerSpecification, SourceSpecification } from "react-map-gl/maplibre"
|
|
11
|
+
import type { LayerSpecification, MapInstance, SourceSpecification } from "react-map-gl/maplibre"
|
|
21
12
|
|
|
22
13
|
import type { LngLat, ResolvedMapPlace } from "#map/place-render"
|
|
23
14
|
import type { PipelineRuntime } from "#pipeline/types"
|
|
@@ -25,9 +16,10 @@ import type { PipelineRuntime } from "#pipeline/types"
|
|
|
25
16
|
import type { MapCanvasStyle } from "./MapCanvas.tsx"
|
|
26
17
|
|
|
27
18
|
/**
|
|
28
|
-
*
|
|
19
|
+
* An alias for {@link LngLat}.
|
|
29
20
|
*
|
|
30
|
-
* @deprecated Alias kept for existing imports — {@link LngLat}
|
|
21
|
+
* @deprecated Alias kept for existing imports — {@link LngLat}
|
|
22
|
+
* (from `@mailwoman/react/map`) is the canonical name.
|
|
31
23
|
*/
|
|
32
24
|
export type LngLatTuple = LngLat
|
|
33
25
|
|
|
@@ -35,40 +27,24 @@ export type LngLatTuple = LngLat
|
|
|
35
27
|
* A viewport bias handed to `runParse` — the map's current center (and optionally zoom) as a soft prior.
|
|
36
28
|
*/
|
|
37
29
|
export interface MapBias {
|
|
38
|
-
/**
|
|
39
|
-
* Map center as `[lon, lat]`, typically read from `map.getCenter()`.
|
|
40
|
-
*/
|
|
41
30
|
center: LngLat
|
|
42
|
-
/**
|
|
43
|
-
* Current zoom, if the host wants distance-aware biasing.
|
|
44
|
-
*/
|
|
45
31
|
zoom?: number
|
|
46
32
|
}
|
|
47
33
|
|
|
48
34
|
/**
|
|
49
|
-
* A host-supplied overlay: one map `<Source>` plus one or more `<Layer>`s laid over the basemap
|
|
50
|
-
* race-dots, …). The host composes the specs; the package renders them declaratively in a later phase.
|
|
35
|
+
* A host-supplied overlay: one map `<Source>` plus one or more `<Layer>`s laid over the basemap.
|
|
51
36
|
*/
|
|
52
37
|
export interface OverlaySpec {
|
|
53
38
|
/**
|
|
54
39
|
* Stable id — used as the `<Source>` id and the layer-id prefix.
|
|
55
40
|
*/
|
|
56
41
|
id: string
|
|
57
|
-
/**
|
|
58
|
-
* The map source spec (vector/geojson/raster).
|
|
59
|
-
*/
|
|
60
42
|
source: SourceSpecification
|
|
61
|
-
/**
|
|
62
|
-
* The layers drawn from that source.
|
|
63
|
-
*/
|
|
64
43
|
layers: LayerSpecification[]
|
|
65
44
|
/**
|
|
66
|
-
*
|
|
45
|
+
* @default true
|
|
67
46
|
*/
|
|
68
47
|
visible?: boolean
|
|
69
|
-
/**
|
|
70
|
-
* Human label for a layer-toggle control.
|
|
71
|
-
*/
|
|
72
48
|
label?: string
|
|
73
49
|
}
|
|
74
50
|
|
|
@@ -95,11 +71,12 @@ export interface Suggestion {
|
|
|
95
71
|
*/
|
|
96
72
|
export interface VersionOption {
|
|
97
73
|
/**
|
|
98
|
-
* The version tag
|
|
74
|
+
* The version tag, such as a git tag or model-card version.
|
|
99
75
|
*/
|
|
100
76
|
version: string
|
|
101
77
|
/**
|
|
102
|
-
* Display label
|
|
78
|
+
* Display label.
|
|
79
|
+
* The picker falls back to `version`.
|
|
103
80
|
*/
|
|
104
81
|
label?: string
|
|
105
82
|
}
|
|
@@ -110,35 +87,27 @@ export interface VersionOption {
|
|
|
110
87
|
export type InferenceBackend = "webgpu" | "wasm"
|
|
111
88
|
|
|
112
89
|
/**
|
|
113
|
-
* The injected geocoder runtime
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* `@mailwoman/neural`'s web loader, httpvfs, or Docusaurus.
|
|
90
|
+
* The injected geocoder runtime extends {@link PipelineRuntime} with the map.
|
|
91
|
+
* It also supplies version and backend controls.
|
|
92
|
+
*
|
|
93
|
+
* The package imports no `@mailwoman/cartographer`, `@mailwoman/neural` web loader, httpvfs, or Docusaurus.
|
|
118
94
|
*/
|
|
119
95
|
export interface GeocoderRuntime extends PipelineRuntime {
|
|
120
|
-
// ── Map ────────────────────────────────────────────────────────────────
|
|
121
96
|
/**
|
|
122
97
|
* The composed basemap style (URL or `StyleSpecification`).
|
|
123
98
|
*/
|
|
124
99
|
mapStyle: MapCanvasStyle
|
|
125
|
-
/**
|
|
126
|
-
* Host-supplied overlays (coverage, race-dots, …).
|
|
127
|
-
*/
|
|
128
100
|
overlays?: OverlaySpec[]
|
|
129
101
|
/**
|
|
130
|
-
* Initial map center as `[lon, lat]
|
|
102
|
+
* Initial map center as `[lon, lat]`.
|
|
131
103
|
*/
|
|
132
104
|
initialCenter: LngLat
|
|
133
|
-
/**
|
|
134
|
-
* Initial zoom for the first camera.
|
|
135
|
-
*/
|
|
136
105
|
initialZoom?: number
|
|
137
106
|
|
|
138
|
-
// ── Parse extras layered over PipelineRuntime.runParse ──────────────────
|
|
139
107
|
/**
|
|
140
|
-
* A bias-aware parse
|
|
141
|
-
*
|
|
108
|
+
* A bias-aware parse that feeds the current viewport center as a soft prior.
|
|
109
|
+
*
|
|
110
|
+
* Absent, the host falls back to {@link PipelineRuntime.runParse}.
|
|
142
111
|
*/
|
|
143
112
|
runParseWithBias?: (
|
|
144
113
|
input: string,
|
|
@@ -154,11 +123,17 @@ export interface GeocoderRuntime extends PipelineRuntime {
|
|
|
154
123
|
*/
|
|
155
124
|
calibrator?: (raw: number) => number | null
|
|
156
125
|
/**
|
|
157
|
-
* Enrich the selected candidate into the richer {@link ResolvedMapPlace} the declarative
|
|
158
|
-
* street tier + uncertainty, a pre-fetched crisp polygon) —
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
126
|
+
* Enrich the selected candidate into the richer {@link ResolvedMapPlace} the declarative
|
|
127
|
+
* map render consumes (bbox, street tier + uncertainty, a pre-fetched crisp polygon) —
|
|
128
|
+
* the fields that live on the host's `ResolvedHit` but not on the shared {@link ResolvedPlaceView}.
|
|
129
|
+
*
|
|
130
|
+
* The host owns this because those extras (and the async polygon fetch in the real runtime)
|
|
131
|
+
* are host/gazetteer concerns.
|
|
132
|
+
* The package keeps {@link ParseResult} unpolluted.
|
|
133
|
+
*
|
|
134
|
+
* Absent → the candidate renders as a bare point (marker + a mid-zoom fly-to).
|
|
135
|
+
*
|
|
136
|
+
* A `null` result also renders no overlay.
|
|
162
137
|
*/
|
|
163
138
|
resolveMapPlace?: (candidate: ResolvedPlaceView, result: ParseResult) => ResolvedMapPlace | null
|
|
164
139
|
|
|
@@ -167,9 +142,6 @@ export interface GeocoderRuntime extends PipelineRuntime {
|
|
|
167
142
|
* The selectable model bundles the version picker offers.
|
|
168
143
|
*/
|
|
169
144
|
availableVersions?: VersionOption[]
|
|
170
|
-
/**
|
|
171
|
-
* The currently-selected model version.
|
|
172
|
-
*/
|
|
173
145
|
selectedVersion?: string
|
|
174
146
|
/**
|
|
175
147
|
* Switch the active model bundle (re-loads weights/tokenizer/gazetteer).
|
|
@@ -180,27 +152,24 @@ export interface GeocoderRuntime extends PipelineRuntime {
|
|
|
180
152
|
*/
|
|
181
153
|
activeBackend?: string
|
|
182
154
|
/**
|
|
183
|
-
* Whether the CPU/
|
|
155
|
+
* Whether the CPU/wasm backend is currently forced (the controlled value for the backend toggle).
|
|
184
156
|
*/
|
|
185
157
|
forceWASM?: boolean
|
|
186
158
|
/**
|
|
187
|
-
* Force the
|
|
159
|
+
* Force the wasm backend (opt out of WebGPU), for the backend toggle.
|
|
188
160
|
*/
|
|
189
161
|
setForceWASM?: (forceWASM: boolean) => void
|
|
190
162
|
}
|
|
191
163
|
|
|
192
164
|
/**
|
|
193
|
-
* The compare-mode state a {@link GeocoderPanels.compare} render-prop receives
|
|
194
|
-
* host-side
|
|
165
|
+
* The compare-mode state a {@link GeocoderPanels.compare} render-prop receives.
|
|
166
|
+
* the second parse itself stays host-side.
|
|
195
167
|
*/
|
|
196
168
|
export interface CompareContext {
|
|
197
169
|
/**
|
|
198
170
|
* The current primary parse result, or `null` before the first submit.
|
|
199
171
|
*/
|
|
200
172
|
result: ParseResult | null
|
|
201
|
-
/**
|
|
202
|
-
* Whether the compare toggle is on.
|
|
203
|
-
*/
|
|
204
173
|
compareMode: boolean
|
|
205
174
|
/**
|
|
206
175
|
* The version selected to compare against, or `null` when none is chosen.
|
|
@@ -209,39 +178,29 @@ export interface CompareContext {
|
|
|
209
178
|
}
|
|
210
179
|
|
|
211
180
|
/**
|
|
212
|
-
* The state a {@link GeocoderPanels.result} render-prop receives, so a host can render its
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* by the package (`useGeocode`).
|
|
181
|
+
* The state a {@link GeocoderPanels.result} render-prop receives, so a host can render its own result block.
|
|
182
|
+
*
|
|
183
|
+
* The candidate-selection state stays owned by the package (`useGeocode`).
|
|
216
184
|
*/
|
|
217
185
|
export interface ResultContext {
|
|
218
|
-
/**
|
|
219
|
-
* The current parse+resolve result.
|
|
220
|
-
*/
|
|
221
186
|
result: ParseResult
|
|
222
187
|
/**
|
|
223
188
|
* The selected candidate (falls back to the first), enriched for the resolved-place detail.
|
|
224
189
|
*/
|
|
225
190
|
selectedCandidate: ResolvedPlaceView | null
|
|
226
|
-
/**
|
|
227
|
-
* The selected candidate index, for the picker's active state.
|
|
228
|
-
*/
|
|
229
191
|
selectedCandidateIndex: number
|
|
230
|
-
/**
|
|
231
|
-
* Fired when a candidate in the picker is chosen.
|
|
232
|
-
*/
|
|
233
192
|
onSelectCandidate: (index: number) => void
|
|
234
193
|
}
|
|
235
194
|
|
|
236
195
|
/**
|
|
237
|
-
* Host-injected panels for {@link Geocoder}, the map analogue of `PipelinePanels`.
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
196
|
+
* Host-injected panels for {@link Geocoder}, the map analogue of `PipelinePanels`.
|
|
197
|
+
*
|
|
198
|
+
* Each is an already-rendered `ReactNode` or a thunk.
|
|
199
|
+
* Every field is optional.
|
|
241
200
|
*/
|
|
242
201
|
export interface GeocoderPanels {
|
|
243
202
|
/**
|
|
244
|
-
* Rendered at the top of the control panel
|
|
203
|
+
* Rendered at the top of the control panel, such as the host's "About this geocoder".
|
|
245
204
|
*/
|
|
246
205
|
header?: ReactNode
|
|
247
206
|
/**
|
|
@@ -249,13 +208,13 @@ export interface GeocoderPanels {
|
|
|
249
208
|
*/
|
|
250
209
|
releaseInfo?: ReactNode
|
|
251
210
|
/**
|
|
252
|
-
* Rendered at the bottom of the control panel
|
|
211
|
+
* Rendered at the bottom of the control panel, such as a guided tour.
|
|
253
212
|
*/
|
|
254
213
|
footer?: ReactNode
|
|
255
214
|
/**
|
|
256
|
-
* A device-location / proximity-bias control, rendered between the query form and the autocomplete list
|
|
257
|
-
*
|
|
258
|
-
* {@link GeocoderRuntime.runParseWithBias}
|
|
215
|
+
* A device-location / proximity-bias control, rendered between the query form and the autocomplete list.
|
|
216
|
+
*
|
|
217
|
+
* Host-owned because the geolocation permission feeds {@link GeocoderRuntime.runParseWithBias}.
|
|
259
218
|
*/
|
|
260
219
|
bias?: ReactNode
|
|
261
220
|
/**
|
|
@@ -263,20 +222,25 @@ export interface GeocoderPanels {
|
|
|
263
222
|
*/
|
|
264
223
|
extras?: (result: ParseResult) => ReactNode
|
|
265
224
|
/**
|
|
266
|
-
* Rendered just above the result block
|
|
267
|
-
*
|
|
268
|
-
* renderers those toggles drive.
|
|
225
|
+
* Rendered just above the result block for content that reads on this answer. a
|
|
226
|
+
* control that reads on the model belongs in {@link developerExtras}.
|
|
269
227
|
*/
|
|
270
228
|
aboveResult?: (context: { result: ParseResult | null }) => ReactNode
|
|
271
229
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
|
|
230
|
+
* Host controls appended to the Developer sheet.
|
|
231
|
+
* The host owns their state and renderers.
|
|
232
|
+
*/
|
|
233
|
+
developerExtras?: ReactNode
|
|
234
|
+
/**
|
|
235
|
+
* Replaces the package's default {@link ResultPanel}.
|
|
236
|
+
*
|
|
237
|
+
* When absent, the built-in panel renders.
|
|
238
|
+
* When provided, the host renders from {@link ResultContext}.
|
|
275
239
|
*/
|
|
276
240
|
result?: (context: ResultContext) => ReactNode
|
|
277
241
|
/**
|
|
278
|
-
* Rendered in place of the resolved-place panel when
|
|
279
|
-
* {@link result} is set.
|
|
242
|
+
* Rendered in place of the resolved-place panel when no place resolved. ignored
|
|
243
|
+
* when {@link result} is set.
|
|
280
244
|
*/
|
|
281
245
|
failure?: (result: ParseResult) => ReactNode
|
|
282
246
|
/**
|
|
@@ -284,15 +248,19 @@ export interface GeocoderPanels {
|
|
|
284
248
|
*/
|
|
285
249
|
compare?: (context: CompareContext) => ReactNode
|
|
286
250
|
/**
|
|
287
|
-
* The model-visualizer / debug drawer
|
|
288
|
-
*
|
|
289
|
-
* dev-mode state and returns `null` when the drawer is closed.
|
|
251
|
+
* The model-visualizer / debug drawer mounted beside the map, as a render-prop
|
|
252
|
+
* receiving the live result and returning `null` when closed.
|
|
290
253
|
*/
|
|
291
254
|
debugDrawer?: (context: { result: ParseResult | null }) => ReactNode
|
|
292
255
|
/**
|
|
293
256
|
* Extra map controls mounted as `<MapCanvas>` children (host's DebugControl / LayerToggle via `useControl`).
|
|
294
257
|
*/
|
|
295
258
|
mapControls?: ReactNode
|
|
259
|
+
/**
|
|
260
|
+
* A layer control rendered in the chrome's top column, as a render-prop over the
|
|
261
|
+
* live map handle (null until the map instantiates).
|
|
262
|
+
*/
|
|
263
|
+
layers?: (context: { map: MapInstance | null }) => ReactNode
|
|
296
264
|
/**
|
|
297
265
|
* A permalink control for the current address (host's PermalinkButton).
|
|
298
266
|
*/
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* `useCompareState` — the small headless state machine behind the demo's compare toggle
|
|
7
|
-
* (`_app.tsx:142-143, 1238-1305`): whether compare mode is on
|
|
8
|
-
*
|
|
9
|
-
* rejected (the picker filters it out, this guards the programmatic path). The
|
|
7
|
+
* (`_app.tsx:142-143, 1238-1305`): whether compare mode is on and which version to compare against.
|
|
8
|
+
* The off state clears the chosen version. A selected compare version equal to the primary is
|
|
9
|
+
* rejected (the picker filters it out, this guards the programmatic path). The second parse itself is a
|
|
10
10
|
* host concern surfaced through `panels.compare` — this hook owns only the toggle + selection.
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -22,7 +22,8 @@ export interface UseCompareState {
|
|
|
22
22
|
*/
|
|
23
23
|
compareVersion: string | null
|
|
24
24
|
/**
|
|
25
|
-
* Flip compare mode
|
|
25
|
+
* Flip compare mode.
|
|
26
|
+
* The off state clears the chosen version.
|
|
26
27
|
*/
|
|
27
28
|
setCompareMode: (compareMode: boolean) => void
|
|
28
29
|
/**
|
package/lib/map/useGeocode.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `useGeocode` — the parse+resolve state machine for the geocoder map. It
|
|
6
|
+
* `useGeocode` — the parse+resolve state machine for the geocoder map. It reuses the pipeline's
|
|
7
7
|
* `useParsePipeline` (text / busy / stage / result / candidate selection) and layers on the two map-only
|
|
8
8
|
* concerns the geocoder adds over the base explorer:
|
|
9
9
|
*
|
|
10
10
|
* 1. Viewport bias — when the runtime exposes `runParseWithBias`, the current map center (read through
|
|
11
|
-
* an injected `getBias`, itself reading the `MapRef`)
|
|
11
|
+
* an injected `getBias`, itself reading the `MapRef`) supplies a soft proximity prior. The
|
|
12
12
|
* bias is injected by deriving a `runParse` that binds it, so `useParsePipeline` is reused verbatim.
|
|
13
13
|
* 2. The map render place — the selected candidate, enriched by the host's `resolveMapPlace` into the
|
|
14
14
|
* richer {@link ResolvedMapPlace} the declarative overlays consume (bbox / tier / polygon). Absent
|
|
@@ -35,7 +35,9 @@ export interface UseGeocodeOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
defaultText: string
|
|
37
37
|
/**
|
|
38
|
-
* Read the current viewport bias (the map center) at submit time.
|
|
38
|
+
* Read the current viewport bias (the map center) at submit time.
|
|
39
|
+
*
|
|
40
|
+
* Absent → no bias.
|
|
39
41
|
*/
|
|
40
42
|
getBias?: () => MapBias | null
|
|
41
43
|
}
|
|
@@ -48,8 +50,8 @@ export interface UseGeocode extends UseParsePipeline {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export function useGeocode({ runtime, defaultText, getBias }: UseGeocodeOptions): UseGeocode {
|
|
51
|
-
// Bind the viewport bias into a derived `runParse` so `useParsePipeline` is reused unchanged.
|
|
52
|
-
// bias-aware parse, pass it straight through.
|
|
53
|
+
// Bind the viewport bias into a derived `runParse` so `useParsePipeline` is reused unchanged.
|
|
54
|
+
// When the runtime has no bias-aware parse, pass it straight through.
|
|
53
55
|
const geoRuntime = useMemo<PipelineRuntime>(() => {
|
|
54
56
|
const withBias = runtime.runParseWithBias
|
|
55
57
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The map's rotation as React state, read through `useSyncExternalStore` and subscribed to `move` as well as `rotate`, since a `flyTo` or `easeTo` carrying a direction fires no rotate event.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useCallback, useSyncExternalStore } from "react"
|
|
10
|
+
import type { MapInstance } from "react-map-gl/maplibre"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The map's bearing and a callback that returns the map to north.
|
|
14
|
+
*/
|
|
15
|
+
export interface UseMapBearing {
|
|
16
|
+
/**
|
|
17
|
+
* Degrees off north, as MapLibre reports it.
|
|
18
|
+
* Zero while there is no map.
|
|
19
|
+
*/
|
|
20
|
+
bearing: number
|
|
21
|
+
/**
|
|
22
|
+
* Rotate the map back to north.
|
|
23
|
+
* A no-op while there is no map.
|
|
24
|
+
*/
|
|
25
|
+
resetNorth: () => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reads the live map bearing and exposes `resetNorth`.
|
|
30
|
+
*/
|
|
31
|
+
export function useMapBearing(map: MapInstance | null): UseMapBearing {
|
|
32
|
+
const subscribe = useCallback(
|
|
33
|
+
(onChange: () => void) => {
|
|
34
|
+
if (!map) return () => undefined
|
|
35
|
+
|
|
36
|
+
map.on("rotate", onChange)
|
|
37
|
+
map.on("move", onChange)
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
map.off("rotate", onChange)
|
|
41
|
+
map.off("move", onChange)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[map]
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
// The server snapshot is the same reading: the server renders no map.
|
|
48
|
+
// and north is what a compass shows with no bearing to report.
|
|
49
|
+
const readBearing = useCallback(() => map?.getBearing() ?? 0, [map])
|
|
50
|
+
|
|
51
|
+
const bearing = useSyncExternalStore(subscribe, readBearing, () => 0)
|
|
52
|
+
|
|
53
|
+
const resetNorth = useCallback(() => map?.easeTo({ bearing: 0, pitch: 0 }), [map])
|
|
54
|
+
|
|
55
|
+
return { bearing, resetNorth }
|
|
56
|
+
}
|