@mapcairn/map 0.0.0-stage → 0.1.0-rc.2
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/LICENSE +661 -0
- package/README.md +167 -2
- package/dist/chrome/Attribution/Attribution.js +304 -0
- package/dist/chrome/Attribution/Attribution.js.map +1 -0
- package/dist/chrome/Attribution/Attribution.styles.js +10 -0
- package/dist/chrome/Attribution/Attribution.styles.js.map +1 -0
- package/dist/chrome/Attribution/AttributionSkeleton.js +29 -0
- package/dist/chrome/Attribution/AttributionSkeleton.js.map +1 -0
- package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js +83 -0
- package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js.map +1 -0
- package/dist/chrome/EndStack/EndStack.js +157 -0
- package/dist/chrome/EndStack/EndStack.js.map +1 -0
- package/dist/chrome/EndStack/EndStack.styles.js +12 -0
- package/dist/chrome/EndStack/EndStack.styles.js.map +1 -0
- package/dist/chrome/EndStack/EndStackSkeleton.js +78 -0
- package/dist/chrome/EndStack/EndStackSkeleton.js.map +1 -0
- package/dist/chrome/EndStack/endStackHeight.js +22 -0
- package/dist/chrome/EndStack/endStackHeight.js.map +1 -0
- package/dist/chrome/MapChrome/MapChrome.js +488 -0
- package/dist/chrome/MapChrome/MapChrome.js.map +1 -0
- package/dist/chrome/MapChrome/MapChrome.styles.js +15 -0
- package/dist/chrome/MapChrome/MapChrome.styles.js.map +1 -0
- package/dist/chrome/MapChrome/chromeSurface.js +18 -0
- package/dist/chrome/MapChrome/chromeSurface.js.map +1 -0
- package/dist/chrome/MapChrome/chromeVars.js +71 -0
- package/dist/chrome/MapChrome/chromeVars.js.map +1 -0
- package/dist/chrome/MapChrome/mapKeyPlacement.js +41 -0
- package/dist/chrome/MapChrome/mapKeyPlacement.js.map +1 -0
- package/dist/chrome/MapChrome/sharesWidth.js +13 -0
- package/dist/chrome/MapChrome/sharesWidth.js.map +1 -0
- package/dist/chrome/MapReadout/MapReadout.js +199 -0
- package/dist/chrome/MapReadout/MapReadout.js.map +1 -0
- package/dist/chrome/MapReadout/MapReadout.styles.js +14 -0
- package/dist/chrome/MapReadout/MapReadout.styles.js.map +1 -0
- package/dist/chrome/Sheet/Sheet.js +412 -0
- package/dist/chrome/Sheet/Sheet.js.map +1 -0
- package/dist/chrome/Sheet/Sheet.styles.js +14 -0
- package/dist/chrome/Sheet/Sheet.styles.js.map +1 -0
- package/dist/chrome/focusRegistry.js +76 -0
- package/dist/chrome/focusRegistry.js.map +1 -0
- package/dist/chrome/layoutContext.js +30 -0
- package/dist/chrome/layoutContext.js.map +1 -0
- package/dist/chrome/useScrollEdges.js +53 -0
- package/dist/chrome/useScrollEdges.js.map +1 -0
- package/dist/host/MapContext.js +16 -0
- package/dist/host/MapContext.js.map +1 -0
- package/dist/host/MapView.js +189 -0
- package/dist/host/MapView.js.map +1 -0
- package/dist/host/MapView.styles.js +16 -0
- package/dist/host/MapView.styles.js.map +1 -0
- package/dist/host/overlays/AccuracyCircle.js +36 -0
- package/dist/host/overlays/AccuracyCircle.js.map +1 -0
- package/dist/host/overlays/CentreCrosshair.js +40 -0
- package/dist/host/overlays/CentreCrosshair.js.map +1 -0
- package/dist/host/overlays/DrawOverlay.js +221 -0
- package/dist/host/overlays/DrawOverlay.js.map +1 -0
- package/dist/host/overlays/MapOverlayLayer.js +27 -0
- package/dist/host/overlays/MapOverlayLayer.js.map +1 -0
- package/dist/host/overlays/MeasureOverlay.js +87 -0
- package/dist/host/overlays/MeasureOverlay.js.map +1 -0
- package/dist/host/overlays/PinMarker.js +40 -0
- package/dist/host/overlays/PinMarker.js.map +1 -0
- package/dist/host/overlays/geometry.js +41 -0
- package/dist/host/overlays/geometry.js.map +1 -0
- package/dist/host/overlays/overlays.styles.js +27 -0
- package/dist/host/overlays/overlays.styles.js.map +1 -0
- package/dist/host/pointerTargets.js +22 -0
- package/dist/host/pointerTargets.js.map +1 -0
- package/dist/host/useLongPress.js +102 -0
- package/dist/host/useLongPress.js.map +1 -0
- package/dist/host/useMapEngine.js +352 -0
- package/dist/host/useMapEngine.js.map +1 -0
- package/dist/host/usePointerPosition.js +60 -0
- package/dist/host/usePointerPosition.js.map +1 -0
- package/dist/index.d.ts +3845 -0
- package/dist/index.js +89 -0
- package/dist/layers/CatalogueStatus.js +138 -0
- package/dist/layers/CatalogueStatus.js.map +1 -0
- package/dist/layers/DateTimeControl.js +101 -0
- package/dist/layers/DateTimeControl.js.map +1 -0
- package/dist/layers/FeatureCard.js +147 -0
- package/dist/layers/FeatureCard.js.map +1 -0
- package/dist/layers/FeatureChoices.js +101 -0
- package/dist/layers/FeatureChoices.js.map +1 -0
- package/dist/layers/FeatureGlyph.js +56 -0
- package/dist/layers/FeatureGlyph.js.map +1 -0
- package/dist/layers/IdentifyStatus.js +36 -0
- package/dist/layers/IdentifyStatus.js.map +1 -0
- package/dist/layers/LayerItem.js +321 -0
- package/dist/layers/LayerItem.js.map +1 -0
- package/dist/layers/LayerKey.js +36 -0
- package/dist/layers/LayerKey.js.map +1 -0
- package/dist/layers/Layers.styles.js +50 -0
- package/dist/layers/Layers.styles.js.map +1 -0
- package/dist/layers/LayersSection.js +267 -0
- package/dist/layers/LayersSection.js.map +1 -0
- package/dist/layers/MapDataLayers.js +261 -0
- package/dist/layers/MapDataLayers.js.map +1 -0
- package/dist/layers/MapKey.js +131 -0
- package/dist/layers/MapKey.js.map +1 -0
- package/dist/layers/MapKey.styles.js +16 -0
- package/dist/layers/MapKey.styles.js.map +1 -0
- package/dist/layers/MarkerGlyph.js +84 -0
- package/dist/layers/MarkerGlyph.js.map +1 -0
- package/dist/layers/SelectionProvider.js +27 -0
- package/dist/layers/SelectionProvider.js.map +1 -0
- package/dist/layers/ShapeGlyph.js +122 -0
- package/dist/layers/ShapeGlyph.js.map +1 -0
- package/dist/layers/TurnOffActions.js +147 -0
- package/dist/layers/TurnOffActions.js.map +1 -0
- package/dist/layers/answersTap.js +16 -0
- package/dist/layers/answersTap.js.map +1 -0
- package/dist/layers/catalogueNotice.js +65 -0
- package/dist/layers/catalogueNotice.js.map +1 -0
- package/dist/layers/catalogueReconcile.js +55 -0
- package/dist/layers/catalogueReconcile.js.map +1 -0
- package/dist/layers/catalogueView.js +32 -0
- package/dist/layers/catalogueView.js.map +1 -0
- package/dist/layers/featureTitle.js +14 -0
- package/dist/layers/featureTitle.js.map +1 -0
- package/dist/layers/identifyFeedback.js +30 -0
- package/dist/layers/identifyFeedback.js.map +1 -0
- package/dist/layers/identifyRun.js +148 -0
- package/dist/layers/identifyRun.js.map +1 -0
- package/dist/layers/layerStatus.js +13 -0
- package/dist/layers/layerStatus.js.map +1 -0
- package/dist/layers/loadOutcome.js +107 -0
- package/dist/layers/loadOutcome.js.map +1 -0
- package/dist/layers/loadReport.js +33 -0
- package/dist/layers/loadReport.js.map +1 -0
- package/dist/layers/loadRequests.js +73 -0
- package/dist/layers/loadRequests.js.map +1 -0
- package/dist/layers/mapFeatures.js +307 -0
- package/dist/layers/mapFeatures.js.map +1 -0
- package/dist/layers/mapKeyBlocks.js +24 -0
- package/dist/layers/mapKeyBlocks.js.map +1 -0
- package/dist/layers/reveal.js +119 -0
- package/dist/layers/reveal.js.map +1 -0
- package/dist/layers/selectionMessages.js +53 -0
- package/dist/layers/selectionMessages.js.map +1 -0
- package/dist/layers/selectionResolve.js +111 -0
- package/dist/layers/selectionResolve.js.map +1 -0
- package/dist/layers/useDataLayers.js +940 -0
- package/dist/layers/useDataLayers.js.map +1 -0
- package/dist/layers/useFeatureSelection.js +179 -0
- package/dist/layers/useFeatureSelection.js.map +1 -0
- package/dist/layers/useScrolls.js +37 -0
- package/dist/layers/useScrolls.js.map +1 -0
- package/dist/panels/BasemapPicker/BasemapPicker.js +169 -0
- package/dist/panels/BasemapPicker/BasemapPicker.js.map +1 -0
- package/dist/panels/BasemapPicker/BasemapPicker.styles.js +42 -0
- package/dist/panels/BasemapPicker/BasemapPicker.styles.js.map +1 -0
- package/dist/panels/ExportSection/ExportSection.js +91 -0
- package/dist/panels/ExportSection/ExportSection.js.map +1 -0
- package/dist/panels/HelpSection/HelpSection.js +163 -0
- package/dist/panels/HelpSection/HelpSection.js.map +1 -0
- package/dist/panels/HelpSection/HelpSection.styles.js +9 -0
- package/dist/panels/HelpSection/HelpSection.styles.js.map +1 -0
- package/dist/panels/PinSection/PinSection.js +39 -0
- package/dist/panels/PinSection/PinSection.js.map +1 -0
- package/dist/panels/Section/Section.js +43 -0
- package/dist/panels/Section/Section.js.map +1 -0
- package/dist/panels/Section/Section.styles.js +13 -0
- package/dist/panels/Section/Section.styles.js.map +1 -0
- package/dist/panels/SettingsSection/LanguageField.js +126 -0
- package/dist/panels/SettingsSection/LanguageField.js.map +1 -0
- package/dist/panels/SettingsSection/SettingsSection.js +175 -0
- package/dist/panels/SettingsSection/SettingsSection.js.map +1 -0
- package/dist/panels/SettingsSection/SettingsSection.styles.js +9 -0
- package/dist/panels/SettingsSection/SettingsSection.styles.js.map +1 -0
- package/dist/panels/ShapesSection/ShapesSection.js +229 -0
- package/dist/panels/ShapesSection/ShapesSection.js.map +1 -0
- package/dist/panels/ShapesSection/ShapesSection.styles.js +7 -0
- package/dist/panels/ShapesSection/ShapesSection.styles.js.map +1 -0
- package/dist/panels/SheetContent/SheetContent.js +92 -0
- package/dist/panels/SheetContent/SheetContent.js.map +1 -0
- package/dist/panels/SheetContent/SheetContent.styles.js +6 -0
- package/dist/panels/SheetContent/SheetContent.styles.js.map +1 -0
- package/dist/services/ServicesProvider.js +42 -0
- package/dist/services/ServicesProvider.js.map +1 -0
- package/dist/services/activeMessages.js +140 -0
- package/dist/services/activeMessages.js.map +1 -0
- package/dist/services/basemapAvailability.js +78 -0
- package/dist/services/basemapAvailability.js.map +1 -0
- package/dist/services/englishMessages.js +10 -0
- package/dist/services/englishMessages.js.map +1 -0
- package/dist/services/hooks.js +214 -0
- package/dist/services/hooks.js.map +1 -0
- package/dist/styles.css +2866 -0
- package/dist/styles.css.d.ts +1 -0
- package/dist/tools/Directions/Directions.styles.js +25 -0
- package/dist/tools/Directions/Directions.styles.js.map +1 -0
- package/dist/tools/Directions/DirectionsOverlay.js +46 -0
- package/dist/tools/Directions/DirectionsOverlay.js.map +1 -0
- package/dist/tools/Directions/DirectionsPanel.js +428 -0
- package/dist/tools/Directions/DirectionsPanel.js.map +1 -0
- package/dist/tools/Directions/MapDirections.js +84 -0
- package/dist/tools/Directions/MapDirections.js.map +1 -0
- package/dist/tools/Directions/useDirections.js +226 -0
- package/dist/tools/Directions/useDirections.js.map +1 -0
- package/dist/tools/Directions/useFreeCentre.js +30 -0
- package/dist/tools/Directions/useFreeCentre.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawMapBindings.js +34 -0
- package/dist/tools/DrawToolbar/DrawMapBindings.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawToolbar.js +296 -0
- package/dist/tools/DrawToolbar/DrawToolbar.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawToolbar.styles.js +21 -0
- package/dist/tools/DrawToolbar/DrawToolbar.styles.js.map +1 -0
- package/dist/tools/DrawToolbar/imageDrawing.js +24 -0
- package/dist/tools/DrawToolbar/imageDrawing.js.map +1 -0
- package/dist/tools/DrawToolbar/useDraw.js +543 -0
- package/dist/tools/DrawToolbar/useDraw.js.map +1 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.js +116 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.js.map +1 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js +12 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js.map +1 -0
- package/dist/tools/MeasureToolbar/useMeasure.js +75 -0
- package/dist/tools/MeasureToolbar/useMeasure.js.map +1 -0
- package/dist/tools/PinCard/PinCard.js +174 -0
- package/dist/tools/PinCard/PinCard.js.map +1 -0
- package/dist/tools/PinCard/PinCard.styles.js +16 -0
- package/dist/tools/PinCard/PinCard.styles.js.map +1 -0
- package/dist/tools/PinCard/useReverseAddress.js +77 -0
- package/dist/tools/PinCard/useReverseAddress.js.map +1 -0
- package/dist/tools/SearchPill/SearchPill.js +292 -0
- package/dist/tools/SearchPill/SearchPill.js.map +1 -0
- package/dist/tools/SearchPill/SearchPill.styles.js +16 -0
- package/dist/tools/SearchPill/SearchPill.styles.js.map +1 -0
- package/dist/tools/SearchPill/SearchPillSkeleton.js +41 -0
- package/dist/tools/SearchPill/SearchPillSkeleton.js.map +1 -0
- package/dist/tools/SearchPill/useSearch.js +143 -0
- package/dist/tools/SearchPill/useSearch.js.map +1 -0
- package/dist/tools/SearchPill/useSuggestions.js +105 -0
- package/dist/tools/SearchPill/useSuggestions.js.map +1 -0
- package/dist/tools/Tour/TourCard.js +156 -0
- package/dist/tools/Tour/TourCard.js.map +1 -0
- package/dist/tools/Tour/TourCard.styles.js +10 -0
- package/dist/tools/Tour/TourCard.styles.js.map +1 -0
- package/dist/tools/Tour/useTour.js +110 -0
- package/dist/tools/Tour/useTour.js.map +1 -0
- package/dist/tools/locate/useLocate.js +94 -0
- package/dist/tools/locate/useLocate.js.map +1 -0
- package/dist/ui/Button/Button.js +36 -0
- package/dist/ui/Button/Button.js.map +1 -0
- package/dist/ui/Button/Button.styles.js +17 -0
- package/dist/ui/Button/Button.styles.js.map +1 -0
- package/dist/ui/Chip/Chip.js +37 -0
- package/dist/ui/Chip/Chip.js.map +1 -0
- package/dist/ui/Chip/Chip.styles.js +29 -0
- package/dist/ui/Chip/Chip.styles.js.map +1 -0
- package/dist/ui/ControlGroup/ControlGroup.js +23 -0
- package/dist/ui/ControlGroup/ControlGroup.js.map +1 -0
- package/dist/ui/ControlGroup/ControlGroup.styles.js +6 -0
- package/dist/ui/ControlGroup/ControlGroup.styles.js.map +1 -0
- package/dist/ui/EmptyState/EmptyState.js +37 -0
- package/dist/ui/EmptyState/EmptyState.js.map +1 -0
- package/dist/ui/EmptyState/EmptyState.styles.js +10 -0
- package/dist/ui/EmptyState/EmptyState.styles.js.map +1 -0
- package/dist/ui/Icon/Icon.js +28 -0
- package/dist/ui/Icon/Icon.js.map +1 -0
- package/dist/ui/Icon/Icon.styles.js +8 -0
- package/dist/ui/Icon/Icon.styles.js.map +1 -0
- package/dist/ui/IconButton/IconButton.js +47 -0
- package/dist/ui/IconButton/IconButton.js.map +1 -0
- package/dist/ui/IconButton/IconButton.styles.js +27 -0
- package/dist/ui/IconButton/IconButton.styles.js.map +1 -0
- package/dist/ui/Isolate/Isolate.js +26 -0
- package/dist/ui/Isolate/Isolate.js.map +1 -0
- package/dist/ui/Isolate/fillSlots.js +27 -0
- package/dist/ui/Isolate/fillSlots.js.map +1 -0
- package/dist/ui/ListRow/ListRow.js +59 -0
- package/dist/ui/ListRow/ListRow.js.map +1 -0
- package/dist/ui/ListRow/ListRow.styles.js +30 -0
- package/dist/ui/ListRow/ListRow.styles.js.map +1 -0
- package/dist/ui/LiveRegion/LiveRegion.js +88 -0
- package/dist/ui/LiveRegion/LiveRegion.js.map +1 -0
- package/dist/ui/LiveRegion/announcer.js +114 -0
- package/dist/ui/LiveRegion/announcer.js.map +1 -0
- package/dist/ui/SegmentedControl/SegmentedControl.js +55 -0
- package/dist/ui/SegmentedControl/SegmentedControl.js.map +1 -0
- package/dist/ui/SegmentedControl/SegmentedControl.styles.js +9 -0
- package/dist/ui/SegmentedControl/SegmentedControl.styles.js.map +1 -0
- package/dist/ui/SkipLink/SkipLink.js +35 -0
- package/dist/ui/SkipLink/SkipLink.js.map +1 -0
- package/dist/ui/SkipLink/SkipLink.styles.js +6 -0
- package/dist/ui/SkipLink/SkipLink.styles.js.map +1 -0
- package/dist/ui/Slider/Slider.js +68 -0
- package/dist/ui/Slider/Slider.js.map +1 -0
- package/dist/ui/Slider/Slider.styles.js +13 -0
- package/dist/ui/Slider/Slider.styles.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessage.js +124 -0
- package/dist/ui/StatusMessage/StatusMessage.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessage.styles.js +28 -0
- package/dist/ui/StatusMessage/StatusMessage.styles.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessageFocus.js +30 -0
- package/dist/ui/StatusMessage/StatusMessageFocus.js.map +1 -0
- package/dist/ui/Surface/Surface.js +22 -0
- package/dist/ui/Surface/Surface.js.map +1 -0
- package/dist/ui/Surface/Surface.styles.js +27 -0
- package/dist/ui/Surface/Surface.styles.js.map +1 -0
- package/dist/ui/Switch/Switch.js +58 -0
- package/dist/ui/Switch/Switch.js.map +1 -0
- package/dist/ui/Switch/Switch.styles.js +13 -0
- package/dist/ui/Switch/Switch.styles.js.map +1 -0
- package/dist/ui/Tooltip/Tooltip.js +66 -0
- package/dist/ui/Tooltip/Tooltip.js.map +1 -0
- package/dist/ui/Tooltip/Tooltip.styles.js +6 -0
- package/dist/ui/Tooltip/Tooltip.styles.js.map +1 -0
- package/dist/ui/Tooltip/inheritColours.js +27 -0
- package/dist/ui/Tooltip/inheritColours.js.map +1 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.js +16 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.js.map +1 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js +6 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js.map +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { feedUrl, isQueryLayer, layerZoomLimit, loadsFeatures, nextQueryWindow } from "@mapcairn/core";
|
|
2
|
+
// src/layers/loadRequests.ts
|
|
3
|
+
/** Whether a query layer is too far out for the view to ask for features. */
|
|
4
|
+
function isTooFarOut(definition, view) {
|
|
5
|
+
return isQueryLayer(definition) && viewZoomLimit(definition, view) !== null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Which way to zoom, and to which level, for a layer to show what the view is
|
|
9
|
+
* at, or null when the view is inside its zoom window, it has none or the map
|
|
10
|
+
* has not said where it is.
|
|
11
|
+
*/
|
|
12
|
+
function viewZoomLimit(definition, view) {
|
|
13
|
+
return view === null ? null : layerZoomLimit(definition, view.zoom);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* What each enabled layer that loads features asks for. A query layer asks
|
|
17
|
+
* for a window around the map's view, kept while the view stays inside it,
|
|
18
|
+
* and for nothing until the map has said where it is or while it is too far
|
|
19
|
+
* out. Pure: the window it chose is remembered with {@link rememberWindows}.
|
|
20
|
+
*/
|
|
21
|
+
function wantedLoads(inputs) {
|
|
22
|
+
const { definitions, view, windows, now } = inputs;
|
|
23
|
+
return inputs.enabled.flatMap((id) => {
|
|
24
|
+
const definition = definitions.get(id);
|
|
25
|
+
if (!definition || !loadsFeatures(definition)) return [];
|
|
26
|
+
const controls = inputs.controls[id] ?? {};
|
|
27
|
+
const retries = inputs.retries[id] ?? 0;
|
|
28
|
+
if (!isQueryLayer(definition)) return [{
|
|
29
|
+
id,
|
|
30
|
+
definition,
|
|
31
|
+
key: `${feedUrl(definition, controls, now)}#${retries}`,
|
|
32
|
+
controls
|
|
33
|
+
}];
|
|
34
|
+
if (!view || isTooFarOut(definition, view)) return [];
|
|
35
|
+
const area = nextQueryWindow(windows.get(id) ?? null, view.area);
|
|
36
|
+
return [{
|
|
37
|
+
id,
|
|
38
|
+
definition,
|
|
39
|
+
key: `${feedUrl(definition, controls, now, area)}#${retries}`,
|
|
40
|
+
controls,
|
|
41
|
+
area
|
|
42
|
+
}];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Keeps the window of each query layer that asks for one, and forgets the
|
|
47
|
+
* window of any layer that no longer does (too far out, or off), so it asks
|
|
48
|
+
* afresh when it next has to.
|
|
49
|
+
*/
|
|
50
|
+
function rememberWindows(windows, wanted) {
|
|
51
|
+
windows.clear();
|
|
52
|
+
for (const { id, area } of wanted) if (area) windows.set(id, area);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Works out what has to change for the layers to have what they want. A
|
|
56
|
+
* request is cancelled, or a settled one forgotten, when its key is no
|
|
57
|
+
* longer wanted (including a layer that is no longer wanted at all). A load
|
|
58
|
+
* starts for each wanted request that is neither in flight nor settled, so
|
|
59
|
+
* a layer that has settled is not loaded again because another was turned
|
|
60
|
+
* on or off.
|
|
61
|
+
*/
|
|
62
|
+
function planLoads(wanted, inFlight, settled) {
|
|
63
|
+
const wantedKeys = new Map(wanted.map((load) => [load.id, load.key]));
|
|
64
|
+
const isStale = (id, key) => wantedKeys.get(id) !== key;
|
|
65
|
+
return {
|
|
66
|
+
cancel: [...inFlight].filter(([id, request]) => isStale(id, request.key)).map(([id]) => id),
|
|
67
|
+
forget: [...settled].filter(([id, key]) => isStale(id, key)).map(([id]) => id),
|
|
68
|
+
start: wanted.filter((load) => inFlight.get(load.id)?.key !== load.key && settled.get(load.id) !== load.key)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export { isTooFarOut, planLoads, rememberWindows, viewZoomLimit, wantedLoads };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=loadRequests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadRequests.js","names":[],"sources":["../../src/layers/loadRequests.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type Bounds,\n type ControlValues,\n type FeedLayerDefinition,\n feedUrl,\n type HeatmapLayerDefinition,\n isQueryLayer,\n type LayerDefinition,\n layerZoomLimit,\n loadsFeatures,\n nextQueryWindow,\n type ZoomLimit,\n} from \"@mapcairn/core\";\n\n/** What the map last showed, which a query layer asks for features around. */\nexport interface QueryView {\n readonly area: Bounds;\n /** The normalised zoom. */\n readonly zoom: number;\n}\n\n/** A layer whose features are loaded, from a feed or a query. */\nexport type LoadableLayer = FeedLayerDefinition | HeatmapLayerDefinition;\n\n/** One load a layer asks for, and the key that says when it has changed. */\nexport interface WantedLoad {\n readonly id: string;\n readonly definition: LoadableLayer;\n /** The request's URL and the layer's retry count: a new key is a new load. */\n readonly key: string;\n /** Every control's value, resolved against the definition. */\n readonly controls: ControlValues;\n /** The window a query layer asks for. Absent for a feed. */\n readonly area?: Bounds;\n}\n\n/** What {@link wantedLoads} reads to work out what the enabled layers ask for. */\nexport interface LoadInputs {\n /** The enabled layers' ids. */\n readonly enabled: readonly string[];\n readonly definitions: ReadonlyMap<string, LayerDefinition>;\n readonly controls: Readonly<Record<string, ControlValues>>;\n readonly retries: Readonly<Record<string, number>>;\n readonly view: QueryView | null;\n /** The window each query layer last asked for, kept while the view stays inside it. */\n readonly windows: ReadonlyMap<string, Bounds>;\n /** The clock, in epoch milliseconds. */\n readonly now: number;\n}\n\n/** What {@link planLoads} decides to do about the loads the layers want. */\nexport interface LoadPlan {\n /** Layers whose request in flight is for something that is no longer wanted. */\n readonly cancel: readonly string[];\n /** Layers whose settled request is for something that is no longer wanted. */\n readonly forget: readonly string[];\n /** Layers with no request in flight or settled for what they want now. */\n readonly start: readonly WantedLoad[];\n}\n\n/** Whether a query layer is too far out for the view to ask for features. */\nexport function isTooFarOut(\n definition: LayerDefinition,\n view: QueryView | null,\n): boolean {\n return isQueryLayer(definition) && viewZoomLimit(definition, view) !== null;\n}\n\n/**\n * Which way to zoom, and to which level, for a layer to show what the view is\n * at, or null when the view is inside its zoom window, it has none or the map\n * has not said where it is.\n */\nexport function viewZoomLimit(\n definition: LayerDefinition,\n view: QueryView | null,\n): ZoomLimit | null {\n return view === null ? null : layerZoomLimit(definition, view.zoom);\n}\n\n/**\n * What each enabled layer that loads features asks for. A query layer asks\n * for a window around the map's view, kept while the view stays inside it,\n * and for nothing until the map has said where it is or while it is too far\n * out. Pure: the window it chose is remembered with {@link rememberWindows}.\n */\nexport function wantedLoads(inputs: LoadInputs): WantedLoad[] {\n const { definitions, view, windows, now } = inputs;\n return inputs.enabled.flatMap((id): WantedLoad[] => {\n const definition = definitions.get(id);\n if (!definition || !loadsFeatures(definition)) {\n return [];\n }\n const controls = inputs.controls[id] ?? {};\n const retries = inputs.retries[id] ?? 0;\n if (!isQueryLayer(definition)) {\n const key = `${feedUrl(definition, controls, now)}#${retries}`;\n return [{ id, definition, key, controls }];\n }\n if (!view || isTooFarOut(definition, view)) {\n return [];\n }\n const area = nextQueryWindow(windows.get(id) ?? null, view.area);\n const key = `${feedUrl(definition, controls, now, area)}#${retries}`;\n return [{ id, definition, key, controls, area }];\n });\n}\n\n/**\n * Keeps the window of each query layer that asks for one, and forgets the\n * window of any layer that no longer does (too far out, or off), so it asks\n * afresh when it next has to.\n */\nexport function rememberWindows(\n windows: Map<string, Bounds>,\n wanted: readonly WantedLoad[],\n): void {\n windows.clear();\n for (const { id, area } of wanted) {\n if (area) {\n windows.set(id, area);\n }\n }\n}\n\n/**\n * Works out what has to change for the layers to have what they want. A\n * request is cancelled, or a settled one forgotten, when its key is no\n * longer wanted (including a layer that is no longer wanted at all). A load\n * starts for each wanted request that is neither in flight nor settled, so\n * a layer that has settled is not loaded again because another was turned\n * on or off.\n */\nexport function planLoads(\n wanted: readonly WantedLoad[],\n inFlight: ReadonlyMap<string, { readonly key: string }>,\n settled: ReadonlyMap<string, string>,\n): LoadPlan {\n const wantedKeys = new Map(wanted.map((load) => [load.id, load.key]));\n const isStale = (id: string, key: string) => wantedKeys.get(id) !== key;\n return {\n cancel: [...inFlight]\n .filter(([id, request]) => isStale(id, request.key))\n .map(([id]) => id),\n forget: [...settled]\n .filter(([id, key]) => isStale(id, key))\n .map(([id]) => id),\n start: wanted.filter(\n (load) =>\n inFlight.get(load.id)?.key !== load.key &&\n settled.get(load.id) !== load.key,\n ),\n };\n}\n"],"mappings":";;;AA+DA,SAAgB,YACd,YACA,MACS;CACT,OAAO,aAAa,UAAU,KAAK,cAAc,YAAY,IAAI,MAAM;AACzE;;;;;;AAOA,SAAgB,cACd,YACA,MACkB;CAClB,OAAO,SAAS,OAAO,OAAO,eAAe,YAAY,KAAK,IAAI;AACpE;;;;;;;AAQA,SAAgB,YAAY,QAAkC;CAC5D,MAAM,EAAE,aAAa,MAAM,SAAS,QAAQ;CAC5C,OAAO,OAAO,QAAQ,SAAS,OAAqB;EAClD,MAA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AE,QAAQ,KAAK,OACpC,QAAQ,IAAI,KAAK,EAAE,MAAM,KAAK,GAClC;CACF;AACF"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { boundsOfPoints, evaluatePointStyle, formatTemplate, heatmapOpacity, heatmapSettings, shapeAppearances, shapeEvaluator, tileUrl } from "@mapcairn/core";
|
|
2
|
+
import { tokenValues } from "@mapcairn/theme";
|
|
3
|
+
// src/layers/mapFeatures.ts
|
|
4
|
+
var PALETTE = tokenValues.dataPalette;
|
|
5
|
+
/**
|
|
6
|
+
* The hex value of a palette slot. Definitions name slots, `@mapcairn/theme`
|
|
7
|
+
* holds the values, and the definition schema only accepts slots that exist,
|
|
8
|
+
* so a missing value is a wiring bug.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
function paletteColour(slot) {
|
|
13
|
+
const colour = PALETTE[slot];
|
|
14
|
+
if (colour === void 0) throw new Error(`The data palette has no colour "${slot}".`);
|
|
15
|
+
return colour;
|
|
16
|
+
}
|
|
17
|
+
/** Every position of a geometry, in any nesting. */
|
|
18
|
+
function positionsOf(geometry) {
|
|
19
|
+
switch (geometry.type) {
|
|
20
|
+
case "Point": return [{
|
|
21
|
+
lng: geometry.coordinates[0],
|
|
22
|
+
lat: geometry.coordinates[1]
|
|
23
|
+
}];
|
|
24
|
+
case "LineString": return geometry.coordinates.map(([lng, lat]) => ({
|
|
25
|
+
lat,
|
|
26
|
+
lng
|
|
27
|
+
}));
|
|
28
|
+
case "MultiLineString":
|
|
29
|
+
case "Polygon": return geometry.coordinates.flatMap((line) => line.map(([lng, lat]) => ({
|
|
30
|
+
lat,
|
|
31
|
+
lng
|
|
32
|
+
})));
|
|
33
|
+
case "MultiPolygon": return geometry.coordinates.flatMap((rings) => rings.flatMap((ring) => ring.map(([lng, lat]) => ({
|
|
34
|
+
lat,
|
|
35
|
+
lng
|
|
36
|
+
}))));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The most vertices one ring or line contributes to an outline drawn over the map. */
|
|
40
|
+
var MAX_OUTLINE_POINTS = 400;
|
|
41
|
+
/** Keeps at most `limit` evenly spread positions, always the first and the last. */
|
|
42
|
+
function thin(positions, limit) {
|
|
43
|
+
if (positions.length <= limit) return [...positions];
|
|
44
|
+
const step = (positions.length - 1) / (limit - 1);
|
|
45
|
+
return Array.from({ length: limit }, (_, index) => positions[Math.round(index * step)]);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The rings and lines of a polygon or line feature, thinned so an outline
|
|
49
|
+
* drawn from them over the map stays cheap to redraw while the map moves. A
|
|
50
|
+
* point has none.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
function featureOutlines(feature) {
|
|
55
|
+
const { geometry } = feature;
|
|
56
|
+
const toPoints = (line) => thin(line.map(([lng, lat]) => ({
|
|
57
|
+
lat,
|
|
58
|
+
lng
|
|
59
|
+
})), 400);
|
|
60
|
+
switch (geometry.type) {
|
|
61
|
+
case "Point": return [];
|
|
62
|
+
case "LineString": return [{
|
|
63
|
+
points: toPoints(geometry.coordinates),
|
|
64
|
+
closed: false
|
|
65
|
+
}];
|
|
66
|
+
case "MultiLineString": return geometry.coordinates.map((line) => ({
|
|
67
|
+
points: toPoints(line),
|
|
68
|
+
closed: false
|
|
69
|
+
}));
|
|
70
|
+
case "Polygon": return geometry.coordinates.map((ring) => ({
|
|
71
|
+
points: toPoints(ring),
|
|
72
|
+
closed: true
|
|
73
|
+
}));
|
|
74
|
+
case "MultiPolygon": return geometry.coordinates.flatMap((rings) => rings.map((ring) => ({
|
|
75
|
+
points: toPoints(ring),
|
|
76
|
+
closed: true
|
|
77
|
+
})));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The box around a feature's geometry, or null when it has no coordinates.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
function featureBounds(feature) {
|
|
86
|
+
const positions = positionsOf(feature.geometry);
|
|
87
|
+
return boundsOfPoints(positions) ?? null;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Where a feature is: a point's own position, and for a polygon or line the
|
|
91
|
+
* centre of its box. Null when the geometry has no coordinates.
|
|
92
|
+
*
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
function featurePosition(feature) {
|
|
96
|
+
const bounds = featureBounds(feature);
|
|
97
|
+
return bounds ? {
|
|
98
|
+
lat: (bounds.south + bounds.north) / 2,
|
|
99
|
+
lng: (bounds.west + bounds.east) / 2
|
|
100
|
+
} : null;
|
|
101
|
+
}
|
|
102
|
+
function toMapLook(look) {
|
|
103
|
+
return {
|
|
104
|
+
colour: paletteColour(look.colour),
|
|
105
|
+
fillOpacity: look.fillOpacity,
|
|
106
|
+
pattern: look.pattern,
|
|
107
|
+
dash: look.dash,
|
|
108
|
+
width: look.width
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Turns a shape style's colour rule into the rule a vector tile engine
|
|
113
|
+
* evaluates for each feature: categories become cases with the other class
|
|
114
|
+
* as the fallback, and steps and equal intervals become ascending minimums.
|
|
115
|
+
*
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
function toLookRule(style) {
|
|
119
|
+
const classes = shapeAppearances(style).map(toMapLook);
|
|
120
|
+
const at = (index) => classes[index];
|
|
121
|
+
const { colour } = style;
|
|
122
|
+
switch (colour.kind) {
|
|
123
|
+
case "fixed": return {
|
|
124
|
+
kind: "fixed",
|
|
125
|
+
look: at(0)
|
|
126
|
+
};
|
|
127
|
+
case "category": return {
|
|
128
|
+
kind: "category",
|
|
129
|
+
field: colour.field,
|
|
130
|
+
cases: colour.categories.map((category, index) => ({
|
|
131
|
+
value: category.value,
|
|
132
|
+
look: at(index)
|
|
133
|
+
})),
|
|
134
|
+
fallback: at(colour.categories.length)
|
|
135
|
+
};
|
|
136
|
+
case "steps": return {
|
|
137
|
+
kind: "steps",
|
|
138
|
+
field: colour.field,
|
|
139
|
+
steps: colour.steps.map((step, index) => ({
|
|
140
|
+
min: step.min,
|
|
141
|
+
look: at(index)
|
|
142
|
+
}))
|
|
143
|
+
};
|
|
144
|
+
case "intervals": {
|
|
145
|
+
const width = (colour.max - colour.min) / colour.ramp.length;
|
|
146
|
+
return {
|
|
147
|
+
kind: "steps",
|
|
148
|
+
field: colour.field,
|
|
149
|
+
steps: colour.ramp.map((_, index) => ({
|
|
150
|
+
min: colour.min + index * width,
|
|
151
|
+
look: at(index)
|
|
152
|
+
}))
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** The engine's source for a definition's vector tiles, with the tile URL filled from the controls. */
|
|
158
|
+
function toMapSource(definition, controls, now) {
|
|
159
|
+
return {
|
|
160
|
+
tiles: tileUrl(definition, controls, now),
|
|
161
|
+
minzoom: definition.source.minzoom ?? 0,
|
|
162
|
+
maxzoom: definition.source.maxzoom
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The vector tile layer for the polygon and line source layers of a
|
|
167
|
+
* definition, with each rule, window and label worked out. Heatmap source
|
|
168
|
+
* layers are drawn separately (see {@link toVectorHeatmaps}).
|
|
169
|
+
*
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
function toMapVector(definition, controls, now) {
|
|
173
|
+
return {
|
|
174
|
+
source: toMapSource(definition, controls, now),
|
|
175
|
+
layers: definition.sourceLayers.flatMap((layer) => {
|
|
176
|
+
if ("heatmap" in layer) return [];
|
|
177
|
+
const { style } = layer;
|
|
178
|
+
return [{
|
|
179
|
+
sourceLayer: layer.sourceLayer,
|
|
180
|
+
geometry: style.geometry,
|
|
181
|
+
rule: toLookRule(style),
|
|
182
|
+
...layer.minzoom !== void 0 ? { minzoom: layer.minzoom } : {},
|
|
183
|
+
...layer.maxzoom !== void 0 ? { maxzoom: layer.maxzoom } : {},
|
|
184
|
+
...style.label ? { label: {
|
|
185
|
+
field: style.label.template.slice(1, -1),
|
|
186
|
+
...style.label.minzoom !== void 0 ? { minzoom: style.label.minzoom } : {}
|
|
187
|
+
} } : {}
|
|
188
|
+
}];
|
|
189
|
+
}),
|
|
190
|
+
...definition.minzoom !== void 0 ? { minzoom: definition.minzoom } : {},
|
|
191
|
+
...definition.maxzoom !== void 0 ? { maxzoom: definition.maxzoom } : {}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function heatmapStyle(definition, spec, controls) {
|
|
195
|
+
return {
|
|
196
|
+
...heatmapSettings(spec, controls),
|
|
197
|
+
opacity: heatmapOpacity(definition, controls),
|
|
198
|
+
ramp: spec.ramp.map(paletteColour)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A heatmap of a feed or query layer's points, weighted by its weight field.
|
|
203
|
+
*
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
function toMapHeatmap(definition, features, controls) {
|
|
207
|
+
const { weightField } = definition.heatmap;
|
|
208
|
+
return {
|
|
209
|
+
source: {
|
|
210
|
+
kind: "points",
|
|
211
|
+
points: features.flatMap((feature) => {
|
|
212
|
+
if (feature.geometry.type !== "Point") return [];
|
|
213
|
+
const raw = weightField ? feature.fields[weightField] : null;
|
|
214
|
+
const [lng, lat] = feature.geometry.coordinates;
|
|
215
|
+
return [{
|
|
216
|
+
position: {
|
|
217
|
+
lat,
|
|
218
|
+
lng
|
|
219
|
+
},
|
|
220
|
+
weight: typeof raw === "number" && Number.isFinite(raw) ? raw : 1
|
|
221
|
+
}];
|
|
222
|
+
})
|
|
223
|
+
},
|
|
224
|
+
style: heatmapStyle(definition, definition.heatmap, controls)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* One heatmap for each heatmap source layer of a vector tile definition, in order.
|
|
229
|
+
*
|
|
230
|
+
* @internal
|
|
231
|
+
*/
|
|
232
|
+
function toVectorHeatmaps(definition, controls, now) {
|
|
233
|
+
return definition.sourceLayers.flatMap((layer) => {
|
|
234
|
+
if (!("heatmap" in layer)) return [];
|
|
235
|
+
return [{
|
|
236
|
+
source: {
|
|
237
|
+
kind: "vector",
|
|
238
|
+
source: toMapSource(definition, controls, now),
|
|
239
|
+
sourceLayer: layer.sourceLayer,
|
|
240
|
+
...layer.heatmap.weightField ? { weightField: layer.heatmap.weightField } : {},
|
|
241
|
+
...layer.minzoom !== void 0 ? { minzoom: layer.minzoom } : {},
|
|
242
|
+
...layer.maxzoom !== void 0 ? { maxzoom: layer.maxzoom } : {}
|
|
243
|
+
},
|
|
244
|
+
style: heatmapStyle(definition, layer.heatmap, controls)
|
|
245
|
+
}];
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Works out how each polygon or line of a feed layer is drawn, with its label
|
|
250
|
+
* text, so the map adapter gets plain colours, widths and patterns and needs
|
|
251
|
+
* no style rule. Features of the geometry the style does not draw are skipped.
|
|
252
|
+
*
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
function toStyledShapes(definition, features, formatters, now, catalogue) {
|
|
256
|
+
const { style } = definition;
|
|
257
|
+
const evaluate = shapeEvaluator(style, catalogue);
|
|
258
|
+
const drawn = style.geometry === "area" ? ["Polygon", "MultiPolygon"] : ["LineString", "MultiLineString"];
|
|
259
|
+
const shapes = features.flatMap((feature) => {
|
|
260
|
+
if (!drawn.includes(feature.geometry.type)) return [];
|
|
261
|
+
const look = evaluate(feature.fields);
|
|
262
|
+
const label = style.label ? formatTemplate(style.label.template, feature.fields, formatters, {
|
|
263
|
+
now,
|
|
264
|
+
catalogue
|
|
265
|
+
}) : null;
|
|
266
|
+
return [{
|
|
267
|
+
id: feature.id,
|
|
268
|
+
geometry: feature.geometry,
|
|
269
|
+
look: {
|
|
270
|
+
colour: paletteColour(look.colour),
|
|
271
|
+
fillOpacity: look.fillOpacity,
|
|
272
|
+
pattern: look.pattern,
|
|
273
|
+
dash: look.dash,
|
|
274
|
+
width: look.width
|
|
275
|
+
},
|
|
276
|
+
...label ? { label } : {}
|
|
277
|
+
}];
|
|
278
|
+
});
|
|
279
|
+
return {
|
|
280
|
+
geometry: style.geometry,
|
|
281
|
+
shapes,
|
|
282
|
+
...style.label?.minzoom !== void 0 ? { labelMinZoom: style.label.minzoom } : {}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Works out how each point of a feed layer is drawn, so the map adapter gets
|
|
287
|
+
* plain colours, sizes and shapes and needs no style rule.
|
|
288
|
+
*
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
function toMapFeatures(style, features) {
|
|
292
|
+
return features.flatMap((feature) => {
|
|
293
|
+
const position = feature.geometry.type === "Point" ? featurePosition(feature) : null;
|
|
294
|
+
if (!position) return [];
|
|
295
|
+
const marker = evaluatePointStyle(style, feature.fields);
|
|
296
|
+
return [{
|
|
297
|
+
id: feature.id,
|
|
298
|
+
position,
|
|
299
|
+
colour: paletteColour(marker.colour),
|
|
300
|
+
radius: marker.radius,
|
|
301
|
+
shape: marker.shape
|
|
302
|
+
}];
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
export { MAX_OUTLINE_POINTS, featureBounds, featureOutlines, featurePosition, paletteColour, toLookRule, toMapFeatures, toMapHeatmap, toMapVector, toStyledShapes, toVectorHeatmaps };
|
|
306
|
+
|
|
307
|
+
//# sourceMappingURL=mapFeatures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapFeatures.js","names":[],"sources":["../../src/layers/mapFeatures.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type Bounds,\n boundsOfPoints,\n type ControlValues,\n evaluatePointStyle,\n type FeedLayerDefinition,\n type FeedShapeStyle,\n type FormatterRegistry,\n formatTemplate,\n type HeatmapLayerDefinition,\n type HeatmapSpec,\n heatmapOpacity,\n heatmapSettings,\n type LatLng,\n type LayerDefinition,\n type LayerFeature,\n type LayerGeometry,\n type MapFeature,\n type MapHeatmap,\n type MapHeatmapStyle,\n type MapLookRule,\n type MapShapeLook,\n type MapStyledShape,\n type MapStyledShapes,\n type MapVectorSourceLayer,\n type MapVectorTiles,\n type MessageCatalogue,\n type PaletteSlot,\n type PointStyle,\n type ShapeAppearance,\n shapeAppearances,\n shapeEvaluator,\n tileUrl,\n type VectorTileLayerDefinition,\n} from \"@mapcairn/core\";\nimport { tokenValues } from \"@mapcairn/theme\";\n\nconst PALETTE: Readonly<Record<string, string>> = tokenValues.dataPalette;\n\n/**\n * The hex value of a palette slot. Definitions name slots, `@mapcairn/theme`\n * holds the values, and the definition schema only accepts slots that exist,\n * so a missing value is a wiring bug.\n *\n * @internal\n */\nexport function paletteColour(slot: PaletteSlot): string {\n const colour = PALETTE[slot];\n if (colour === undefined) {\n throw new Error(`The data palette has no colour \"${slot}\".`);\n }\n return colour;\n}\n\n/** Every position of a geometry, in any nesting. */\nfunction positionsOf(geometry: LayerGeometry): LatLng[] {\n switch (geometry.type) {\n case \"Point\":\n return [{ lng: geometry.coordinates[0], lat: geometry.coordinates[1] }];\n case \"LineString\":\n return geometry.coordinates.map(([lng, lat]) => ({ lat, lng }));\n case \"MultiLineString\":\n case \"Polygon\":\n return geometry.coordinates.flatMap((line) =>\n line.map(([lng, lat]) => ({ lat, lng })),\n );\n case \"MultiPolygon\":\n return geometry.coordinates.flatMap((rings) =>\n rings.flatMap((ring) => ring.map(([lng, lat]) => ({ lat, lng }))),\n );\n }\n}\n\n/** The most vertices one ring or line contributes to an outline drawn over the map. */\nexport const MAX_OUTLINE_POINTS = 400;\n\n/** One ring or line of a feature, ready to draw as a path. */\nexport interface FeatureOutline {\n readonly points: readonly LatLng[];\n /** True for a polygon ring, whose path closes. */\n readonly closed: boolean;\n}\n\n/** Keeps at most `limit` evenly spread positions, always the first and the last. */\nfunction thin(positions: readonly LatLng[], limit: number): LatLng[] {\n if (positions.length <= limit) {\n return [...positions];\n }\n const step = (positions.length - 1) / (limit - 1);\n return Array.from(\n { length: limit },\n (_, index) => positions[Math.round(index * step)] as LatLng,\n );\n}\n\n/**\n * The rings and lines of a polygon or line feature, thinned so an outline\n * drawn from them over the map stays cheap to redraw while the map moves. A\n * point has none.\n *\n * @internal\n */\nexport function featureOutlines(feature: LayerFeature): FeatureOutline[] {\n const { geometry } = feature;\n const toPoints = (line: readonly (readonly [number, number])[]) =>\n thin(\n line.map(([lng, lat]) => ({ lat, lng })),\n MAX_OUTLINE_POINTS,\n );\n switch (geometry.type) {\n case \"Point\":\n return [];\n case \"LineString\":\n return [{ points: toPoints(geometry.coordinates), closed: false }];\n case \"MultiLineString\":\n return geometry.coordinates.map((line) => ({\n points: toPoints(line),\n closed: false,\n }));\n case \"Polygon\":\n return geometry.coordinates.map((ring) => ({\n points: toPoints(ring),\n closed: true,\n }));\n case \"MultiPolygon\":\n return geometry.coordinates.flatMap((rings) =>\n rings.map((ring) => ({ points: toPoints(ring), closed: true })),\n );\n }\n}\n\n/**\n * The box around a feature's geometry, or null when it has no coordinates.\n *\n * @internal\n */\nexport function featureBounds(feature: LayerFeature): Bounds | null {\n const positions = positionsOf(feature.geometry);\n return boundsOfPoints(positions) ?? null;\n}\n\n/**\n * Where a feature is: a point's own position, and for a polygon or line the\n * centre of its box. Null when the geometry has no coordinates.\n *\n * @internal\n */\nexport function featurePosition(feature: LayerFeature): LatLng | null {\n const bounds = featureBounds(feature);\n return bounds\n ? {\n lat: (bounds.south + bounds.north) / 2,\n lng: (bounds.west + bounds.east) / 2,\n }\n : null;\n}\n\nfunction toMapLook(look: ShapeAppearance): MapShapeLook {\n return {\n colour: paletteColour(look.colour),\n fillOpacity: look.fillOpacity,\n pattern: look.pattern,\n dash: look.dash,\n width: look.width,\n };\n}\n\n/**\n * Turns a shape style's colour rule into the rule a vector tile engine\n * evaluates for each feature: categories become cases with the other class\n * as the fallback, and steps and equal intervals become ascending minimums.\n *\n * @internal\n */\nexport function toLookRule(style: FeedShapeStyle): MapLookRule {\n const classes = shapeAppearances(style).map(toMapLook);\n const at = (index: number) => classes[index] as MapShapeLook;\n const { colour } = style;\n switch (colour.kind) {\n case \"fixed\":\n return { kind: \"fixed\", look: at(0) };\n case \"category\":\n return {\n kind: \"category\",\n field: colour.field,\n cases: colour.categories.map((category, index) => ({\n value: category.value,\n look: at(index),\n })),\n fallback: at(colour.categories.length),\n };\n case \"steps\":\n return {\n kind: \"steps\",\n field: colour.field,\n steps: colour.steps.map((step, index) => ({\n min: step.min,\n look: at(index),\n })),\n };\n case \"intervals\": {\n const width = (colour.max - colour.min) / colour.ramp.length;\n return {\n kind: \"steps\",\n field: colour.field,\n steps: colour.ramp.map((_, index) => ({\n min: colour.min + index * width,\n look: at(index),\n })),\n };\n }\n }\n}\n\n/** The engine's source for a definition's vector tiles, with the tile URL filled from the controls. */\nfunction toMapSource(\n definition: VectorTileLayerDefinition,\n controls: ControlValues,\n now: number,\n) {\n return {\n tiles: tileUrl(definition, controls, now),\n minzoom: definition.source.minzoom ?? 0,\n maxzoom: definition.source.maxzoom,\n };\n}\n\n/**\n * The vector tile layer for the polygon and line source layers of a\n * definition, with each rule, window and label worked out. Heatmap source\n * layers are drawn separately (see {@link toVectorHeatmaps}).\n *\n * @internal\n */\nexport function toMapVector(\n definition: VectorTileLayerDefinition,\n controls: ControlValues,\n now: number,\n): MapVectorTiles {\n return {\n source: toMapSource(definition, controls, now),\n layers: definition.sourceLayers.flatMap((layer): MapVectorSourceLayer[] => {\n if (\"heatmap\" in layer) {\n return [];\n }\n const { style } = layer;\n return [\n {\n sourceLayer: layer.sourceLayer,\n geometry: style.geometry,\n rule: toLookRule(style),\n ...(layer.minzoom !== undefined ? { minzoom: layer.minzoom } : {}),\n ...(layer.maxzoom !== undefined ? { maxzoom: layer.maxzoom } : {}),\n ...(style.label\n ? {\n label: {\n field: style.label.template.slice(1, -1),\n ...(style.label.minzoom !== undefined\n ? { minzoom: style.label.minzoom }\n : {}),\n },\n }\n : {}),\n },\n ];\n }),\n ...(definition.minzoom !== undefined\n ? { minzoom: definition.minzoom }\n : {}),\n ...(definition.maxzoom !== undefined\n ? { maxzoom: definition.maxzoom }\n : {}),\n };\n}\n\nfunction heatmapStyle(\n definition: LayerDefinition,\n spec: HeatmapSpec,\n controls: ControlValues,\n): MapHeatmapStyle {\n return {\n ...heatmapSettings(spec, controls),\n opacity: heatmapOpacity(definition, controls),\n ramp: spec.ramp.map(paletteColour),\n };\n}\n\n/**\n * A heatmap of a feed or query layer's points, weighted by its weight field.\n *\n * @internal\n */\nexport function toMapHeatmap(\n definition: HeatmapLayerDefinition,\n features: readonly LayerFeature[],\n controls: ControlValues,\n): MapHeatmap {\n const { weightField } = definition.heatmap;\n return {\n source: {\n kind: \"points\",\n points: features.flatMap((feature) => {\n if (feature.geometry.type !== \"Point\") {\n return [];\n }\n const raw = weightField ? feature.fields[weightField] : null;\n const [lng, lat] = feature.geometry.coordinates;\n return [\n {\n position: { lat, lng },\n weight: typeof raw === \"number\" && Number.isFinite(raw) ? raw : 1,\n },\n ];\n }),\n },\n style: heatmapStyle(definition, definition.heatmap, controls),\n };\n}\n\n/**\n * One heatmap for each heatmap source layer of a vector tile definition, in order.\n *\n * @internal\n */\nexport function toVectorHeatmaps(\n definition: VectorTileLayerDefinition,\n controls: ControlValues,\n now: number,\n): MapHeatmap[] {\n return definition.sourceLayers.flatMap((layer): MapHeatmap[] => {\n if (!(\"heatmap\" in layer)) {\n return [];\n }\n return [\n {\n source: {\n kind: \"vector\",\n source: toMapSource(definition, controls, now),\n sourceLayer: layer.sourceLayer,\n ...(layer.heatmap.weightField\n ? { weightField: layer.heatmap.weightField }\n : {}),\n ...(layer.minzoom !== undefined ? { minzoom: layer.minzoom } : {}),\n ...(layer.maxzoom !== undefined ? { maxzoom: layer.maxzoom } : {}),\n },\n style: heatmapStyle(definition, layer.heatmap, controls),\n },\n ];\n });\n}\n\n/**\n * Works out how each polygon or line of a feed layer is drawn, with its label\n * text, so the map adapter gets plain colours, widths and patterns and needs\n * no style rule. Features of the geometry the style does not draw are skipped.\n *\n * @internal\n */\nexport function toStyledShapes(\n definition: FeedLayerDefinition<FeedShapeStyle>,\n features: readonly LayerFeature[],\n formatters: FormatterRegistry,\n now: number,\n catalogue: MessageCatalogue,\n): MapStyledShapes {\n const { style } = definition;\n const evaluate = shapeEvaluator(style, catalogue);\n const drawn =\n style.geometry === \"area\"\n ? [\"Polygon\", \"MultiPolygon\"]\n : [\"LineString\", \"MultiLineString\"];\n const shapes = features.flatMap((feature): MapStyledShape[] => {\n if (!drawn.includes(feature.geometry.type)) {\n return [];\n }\n const look = evaluate(feature.fields);\n const label = style.label\n ? formatTemplate(style.label.template, feature.fields, formatters, {\n now,\n catalogue,\n })\n : null;\n return [\n {\n id: feature.id,\n geometry: feature.geometry,\n look: {\n colour: paletteColour(look.colour),\n fillOpacity: look.fillOpacity,\n pattern: look.pattern,\n dash: look.dash,\n width: look.width,\n },\n ...(label ? { label } : {}),\n },\n ];\n });\n return {\n geometry: style.geometry,\n shapes,\n ...(style.label?.minzoom !== undefined\n ? { labelMinZoom: style.label.minzoom }\n : {}),\n };\n}\n\n/**\n * Works out how each point of a feed layer is drawn, so the map adapter gets\n * plain colours, sizes and shapes and needs no style rule.\n *\n * @internal\n */\nexport function toMapFeatures(\n style: PointStyle,\n features: readonly LayerFeature[],\n): MapFeature[] {\n return features.flatMap((feature) => {\n const position =\n feature.geometry.type === \"Point\" ? featurePosition(feature) : null;\n if (!position) {\n return [];\n }\n const marker = evaluatePointStyle(style, feature.fields);\n return [\n {\n id: feature.id,\n position,\n colour: paletteColour(marker.colour),\n radius: marker.radius,\n shape: marker.shape,\n },\n ];\n });\n}\n"],"mappings":";;;AAuCA,IAAM,UAA4C,YAAY;;;;;;;;AAS9D,SAAgB,cAAc,MAA2B;CACvD,MAAM,SAAS,QAAQ;CACvB,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,mCAAmC,KAAK,GAAG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,QAAQ,SAAS,IAAI,GACvC,OAAO,CAAC;EAEV,MAAM,OAAO,SAAS,QAAQ,MAAM;EACpC,MAAM,QAAQ,MAAM,QAChB,eAAe,MAAM,MAAM,UAAU,QAAQ,QAAQ,YAAY;GAC/D;GACA;EACF,CAAC,IACD;EACJ,OAAO,CACL;GACE,IAAI,QAAQ;GACZ,UAAU,QAAQ;GAClB,MAAM;IACJ,QAAQ,cAAc,KAAK,MAAM;IACjC,aAAa,KAAK;IAClB,SAAS,KAAK;IACd,MAAM,KAAK;IACX,OAAO,KAAK;GACd;GACA,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAC3B,CACF;CACF,CAAC;CACD,OAAO;EACL,UAAU,MAAM;EAChB;EACA,GAAI,MAAM,OAAO,YAAY,KAAA,IACzB,EAAE,cAAc,MAAM,MAAM,QAAQ,IACpC,CAAC;CACP;AACF;;;;;;;AAQA,SAAgB,cACd,OACA,UACc;CACd,OAAO,SAAS,SAAS,YAAY;EACnC,MAAM,WACJ,QAAQ,SAAS,SAAS,UAAU,gBAAgB,OAAO,IAAI;EACjE,IAAI,CAAC,UACH,OAAO,CAAC;EAEV,MAAM,SAAS,mBAAmB,OAAO,QAAQ,MAAM;EACvD,OAAO,CACL;GACE,IAAI,QAAQ;GACZ;GACA,QAAQ,cAAc,OAAO,MAAM;GACnC,QAAQ,OAAO;GACf,OAAO,OAAO;EAChB,CACF;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describeChosenTime, legendFor, resolveText } from "@mapcairn/core";
|
|
2
|
+
// src/layers/mapKeyBlocks.ts
|
|
3
|
+
/**
|
|
4
|
+
* The blocks of the map key: one for each layer that is on and has a key, in
|
|
5
|
+
* catalogue order. Pure, so the image export can draw the same key the map
|
|
6
|
+
* shows. The words for an interval are written in `catalogue`'s language.
|
|
7
|
+
* An empty result means there is no key to show at all.
|
|
8
|
+
*/
|
|
9
|
+
function mapKeyBlocks(layers, catalogue) {
|
|
10
|
+
return layers.flatMap(({ definition, enabled, controls }) => {
|
|
11
|
+
const [first, ...rest] = legendFor(definition, catalogue).entries;
|
|
12
|
+
if (!enabled || first === void 0) return [];
|
|
13
|
+
return [{
|
|
14
|
+
id: definition.id,
|
|
15
|
+
name: resolveText(catalogue, definition.name),
|
|
16
|
+
definition,
|
|
17
|
+
entries: [first, ...rest],
|
|
18
|
+
chosenTime: describeChosenTime(definition, controls)
|
|
19
|
+
}];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export { mapKeyBlocks };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=mapKeyBlocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapKeyBlocks.js","names":[],"sources":["../../src/layers/mapKeyBlocks.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n describeChosenTime,\n type LayerDefinition,\n type LegendEntry,\n legendFor,\n type Message,\n type MessageCatalogue,\n resolveText,\n} from \"@mapcairn/core\";\nimport type { DataLayerState } from \"./useDataLayers\";\n\n/** What the map key shows for one layer that is on. */\nexport interface MapKeyBlock {\n readonly id: string;\n readonly name: string;\n readonly definition: LayerDefinition;\n /** The key's rows, in the order the layer's style lists them. Never empty. */\n readonly entries: readonly [LegendEntry, ...LegendEntry[]];\n /**\n * The day or time the layer is set to, in words such as `13:00 UTC on 11\n * November 2026`, or null when it has no date or time control.\n */\n readonly chosenTime: Message | null;\n}\n\n/**\n * The blocks of the map key: one for each layer that is on and has a key, in\n * catalogue order. Pure, so the image export can draw the same key the map\n * shows. The words for an interval are written in `catalogue`'s language.\n * An empty result means there is no key to show at all.\n */\nexport function mapKeyBlocks(\n layers: readonly DataLayerState[],\n catalogue: MessageCatalogue,\n): readonly MapKeyBlock[] {\n return layers.flatMap(({ definition, enabled, controls }) => {\n const [first, ...rest] = legendFor(definition, catalogue).entries;\n if (!enabled || first === undefined) {\n return [];\n }\n return [\n {\n id: definition.id,\n name: resolveText(catalogue, definition.name),\n definition,\n entries: [first, ...rest],\n chosenTime: describeChosenTime(definition, controls),\n },\n ];\n });\n}\n"],"mappings":";;;;;;;;AAiCA,SAAgB,aACd,QACA,WACwB;CACxB,OAAO,OAAO,SAAS,EAAE,YAAY,SAAS,eAAe;EAC3D,MAAM,CAAC,OAAO,GAAG,QAAQ,UAAU,YAAY,SAAS,CAAC,CAAC;EAC1D,IAAI,CAAC,WAAW,UAAU,KAAA,GACxB,OAAO,CAAC;EAEV,OAAO,CACL;GACE,IAAI,WAAW;GACf,MAAM,YAAY,WAAW,WAAW,IAAI;GAC5C;GACA,SAAS,CAAC,OAAO,GAAG,IAAI;GACxB,YAAY,mBAAmB,YAAY,QAAQ;EACrD,CACF;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { computeDetentHeights } from "@mapcairn/core";
|
|
2
|
+
// src/layers/reveal.ts
|
|
3
|
+
/**
|
|
4
|
+
* The detent a bottom sheet rests at when a feature is shown, so its card and
|
|
5
|
+
* the map share the screen. The host raises or lowers the sheet to it after
|
|
6
|
+
* "Show on map" and after a tap on a point.
|
|
7
|
+
*/
|
|
8
|
+
var REVEAL_DETENT = "half";
|
|
9
|
+
/**
|
|
10
|
+
* Room kept round a fitted result, in pixels: the search pill above it and the
|
|
11
|
+
* end stack beside it are bigger than the plain margin, so nothing is drawn
|
|
12
|
+
* under them.
|
|
13
|
+
*/
|
|
14
|
+
var FIT_CLEARANCE_PX = 32;
|
|
15
|
+
var FIT_CLEARANCE_TOP_PX = 88;
|
|
16
|
+
var FIT_CLEARANCE_END_PX = 80;
|
|
17
|
+
/**
|
|
18
|
+
* The part of the map the sheet (at {@link REVEAL_DETENT}) or the side panel
|
|
19
|
+
* covers, as fit padding.
|
|
20
|
+
* @returns `null` while the map has no size, or when the cover would leave no
|
|
21
|
+
* map to look at.
|
|
22
|
+
*/
|
|
23
|
+
function coveredPadding(geometry) {
|
|
24
|
+
const { layout, viewport, panelEdge, direction = "ltr" } = geometry;
|
|
25
|
+
const padding = layout === "panel" ? {
|
|
26
|
+
top: 0,
|
|
27
|
+
right: direction === "rtl" ? panelEdge ?? 0 : 0,
|
|
28
|
+
bottom: 0,
|
|
29
|
+
left: direction === "ltr" ? panelEdge ?? 0 : 0
|
|
30
|
+
} : {
|
|
31
|
+
top: 0,
|
|
32
|
+
right: 0,
|
|
33
|
+
bottom: computeDetentHeights({
|
|
34
|
+
viewportHeight: viewport.height,
|
|
35
|
+
insetBottom: 0
|
|
36
|
+
})[REVEAL_DETENT],
|
|
37
|
+
left: 0
|
|
38
|
+
};
|
|
39
|
+
const width = viewport.width - padding.left - padding.right;
|
|
40
|
+
const height = viewport.height - padding.top - padding.bottom;
|
|
41
|
+
return width > 0 && height > 0 ? padding : null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The middle of the part of the map the sheet (at {@link REVEAL_DETENT}) or
|
|
45
|
+
* the side panel leaves free, in pixels from the map's top left. A tool that
|
|
46
|
+
* works "at the map centre" uses it, so its target is never under the sheet.
|
|
47
|
+
* @returns `null` while the map has no size, so the caller falls back to the
|
|
48
|
+
* centre of the whole map.
|
|
49
|
+
*/
|
|
50
|
+
function freeCentre(geometry) {
|
|
51
|
+
const padding = coveredPadding(geometry);
|
|
52
|
+
if (!padding) return null;
|
|
53
|
+
const { width, height } = geometry.viewport;
|
|
54
|
+
return {
|
|
55
|
+
x: (padding.left + width - padding.right) / 2,
|
|
56
|
+
y: (padding.top + height - padding.bottom) / 2
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* How far to pan the map so a point shows clear of the sheet or side panel.
|
|
61
|
+
* @param point - Where the point is now, in pixels from the map's top left.
|
|
62
|
+
* @returns The pan in pixels that puts the point in the middle of the free
|
|
63
|
+
* part of the map, or `null` when it is already comfortably inside it (a
|
|
64
|
+
* point that is visible is never moved).
|
|
65
|
+
*/
|
|
66
|
+
function revealOffset(point, geometry) {
|
|
67
|
+
const padding = coveredPadding(geometry);
|
|
68
|
+
if (!padding) return null;
|
|
69
|
+
const { width, height } = geometry.viewport;
|
|
70
|
+
const free = {
|
|
71
|
+
left: padding.left,
|
|
72
|
+
top: padding.top,
|
|
73
|
+
right: width - padding.right,
|
|
74
|
+
bottom: height - padding.bottom
|
|
75
|
+
};
|
|
76
|
+
const margin = free.right - free.left > 128 && free.bottom - free.top > 128 ? 64 : 0;
|
|
77
|
+
if (point.x >= free.left + margin && point.x <= free.right - margin && point.y >= free.top + margin && point.y <= free.bottom - margin) return null;
|
|
78
|
+
return {
|
|
79
|
+
dx: point.x - (free.left + free.right) / 2,
|
|
80
|
+
dy: point.y - (free.top + free.bottom) / 2
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The least map height a fit keeps between its top and bottom padding before
|
|
85
|
+
* it gives up keeping clear of the map key: room for a revealed point with
|
|
86
|
+
* {@link REVEAL_CLEARANCE} above and below it.
|
|
87
|
+
*/
|
|
88
|
+
var FIT_MIN_MAP_PX = 128;
|
|
89
|
+
/**
|
|
90
|
+
* Fit padding that keeps a result clear of the sheet (at {@link REVEAL_DETENT})
|
|
91
|
+
* or the side panel, and of the search pill and the end stack, so a route or
|
|
92
|
+
* imported shapes are drawn where they can be seen. Given a
|
|
93
|
+
* `mapKeyClearance`, it also keeps the result above the map key, where that
|
|
94
|
+
* still leaves {@link FIT_MIN_MAP_PX} of map.
|
|
95
|
+
*/
|
|
96
|
+
function fitPadding(geometry) {
|
|
97
|
+
const covered = coveredPadding(geometry);
|
|
98
|
+
const rtl = geometry.direction === "rtl";
|
|
99
|
+
const top = (covered?.top ?? 0) + FIT_CLEARANCE_TOP_PX;
|
|
100
|
+
const bottom = (covered?.bottom ?? 0) + FIT_CLEARANCE_PX;
|
|
101
|
+
return {
|
|
102
|
+
top,
|
|
103
|
+
right: (covered?.right ?? 0) + (rtl ? FIT_CLEARANCE_PX : FIT_CLEARANCE_END_PX),
|
|
104
|
+
bottom: Math.max(bottom, keyPadding(geometry, top)),
|
|
105
|
+
left: (covered?.left ?? 0) + (rtl ? FIT_CLEARANCE_END_PX : FIT_CLEARANCE_PX)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Bottom padding that keeps a result above the map key, or zero without a
|
|
110
|
+
* key or where it would leave less than {@link FIT_MIN_MAP_PX} under `top`.
|
|
111
|
+
*/
|
|
112
|
+
function keyPadding(geometry, top) {
|
|
113
|
+
if (geometry.mapKeyClearance == null) return 0;
|
|
114
|
+
const bottom = geometry.mapKeyClearance + FIT_CLEARANCE_PX;
|
|
115
|
+
return geometry.viewport.height - top - bottom >= FIT_MIN_MAP_PX ? bottom : 0;
|
|
116
|
+
}
|
|
117
|
+
export { REVEAL_DETENT, coveredPadding, fitPadding, freeCentre, revealOffset };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=reveal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal.js","names":[],"sources":["../../src/layers/reveal.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type ChromeLayout,\n computeDetentHeights,\n type MapFitOptions,\n type SheetDetent,\n} from \"@mapcairn/core\";\nimport type { ReadingDirection } from \"@mapcairn/react\";\n\n/**\n * The detent a bottom sheet rests at when a feature is shown, so its card and\n * the map share the screen. The host raises or lowers the sheet to it after\n * \"Show on map\" and after a tap on a point.\n */\nexport const REVEAL_DETENT: SheetDetent = \"half\";\n\n/** How far inside the free part of the map a revealed point must lie, in pixels. */\nexport const REVEAL_CLEARANCE = 64;\n\n/** What the reveal needs to know about the chrome. */\nexport interface RevealGeometry {\n readonly layout: ChromeLayout;\n /** The size of the chrome container, which is the map's size. */\n readonly viewport: { readonly width: number; readonly height: number };\n /** The distance from inline-start to the open panel's far edge, once measured. */\n readonly panelEdge: number | null;\n /** The reading direction. Defaults to left to right. */\n readonly direction?: ReadingDirection;\n /**\n * How far up from the map's bottom edge the shown map key reaches, in\n * pixels, or null while no key shows. Only {@link fitPadding} reads it.\n */\n readonly mapKeyClearance?: number | null;\n}\n\ntype Padding = NonNullable<MapFitOptions[\"padding\"]>;\n\n/** The closest a fit to a result zooms, so a short route or a single point keeps its surroundings. */\nexport const FIT_MAX_ZOOM = 16;\n\n/**\n * Room kept round a fitted result, in pixels: the search pill above it and the\n * end stack beside it are bigger than the plain margin, so nothing is drawn\n * under them.\n */\nconst FIT_CLEARANCE_PX = 32;\nconst FIT_CLEARANCE_TOP_PX = 88;\nconst FIT_CLEARANCE_END_PX = 80;\n\n/**\n * The part of the map the sheet (at {@link REVEAL_DETENT}) or the side panel\n * covers, as fit padding.\n * @returns `null` while the map has no size, or when the cover would leave no\n * map to look at.\n */\nexport function coveredPadding(geometry: RevealGeometry): Padding | null {\n const { layout, viewport, panelEdge, direction = \"ltr\" } = geometry;\n const padding: Padding =\n layout === \"panel\"\n ? {\n top: 0,\n right: direction === \"rtl\" ? (panelEdge ?? 0) : 0,\n bottom: 0,\n left: direction === \"ltr\" ? (panelEdge ?? 0) : 0,\n }\n : {\n top: 0,\n right: 0,\n bottom: computeDetentHeights({\n viewportHeight: viewport.height,\n insetBottom: 0,\n })[REVEAL_DETENT],\n left: 0,\n };\n const width = viewport.width - padding.left - padding.right;\n const height = viewport.height - padding.top - padding.bottom;\n return width > 0 && height > 0 ? padding : null;\n}\n\n/**\n * The middle of the part of the map the sheet (at {@link REVEAL_DETENT}) or\n * the side panel leaves free, in pixels from the map's top left. A tool that\n * works \"at the map centre\" uses it, so its target is never under the sheet.\n * @returns `null` while the map has no size, so the caller falls back to the\n * centre of the whole map.\n */\nexport function freeCentre(\n geometry: RevealGeometry,\n): { readonly x: number; readonly y: number } | null {\n const padding = coveredPadding(geometry);\n if (!padding) {\n return null;\n }\n const { width, height } = geometry.viewport;\n return {\n x: (padding.left + width - padding.right) / 2,\n y: (padding.top + height - padding.bottom) / 2,\n };\n}\n\n/**\n * How far to pan the map so a point shows clear of the sheet or side panel.\n * @param point - Where the point is now, in pixels from the map's top left.\n * @returns The pan in pixels that puts the point in the middle of the free\n * part of the map, or `null` when it is already comfortably inside it (a\n * point that is visible is never moved).\n */\nexport function revealOffset(\n point: { readonly x: number; readonly y: number },\n geometry: RevealGeometry,\n): { readonly dx: number; readonly dy: number } | null {\n const padding = coveredPadding(geometry);\n if (!padding) {\n return null;\n }\n const { width, height } = geometry.viewport;\n const free = {\n left: padding.left,\n top: padding.top,\n right: width - padding.right,\n bottom: height - padding.bottom,\n };\n const roomy =\n free.right - free.left > 2 * REVEAL_CLEARANCE &&\n free.bottom - free.top > 2 * REVEAL_CLEARANCE;\n const margin = roomy ? REVEAL_CLEARANCE : 0;\n const inside =\n point.x >= free.left + margin &&\n point.x <= free.right - margin &&\n point.y >= free.top + margin &&\n point.y <= free.bottom - margin;\n if (inside) {\n return null;\n }\n return {\n dx: point.x - (free.left + free.right) / 2,\n dy: point.y - (free.top + free.bottom) / 2,\n };\n}\n\n/**\n * The least map height a fit keeps between its top and bottom padding before\n * it gives up keeping clear of the map key: room for a revealed point with\n * {@link REVEAL_CLEARANCE} above and below it.\n */\nconst FIT_MIN_MAP_PX = 2 * REVEAL_CLEARANCE;\n\n/**\n * Fit padding that keeps a result clear of the sheet (at {@link REVEAL_DETENT})\n * or the side panel, and of the search pill and the end stack, so a route or\n * imported shapes are drawn where they can be seen. Given a\n * `mapKeyClearance`, it also keeps the result above the map key, where that\n * still leaves {@link FIT_MIN_MAP_PX} of map.\n */\nexport function fitPadding(geometry: RevealGeometry): Padding {\n const covered = coveredPadding(geometry);\n const rtl = geometry.direction === \"rtl\";\n const top = (covered?.top ?? 0) + FIT_CLEARANCE_TOP_PX;\n const bottom = (covered?.bottom ?? 0) + FIT_CLEARANCE_PX;\n return {\n top,\n right:\n (covered?.right ?? 0) + (rtl ? FIT_CLEARANCE_PX : FIT_CLEARANCE_END_PX),\n bottom: Math.max(bottom, keyPadding(geometry, top)),\n left:\n (covered?.left ?? 0) + (rtl ? FIT_CLEARANCE_END_PX : FIT_CLEARANCE_PX),\n };\n}\n\n/**\n * Bottom padding that keeps a result above the map key, or zero without a\n * key or where it would leave less than {@link FIT_MIN_MAP_PX} under `top`.\n */\nfunction keyPadding(geometry: RevealGeometry, top: number): number {\n if (geometry.mapKeyClearance == null) {\n return 0;\n }\n const bottom = geometry.mapKeyClearance + FIT_CLEARANCE_PX;\n return geometry.viewport.height - top - bottom >= FIT_MIN_MAP_PX ? bottom : 0;\n}\n"],"mappings":";;;;;;;AAeA,IAAa,gBAA6B;;;;;;AA+B1C,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAC7B,IAAM,uBAAuB;;;;;;;AAQ7B,SAAgB,eAAe,UAA0C;CACvE,MAAM,EAAE,QAAQ,UAAU,WAAW,YAAY,UAAU;CAC3D,MAAM,UACJ,WAAW,UACP;EACE,KAAK;EACL,OAAO,cAAc,QAAS,aAAa,IAAK;EAChD,QAAQ;EACR,MAAM,cAAc,QAAS,aAAa,IAAK;CACjD,IACA;EACE,KAAK;EACL,OAAO;EACP,QAAQ,qBAAqB;GAC3B,gBAAgB,SAAS;GACzB,aAAa;EACf,CAAC,CAAC,CAAC;EACH,MAAM;CACR;CACN,MAAM,QAAQ,SAAS,QAAQ,QAAQ,OAAO,QAAQ;CACtD,MAAM,SAAS,SAAS,SAAS,QAAQ,MAAM,QAAQ;CACvD,OAAO,QAAQ,KAAK,SAAS,IAAI,UAAU;AAC7C;;;;;;;;AASA,SAAgB,WACd,UACmD;CACnD,MAAM,UAAU,eAAe,QAAQ;CACvC,IAAI,CAAC,SACH,OAAO;CAET,MAAM,EAAE,OAAO,WAAW,SAAS;CACnC,OAAO;EACL,IAAI,QAAQ,OAAO,QAAQ,QAAQ,SAAS;EAC5C,IAAI,QAAQ,MAAM,SAAS,QAAQ,UAAU;CAC/C;AACF;;;;;;;;AASA,SAAgB,aACd,OACA,UACqD;CACrD,MAAM,UAAU,eAAe,QAAQ;CACvC,IAAI,CAAC,SACH,OAAO;CAET,MAAM,EAAE,OAAO,WAAW,SAAS;CACnC,MAAM,OAAO;EACX,MAAM,QAAQ;EACd,KAAK,QAAQ;EACb,OAAO,QAAQ,QAAQ;EACvB,QAAQ,SAAS,QAAQ;CAC3B;CAIA,MAAM,SAFJ,KAAK,QAAQ,KAAK,OAAO,OACzB,KAAK,SAAS,KAAK,MAAM,MAAA,KACe;CAM1C,IAJE,MAAM,KAAK,KAAK,OAAO,UACvB,MAAM,KAAK,KAAK,QAAQ,UACxB,MAAM,KAAK,KAAK,MAAM,UACtB,MAAM,KAAK,KAAK,SAAS,QAEzB,OAAO;CAET,OAAO;EACL,IAAI,MAAM,KAAK,KAAK,OAAO,KAAK,SAAS;EACzC,IAAI,MAAM,KAAK,KAAK,MAAM,KAAK,UAAU;CAC3C;AACF;;;;;;AAOA,IAAM,iBAAiB;;;;;;;;AASvB,SAAgB,WAAW,UAAmC;CAC5D,MAAM,UAAU,eAAe,QAAQ;CACvC,MAAM,MAAM,SAAS,cAAc;CACnC,MAAM,OAAO,SAAS,OAAO,KAAK;CAClC,MAAM,UAAU,SAAS,UAAU,KAAK;CACxC,OAAO;EACL;EACA,QACG,SAAS,SAAS,MAAM,MAAM,mBAAmB;EACpD,QAAQ,KAAK,IAAI,QAAQ,WAAW,UAAU,GAAG,CAAC;EAClD,OACG,SAAS,QAAQ,MAAM,MAAM,uBAAuB;CACzD;AACF;;;;;AAMA,SAAS,WAAW,UAA0B,KAAqB;CACjE,IAAI,SAAS,mBAAmB,MAC9B,OAAO;CAET,MAAM,SAAS,SAAS,kBAAkB;CAC1C,OAAO,SAAS,SAAS,SAAS,MAAM,UAAU,iBAAiB,SAAS;AAC9E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { announceFeatureDeselected, announceFeatureSelected, announceFeaturesDeselected, announceFeaturesSelected, announceSelectionCleared, announceSelectionFull, featureRefKey } from "@mapcairn/core";
|
|
2
|
+
// src/layers/selectionMessages.ts
|
|
3
|
+
function keysOf(refs) {
|
|
4
|
+
return new Set(refs.map(featureRefKey));
|
|
5
|
+
}
|
|
6
|
+
/** The references of `refs` whose keys are not in `held`. */
|
|
7
|
+
function missingFrom(held, refs) {
|
|
8
|
+
return refs.filter((ref) => !held.has(featureRefKey(ref)));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What an addition did, from the set before and after it: one message with
|
|
12
|
+
* the new total when something was added, naming the feature when exactly one
|
|
13
|
+
* was and it has a title. When nothing was added but `requested` held a
|
|
14
|
+
* reference that was not already selected, the store refused the batch for
|
|
15
|
+
* its `limit`, which is announced assertively, as a refused import is, so a
|
|
16
|
+
* later polite message cannot replace it. When every reference was already
|
|
17
|
+
* selected nothing changed, and nothing is said.
|
|
18
|
+
*/
|
|
19
|
+
function addedAnnouncement(requested, before, after, limit, titleOf) {
|
|
20
|
+
const held = keysOf(before);
|
|
21
|
+
const added = missingFrom(held, after);
|
|
22
|
+
if (added.length === 0) return missingFrom(held, requested).length > 0 ? {
|
|
23
|
+
message: announceSelectionFull(limit),
|
|
24
|
+
options: { priority: "assertive" }
|
|
25
|
+
} : null;
|
|
26
|
+
const [only] = added;
|
|
27
|
+
const title = added.length === 1 && only ? titleOf(only) : null;
|
|
28
|
+
return {
|
|
29
|
+
message: title === null ? announceFeaturesSelected(added.length, after.length) : announceFeatureSelected(title, after.length),
|
|
30
|
+
options: { priority: "polite" }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** What a removal did, from the set before and after it: one message with the new total, or null when nothing was removed. */
|
|
34
|
+
function removedAnnouncement(before, after, titleOf) {
|
|
35
|
+
const removed = missingFrom(keysOf(after), before);
|
|
36
|
+
if (removed.length === 0) return null;
|
|
37
|
+
const [only] = removed;
|
|
38
|
+
const title = removed.length === 1 && only ? titleOf(only) : null;
|
|
39
|
+
return {
|
|
40
|
+
message: title === null ? announceFeaturesDeselected(removed.length, after.length) : announceFeatureDeselected(title, after.length),
|
|
41
|
+
options: { priority: "polite" }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** What emptying the set did: "Selection cleared.", or null when it was already empty. */
|
|
45
|
+
function clearedAnnouncement(before) {
|
|
46
|
+
return before.length === 0 ? null : {
|
|
47
|
+
message: announceSelectionCleared(),
|
|
48
|
+
options: { priority: "polite" }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export { addedAnnouncement, clearedAnnouncement, removedAnnouncement };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=selectionMessages.js.map
|