@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,65 @@
|
|
|
1
|
+
import { catalogueView, hidesSection } from "./catalogueView.js";
|
|
2
|
+
import { announceCatalogueChange, describeLayersLoadFailed, describeLayersLoading, describeLayersRefreshFailed } from "@mapcairn/core";
|
|
3
|
+
// src/layers/catalogueNotice.ts
|
|
4
|
+
var politely = (message) => ({
|
|
5
|
+
message,
|
|
6
|
+
priority: "polite",
|
|
7
|
+
keep: true
|
|
8
|
+
});
|
|
9
|
+
var assertively = (message) => ({
|
|
10
|
+
message,
|
|
11
|
+
priority: "assertive",
|
|
12
|
+
keep: true
|
|
13
|
+
});
|
|
14
|
+
/** "Loading layers": a state, not an outcome, so a later message may replace it. */
|
|
15
|
+
var loadingMessage = () => ({
|
|
16
|
+
message: describeLayersLoading(),
|
|
17
|
+
priority: "polite",
|
|
18
|
+
keep: false
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* What a ready state says. A failed refresh is its own assertive message,
|
|
22
|
+
* unless the section is hidden (see `hidesSection`), which has no list to say
|
|
23
|
+
* was kept. Anything else is one composed polite message (see
|
|
24
|
+
* `announceCatalogueChange` for its order). The first list is not an update,
|
|
25
|
+
* so "Layers updated" waits for a list that follows one; the skipped count is
|
|
26
|
+
* said each time it changes to a count above zero, the first list included.
|
|
27
|
+
*/
|
|
28
|
+
function readyNotice({ previous, next, awaited, change }) {
|
|
29
|
+
const before = previous?.status === "ready" ? previous : null;
|
|
30
|
+
if (next.refresh === "failed") {
|
|
31
|
+
const hidden = hidesSection(catalogueView(next, awaited), next.layers.length);
|
|
32
|
+
return before?.refresh === "failed" || hidden ? null : assertively(describeLayersRefreshFailed());
|
|
33
|
+
}
|
|
34
|
+
const skipped = next.skipped.length;
|
|
35
|
+
const message = announceCatalogueChange({
|
|
36
|
+
turnedOff: change?.switchedOff.map(({ name }) => name) ?? [],
|
|
37
|
+
linkUnavailable: awaited ? change?.linkMissing ?? 0 : 0,
|
|
38
|
+
skipped: skipped === (before?.skipped.length ?? 0) ? 0 : skipped,
|
|
39
|
+
added: before ? change?.added.length ?? 0 : 0,
|
|
40
|
+
removed: before ? change?.removed.length ?? 0 : 0,
|
|
41
|
+
empty: awaited && before === null && next.layers.length === 0
|
|
42
|
+
});
|
|
43
|
+
return message === null ? null : politely(message);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The one message a catalogue transition makes, or null for silence. Each
|
|
47
|
+
* state is said once, when it is entered: "Loading layers" only while a layer
|
|
48
|
+
* named by the link is waiting, a failed load or refresh assertively and on
|
|
49
|
+
* its own, and a new list as one composed message. Pure, so the hook can keep
|
|
50
|
+
* it in its state and say it once from an effect.
|
|
51
|
+
*/
|
|
52
|
+
function catalogueNotice(inputs) {
|
|
53
|
+
const { previous, next, linkWaiting } = inputs;
|
|
54
|
+
switch (next.status) {
|
|
55
|
+
case "loading": return previous?.status !== "loading" && linkWaiting > 0 ? loadingMessage() : null;
|
|
56
|
+
case "failed": return previous?.status === "failed" ? null : assertively(describeLayersLoadFailed());
|
|
57
|
+
case "ready": return readyNotice({
|
|
58
|
+
...inputs,
|
|
59
|
+
next
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export { catalogueNotice };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=catalogueNotice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalogueNotice.js","names":[],"sources":["../../src/layers/catalogueNotice.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceCatalogueChange,\n type CatalogueState,\n describeLayersLoadFailed,\n describeLayersLoading,\n describeLayersRefreshFailed,\n type Message,\n} from \"@mapcairn/core\";\nimport type { AnnouncePriority } from \"../ui/LiveRegion\";\nimport type { Reconciled } from \"./catalogueReconcile\";\nimport { catalogueView, hidesSection } from \"./catalogueView\";\n\n/** The `ready` member of a catalogue state. */\ntype ReadyState = Extract<CatalogueState, { status: \"ready\" }>;\n\n/** What a transition of the catalogue says aloud, and how urgently. */\nexport interface CatalogueMessage {\n readonly message: Message;\n readonly priority: AnnouncePriority;\n /**\n * Whether a later message must not replace it (the announcer's `keep`).\n * True for the outcome of a discrete change, such as a list arriving or a\n * load failing; false for \"Loading layers\", a state a later message may\n * replace.\n */\n readonly keep: boolean;\n}\n\n/** What {@link catalogueNotice} reads. */\nexport interface CatalogueNoticeInputs {\n /** The state last taken in: none before the first one. */\n readonly previous: CatalogueState | null;\n /** The state the catalogue holds now. */\n readonly next: CatalogueState;\n /** How many layers the link names that no list has answered for yet. */\n readonly linkWaiting: number;\n /** Whether the catalogue was not ready at mount, so its list arrives later. */\n readonly awaited: boolean;\n /** What {@link reconcile} worked out for a new list, or null when the list is the one already taken in. */\n readonly change: Reconciled | null;\n}\n\nconst politely = (message: Message): CatalogueMessage => ({\n message,\n priority: \"polite\",\n keep: true,\n});\n\nconst assertively = (message: Message): CatalogueMessage => ({\n message,\n priority: \"assertive\",\n keep: true,\n});\n\n/** \"Loading layers\": a state, not an outcome, so a later message may replace it. */\nconst loadingMessage = (): CatalogueMessage => ({\n message: describeLayersLoading(),\n priority: \"polite\",\n keep: false,\n});\n\n/**\n * What a ready state says. A failed refresh is its own assertive message,\n * unless the section is hidden (see `hidesSection`), which has no list to say\n * was kept. Anything else is one composed polite message (see\n * `announceCatalogueChange` for its order). The first list is not an update,\n * so \"Layers updated\" waits for a list that follows one; the skipped count is\n * said each time it changes to a count above zero, the first list included.\n */\nfunction readyNotice({\n previous,\n next,\n awaited,\n change,\n}: CatalogueNoticeInputs & {\n readonly next: ReadyState;\n}): CatalogueMessage | null {\n const before = previous?.status === \"ready\" ? previous : null;\n if (next.refresh === \"failed\") {\n const hidden = hidesSection(\n catalogueView(next, awaited),\n next.layers.length,\n );\n return before?.refresh === \"failed\" || hidden\n ? null\n : assertively(describeLayersRefreshFailed());\n }\n const skipped = next.skipped.length;\n const message = announceCatalogueChange({\n turnedOff: change?.switchedOff.map(({ name }) => name) ?? [],\n linkUnavailable: awaited ? (change?.linkMissing ?? 0) : 0,\n skipped: skipped === (before?.skipped.length ?? 0) ? 0 : skipped,\n added: before ? (change?.added.length ?? 0) : 0,\n removed: before ? (change?.removed.length ?? 0) : 0,\n empty: awaited && before === null && next.layers.length === 0,\n });\n return message === null ? null : politely(message);\n}\n\n/**\n * The one message a catalogue transition makes, or null for silence. Each\n * state is said once, when it is entered: \"Loading layers\" only while a layer\n * named by the link is waiting, a failed load or refresh assertively and on\n * its own, and a new list as one composed message. Pure, so the hook can keep\n * it in its state and say it once from an effect.\n */\nexport function catalogueNotice(\n inputs: CatalogueNoticeInputs,\n): CatalogueMessage | null {\n const { previous, next, linkWaiting } = inputs;\n switch (next.status) {\n case \"loading\":\n return previous?.status !== \"loading\" && linkWaiting > 0\n ? loadingMessage()\n : null;\n case \"failed\":\n return previous?.status === \"failed\"\n ? null\n : assertively(describeLayersLoadFailed());\n case \"ready\":\n return readyNotice({ ...inputs, next });\n }\n}\n"],"mappings":";;;AA4CA,IAAM,YAAY,aAAwC;CACxD;CACA,UAAU;CACV,MAAM;AACR;AAEA,IAAM,eAAe,aAAwC;CAC3D;CACA,UAAU;CACV,MAAM;AACR;;AAGA,IAAM,wBAA0C;CAC9C,SAAS,sBAAsB;CAC/B,UAAU;CACV,MAAM;AACR;;;;;;;;;AAUA,SAAS,YAAY,EACnB,UACA,MACA,SACA,UAG0B;CAC1B,MAAM,SAAS,UAAU,WAAW,UAAU,WAAW;CACzD,IAAI,KAAK,YAAY,UAAU;EAC7B,MAAM,SAAS,aACb,cAAc,MAAM,OAAO,GAC3B,KAAK,OAAO,MACd;EACA,OAAO,QAAQ,YAAY,YAAY,SACnC,OACA,YAAY,4BAA4B,CAAC;CAC/C;CACA,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,UAAU,wBAAwB;EACtC,WAAW,QAAQ,YAAY,KAAK,EAAE,WAAW,IAAI,KAAK,CAAC;EAC3D,iBAAiB,UAAW,QAAQ,eAAe,IAAK;EACxD,SAAS,aAAa,QAAQ,QAAQ,UAAU,KAAK,IAAI;EACzD,OAAO,SAAU,QAAQ,MAAM,UAAU,IAAK;EAC9C,SAAS,SAAU,QAAQ,QAAQ,UAAU,IAAK;EAClD,OAAO,WAAW,WAAW,QAAQ,KAAK,OAAO,WAAW;CAC9D,CAAC;CACD,OAAO,YAAY,OAAO,OAAO,SAAS,OAAO;AACnD;;;;;;;;AASA,SAAgB,gBACd,QACyB;CACzB,MAAM,EAAE,UAAU,MAAM,gBAAgB;CACxC,QAAQ,KAAK,QAAb;EACE,KAAK,WACH,OAAO,UAAU,WAAW,aAAa,cAAc,IACnD,eAAe,IACf;EACN,KAAK,UACH,OAAO,UAAU,WAAW,WACxB,OACA,YAAY,yBAAyB,CAAC;EAC5C,KAAK,SACH,OAAO,YAAY;GAAE,GAAG;GAAQ;EAAK,CAAC;CAC1C;AACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { resolveControlValues, textOrMessage } from "@mapcairn/core";
|
|
2
|
+
// src/layers/catalogueReconcile.ts
|
|
3
|
+
/**
|
|
4
|
+
* The control values of every layer in the new list. A layer that arrives
|
|
5
|
+
* gets its defaults, or the link's values when the link named it. A layer
|
|
6
|
+
* whose definition changed keeps the values that are still valid and takes
|
|
7
|
+
* the default for the rest. A layer whose definition is the same object keeps
|
|
8
|
+
* its values as they are, so a refresh that changes nothing changes nothing.
|
|
9
|
+
*/
|
|
10
|
+
function controlsOf(inputs) {
|
|
11
|
+
const { chosen, link, known, next, now } = inputs;
|
|
12
|
+
const before = new Map(known.map((definition) => [definition.id, definition]));
|
|
13
|
+
return Object.fromEntries(next.map((definition) => {
|
|
14
|
+
const { id } = definition;
|
|
15
|
+
const current = chosen.controls[id];
|
|
16
|
+
if (current && before.get(id) === definition) return [id, current];
|
|
17
|
+
const given = current ?? (link.waiting.includes(id) ? link.controls[id] : void 0);
|
|
18
|
+
return [id, resolveControlValues(definition, given, now)];
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Brings the person's choices in line with a new list of layers: a link layer
|
|
23
|
+
* that was waiting is turned on if the list has it and dropped if not, a layer
|
|
24
|
+
* that arrives gets its controls, a layer that is on and has gone is turned
|
|
25
|
+
* off, and a layer that changed keeps what is still valid. Pure: the caller
|
|
26
|
+
* clears what the layers that went had loaded and says the change aloud.
|
|
27
|
+
*/
|
|
28
|
+
function reconcile(inputs) {
|
|
29
|
+
const { chosen, link, known, next } = inputs;
|
|
30
|
+
const inList = new Set(next.map((definition) => definition.id));
|
|
31
|
+
const wasListed = new Set(known.map((definition) => definition.id));
|
|
32
|
+
const names = new Map(known.map((definition) => [definition.id, textOrMessage(definition.name)]));
|
|
33
|
+
const stillOn = chosen.enabled.filter((id) => inList.has(id));
|
|
34
|
+
const arrived = link.waiting.filter((id) => inList.has(id) && !stillOn.includes(id));
|
|
35
|
+
return {
|
|
36
|
+
chosen: {
|
|
37
|
+
enabled: [...stillOn, ...arrived],
|
|
38
|
+
controls: controlsOf(inputs)
|
|
39
|
+
},
|
|
40
|
+
link: {
|
|
41
|
+
waiting: [],
|
|
42
|
+
controls: {}
|
|
43
|
+
},
|
|
44
|
+
added: next.map(({ id }) => id).filter((id) => !wasListed.has(id)),
|
|
45
|
+
removed: known.map(({ id }) => id).filter((id) => !inList.has(id)),
|
|
46
|
+
switchedOff: chosen.enabled.filter((id) => !inList.has(id)).map((id) => ({
|
|
47
|
+
id,
|
|
48
|
+
name: names.get(id) ?? id
|
|
49
|
+
})),
|
|
50
|
+
linkMissing: link.waiting.filter((id) => !inList.has(id)).length + (link.dropped ?? 0)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { reconcile };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=catalogueReconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalogueReconcile.js","names":[],"sources":["../../src/layers/catalogueReconcile.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type ControlValues,\n type LayerDefinition,\n type MessagePart,\n resolveControlValues,\n textOrMessage,\n} from \"@mapcairn/core\";\n\n/** Control values by layer id. */\nexport type ControlsById = Readonly<Record<string, ControlValues>>;\n\n/** What the person has chosen: which layers are on, and every listed layer's control values. */\nexport interface Chosen {\n readonly enabled: readonly string[];\n readonly controls: ControlsById;\n}\n\n/**\n * The layers a link named that no list has answered for yet, with the\n * link's own control values for them, as written and not yet resolved.\n */\nexport interface Link {\n readonly waiting: readonly string[];\n readonly controls: ControlsById;\n /**\n * How many ids the link carried past its limit on layers (see\n * `LayersUrlState.dropped`), none when absent. They were never kept, so they\n * only add to the count of layers the link named that the list lacks.\n */\n readonly dropped?: number;\n}\n\n/** What {@link reconcile} reads. */\nexport interface ReconcileInputs {\n readonly chosen: Chosen;\n readonly link: Link;\n /** The list the choices were last reconciled with: none before the first one. */\n readonly known: readonly LayerDefinition[];\n /** The list the catalogue holds now. */\n readonly next: readonly LayerDefinition[];\n /** The clock, in epoch milliseconds, for relative control defaults. */\n readonly now: number;\n}\n\n/** An enabled layer that left the list, by id and by the name it had. */\nexport interface SwitchedOff {\n readonly id: string;\n /** The layer's name as a placeholder value: plain text, a message for a keyed name, or a host text. */\n readonly name: MessagePart;\n}\n\n/**\n * What {@link reconcile} works out. How many definitions were skipped is not\n * here: it is in the catalogue's own state (`skipped`).\n */\nexport interface Reconciled {\n readonly chosen: Chosen;\n /** The link once answered: nothing waits any longer, so a dropped id stays dropped. */\n readonly link: Link;\n /** The ids the list has that the last one did not. */\n readonly added: readonly string[];\n /** The ids the last list had that this one does not, whether the layer was on or off. */\n readonly removed: readonly string[];\n /** The enabled layers among those removed, which are now off. */\n readonly switchedOff: readonly SwitchedOff[];\n /** How many layers the link named that the list does not have, with those it carried past its limit. */\n readonly linkMissing: number;\n}\n\n/**\n * The control values of every layer in the new list. A layer that arrives\n * gets its defaults, or the link's values when the link named it. A layer\n * whose definition changed keeps the values that are still valid and takes\n * the default for the rest. A layer whose definition is the same object keeps\n * its values as they are, so a refresh that changes nothing changes nothing.\n */\nfunction controlsOf(inputs: ReconcileInputs): ControlsById {\n const { chosen, link, known, next, now } = inputs;\n const before = new Map(\n known.map((definition) => [definition.id, definition]),\n );\n return Object.fromEntries(\n next.map((definition) => {\n const { id } = definition;\n const current = chosen.controls[id];\n if (current && before.get(id) === definition) {\n return [id, current];\n }\n const given =\n current ?? (link.waiting.includes(id) ? link.controls[id] : undefined);\n return [id, resolveControlValues(definition, given, now)];\n }),\n );\n}\n\n/**\n * Brings the person's choices in line with a new list of layers: a link layer\n * that was waiting is turned on if the list has it and dropped if not, a layer\n * that arrives gets its controls, a layer that is on and has gone is turned\n * off, and a layer that changed keeps what is still valid. Pure: the caller\n * clears what the layers that went had loaded and says the change aloud.\n */\nexport function reconcile(inputs: ReconcileInputs): Reconciled {\n const { chosen, link, known, next } = inputs;\n const inList = new Set(next.map((definition) => definition.id));\n const wasListed = new Set(known.map((definition) => definition.id));\n const names = new Map(\n known.map((definition) => [definition.id, textOrMessage(definition.name)]),\n );\n const stillOn = chosen.enabled.filter((id) => inList.has(id));\n const arrived = link.waiting.filter(\n (id) => inList.has(id) && !stillOn.includes(id),\n );\n return {\n chosen: {\n enabled: [...stillOn, ...arrived],\n controls: controlsOf(inputs),\n },\n link: { waiting: [], controls: {} },\n added: next.map(({ id }) => id).filter((id) => !wasListed.has(id)),\n removed: known.map(({ id }) => id).filter((id) => !inList.has(id)),\n switchedOff: chosen.enabled\n .filter((id) => !inList.has(id))\n .map((id) => ({ id, name: names.get(id) ?? id })),\n linkMissing:\n link.waiting.filter((id) => !inList.has(id)).length + (link.dropped ?? 0),\n };\n}\n"],"mappings":";;;;;;;;;AA8EA,SAAS,WAAW,QAAuC;CACzD,MAAM,EAAE,QAAQ,MAAM,OAAO,MAAM,QAAQ;CAC3C,MAAM,SAAS,IAAI,IACjB,MAAM,KAAK,eAAe,CAAC,WAAW,IAAI,UAAU,CAAC,CACvD;CACA,OAAO,OAAO,YACZ,KAAK,KAAK,eAAe;EACvB,MAAM,EAAE,OAAO;EACf,MAAM,UAAU,OAAO,SAAS;EAChC,IAAI,WAAW,OAAO,IAAI,EAAE,MAAM,YAChC,OAAO,CAAC,IAAI,OAAO;EAErB,MAAM,QACJ,YAAY,KAAK,QAAQ,SAAS,EAAE,IAAI,KAAK,SAAS,MAAM,KAAA;EAC9D,OAAO,CAAC,IAAI,qBAAqB,YAAY,OAAO,GAAG,CAAC;CAC1D,CAAC,CACH;AACF;;;;;;;;AASA,SAAgB,UAAU,QAAqC;CAC7D,MAAM,EAAE,QAAQ,MAAM,OAAO,SAAS;CACtC,MAAM,SAAS,IAAI,IAAI,KAAK,KAAK,eAAe,WAAW,EAAE,CAAC;CAC9D,MAAM,YAAY,IAAI,IAAI,MAAM,KAAK,eAAe,WAAW,EAAE,CAAC;CAClE,MAAM,QAAQ,IAAI,IAChB,MAAM,KAAK,eAAe,CAAC,WAAW,IAAI,cAAc,WAAW,IAAI,CAAC,CAAC,CAC3E;CACA,MAAM,UAAU,OAAO,QAAQ,QAAQ,OAAO,OAAO,IAAI,EAAE,CAAC;CAC5D,MAAM,UAAU,KAAK,QAAQ,QAC1B,OAAO,OAAO,IAAI,EAAE,KAAK,CAAC,QAAQ,SAAS,EAAE,CAChD;CACA,OAAO;EACL,QAAQ;GACN,SAAS,CAAC,GAAG,SAAS,GAAG,OAAO;GAChC,UAAU,WAAW,MAAM;EAC7B;EACA,MAAM;GAAE,SAAS,CAAC;GAAG,UAAU,CAAC;EAAE;EAClC,OAAO,KAAK,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,QAAQ,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;EACjE,SAAS,MAAM,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,QAAQ,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;EACjE,aAAa,OAAO,QACjB,QAAQ,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAC/B,KAAK,QAAQ;GAAE;GAAI,MAAM,MAAM,IAAI,EAAE,KAAK;EAAG,EAAE;EAClD,aACE,KAAK,QAAQ,QAAQ,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,WAAW;CAC3E;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/layers/catalogueView.ts
|
|
2
|
+
/** The view of a catalogue state. `awaited` is fixed at mount by the caller. */
|
|
3
|
+
function catalogueView(state, awaited) {
|
|
4
|
+
const failed = loadFailed(state);
|
|
5
|
+
return state.status === "ready" ? {
|
|
6
|
+
status: "ready",
|
|
7
|
+
skipped: state.skipped.length,
|
|
8
|
+
refresh: state.refresh,
|
|
9
|
+
failed,
|
|
10
|
+
awaited
|
|
11
|
+
} : {
|
|
12
|
+
status: state.status,
|
|
13
|
+
skipped: 0,
|
|
14
|
+
refresh: "idle",
|
|
15
|
+
failed,
|
|
16
|
+
awaited
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Whether the last attempt to load the catalogue failed, as a failed load or a failed refresh. */
|
|
20
|
+
function loadFailed(state) {
|
|
21
|
+
return state.status === "failed" || state.status === "ready" && state.refresh === "failed";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether the section is left out: the catalogue is ready and has no layers,
|
|
25
|
+
* and it was ready and empty from the start, so the host has none to offer.
|
|
26
|
+
*/
|
|
27
|
+
function hidesSection(view, layerCount) {
|
|
28
|
+
return view.status === "ready" && layerCount === 0 && !view.awaited;
|
|
29
|
+
}
|
|
30
|
+
export { catalogueView, hidesSection, loadFailed };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=catalogueView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalogueView.js","names":[],"sources":["../../src/layers/catalogueView.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { CatalogueRefresh, CatalogueState } from \"@mapcairn/core\";\n\n/** What the Layers section needs to know about the catalogue besides its layers. */\nexport interface CatalogueView {\n readonly status: CatalogueState[\"status\"];\n /** How many definitions the host supplied that were left out. Zero unless `ready`. */\n readonly skipped: number;\n /** Where a refresh of the list has got to. `idle` unless `ready`. */\n readonly refresh: CatalogueRefresh;\n /** Whether the last attempt to load failed (see {@link loadFailed}), so Try again has something to do. */\n readonly failed: boolean;\n /**\n * True when the catalogue was not ready at mount, so its list arrived or\n * will arrive later and an empty one is worth saying. False for a host whose\n * layers were there from the start.\n */\n readonly awaited: boolean;\n}\n\n/** The view of a catalogue state. `awaited` is fixed at mount by the caller. */\nexport function catalogueView(\n state: CatalogueState,\n awaited: boolean,\n): CatalogueView {\n const failed = loadFailed(state);\n return state.status === \"ready\"\n ? {\n status: \"ready\",\n skipped: state.skipped.length,\n refresh: state.refresh,\n failed,\n awaited,\n }\n : { status: state.status, skipped: 0, refresh: \"idle\", failed, awaited };\n}\n\n/** Whether the last attempt to load the catalogue failed, as a failed load or a failed refresh. */\nexport function loadFailed(state: CatalogueState): boolean {\n return (\n state.status === \"failed\" ||\n (state.status === \"ready\" && state.refresh === \"failed\")\n );\n}\n\n/**\n * Whether the section is left out: the catalogue is ready and has no layers,\n * and it was ready and empty from the start, so the host has none to offer.\n */\nexport function hidesSection(view: CatalogueView, layerCount: number): boolean {\n return view.status === \"ready\" && layerCount === 0 && !view.awaited;\n}\n"],"mappings":";;AAsBA,SAAgB,cACd,OACA,SACe;CACf,MAAM,SAAS,WAAW,KAAK;CAC/B,OAAO,MAAM,WAAW,UACpB;EACE,QAAQ;EACR,SAAS,MAAM,QAAQ;EACvB,SAAS,MAAM;EACf;EACA;CACF,IACA;EAAE,QAAQ,MAAM;EAAQ,SAAS;EAAG,SAAS;EAAQ;EAAQ;CAAQ;AAC3E;;AAGA,SAAgB,WAAW,OAAgC;CACzD,OACE,MAAM,WAAW,YAChB,MAAM,WAAW,WAAW,MAAM,YAAY;AAEnD;;;;;AAMA,SAAgB,aAAa,MAAqB,YAA6B;CAC7E,OAAO,KAAK,WAAW,WAAW,eAAe,KAAK,CAAC,KAAK;AAC9D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cardOf, formatTemplate, hasCard, resolveText } from "@mapcairn/core";
|
|
2
|
+
// src/layers/featureTitle.ts
|
|
3
|
+
/**
|
|
4
|
+
* The title of a feature's card, from its layer's card template (a feed's own
|
|
5
|
+
* or a tile layer's `identify` card), or the layer's name (read in the context's language) when the layer has
|
|
6
|
+
* no card or the template fills to nothing.
|
|
7
|
+
*/
|
|
8
|
+
function featureTitle(definition, feature, formatters, context) {
|
|
9
|
+
if (!hasCard(definition)) return resolveText(context.catalogue, definition.name);
|
|
10
|
+
return formatTemplate(cardOf(definition).title, feature.fields, formatters, context) ?? resolveText(context.catalogue, definition.name);
|
|
11
|
+
}
|
|
12
|
+
export { featureTitle };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=featureTitle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"featureTitle.js","names":[],"sources":["../../src/layers/featureTitle.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n cardOf,\n type FormatContext,\n type FormatterRegistry,\n formatTemplate,\n hasCard,\n type LayerDefinition,\n type LayerFeature,\n resolveText,\n} from \"@mapcairn/core\";\n\n/**\n * The title of a feature's card, from its layer's card template (a feed's own\n * or a tile layer's `identify` card), or the layer's name (read in the context's language) when the layer has\n * no card or the template fills to nothing.\n */\nexport function featureTitle(\n definition: LayerDefinition,\n feature: LayerFeature,\n formatters: FormatterRegistry,\n context: FormatContext,\n): string {\n if (!hasCard(definition)) {\n return resolveText(context.catalogue, definition.name);\n }\n return (\n formatTemplate(\n cardOf(definition).title,\n feature.fields,\n formatters,\n context,\n ) ?? resolveText(context.catalogue, definition.name)\n );\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,aACd,YACA,SACA,YACA,SACQ;CACR,IAAI,CAAC,QAAQ,UAAU,GACrB,OAAO,YAAY,QAAQ,WAAW,WAAW,IAAI;CAEvD,OACE,eACE,OAAO,UAAU,CAAC,CAAC,OACnB,QAAQ,QACR,YACA,OACF,KAAK,YAAY,QAAQ,WAAW,WAAW,IAAI;AAEvD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
// src/layers/identifyFeedback.ts
|
|
3
|
+
/**
|
|
4
|
+
* How long a lookup may run before the interface says it is waiting. An
|
|
5
|
+
* answer that comes sooner shows nothing, so a quick tap does not flash a
|
|
6
|
+
* line.
|
|
7
|
+
*/
|
|
8
|
+
var IDENTIFY_FEEDBACK_MS = 400;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to show the "Looking up what is here" line: true once `identifying`
|
|
11
|
+
* (see `DataLayers.identifying`) has been true for {@link IDENTIFY_FEEDBACK_MS},
|
|
12
|
+
* and false again the moment it ends. The line is for the eye only. The
|
|
13
|
+
* lookup's result is said once, when it arrives, so nothing is announced
|
|
14
|
+
* while waiting: a message at the delay would be coalesced with the result.
|
|
15
|
+
*/
|
|
16
|
+
function useIdentifyFeedback(identifying) {
|
|
17
|
+
const [late, setLate] = useState(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!identifying) {
|
|
20
|
+
setLate(false);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const timer = setTimeout(() => setLate(true), 400);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
25
|
+
}, [identifying]);
|
|
26
|
+
return identifying && late;
|
|
27
|
+
}
|
|
28
|
+
export { IDENTIFY_FEEDBACK_MS, useIdentifyFeedback };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=identifyFeedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifyFeedback.js","names":[],"sources":["../../src/layers/identifyFeedback.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { useEffect, useState } from \"react\";\n\n/**\n * How long a lookup may run before the interface says it is waiting. An\n * answer that comes sooner shows nothing, so a quick tap does not flash a\n * line.\n */\nexport const IDENTIFY_FEEDBACK_MS = 400;\n\n/**\n * Whether to show the \"Looking up what is here\" line: true once `identifying`\n * (see `DataLayers.identifying`) has been true for {@link IDENTIFY_FEEDBACK_MS},\n * and false again the moment it ends. The line is for the eye only. The\n * lookup's result is said once, when it arrives, so nothing is announced\n * while waiting: a message at the delay would be coalesced with the result.\n */\nexport function useIdentifyFeedback(identifying: boolean): boolean {\n const [late, setLate] = useState(false);\n useEffect(() => {\n if (!identifying) {\n setLate(false);\n return;\n }\n const timer = setTimeout(() => setLate(true), IDENTIFY_FEEDBACK_MS);\n return () => clearTimeout(timer);\n }, [identifying]);\n return identifying && late;\n}\n"],"mappings":";;;;;;;AASA,IAAa,uBAAuB;;;;;;;;AASpC,SAAgB,oBAAoB,aAA+B;CACjE,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CACtC,gBAAgB;EACd,IAAI,CAAC,aAAa;GAChB,QAAQ,KAAK;GACb;EACF;EACA,MAAM,QAAQ,iBAAiB,QAAQ,IAAI,GAAA,GAAuB;EAClE,aAAa,aAAa,KAAK;CACjC,GAAG,CAAC,WAAW,CAAC;CAChB,OAAO,eAAe;AACxB"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { errorKind } from "./layerStatus.js";
|
|
2
|
+
import { isIdentifiable, textOrMessage, tileUrl } from "@mapcairn/core";
|
|
3
|
+
// src/layers/identifyRun.ts
|
|
4
|
+
/** The most layers one tap asks, in catalogue order. A tap that could ask more says how many it asked. */
|
|
5
|
+
var MAX_IDENTIFY_LAYERS = 4;
|
|
6
|
+
/**
|
|
7
|
+
* How long one layer has to answer a tap, in milliseconds. The hook counts it
|
|
8
|
+
* itself: a source only sees that its request was aborted.
|
|
9
|
+
*/
|
|
10
|
+
var IDENTIFY_TIMEOUT_MS = 8e3;
|
|
11
|
+
/** The layers that are on and answer a tap, in catalogue order. */
|
|
12
|
+
function identifiableLayers({ definitions, enabled, controls, now }) {
|
|
13
|
+
return definitions.flatMap((definition) => {
|
|
14
|
+
if (!isIdentifiable(definition) || !enabled.includes(definition.id)) return [];
|
|
15
|
+
const own = controls[definition.id] ?? {};
|
|
16
|
+
return [{
|
|
17
|
+
definition,
|
|
18
|
+
controls: own,
|
|
19
|
+
tiles: tileUrl(definition, own, now)
|
|
20
|
+
}];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Whether a tile layer's `bounds` hold a place. A layer with no bounds holds every place. */
|
|
24
|
+
function holds(bounds, place) {
|
|
25
|
+
if (!bounds) return true;
|
|
26
|
+
const [west, south, east, north] = bounds;
|
|
27
|
+
return place.lng >= west && place.lng <= east && place.lat >= south && place.lat <= north;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The layers a tap could ask: those that show imagery (the map has not
|
|
31
|
+
* reported none of their tiles loaded, `unavailable` being the tiles each was
|
|
32
|
+
* reported for) and whose `bounds` hold the place.
|
|
33
|
+
*/
|
|
34
|
+
function askableLayers(layers, unavailable, place) {
|
|
35
|
+
return layers.filter(({ definition }) => unavailable[definition.id] === void 0 && holds(definition.source.bounds, place));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What a batch of answers comes to, or null when every layer was cancelled,
|
|
39
|
+
* which opens and says nothing. A cancelled layer is left out of what was
|
|
40
|
+
* asked and of what was available, because it is no longer there to ask.
|
|
41
|
+
* `available` is how many layers could have been asked, so the report can say
|
|
42
|
+
* when the cap held some back.
|
|
43
|
+
*/
|
|
44
|
+
function outcomeOf(answers, available) {
|
|
45
|
+
const found = answers.filter((answer) => answer.kind === "found");
|
|
46
|
+
const failed = answers.filter((answer) => answer.kind === "failed");
|
|
47
|
+
const cancelled = answers.length - found.length - failed.length;
|
|
48
|
+
if (found.length + failed.length === 0) return null;
|
|
49
|
+
const hits = found.flatMap(({ layer, features }) => features.map((feature) => ({
|
|
50
|
+
layerId: layer.definition.id,
|
|
51
|
+
featureId: feature.id
|
|
52
|
+
})));
|
|
53
|
+
return {
|
|
54
|
+
entries: Object.fromEntries(found.map(({ layer, features }) => [layer.definition.id, {
|
|
55
|
+
tiles: layer.tiles,
|
|
56
|
+
features
|
|
57
|
+
}])),
|
|
58
|
+
hits,
|
|
59
|
+
report: {
|
|
60
|
+
found: hits.length,
|
|
61
|
+
asked: found.length + failed.length,
|
|
62
|
+
available: available - cancelled,
|
|
63
|
+
failed: failed.map(({ layer }) => textOrMessage(layer.definition.name))
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The answers with those that no longer describe what is shown set to
|
|
69
|
+
* cancelled: a layer that is off now, or whose tiles are not the ones it was
|
|
70
|
+
* asked about, whether it answered or failed. `current` is each layer that is
|
|
71
|
+
* on and answers a tap, with its tile URL, as {@link IdentifyRun.abortStale}
|
|
72
|
+
* reads it.
|
|
73
|
+
*/
|
|
74
|
+
function stillCurrent(answers, current) {
|
|
75
|
+
return answers.map((answer) => answer.kind === "cancelled" || current.get(answer.layer.definition.id) === answer.layer.tiles ? answer : {
|
|
76
|
+
kind: "cancelled",
|
|
77
|
+
layer: answer.layer
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* One tap's requests: one for each layer asked, each with its own abort
|
|
82
|
+
* controller and its own time limit. A request ends in an answer whichever
|
|
83
|
+
* comes first, the source's reply or the abort, so a source that is slow to
|
|
84
|
+
* notice an abort does not hold the tap up.
|
|
85
|
+
*/
|
|
86
|
+
var IdentifyRun = class {
|
|
87
|
+
#requests = /* @__PURE__ */ new Map();
|
|
88
|
+
/**
|
|
89
|
+
* Asks one layer what is at `at`. Resolves, never rejects: with the
|
|
90
|
+
* features, as failed (the source failed, or the layer ran out of
|
|
91
|
+
* {@link IDENTIFY_TIMEOUT_MS}), or as cancelled when it was aborted for
|
|
92
|
+
* another reason.
|
|
93
|
+
*/
|
|
94
|
+
ask(source, layer, at, now) {
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
this.#requests.set(layer.definition.id, {
|
|
97
|
+
controller,
|
|
98
|
+
tiles: layer.tiles
|
|
99
|
+
});
|
|
100
|
+
let timedOut = false;
|
|
101
|
+
const timer = setTimeout(() => {
|
|
102
|
+
timedOut = true;
|
|
103
|
+
controller.abort();
|
|
104
|
+
}, IDENTIFY_TIMEOUT_MS);
|
|
105
|
+
const stopped = () => ({
|
|
106
|
+
kind: timedOut ? "failed" : "cancelled",
|
|
107
|
+
layer
|
|
108
|
+
});
|
|
109
|
+
return new Promise((resolve) => {
|
|
110
|
+
controller.signal.addEventListener("abort", () => resolve(stopped()), { once: true });
|
|
111
|
+
let request;
|
|
112
|
+
try {
|
|
113
|
+
request = source.identify({
|
|
114
|
+
definition: layer.definition,
|
|
115
|
+
controls: layer.controls,
|
|
116
|
+
now,
|
|
117
|
+
at,
|
|
118
|
+
signal: controller.signal
|
|
119
|
+
});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
request = Promise.reject(error);
|
|
122
|
+
}
|
|
123
|
+
request.then((features) => resolve({
|
|
124
|
+
kind: "found",
|
|
125
|
+
layer,
|
|
126
|
+
features
|
|
127
|
+
}), (error) => resolve(errorKind(error) === "aborted" ? stopped() : {
|
|
128
|
+
kind: "failed",
|
|
129
|
+
layer
|
|
130
|
+
}));
|
|
131
|
+
}).finally(() => clearTimeout(timer));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Aborts the requests of layers that are no longer on, or whose tiles are no
|
|
135
|
+
* longer the ones they were asked about. `current` is each layer that is on
|
|
136
|
+
* and answers a tap, with its tile URL.
|
|
137
|
+
*/
|
|
138
|
+
abortStale(current) {
|
|
139
|
+
for (const [id, { controller, tiles }] of this.#requests) if (current.get(id) !== tiles) controller.abort();
|
|
140
|
+
}
|
|
141
|
+
/** Aborts every request. */
|
|
142
|
+
cancel() {
|
|
143
|
+
for (const { controller } of this.#requests.values()) controller.abort();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
export { IDENTIFY_TIMEOUT_MS, IdentifyRun, MAX_IDENTIFY_LAYERS, askableLayers, identifiableLayers, outcomeOf, stillCurrent };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=identifyRun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifyRun.js","names":[],"sources":["../../src/layers/identifyRun.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type ControlValues,\n type IdentifiableLayerDefinition,\n type IdentifyReport,\n type IdentifyTarget,\n isIdentifiable,\n type LatLng,\n type LayerDefinition,\n type LayerFeature,\n type LayerSource,\n textOrMessage,\n tileUrl,\n} from \"@mapcairn/core\";\nimport { errorKind } from \"./layerStatus\";\n\n/** The most layers one tap asks, in catalogue order. A tap that could ask more says how many it asked. */\nexport const MAX_IDENTIFY_LAYERS = 4;\n\n/**\n * How long one layer has to answer a tap, in milliseconds. The hook counts it\n * itself: a source only sees that its request was aborted.\n */\nexport const IDENTIFY_TIMEOUT_MS = 8_000;\n\n/** What a layer found at the last tap that answered for it, with the tiles it was showing. */\nexport interface IdentifiedEntry {\n /** The layer's tile URL at the time, so an answer is dropped when its tiles change. */\n readonly tiles: string;\n readonly features: readonly LayerFeature[];\n}\n\n/** A layer that is on and answers a tap, with what a request for it needs. */\nexport interface IdentifiableLayer {\n readonly definition: IdentifiableLayerDefinition;\n readonly controls: ControlValues;\n /** The tile URL its controls give now. */\n readonly tiles: string;\n}\n\n/** What {@link identifiableLayers} reads. */\nexport interface IdentifyInputs {\n /** Every layer in the catalogue, in order. */\n readonly definitions: readonly LayerDefinition[];\n /** The ids of the layers that are on. */\n readonly enabled: readonly string[];\n /** Every listed layer's control values. */\n readonly controls: Readonly<Record<string, ControlValues>>;\n /** The clock, in epoch milliseconds. */\n readonly now: number;\n}\n\n/** The layers that are on and answer a tap, in catalogue order. */\nexport function identifiableLayers({\n definitions,\n enabled,\n controls,\n now,\n}: IdentifyInputs): IdentifiableLayer[] {\n return definitions.flatMap((definition) => {\n if (!isIdentifiable(definition) || !enabled.includes(definition.id)) {\n return [];\n }\n const own = controls[definition.id] ?? {};\n return [\n { definition, controls: own, tiles: tileUrl(definition, own, now) },\n ];\n });\n}\n\n/** Whether a tile layer's `bounds` hold a place. A layer with no bounds holds every place. */\nfunction holds(\n bounds: IdentifiableLayerDefinition[\"source\"][\"bounds\"],\n place: LatLng,\n): boolean {\n if (!bounds) {\n return true;\n }\n const [west, south, east, north] = bounds;\n return (\n place.lng >= west &&\n place.lng <= east &&\n place.lat >= south &&\n place.lat <= north\n );\n}\n\n/**\n * The layers a tap could ask: those that show imagery (the map has not\n * reported none of their tiles loaded, `unavailable` being the tiles each was\n * reported for) and whose `bounds` hold the place.\n */\nexport function askableLayers(\n layers: readonly IdentifiableLayer[],\n unavailable: Readonly<Record<string, string>>,\n place: LatLng,\n): IdentifiableLayer[] {\n return layers.filter(\n ({ definition }) =>\n unavailable[definition.id] === undefined &&\n holds(definition.source.bounds, place),\n );\n}\n\n/** How one layer's request ended. A cancelled one is neither shown nor said. */\nexport type IdentifyAnswer =\n | {\n readonly kind: \"found\";\n readonly layer: IdentifiableLayer;\n readonly features: readonly LayerFeature[];\n }\n | { readonly kind: \"failed\"; readonly layer: IdentifiableLayer }\n | { readonly kind: \"cancelled\"; readonly layer: IdentifiableLayer };\n\n/** What a batch of answers comes to: what to store, what to open and what to say. */\nexport interface IdentifyOutcome {\n /** What each layer that answered found, by layer id. Empty answers are entries too. */\n readonly entries: Readonly<Record<string, IdentifiedEntry>>;\n /** Every feature found, in layer order. */\n readonly hits: readonly {\n readonly layerId: string;\n readonly featureId: string;\n }[];\n readonly report: IdentifyReport;\n}\n\n/**\n * What a batch of answers comes to, or null when every layer was cancelled,\n * which opens and says nothing. A cancelled layer is left out of what was\n * asked and of what was available, because it is no longer there to ask.\n * `available` is how many layers could have been asked, so the report can say\n * when the cap held some back.\n */\nexport function outcomeOf(\n answers: readonly IdentifyAnswer[],\n available: number,\n): IdentifyOutcome | null {\n const found = answers.filter((answer) => answer.kind === \"found\");\n const failed = answers.filter((answer) => answer.kind === \"failed\");\n const cancelled = answers.length - found.length - failed.length;\n if (found.length + failed.length === 0) {\n return null;\n }\n const hits = found.flatMap(({ layer, features }) =>\n features.map((feature) => ({\n layerId: layer.definition.id,\n featureId: feature.id,\n })),\n );\n return {\n entries: Object.fromEntries(\n found.map(({ layer, features }) => [\n layer.definition.id,\n { tiles: layer.tiles, features },\n ]),\n ),\n hits,\n report: {\n found: hits.length,\n asked: found.length + failed.length,\n available: available - cancelled,\n failed: failed.map(({ layer }) => textOrMessage(layer.definition.name)),\n },\n };\n}\n\n/**\n * The answers with those that no longer describe what is shown set to\n * cancelled: a layer that is off now, or whose tiles are not the ones it was\n * asked about, whether it answered or failed. `current` is each layer that is\n * on and answers a tap, with its tile URL, as {@link IdentifyRun.abortStale}\n * reads it.\n */\nexport function stillCurrent(\n answers: readonly IdentifyAnswer[],\n current: ReadonlyMap<string, string>,\n): IdentifyAnswer[] {\n return answers.map((answer) =>\n answer.kind === \"cancelled\" ||\n current.get(answer.layer.definition.id) === answer.layer.tiles\n ? answer\n : { kind: \"cancelled\", layer: answer.layer },\n );\n}\n\n/**\n * One tap's requests: one for each layer asked, each with its own abort\n * controller and its own time limit. A request ends in an answer whichever\n * comes first, the source's reply or the abort, so a source that is slow to\n * notice an abort does not hold the tap up.\n */\nexport class IdentifyRun {\n readonly #requests = new Map<\n string,\n { readonly controller: AbortController; readonly tiles: string }\n >();\n\n /**\n * Asks one layer what is at `at`. Resolves, never rejects: with the\n * features, as failed (the source failed, or the layer ran out of\n * {@link IDENTIFY_TIMEOUT_MS}), or as cancelled when it was aborted for\n * another reason.\n */\n ask(\n source: LayerSource,\n layer: IdentifiableLayer,\n at: IdentifyTarget,\n now: number,\n ): Promise<IdentifyAnswer> {\n const controller = new AbortController();\n this.#requests.set(layer.definition.id, {\n controller,\n tiles: layer.tiles,\n });\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, IDENTIFY_TIMEOUT_MS);\n const stopped = (): IdentifyAnswer => ({\n kind: timedOut ? \"failed\" : \"cancelled\",\n layer,\n });\n return new Promise<IdentifyAnswer>((resolve) => {\n controller.signal.addEventListener(\"abort\", () => resolve(stopped()), {\n once: true,\n });\n // A source that throws before it returns a promise fails like one that rejects.\n let request: Promise<readonly LayerFeature[]>;\n try {\n request = source.identify({\n definition: layer.definition,\n controls: layer.controls,\n now,\n at,\n signal: controller.signal,\n });\n } catch (error) {\n request = Promise.reject(error);\n }\n request.then(\n (features) => resolve({ kind: \"found\", layer, features }),\n (error: unknown) =>\n resolve(\n errorKind(error) === \"aborted\"\n ? stopped()\n : { kind: \"failed\", layer },\n ),\n );\n }).finally(() => clearTimeout(timer));\n }\n\n /**\n * Aborts the requests of layers that are no longer on, or whose tiles are no\n * longer the ones they were asked about. `current` is each layer that is on\n * and answers a tap, with its tile URL.\n */\n abortStale(current: ReadonlyMap<string, string>): void {\n for (const [id, { controller, tiles }] of this.#requests) {\n if (current.get(id) !== tiles) {\n controller.abort();\n }\n }\n }\n\n /** Aborts every request. */\n cancel(): void {\n for (const { controller } of this.#requests.values()) {\n controller.abort();\n }\n }\n}\n"],"mappings":";;;;AAkBA,IAAa,sBAAsB;;;;;AAMnC,IAAa,sBAAsB;;AA8BnC,SAAgB,mBAAmB,EACjC,aACA,SACA,UACA,OACsC;CACtC,OAAO,YAAY,SAAS,eAAe;EACzC,IAAI,CAAC,eAAe,UAAU,KAAK,CAAC,QAAQ,SAAS,WAAW,EAAE,GAChE,OAAO,CAAC;EAEV,MAAM,MAAM,SAAS,WAAW,OAAO,CAAC;EACxC,OAAO,CACL;GAAE;GAAY,UAAU;GAAK,OAAO,QAAQ,YAAY,KAAK,GAAG;EAAE,CACpE;CACF,CAAC;AACH;;AAGA,SAAS,MACP,QACA,OACS;CACT,IAAI,CAAC,QACH,OAAO;CAET,MAAM,CAAC,MAAM,OAAO,MAAM,SAAS;CACnC,OACE,MAAM,OAAO,QACb,MAAM,OAAO,QACb,MAAM,OAAO,SACb,MAAM,OAAO;AAEjB;;;;;;AAOA,SAAgB,cACd,QACA,aACA,OACqB;CACrB,OAAO,OAAO,QACX,EAAE,iBACD,YAAY,WAAW,QAAQ,KAAA,KAC/B,MAAM,WAAW,OAAO,QAAQ,KAAK,CACzC;AACF;;;;;;;;AA+BA,SAAgB,UACd,SACA,WACwB;CACxB,MAAM,QAAQ,QAAQ,QAAQ,WAAW,OAAO,SAAS,OAAO;CAChE,MAAM,SAAS,QAAQ,QAAQ,WAAW,OAAO,SAAS,QAAQ;CAClE,MAAM,YAAY,QAAQ,SAAS,MAAM,SAAS,OAAO;CACzD,IAAI,MAAM,SAAS,OAAO,WAAW,GACnC,OAAO;CAET,MAAM,OAAO,MAAM,SAAS,EAAE,OAAO,eACnC,SAAS,KAAK,aAAa;EACzB,SAAS,MAAM,WAAW;EAC1B,WAAW,QAAQ;CACrB,EAAE,CACJ;CACA,OAAO;EACL,SAAS,OAAO,YACd,MAAM,KAAK,EAAE,OAAO,eAAe,CACjC,MAAM,WAAW,IACjB;GAAE,OAAO,MAAM;GAAO;EAAS,CACjC,CAAC,CACH;EACA;EACA,QAAQ;GACN,OAAO,KAAK;GACZ,OAAO,MAAM,SAAS,OAAO;GAC7B,WAAW,YAAY;GACvB,QAAQ,OAAO,KAAK,EAAE,YAAY,cAAc,MAAM,WAAW,IAAI,CAAC;EACxE;CACF;AACF;;;;;;;;AASA,SAAgB,aACd,SACA,SACkB;CAClB,OAAO,QAAQ,KAAK,WAClB,OAAO,SAAS,eAChB,QAAQ,IAAI,OAAO,MAAM,WAAW,EAAE,MAAM,OAAO,MAAM,QACrD,SACA;EAAE,MAAM;EAAa,OAAO,OAAO;CAAM,CAC/C;AACF;;;;;;;AAQA,IAAa,cAAb,MAAyB;CACvB,4BAAqB,IAAI,IAGvB;;;;;;;CAQF,IACE,QACA,OACA,IACA,KACyB;EACzB,MAAM,aAAa,IAAI,gBAAgB;EACvC,KAAK,UAAU,IAAI,MAAM,WAAW,IAAI;GACtC;GACA,OAAO,MAAM;EACf,CAAC;EACD,IAAI,WAAW;EACf,MAAM,QAAQ,iBAAiB;GAC7B,WAAW;GACX,WAAW,MAAM;EACnB,GAAG,mBAAmB;EACtB,MAAM,iBAAiC;GACrC,MAAM,WAAW,WAAW;GAC5B;EACF;EACA,OAAO,IAAI,SAAyB,YAAY;GAC9C,WAAW,OAAO,iBAAiB,eAAe,QAAQ,QAAQ,CAAC,GAAG,EACpE,MAAM,KACR,CAAC;GAED,IAAI;GACJ,IAAI;IACF,UAAU,OAAO,SAAS;KACxB,YAAY,MAAM;KAClB,UAAU,MAAM;KAChB;KACA;KACA,QAAQ,WAAW;IACrB,CAAC;GACH,SAAS,OAAO;IACd,UAAU,QAAQ,OAAO,KAAK;GAChC;GACA,QAAQ,MACL,aAAa,QAAQ;IAAE,MAAM;IAAS;IAAO;GAAS,CAAC,IACvD,UACC,QACE,UAAU,KAAK,MAAM,YACjB,QAAQ,IACR;IAAE,MAAM;IAAU;GAAM,CAC9B,CACJ;EACF,CAAC,CAAC,CAAC,cAAc,aAAa,KAAK,CAAC;CACtC;;;;;;CAOA,WAAW,SAA4C;EACrD,KAAK,MAAM,CAAC,IAAI,EAAE,YAAY,YAAY,KAAK,WAC7C,IAAI,QAAQ,IAAI,EAAE,MAAM,OACtB,WAAW,MAAM;CAGvB;;CAGA,SAAe;EACb,KAAK,MAAM,EAAE,gBAAgB,KAAK,UAAU,OAAO,GACjD,WAAW,MAAM;CAErB;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LayerError } from "@mapcairn/core";
|
|
2
|
+
// src/layers/layerStatus.ts
|
|
3
|
+
/**
|
|
4
|
+
* The kind of a failed load or detail request, with anything that is not a
|
|
5
|
+
* `LayerError` counted as `invalid`. `aborted` and `empty` are not failures
|
|
6
|
+
* the layer shows as an error.
|
|
7
|
+
*/
|
|
8
|
+
function errorKind(error) {
|
|
9
|
+
return error instanceof LayerError ? error.kind : "invalid";
|
|
10
|
+
}
|
|
11
|
+
export { errorKind };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=layerStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layerStatus.js","names":[],"sources":["../../src/layers/layerStatus.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { LayerError, type ZoomLimit } from \"@mapcairn/core\";\n\n/**\n * Where a layer is: off, on (tiles), loading, loaded, empty, failed, or\n * outside its zoom window. Outside it, the status says the normalised level\n * to zoom to: `zoom-in` for a query layer too far out to ask for features or\n * a vector tile layer too far out to show, `zoom-out` for a vector tile layer\n * too far in. A tile layer is `on` until the map reports that it is still\n * waiting for its first tile (`tiles-slow`) or that none of its tiles loaded\n * (`tiles-unavailable`, which replaces `tiles-slow`). Either lasts until its\n * tiles change, it is turned off, or the map reports that a tile loaded\n * later, when it is `on` again.\n */\nexport type LayerStatus =\n | { readonly kind: \"off\" }\n | { readonly kind: \"on\" }\n | { readonly kind: \"tiles-slow\" }\n | { readonly kind: \"tiles-unavailable\" }\n | { readonly kind: \"loading\" }\n | {\n readonly kind: \"ready\";\n /** How many are drawn. */\n readonly count: number;\n readonly updatedAt: number;\n /** True when the query had more than its cap, so only the first are drawn. */\n readonly capped?: boolean;\n }\n | ZoomLimit\n | { readonly kind: \"empty\"; readonly updatedAt: number }\n | {\n readonly kind: \"error\";\n readonly error: \"network\" | \"invalid\";\n /**\n * Set when the device said it was offline as the request failed, so\n * the layer can word it as that while it still is. Absent otherwise.\n */\n readonly offline?: true;\n };\n\n/**\n * The kind of a failed load or detail request, with anything that is not a\n * `LayerError` counted as `invalid`. `aborted` and `empty` are not failures\n * the layer shows as an error.\n */\nexport function errorKind(\n error: unknown,\n): \"network\" | \"invalid\" | \"aborted\" | \"empty\" {\n return error instanceof LayerError ? error.kind : \"invalid\";\n}\n"],"mappings":";;;;;;;AA8CA,SAAgB,UACd,OAC6C;CAC7C,OAAO,iBAAiB,aAAa,MAAM,OAAO;AACpD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { errorKind } from "./layerStatus.js";
|
|
2
|
+
import { announceLayerCapped, announceLayerEmpty, announceLayerError, announceLayerLoaded, announceLayerOffline, isQueryLayer, textOrMessage } from "@mapcairn/core";
|
|
3
|
+
// src/layers/loadOutcome.ts
|
|
4
|
+
/** The features a layer draws: a query layer draws at most `maxFeatures` of what came back. */
|
|
5
|
+
function drawn(definition, loaded) {
|
|
6
|
+
if (isQueryLayer(definition) && loaded.length > definition.source.maxFeatures) return {
|
|
7
|
+
features: loaded.slice(0, definition.source.maxFeatures),
|
|
8
|
+
capped: true
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
features: loaded,
|
|
12
|
+
capped: false
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** The outcome of a load that returned features, saying so when a query layer drew only the first. */
|
|
16
|
+
function outcomeOfFeatures(definition, loaded, now) {
|
|
17
|
+
const { features, capped } = drawn(definition, loaded);
|
|
18
|
+
return {
|
|
19
|
+
result: {
|
|
20
|
+
status: {
|
|
21
|
+
kind: "ready",
|
|
22
|
+
count: features.length,
|
|
23
|
+
updatedAt: now,
|
|
24
|
+
...capped ? { capped: true } : {}
|
|
25
|
+
},
|
|
26
|
+
features
|
|
27
|
+
},
|
|
28
|
+
spoken: {
|
|
29
|
+
state: capped ? "capped" : "ready",
|
|
30
|
+
message: capped ? announceLayerCapped(textOrMessage(definition.name), features.length) : announceLayerLoaded(textOrMessage(definition.name), features.length),
|
|
31
|
+
priority: "polite"
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The outcome of a load that failed, or null when it was aborted, which says
|
|
37
|
+
* nothing and changes nothing. A feed with nothing in it is `empty`, in the
|
|
38
|
+
* layer's own words; anything else is an error. A network failure while
|
|
39
|
+
* `offline` (the device's own signal at the moment of failure) is worded as
|
|
40
|
+
* that and said politely, since the connection notice has already said so.
|
|
41
|
+
*/
|
|
42
|
+
function outcomeOfFailure(definition, error, now, offline = false) {
|
|
43
|
+
const kind = errorKind(error);
|
|
44
|
+
if (kind === "aborted") return null;
|
|
45
|
+
if (kind === "empty") return {
|
|
46
|
+
result: {
|
|
47
|
+
status: {
|
|
48
|
+
kind: "empty",
|
|
49
|
+
updatedAt: now
|
|
50
|
+
},
|
|
51
|
+
features: []
|
|
52
|
+
},
|
|
53
|
+
spoken: {
|
|
54
|
+
state: "empty",
|
|
55
|
+
message: announceLayerEmpty(textOrMessage(definition.name), textOrMessage(definition.emptyText)),
|
|
56
|
+
priority: "polite"
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
if (kind === "network" && offline) return {
|
|
60
|
+
result: {
|
|
61
|
+
status: {
|
|
62
|
+
kind: "error",
|
|
63
|
+
error: kind,
|
|
64
|
+
offline: true
|
|
65
|
+
},
|
|
66
|
+
features: []
|
|
67
|
+
},
|
|
68
|
+
spoken: {
|
|
69
|
+
state: "error",
|
|
70
|
+
message: announceLayerOffline(textOrMessage(definition.name)),
|
|
71
|
+
priority: "polite"
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
result: {
|
|
76
|
+
status: {
|
|
77
|
+
kind: "error",
|
|
78
|
+
error: kind
|
|
79
|
+
},
|
|
80
|
+
features: []
|
|
81
|
+
},
|
|
82
|
+
spoken: {
|
|
83
|
+
state: "error",
|
|
84
|
+
message: announceLayerError(textOrMessage(definition.name), kind),
|
|
85
|
+
priority: "assertive"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Loads what a layer wants through the source and works out what the layer
|
|
91
|
+
* then shows and says. Resolves to null when the load was cancelled, by its
|
|
92
|
+
* own signal or because the source said it was aborted. `isOffline` is asked
|
|
93
|
+
* when a load fails, not before it, so a failure is worded by what was true then.
|
|
94
|
+
*/
|
|
95
|
+
function loadOutcome(source, load, now, signal, isOffline = () => false) {
|
|
96
|
+
const { definition, controls, area } = load;
|
|
97
|
+
return source.load({
|
|
98
|
+
definition,
|
|
99
|
+
controls,
|
|
100
|
+
now: now(),
|
|
101
|
+
signal,
|
|
102
|
+
...area ? { area } : {}
|
|
103
|
+
}).then((loaded) => outcomeOfFeatures(definition, loaded, now()), (error) => signal.aborted ? null : outcomeOfFailure(definition, error, now(), isOffline()));
|
|
104
|
+
}
|
|
105
|
+
export { loadOutcome, outcomeOfFailure, outcomeOfFeatures };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=loadOutcome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadOutcome.js","names":[],"sources":["../../src/layers/loadOutcome.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceLayerCapped,\n announceLayerEmpty,\n announceLayerError,\n announceLayerLoaded,\n announceLayerOffline,\n isQueryLayer,\n type LayerFeature,\n type LayerSource,\n type Message,\n textOrMessage,\n} from \"@mapcairn/core\";\nimport type { AnnouncePriority } from \"../ui/LiveRegion\";\nimport { errorKind, type LayerStatus } from \"./layerStatus\";\nimport type { LoadableLayer, WantedLoad } from \"./loadRequests\";\n\n/** What a layer shows once a load has settled. */\nexport interface LoadResult {\n readonly status: LayerStatus;\n readonly features: readonly LayerFeature[];\n}\n\n/** What a settled load says aloud, so a query layer can say each of them once. */\nexport type SpokenState = \"ready\" | \"capped\" | \"empty\" | \"error\";\n\n/** A line for the live region, and the state of the layer it describes. */\nexport interface Spoken {\n readonly state: SpokenState;\n readonly message: Message;\n readonly priority: AnnouncePriority;\n}\n\n/** A settled load: what the layer shows, and what is said about it. */\nexport interface LoadOutcome {\n readonly result: LoadResult;\n readonly spoken: Spoken;\n}\n\n/** The features a layer draws: a query layer draws at most `maxFeatures` of what came back. */\nfunction drawn(\n definition: LoadableLayer,\n loaded: readonly LayerFeature[],\n): { readonly features: readonly LayerFeature[]; readonly capped: boolean } {\n if (\n isQueryLayer(definition) &&\n loaded.length > definition.source.maxFeatures\n ) {\n return {\n features: loaded.slice(0, definition.source.maxFeatures),\n capped: true,\n };\n }\n return { features: loaded, capped: false };\n}\n\n/** The outcome of a load that returned features, saying so when a query layer drew only the first. */\nexport function outcomeOfFeatures(\n definition: LoadableLayer,\n loaded: readonly LayerFeature[],\n now: number,\n): LoadOutcome {\n const { features, capped } = drawn(definition, loaded);\n return {\n result: {\n status: {\n kind: \"ready\",\n count: features.length,\n updatedAt: now,\n ...(capped ? { capped: true } : {}),\n },\n features,\n },\n spoken: {\n state: capped ? \"capped\" : \"ready\",\n message: capped\n ? announceLayerCapped(textOrMessage(definition.name), features.length)\n : announceLayerLoaded(textOrMessage(definition.name), features.length),\n priority: \"polite\",\n },\n };\n}\n\n/**\n * The outcome of a load that failed, or null when it was aborted, which says\n * nothing and changes nothing. A feed with nothing in it is `empty`, in the\n * layer's own words; anything else is an error. A network failure while\n * `offline` (the device's own signal at the moment of failure) is worded as\n * that and said politely, since the connection notice has already said so.\n */\nexport function outcomeOfFailure(\n definition: LoadableLayer,\n error: unknown,\n now: number,\n offline = false,\n): LoadOutcome | null {\n const kind = errorKind(error);\n if (kind === \"aborted\") {\n return null;\n }\n if (kind === \"empty\") {\n return {\n result: { status: { kind: \"empty\", updatedAt: now }, features: [] },\n spoken: {\n state: \"empty\",\n message: announceLayerEmpty(\n textOrMessage(definition.name),\n textOrMessage(definition.emptyText),\n ),\n priority: \"polite\",\n },\n };\n }\n if (kind === \"network\" && offline) {\n return {\n result: {\n status: { kind: \"error\", error: kind, offline: true },\n features: [],\n },\n spoken: {\n state: \"error\",\n message: announceLayerOffline(textOrMessage(definition.name)),\n priority: \"polite\",\n },\n };\n }\n return {\n result: { status: { kind: \"error\", error: kind }, features: [] },\n spoken: {\n state: \"error\",\n message: announceLayerError(textOrMessage(definition.name), kind),\n priority: \"assertive\",\n },\n };\n}\n\n/**\n * Loads what a layer wants through the source and works out what the layer\n * then shows and says. Resolves to null when the load was cancelled, by its\n * own signal or because the source said it was aborted. `isOffline` is asked\n * when a load fails, not before it, so a failure is worded by what was true then.\n */\nexport function loadOutcome(\n source: LayerSource,\n load: WantedLoad,\n now: () => number,\n signal: AbortSignal,\n isOffline: () => boolean = () => false,\n): Promise<LoadOutcome | null> {\n const { definition, controls, area } = load;\n return source\n .load({\n definition,\n controls,\n now: now(),\n signal,\n ...(area ? { area } : {}),\n })\n .then(\n (loaded) => outcomeOfFeatures(definition, loaded, now()),\n (error: unknown) =>\n signal.aborted\n ? null\n : outcomeOfFailure(definition, error, now(), isOffline()),\n );\n}\n"],"mappings":";;;;AAyCA,SAAS,MACP,YACA,QAC0E;CAC1E,IACE,aAAa,UAAU,KACvB,OAAO,SAAS,WAAW,OAAO,aAElC,OAAO;EACL,UAAU,OAAO,MAAM,GAAG,WAAW,OAAO,WAAW;EACvD,QAAQ;CACV;CAEF,OAAO;EAAE,UAAU;EAAQ,QAAQ;CAAM;AAC3C;;AAGA,SAAgB,kBACd,YACA,QACA,KACa;CACb,MAAM,EAAE,UAAU,WAAW,MAAM,YAAY,MAAM;CACrD,OAAO;EACL,QAAQ;GACN,QAAQ;IACN,MAAM;IACN,OAAO,SAAS;IAChB,WAAW;IACX,GAAI,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;GACnC;GACA;EACF;EACA,QAAQ;GACN,OAAO,SAAS,WAAW;GAC3B,SAAS,SACL,oBAAoB,cAAc,WAAW,IAAI,GAAG,SAAS,MAAM,IACnE,oBAAoB,cAAc,WAAW,IAAI,GAAG,SAAS,MAAM;GACvE,UAAU;EACZ;CACF;AACF;;;;;;;;AASA,SAAgB,iBACd,YACA,OACA,KACA,UAAU,OACU;CACpB,MAAM,OAAO,UAAU,KAAK;CAC5B,IAAI,SAAS,WACX,OAAO;CAET,IAAI,SAAS,SACX,OAAO;EACL,QAAQ;GAAE,QAAQ;IAAE,MAAM;IAAS,WAAW;GAAI;GAAG,UAAU,CAAC;EAAE;EAClE,QAAQ;GACN,OAAO;GACP,SAAS,mBACP,cAAc,WAAW,IAAI,GAC7B,cAAc,WAAW,SAAS,CACpC;GACA,UAAU;EACZ;CACF;CAEF,IAAI,SAAS,aAAa,SACxB,OAAO;EACL,QAAQ;GACN,QAAQ;IAAE,MAAM;IAAS,OAAO;IAAM,SAAS;GAAK;GACpD,UAAU,CAAC;EACb;EACA,QAAQ;GACN,OAAO;GACP,SAAS,qBAAqB,cAAc,WAAW,IAAI,CAAC;GAC5D,UAAU;EACZ;CACF;CAEF,OAAO;EACL,QAAQ;GAAE,QAAQ;IAAE,MAAM;IAAS,OAAO;GAAK;GAAG,UAAU,CAAC;EAAE;EAC/D,QAAQ;GACN,OAAO;GACP,SAAS,mBAAmB,cAAc,WAAW,IAAI,GAAG,IAAI;GAChE,UAAU;EACZ;CACF;AACF;;;;;;;AAQA,SAAgB,YACd,QACA,MACA,KACA,QACA,kBAAiC,OACJ;CAC7B,MAAM,EAAE,YAAY,UAAU,SAAS;CACvC,OAAO,OACJ,KAAK;EACJ;EACA;EACA,KAAK,IAAI;EACT;EACA,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;CACzB,CAAC,CAAC,CACD,MACE,WAAW,kBAAkB,YAAY,QAAQ,IAAI,CAAC,IACtD,UACC,OAAO,UACH,OACA,iBAAiB,YAAY,OAAO,IAAI,GAAG,UAAU,CAAC,CAC9D;AACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { announceLayerZoomIn, announceLayerZoomOut, isQueryLayer, textOrMessage } from "@mapcairn/core";
|
|
2
|
+
// src/layers/loadReport.ts
|
|
3
|
+
/**
|
|
4
|
+
* Says what a settled load found. A feed layer says it every time; a query
|
|
5
|
+
* layer says each state once, because a pan to another window is not news.
|
|
6
|
+
*/
|
|
7
|
+
function reportLoad(definition, spoken, announced, announce) {
|
|
8
|
+
if (isQueryLayer(definition) && announced.get(definition.id) === spoken.state) return;
|
|
9
|
+
announced.set(definition.id, spoken.state);
|
|
10
|
+
announce(spoken.message, { priority: spoken.priority });
|
|
11
|
+
}
|
|
12
|
+
function isZoomState(state) {
|
|
13
|
+
return state === "zoom-in" || state === "zoom-out";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Tells each layer that is outside its zoom window which way to zoom and to
|
|
17
|
+
* which level, once until it says something else. A layer that is no longer
|
|
18
|
+
* outside its window forgets what it said, so it is told again the next time
|
|
19
|
+
* it goes out: a layer with nothing to load (vector tiles) says nothing else
|
|
20
|
+
* in between.
|
|
21
|
+
*/
|
|
22
|
+
function reportZoomLimits(limited, announced, announce) {
|
|
23
|
+
const stillOut = new Set(limited.map(({ definition }) => definition.id));
|
|
24
|
+
for (const [id, state] of announced) if (isZoomState(state) && !stillOut.has(id)) announced.delete(id);
|
|
25
|
+
for (const { definition, limit } of limited) {
|
|
26
|
+
if (announced.get(definition.id) === limit.kind) continue;
|
|
27
|
+
announced.set(definition.id, limit.kind);
|
|
28
|
+
announce(limit.kind === "zoom-in" ? announceLayerZoomIn(textOrMessage(definition.name), limit.level) : announceLayerZoomOut(textOrMessage(definition.name), limit.level), { priority: "polite" });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export { reportLoad, reportZoomLimits };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=loadReport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadReport.js","names":[],"sources":["../../src/layers/loadReport.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceLayerZoomIn,\n announceLayerZoomOut,\n isQueryLayer,\n type LayerDefinition,\n textOrMessage,\n type ZoomLimit,\n} from \"@mapcairn/core\";\nimport type { Announce } from \"../ui/LiveRegion\";\nimport type { Spoken, SpokenState } from \"./loadOutcome\";\n\n/** What a layer last said aloud, or which way it was told to zoom. */\nexport type AnnouncedState = SpokenState | ZoomLimit[\"kind\"];\n\n/**\n * What each query layer last said aloud, by layer id, so a refresh for\n * another part of the map is not announced again, only a change in what it\n * shows.\n */\nexport type AnnouncedStates = Map<string, AnnouncedState>;\n\n/**\n * Says what a settled load found. A feed layer says it every time; a query\n * layer says each state once, because a pan to another window is not news.\n */\nexport function reportLoad(\n definition: LayerDefinition,\n spoken: Spoken,\n announced: AnnouncedStates,\n announce: Announce,\n): void {\n if (\n isQueryLayer(definition) &&\n announced.get(definition.id) === spoken.state\n ) {\n return;\n }\n announced.set(definition.id, spoken.state);\n announce(spoken.message, { priority: spoken.priority });\n}\n\n/** A layer outside its zoom window, and the limit it is outside. */\nexport interface LimitedLayer {\n readonly definition: LayerDefinition;\n readonly limit: ZoomLimit;\n}\n\nfunction isZoomState(state: AnnouncedState | undefined): boolean {\n return state === \"zoom-in\" || state === \"zoom-out\";\n}\n\n/**\n * Tells each layer that is outside its zoom window which way to zoom and to\n * which level, once until it says something else. A layer that is no longer\n * outside its window forgets what it said, so it is told again the next time\n * it goes out: a layer with nothing to load (vector tiles) says nothing else\n * in between.\n */\nexport function reportZoomLimits(\n limited: readonly LimitedLayer[],\n announced: AnnouncedStates,\n announce: Announce,\n): void {\n const stillOut = new Set(limited.map(({ definition }) => definition.id));\n for (const [id, state] of announced) {\n if (isZoomState(state) && !stillOut.has(id)) {\n announced.delete(id);\n }\n }\n for (const { definition, limit } of limited) {\n if (announced.get(definition.id) === limit.kind) {\n continue;\n }\n announced.set(definition.id, limit.kind);\n announce(\n limit.kind === \"zoom-in\"\n ? announceLayerZoomIn(textOrMessage(definition.name), limit.level)\n : announceLayerZoomOut(textOrMessage(definition.name), limit.level),\n { priority: \"polite\" },\n );\n }\n}\n"],"mappings":";;;;;;AA2BA,SAAgB,WACd,YACA,QACA,WACA,UACM;CACN,IACE,aAAa,UAAU,KACvB,UAAU,IAAI,WAAW,EAAE,MAAM,OAAO,OAExC;CAEF,UAAU,IAAI,WAAW,IAAI,OAAO,KAAK;CACzC,SAAS,OAAO,SAAS,EAAE,UAAU,OAAO,SAAS,CAAC;AACxD;AAQA,SAAS,YAAY,OAA4C;CAC/D,OAAO,UAAU,aAAa,UAAU;AAC1C;;;;;;;;AASA,SAAgB,iBACd,SACA,WACA,UACM;CACN,MAAM,WAAW,IAAI,IAAI,QAAQ,KAAK,EAAE,iBAAiB,WAAW,EAAE,CAAC;CACvE,KAAK,MAAM,CAAC,IAAI,UAAU,WACxB,IAAI,YAAY,KAAK,KAAK,CAAC,SAAS,IAAI,EAAE,GACxC,UAAU,OAAO,EAAE;CAGvB,KAAK,MAAM,EAAE,YAAY,WAAW,SAAS;EAC3C,IAAI,UAAU,IAAI,WAAW,EAAE,MAAM,MAAM,MACzC;EAEF,UAAU,IAAI,WAAW,IAAI,MAAM,IAAI;EACvC,SACE,MAAM,SAAS,YACX,oBAAoB,cAAc,WAAW,IAAI,GAAG,MAAM,KAAK,IAC/D,qBAAqB,cAAc,WAAW,IAAI,GAAG,MAAM,KAAK,GACpE,EAAE,UAAU,SAAS,CACvB;CACF;AACF"}
|