@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.
Files changed (315) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +167 -2
  3. package/dist/chrome/Attribution/Attribution.js +304 -0
  4. package/dist/chrome/Attribution/Attribution.js.map +1 -0
  5. package/dist/chrome/Attribution/Attribution.styles.js +10 -0
  6. package/dist/chrome/Attribution/Attribution.styles.js.map +1 -0
  7. package/dist/chrome/Attribution/AttributionSkeleton.js +29 -0
  8. package/dist/chrome/Attribution/AttributionSkeleton.js.map +1 -0
  9. package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js +83 -0
  10. package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js.map +1 -0
  11. package/dist/chrome/EndStack/EndStack.js +157 -0
  12. package/dist/chrome/EndStack/EndStack.js.map +1 -0
  13. package/dist/chrome/EndStack/EndStack.styles.js +12 -0
  14. package/dist/chrome/EndStack/EndStack.styles.js.map +1 -0
  15. package/dist/chrome/EndStack/EndStackSkeleton.js +78 -0
  16. package/dist/chrome/EndStack/EndStackSkeleton.js.map +1 -0
  17. package/dist/chrome/EndStack/endStackHeight.js +22 -0
  18. package/dist/chrome/EndStack/endStackHeight.js.map +1 -0
  19. package/dist/chrome/MapChrome/MapChrome.js +488 -0
  20. package/dist/chrome/MapChrome/MapChrome.js.map +1 -0
  21. package/dist/chrome/MapChrome/MapChrome.styles.js +15 -0
  22. package/dist/chrome/MapChrome/MapChrome.styles.js.map +1 -0
  23. package/dist/chrome/MapChrome/chromeSurface.js +18 -0
  24. package/dist/chrome/MapChrome/chromeSurface.js.map +1 -0
  25. package/dist/chrome/MapChrome/chromeVars.js +71 -0
  26. package/dist/chrome/MapChrome/chromeVars.js.map +1 -0
  27. package/dist/chrome/MapChrome/mapKeyPlacement.js +41 -0
  28. package/dist/chrome/MapChrome/mapKeyPlacement.js.map +1 -0
  29. package/dist/chrome/MapChrome/sharesWidth.js +13 -0
  30. package/dist/chrome/MapChrome/sharesWidth.js.map +1 -0
  31. package/dist/chrome/MapReadout/MapReadout.js +199 -0
  32. package/dist/chrome/MapReadout/MapReadout.js.map +1 -0
  33. package/dist/chrome/MapReadout/MapReadout.styles.js +14 -0
  34. package/dist/chrome/MapReadout/MapReadout.styles.js.map +1 -0
  35. package/dist/chrome/Sheet/Sheet.js +412 -0
  36. package/dist/chrome/Sheet/Sheet.js.map +1 -0
  37. package/dist/chrome/Sheet/Sheet.styles.js +14 -0
  38. package/dist/chrome/Sheet/Sheet.styles.js.map +1 -0
  39. package/dist/chrome/focusRegistry.js +76 -0
  40. package/dist/chrome/focusRegistry.js.map +1 -0
  41. package/dist/chrome/layoutContext.js +30 -0
  42. package/dist/chrome/layoutContext.js.map +1 -0
  43. package/dist/chrome/useScrollEdges.js +53 -0
  44. package/dist/chrome/useScrollEdges.js.map +1 -0
  45. package/dist/host/MapContext.js +16 -0
  46. package/dist/host/MapContext.js.map +1 -0
  47. package/dist/host/MapView.js +189 -0
  48. package/dist/host/MapView.js.map +1 -0
  49. package/dist/host/MapView.styles.js +16 -0
  50. package/dist/host/MapView.styles.js.map +1 -0
  51. package/dist/host/overlays/AccuracyCircle.js +36 -0
  52. package/dist/host/overlays/AccuracyCircle.js.map +1 -0
  53. package/dist/host/overlays/CentreCrosshair.js +40 -0
  54. package/dist/host/overlays/CentreCrosshair.js.map +1 -0
  55. package/dist/host/overlays/DrawOverlay.js +221 -0
  56. package/dist/host/overlays/DrawOverlay.js.map +1 -0
  57. package/dist/host/overlays/MapOverlayLayer.js +27 -0
  58. package/dist/host/overlays/MapOverlayLayer.js.map +1 -0
  59. package/dist/host/overlays/MeasureOverlay.js +87 -0
  60. package/dist/host/overlays/MeasureOverlay.js.map +1 -0
  61. package/dist/host/overlays/PinMarker.js +40 -0
  62. package/dist/host/overlays/PinMarker.js.map +1 -0
  63. package/dist/host/overlays/geometry.js +41 -0
  64. package/dist/host/overlays/geometry.js.map +1 -0
  65. package/dist/host/overlays/overlays.styles.js +27 -0
  66. package/dist/host/overlays/overlays.styles.js.map +1 -0
  67. package/dist/host/pointerTargets.js +22 -0
  68. package/dist/host/pointerTargets.js.map +1 -0
  69. package/dist/host/useLongPress.js +102 -0
  70. package/dist/host/useLongPress.js.map +1 -0
  71. package/dist/host/useMapEngine.js +352 -0
  72. package/dist/host/useMapEngine.js.map +1 -0
  73. package/dist/host/usePointerPosition.js +60 -0
  74. package/dist/host/usePointerPosition.js.map +1 -0
  75. package/dist/index.d.ts +3845 -0
  76. package/dist/index.js +89 -0
  77. package/dist/layers/CatalogueStatus.js +138 -0
  78. package/dist/layers/CatalogueStatus.js.map +1 -0
  79. package/dist/layers/DateTimeControl.js +101 -0
  80. package/dist/layers/DateTimeControl.js.map +1 -0
  81. package/dist/layers/FeatureCard.js +147 -0
  82. package/dist/layers/FeatureCard.js.map +1 -0
  83. package/dist/layers/FeatureChoices.js +101 -0
  84. package/dist/layers/FeatureChoices.js.map +1 -0
  85. package/dist/layers/FeatureGlyph.js +56 -0
  86. package/dist/layers/FeatureGlyph.js.map +1 -0
  87. package/dist/layers/IdentifyStatus.js +36 -0
  88. package/dist/layers/IdentifyStatus.js.map +1 -0
  89. package/dist/layers/LayerItem.js +321 -0
  90. package/dist/layers/LayerItem.js.map +1 -0
  91. package/dist/layers/LayerKey.js +36 -0
  92. package/dist/layers/LayerKey.js.map +1 -0
  93. package/dist/layers/Layers.styles.js +50 -0
  94. package/dist/layers/Layers.styles.js.map +1 -0
  95. package/dist/layers/LayersSection.js +267 -0
  96. package/dist/layers/LayersSection.js.map +1 -0
  97. package/dist/layers/MapDataLayers.js +261 -0
  98. package/dist/layers/MapDataLayers.js.map +1 -0
  99. package/dist/layers/MapKey.js +131 -0
  100. package/dist/layers/MapKey.js.map +1 -0
  101. package/dist/layers/MapKey.styles.js +16 -0
  102. package/dist/layers/MapKey.styles.js.map +1 -0
  103. package/dist/layers/MarkerGlyph.js +84 -0
  104. package/dist/layers/MarkerGlyph.js.map +1 -0
  105. package/dist/layers/SelectionProvider.js +27 -0
  106. package/dist/layers/SelectionProvider.js.map +1 -0
  107. package/dist/layers/ShapeGlyph.js +122 -0
  108. package/dist/layers/ShapeGlyph.js.map +1 -0
  109. package/dist/layers/TurnOffActions.js +147 -0
  110. package/dist/layers/TurnOffActions.js.map +1 -0
  111. package/dist/layers/answersTap.js +16 -0
  112. package/dist/layers/answersTap.js.map +1 -0
  113. package/dist/layers/catalogueNotice.js +65 -0
  114. package/dist/layers/catalogueNotice.js.map +1 -0
  115. package/dist/layers/catalogueReconcile.js +55 -0
  116. package/dist/layers/catalogueReconcile.js.map +1 -0
  117. package/dist/layers/catalogueView.js +32 -0
  118. package/dist/layers/catalogueView.js.map +1 -0
  119. package/dist/layers/featureTitle.js +14 -0
  120. package/dist/layers/featureTitle.js.map +1 -0
  121. package/dist/layers/identifyFeedback.js +30 -0
  122. package/dist/layers/identifyFeedback.js.map +1 -0
  123. package/dist/layers/identifyRun.js +148 -0
  124. package/dist/layers/identifyRun.js.map +1 -0
  125. package/dist/layers/layerStatus.js +13 -0
  126. package/dist/layers/layerStatus.js.map +1 -0
  127. package/dist/layers/loadOutcome.js +107 -0
  128. package/dist/layers/loadOutcome.js.map +1 -0
  129. package/dist/layers/loadReport.js +33 -0
  130. package/dist/layers/loadReport.js.map +1 -0
  131. package/dist/layers/loadRequests.js +73 -0
  132. package/dist/layers/loadRequests.js.map +1 -0
  133. package/dist/layers/mapFeatures.js +307 -0
  134. package/dist/layers/mapFeatures.js.map +1 -0
  135. package/dist/layers/mapKeyBlocks.js +24 -0
  136. package/dist/layers/mapKeyBlocks.js.map +1 -0
  137. package/dist/layers/reveal.js +119 -0
  138. package/dist/layers/reveal.js.map +1 -0
  139. package/dist/layers/selectionMessages.js +53 -0
  140. package/dist/layers/selectionMessages.js.map +1 -0
  141. package/dist/layers/selectionResolve.js +111 -0
  142. package/dist/layers/selectionResolve.js.map +1 -0
  143. package/dist/layers/useDataLayers.js +940 -0
  144. package/dist/layers/useDataLayers.js.map +1 -0
  145. package/dist/layers/useFeatureSelection.js +179 -0
  146. package/dist/layers/useFeatureSelection.js.map +1 -0
  147. package/dist/layers/useScrolls.js +37 -0
  148. package/dist/layers/useScrolls.js.map +1 -0
  149. package/dist/panels/BasemapPicker/BasemapPicker.js +169 -0
  150. package/dist/panels/BasemapPicker/BasemapPicker.js.map +1 -0
  151. package/dist/panels/BasemapPicker/BasemapPicker.styles.js +42 -0
  152. package/dist/panels/BasemapPicker/BasemapPicker.styles.js.map +1 -0
  153. package/dist/panels/ExportSection/ExportSection.js +91 -0
  154. package/dist/panels/ExportSection/ExportSection.js.map +1 -0
  155. package/dist/panels/HelpSection/HelpSection.js +163 -0
  156. package/dist/panels/HelpSection/HelpSection.js.map +1 -0
  157. package/dist/panels/HelpSection/HelpSection.styles.js +9 -0
  158. package/dist/panels/HelpSection/HelpSection.styles.js.map +1 -0
  159. package/dist/panels/PinSection/PinSection.js +39 -0
  160. package/dist/panels/PinSection/PinSection.js.map +1 -0
  161. package/dist/panels/Section/Section.js +43 -0
  162. package/dist/panels/Section/Section.js.map +1 -0
  163. package/dist/panels/Section/Section.styles.js +13 -0
  164. package/dist/panels/Section/Section.styles.js.map +1 -0
  165. package/dist/panels/SettingsSection/LanguageField.js +126 -0
  166. package/dist/panels/SettingsSection/LanguageField.js.map +1 -0
  167. package/dist/panels/SettingsSection/SettingsSection.js +175 -0
  168. package/dist/panels/SettingsSection/SettingsSection.js.map +1 -0
  169. package/dist/panels/SettingsSection/SettingsSection.styles.js +9 -0
  170. package/dist/panels/SettingsSection/SettingsSection.styles.js.map +1 -0
  171. package/dist/panels/ShapesSection/ShapesSection.js +229 -0
  172. package/dist/panels/ShapesSection/ShapesSection.js.map +1 -0
  173. package/dist/panels/ShapesSection/ShapesSection.styles.js +7 -0
  174. package/dist/panels/ShapesSection/ShapesSection.styles.js.map +1 -0
  175. package/dist/panels/SheetContent/SheetContent.js +92 -0
  176. package/dist/panels/SheetContent/SheetContent.js.map +1 -0
  177. package/dist/panels/SheetContent/SheetContent.styles.js +6 -0
  178. package/dist/panels/SheetContent/SheetContent.styles.js.map +1 -0
  179. package/dist/services/ServicesProvider.js +42 -0
  180. package/dist/services/ServicesProvider.js.map +1 -0
  181. package/dist/services/activeMessages.js +140 -0
  182. package/dist/services/activeMessages.js.map +1 -0
  183. package/dist/services/basemapAvailability.js +78 -0
  184. package/dist/services/basemapAvailability.js.map +1 -0
  185. package/dist/services/englishMessages.js +10 -0
  186. package/dist/services/englishMessages.js.map +1 -0
  187. package/dist/services/hooks.js +214 -0
  188. package/dist/services/hooks.js.map +1 -0
  189. package/dist/styles.css +2866 -0
  190. package/dist/styles.css.d.ts +1 -0
  191. package/dist/tools/Directions/Directions.styles.js +25 -0
  192. package/dist/tools/Directions/Directions.styles.js.map +1 -0
  193. package/dist/tools/Directions/DirectionsOverlay.js +46 -0
  194. package/dist/tools/Directions/DirectionsOverlay.js.map +1 -0
  195. package/dist/tools/Directions/DirectionsPanel.js +428 -0
  196. package/dist/tools/Directions/DirectionsPanel.js.map +1 -0
  197. package/dist/tools/Directions/MapDirections.js +84 -0
  198. package/dist/tools/Directions/MapDirections.js.map +1 -0
  199. package/dist/tools/Directions/useDirections.js +226 -0
  200. package/dist/tools/Directions/useDirections.js.map +1 -0
  201. package/dist/tools/Directions/useFreeCentre.js +30 -0
  202. package/dist/tools/Directions/useFreeCentre.js.map +1 -0
  203. package/dist/tools/DrawToolbar/DrawMapBindings.js +34 -0
  204. package/dist/tools/DrawToolbar/DrawMapBindings.js.map +1 -0
  205. package/dist/tools/DrawToolbar/DrawToolbar.js +296 -0
  206. package/dist/tools/DrawToolbar/DrawToolbar.js.map +1 -0
  207. package/dist/tools/DrawToolbar/DrawToolbar.styles.js +21 -0
  208. package/dist/tools/DrawToolbar/DrawToolbar.styles.js.map +1 -0
  209. package/dist/tools/DrawToolbar/imageDrawing.js +24 -0
  210. package/dist/tools/DrawToolbar/imageDrawing.js.map +1 -0
  211. package/dist/tools/DrawToolbar/useDraw.js +543 -0
  212. package/dist/tools/DrawToolbar/useDraw.js.map +1 -0
  213. package/dist/tools/MeasureToolbar/MeasureToolbar.js +116 -0
  214. package/dist/tools/MeasureToolbar/MeasureToolbar.js.map +1 -0
  215. package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js +12 -0
  216. package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js.map +1 -0
  217. package/dist/tools/MeasureToolbar/useMeasure.js +75 -0
  218. package/dist/tools/MeasureToolbar/useMeasure.js.map +1 -0
  219. package/dist/tools/PinCard/PinCard.js +174 -0
  220. package/dist/tools/PinCard/PinCard.js.map +1 -0
  221. package/dist/tools/PinCard/PinCard.styles.js +16 -0
  222. package/dist/tools/PinCard/PinCard.styles.js.map +1 -0
  223. package/dist/tools/PinCard/useReverseAddress.js +77 -0
  224. package/dist/tools/PinCard/useReverseAddress.js.map +1 -0
  225. package/dist/tools/SearchPill/SearchPill.js +292 -0
  226. package/dist/tools/SearchPill/SearchPill.js.map +1 -0
  227. package/dist/tools/SearchPill/SearchPill.styles.js +16 -0
  228. package/dist/tools/SearchPill/SearchPill.styles.js.map +1 -0
  229. package/dist/tools/SearchPill/SearchPillSkeleton.js +41 -0
  230. package/dist/tools/SearchPill/SearchPillSkeleton.js.map +1 -0
  231. package/dist/tools/SearchPill/useSearch.js +143 -0
  232. package/dist/tools/SearchPill/useSearch.js.map +1 -0
  233. package/dist/tools/SearchPill/useSuggestions.js +105 -0
  234. package/dist/tools/SearchPill/useSuggestions.js.map +1 -0
  235. package/dist/tools/Tour/TourCard.js +156 -0
  236. package/dist/tools/Tour/TourCard.js.map +1 -0
  237. package/dist/tools/Tour/TourCard.styles.js +10 -0
  238. package/dist/tools/Tour/TourCard.styles.js.map +1 -0
  239. package/dist/tools/Tour/useTour.js +110 -0
  240. package/dist/tools/Tour/useTour.js.map +1 -0
  241. package/dist/tools/locate/useLocate.js +94 -0
  242. package/dist/tools/locate/useLocate.js.map +1 -0
  243. package/dist/ui/Button/Button.js +36 -0
  244. package/dist/ui/Button/Button.js.map +1 -0
  245. package/dist/ui/Button/Button.styles.js +17 -0
  246. package/dist/ui/Button/Button.styles.js.map +1 -0
  247. package/dist/ui/Chip/Chip.js +37 -0
  248. package/dist/ui/Chip/Chip.js.map +1 -0
  249. package/dist/ui/Chip/Chip.styles.js +29 -0
  250. package/dist/ui/Chip/Chip.styles.js.map +1 -0
  251. package/dist/ui/ControlGroup/ControlGroup.js +23 -0
  252. package/dist/ui/ControlGroup/ControlGroup.js.map +1 -0
  253. package/dist/ui/ControlGroup/ControlGroup.styles.js +6 -0
  254. package/dist/ui/ControlGroup/ControlGroup.styles.js.map +1 -0
  255. package/dist/ui/EmptyState/EmptyState.js +37 -0
  256. package/dist/ui/EmptyState/EmptyState.js.map +1 -0
  257. package/dist/ui/EmptyState/EmptyState.styles.js +10 -0
  258. package/dist/ui/EmptyState/EmptyState.styles.js.map +1 -0
  259. package/dist/ui/Icon/Icon.js +28 -0
  260. package/dist/ui/Icon/Icon.js.map +1 -0
  261. package/dist/ui/Icon/Icon.styles.js +8 -0
  262. package/dist/ui/Icon/Icon.styles.js.map +1 -0
  263. package/dist/ui/IconButton/IconButton.js +47 -0
  264. package/dist/ui/IconButton/IconButton.js.map +1 -0
  265. package/dist/ui/IconButton/IconButton.styles.js +27 -0
  266. package/dist/ui/IconButton/IconButton.styles.js.map +1 -0
  267. package/dist/ui/Isolate/Isolate.js +26 -0
  268. package/dist/ui/Isolate/Isolate.js.map +1 -0
  269. package/dist/ui/Isolate/fillSlots.js +27 -0
  270. package/dist/ui/Isolate/fillSlots.js.map +1 -0
  271. package/dist/ui/ListRow/ListRow.js +59 -0
  272. package/dist/ui/ListRow/ListRow.js.map +1 -0
  273. package/dist/ui/ListRow/ListRow.styles.js +30 -0
  274. package/dist/ui/ListRow/ListRow.styles.js.map +1 -0
  275. package/dist/ui/LiveRegion/LiveRegion.js +88 -0
  276. package/dist/ui/LiveRegion/LiveRegion.js.map +1 -0
  277. package/dist/ui/LiveRegion/announcer.js +114 -0
  278. package/dist/ui/LiveRegion/announcer.js.map +1 -0
  279. package/dist/ui/SegmentedControl/SegmentedControl.js +55 -0
  280. package/dist/ui/SegmentedControl/SegmentedControl.js.map +1 -0
  281. package/dist/ui/SegmentedControl/SegmentedControl.styles.js +9 -0
  282. package/dist/ui/SegmentedControl/SegmentedControl.styles.js.map +1 -0
  283. package/dist/ui/SkipLink/SkipLink.js +35 -0
  284. package/dist/ui/SkipLink/SkipLink.js.map +1 -0
  285. package/dist/ui/SkipLink/SkipLink.styles.js +6 -0
  286. package/dist/ui/SkipLink/SkipLink.styles.js.map +1 -0
  287. package/dist/ui/Slider/Slider.js +68 -0
  288. package/dist/ui/Slider/Slider.js.map +1 -0
  289. package/dist/ui/Slider/Slider.styles.js +13 -0
  290. package/dist/ui/Slider/Slider.styles.js.map +1 -0
  291. package/dist/ui/StatusMessage/StatusMessage.js +124 -0
  292. package/dist/ui/StatusMessage/StatusMessage.js.map +1 -0
  293. package/dist/ui/StatusMessage/StatusMessage.styles.js +28 -0
  294. package/dist/ui/StatusMessage/StatusMessage.styles.js.map +1 -0
  295. package/dist/ui/StatusMessage/StatusMessageFocus.js +30 -0
  296. package/dist/ui/StatusMessage/StatusMessageFocus.js.map +1 -0
  297. package/dist/ui/Surface/Surface.js +22 -0
  298. package/dist/ui/Surface/Surface.js.map +1 -0
  299. package/dist/ui/Surface/Surface.styles.js +27 -0
  300. package/dist/ui/Surface/Surface.styles.js.map +1 -0
  301. package/dist/ui/Switch/Switch.js +58 -0
  302. package/dist/ui/Switch/Switch.js.map +1 -0
  303. package/dist/ui/Switch/Switch.styles.js +13 -0
  304. package/dist/ui/Switch/Switch.styles.js.map +1 -0
  305. package/dist/ui/Tooltip/Tooltip.js +66 -0
  306. package/dist/ui/Tooltip/Tooltip.js.map +1 -0
  307. package/dist/ui/Tooltip/Tooltip.styles.js +6 -0
  308. package/dist/ui/Tooltip/Tooltip.styles.js.map +1 -0
  309. package/dist/ui/Tooltip/inheritColours.js +27 -0
  310. package/dist/ui/Tooltip/inheritColours.js.map +1 -0
  311. package/dist/ui/VisuallyHidden/VisuallyHidden.js +16 -0
  312. package/dist/ui/VisuallyHidden/VisuallyHidden.js.map +1 -0
  313. package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js +6 -0
  314. package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js.map +1 -0
  315. package/package.json +82 -4
@@ -0,0 +1,940 @@
1
+ import { useMessages, useOnline } from "../services/hooks.js";
2
+ import { useServices } from "../services/ServicesProvider.js";
3
+ import { useAnnounce } from "../ui/LiveRegion/LiveRegion.js";
4
+ import { catalogueNotice } from "./catalogueNotice.js";
5
+ import { reconcile } from "./catalogueReconcile.js";
6
+ import { catalogueView, loadFailed } from "./catalogueView.js";
7
+ import { IDENTIFY_TIMEOUT_MS, IdentifyRun, MAX_IDENTIFY_LAYERS, askableLayers, identifiableLayers, outcomeOf, stillCurrent } from "./identifyRun.js";
8
+ import { errorKind } from "./layerStatus.js";
9
+ import { loadOutcome } from "./loadOutcome.js";
10
+ import { reportLoad, reportZoomLimits } from "./loadReport.js";
11
+ import { planLoads, rememberWindows, viewZoomLimit, wantedLoads } from "./loadRequests.js";
12
+ import { announceDetailError, announceDetailShown, announceFeaturesFound, announceIdentified, announceLayerOn, announceLayersTurnedBackOn, announceLayersTurnedOff, announceTilesRecovered, announceTilesSlow, announceTilesUnavailable, describeChosenTime, isFeedLayer, isQueryLayer, isRasterTileLayer, loadsFeatures, parseTime, readyLayers, resolveControlValues, textOrMessage, tileUrl } from "@mapcairn/core";
13
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
14
+ import { useLatestRef } from "@mapcairn/react";
15
+ // src/layers/useDataLayers.ts
16
+ /**
17
+ * How long the Undo after turning layers off stays on offer, in milliseconds.
18
+ * It is not shorter than a status message's shortest stay, so there is time to
19
+ * read it and to reach Undo by keyboard.
20
+ */
21
+ var UNDO_TIMEOUT_MS = 1e4;
22
+ /**
23
+ * The offer without the layers a refresh removed from the catalogue, so a
24
+ * layer that is listed again later is not one Undo would turn on. Null when
25
+ * nothing is left.
26
+ */
27
+ function withoutRemoved(offer, removed) {
28
+ if (!offer || removed.length === 0) return offer;
29
+ const ids = offer.ids.filter((id) => !removed.includes(id));
30
+ return ids.length > 0 ? {
31
+ ...offer,
32
+ ids
33
+ } : null;
34
+ }
35
+ /** The layers of an offer that Undo would turn on: still off, and still in the catalogue. */
36
+ function stillOff(offer, enabled, known) {
37
+ return offer.ids.filter((id) => known.has(id) && !enabled.includes(id));
38
+ }
39
+ var OFF = {
40
+ status: { kind: "off" },
41
+ features: []
42
+ };
43
+ /**
44
+ * The state at mount: the link's layers wait, and are resolved at once when
45
+ * the catalogue is ready already (a static one), as they are when a list
46
+ * arrives later. `awaited` says the catalogue was not ready at mount, so its
47
+ * list arrives later: only then is a link layer the list lacks said aloud, and
48
+ * an empty list, because a host whose layers are there from the start has no
49
+ * list to wait for.
50
+ */
51
+ function initialState(initial, catalogue, awaited, now) {
52
+ return applyCatalogue({
53
+ enabled: [],
54
+ controls: {},
55
+ link: {
56
+ waiting: initial?.enabled ?? [],
57
+ controls: initial?.controls ?? {},
58
+ dropped: initial?.dropped
59
+ },
60
+ known: [],
61
+ reconciled: null,
62
+ notice: null,
63
+ sorts: {},
64
+ results: {},
65
+ retries: {},
66
+ tilesUnavailable: {},
67
+ tilesSlow: {},
68
+ identified: {},
69
+ identifying: false,
70
+ selection: null,
71
+ choices: null,
72
+ view: null,
73
+ focusRequest: 0,
74
+ focusHandled: 0,
75
+ detail: null,
76
+ undo: null
77
+ }, catalogue, awaited, now);
78
+ }
79
+ /** The record without these layers' entries. */
80
+ function without(record, ids) {
81
+ return Object.fromEntries(Object.entries(record).filter(([id]) => !ids.has(id)));
82
+ }
83
+ /** The state with the open card, the entries in a list of choices and the affected area of these layers closed. */
84
+ function withoutOpenIn(state, ids) {
85
+ const choices = state.choices?.filter((choice) => !ids.has(choice.layerId));
86
+ return {
87
+ ...state,
88
+ selection: state.selection && ids.has(state.selection.layerId) ? null : state.selection,
89
+ choices: choices && choices.length > 0 ? choices : null,
90
+ detail: state.detail && ids.has(state.detail.layerId) ? null : state.detail
91
+ };
92
+ }
93
+ /**
94
+ * The state with what belongs to these layers cleared, for layers that are
95
+ * turning on or off: what they loaded, what a tap found, tiles known to have
96
+ * failed, their open card, their entries in a list of choices and their
97
+ * affected area.
98
+ */
99
+ function withoutTraces(state, ids) {
100
+ return {
101
+ ...withoutOpenIn(state, ids),
102
+ results: without(state.results, ids),
103
+ identified: without(state.identified, ids),
104
+ tilesUnavailable: without(state.tilesUnavailable, ids),
105
+ tilesSlow: without(state.tilesSlow, ids)
106
+ };
107
+ }
108
+ /**
109
+ * The state with these features open: one opens its card, several open the
110
+ * list to choose from. `focus` asks for the card or list to take focus.
111
+ */
112
+ function withOpened(state, hits, focus) {
113
+ const [only] = hits;
114
+ return {
115
+ ...state,
116
+ selection: hits.length === 1 && only ? { ...only } : null,
117
+ choices: hits.length > 1 ? hits : null,
118
+ focusRequest: state.focusRequest + (focus ? 1 : 0)
119
+ };
120
+ }
121
+ /**
122
+ * The state once a tap settled: the layers that answered keep what they
123
+ * found, replacing what an earlier tap found, and what was found opens. When
124
+ * nothing was found the card that is open stays, unless it points into a
125
+ * layer that answered, whose features it was a feature of before.
126
+ */
127
+ function withIdentified(state, entries, hits, focus) {
128
+ const settled = {
129
+ ...state,
130
+ identified: {
131
+ ...state.identified,
132
+ ...entries
133
+ },
134
+ identifying: false
135
+ };
136
+ return hits.length === 0 ? withoutOpenIn(settled, new Set(Object.keys(entries))) : withOpened(settled, hits, focus);
137
+ }
138
+ /**
139
+ * The state without what a tap found for a layer, once the tiles it asked
140
+ * about are not the ones it shows now: the answer describes other imagery.
141
+ * `tiles` is the URL the layer shows now, or null for a layer without tiles.
142
+ */
143
+ function withoutStaleIdentified(state, id, tiles) {
144
+ const entry = state.identified[id];
145
+ return entry === void 0 || entry.tiles === tiles ? state : {
146
+ ...withoutOpenIn(state, /* @__PURE__ */ new Set([id])),
147
+ identified: without(state.identified, /* @__PURE__ */ new Set([id]))
148
+ };
149
+ }
150
+ /** The features a layer has: those a tap found for it, else the `loaded` ones (a feed's or a query's). */
151
+ function featuresFor(identified, layerId, loaded) {
152
+ return identified[layerId]?.features ?? loaded;
153
+ }
154
+ /**
155
+ * Takes a ready list in, when it is a new one or a link layer is waiting for
156
+ * it: the choices `reconcile` works out, the layers that went cleared as
157
+ * turning them off clears them, and the list remembered as the one the
158
+ * choices match. Anything else (the list already taken in, a loading or
159
+ * failed catalogue) changes no choice, and has no result.
160
+ */
161
+ function takeIn(state, catalogue, now) {
162
+ if (catalogue.status !== "ready" || catalogue.layers === state.known && state.link.waiting.length === 0) return {
163
+ taken: state,
164
+ result: null
165
+ };
166
+ const result = reconcile({
167
+ chosen: {
168
+ enabled: state.enabled,
169
+ controls: state.controls
170
+ },
171
+ link: state.link,
172
+ known: state.known,
173
+ next: catalogue.layers,
174
+ now
175
+ });
176
+ const gone = result.switchedOff.map(({ id }) => id);
177
+ return {
178
+ taken: {
179
+ ...gone.length > 0 ? withoutTraces(state, new Set(gone)) : state,
180
+ ...result.chosen,
181
+ link: result.link,
182
+ known: catalogue.layers,
183
+ undo: withoutRemoved(state.undo, result.removed)
184
+ },
185
+ result
186
+ };
187
+ }
188
+ /**
189
+ * The state once it has taken in a catalogue state. Only a ready list changes
190
+ * the choices (see `takeIn`): while the catalogue loads or has failed the
191
+ * link's layers keep waiting. A list that is the one already taken in changes
192
+ * no choice, though its skipped count or refresh state may. Whatever the state
193
+ * says aloud is kept as a notice for the effect that says it (see
194
+ * `catalogueNotice`), so every transition is said once.
195
+ */
196
+ function applyCatalogue(state, catalogue, awaited, now) {
197
+ const { taken, result } = takeIn(state, catalogue, now);
198
+ const message = catalogueNotice({
199
+ previous: state.reconciled,
200
+ next: catalogue,
201
+ linkWaiting: state.link.waiting.length,
202
+ awaited,
203
+ change: result
204
+ });
205
+ return {
206
+ ...taken,
207
+ reconciled: catalogue,
208
+ notice: message ? {
209
+ ...message,
210
+ gone: result?.switchedOff.map(({ id }) => id) ?? []
211
+ } : taken.notice
212
+ };
213
+ }
214
+ /**
215
+ * The state with a layer loading. A query layer keeps what it draws while the
216
+ * next window loads; a feed clears its features.
217
+ */
218
+ function withLoading(state, load) {
219
+ const { id, definition } = load;
220
+ const kept = isQueryLayer(definition) ? state.results[id]?.features ?? [] : [];
221
+ return {
222
+ ...state,
223
+ results: {
224
+ ...state.results,
225
+ [id]: {
226
+ status: { kind: "loading" },
227
+ features: kept
228
+ }
229
+ }
230
+ };
231
+ }
232
+ /** The tiles a raster tile layer asks for with these controls, or null for any other layer. */
233
+ function tilesOf(definition, controls, now) {
234
+ return isRasterTileLayer(definition) ? tileUrl(definition, controls, now) : null;
235
+ }
236
+ /** The status of a tile layer that is on: unavailable outranks slow, which outranks nothing reported. */
237
+ function tileStatusKind(state, id) {
238
+ if (state.tilesUnavailable[id] !== void 0) return "tiles-unavailable";
239
+ return state.tilesSlow[id] === void 0 ? "on" : "tiles-slow";
240
+ }
241
+ /**
242
+ * What is known of reported tiles (slow or unavailable) once the layer asks for
243
+ * `tiles`: nothing, if they are not the ones that were reported.
244
+ */
245
+ function reportedTilesFor(reported, id, tiles) {
246
+ if (reported[id] === void 0 || reported[id] === tiles) return reported;
247
+ const rest = { ...reported };
248
+ delete rest[id];
249
+ return rest;
250
+ }
251
+ /** A value to sort by: numbers and readable times as numbers, else text. */
252
+ function sortable(value) {
253
+ if (typeof value === "number") return value;
254
+ if (typeof value === "string") return parseTime(value) ?? value;
255
+ return null;
256
+ }
257
+ function compare(a, b, collator) {
258
+ const left = sortable(a);
259
+ const right = sortable(b);
260
+ if (left === null || right === null) {
261
+ if (left === right) return 0;
262
+ return left === null ? 1 : -1;
263
+ }
264
+ if (typeof left === "number" && typeof right === "number") return left - right;
265
+ return collator.compare(String(left), String(right));
266
+ }
267
+ function sortFeatures(definition, features, sortId, collator) {
268
+ if (!isFeedLayer(definition)) return features;
269
+ const sorts = definition.list.sorts;
270
+ const sort = sorts.find((item) => item.id === sortId) ?? sorts[0];
271
+ if (!sort) return features;
272
+ const direction = sort.direction === "desc" ? -1 : 1;
273
+ return [...features].sort((a, b) => {
274
+ const order = compare(a.fields[sort.field], b.fields[sort.field], collator);
275
+ return a.fields[sort.field] == null || b.fields[sort.field] == null ? order : order * direction;
276
+ });
277
+ }
278
+ /**
279
+ * The state of every data layer and the actions on it, driven entirely by
280
+ * the definitions in the catalogue: nothing here names a layer. It reads the
281
+ * catalogue as a store, so the layers appear when a catalogue that loads
282
+ * becomes ready; while it is loading or has failed there are none, and the
283
+ * layers a link names wait for the first list. Each list that arrives is
284
+ * reconciled with the choices in the same render, before anything is drawn
285
+ * or requested: a layer that arrives has its controls' defaults, one that
286
+ * changed keeps the values that are still valid, and an enabled one that went
287
+ * is turned off as `setEnabled(id, false)` turns it off and said once.
288
+ *
289
+ * @remarks Nothing is requested until a layer is turned on. A feed layer is
290
+ * loaded on enable, on a control change and on retry; the request for the
291
+ * previous URL is cancelled. Tile layers need no request here: the map
292
+ * draws their tiles, and says through `reportTilesSlow` when none has
293
+ * loaded for a long while, `reportTilesUnavailable` when the map settled
294
+ * with none loaded and `reportTilesRecovered` when one loads later. Loads,
295
+ * empty feeds and failures are announced once each through the shared live
296
+ * region, failures assertively and a tile layer that is slow or has no
297
+ * tiles, and its recovery, politely. Turning a layer off clears its features, its open card
298
+ * and its affected area.
299
+ */
300
+ function useDataLayers(options = {}) {
301
+ const { layers: catalogue, layerSource } = useServices();
302
+ const { language } = useMessages();
303
+ const collator = useMemo(() => new Intl.Collator(language), [language]);
304
+ const announce = useAnnounce();
305
+ const now = useCallback(() => (options.now ?? Date.now)(), [options.now]);
306
+ const onlineRef = useLatestRef(useOnline());
307
+ const isOffline = useCallback(() => !onlineRef.current, [onlineRef]);
308
+ const catalogueState = useSyncExternalStore(catalogue.subscribe, catalogue.getState, catalogue.getState);
309
+ const definitions = readyLayers(catalogueState);
310
+ const [awaited] = useState(catalogueState.status !== "ready");
311
+ const [stored, setState] = useState(() => initialState(options.initial, catalogueState, awaited, now()));
312
+ let state = stored;
313
+ if (stored.reconciled !== catalogueState) {
314
+ state = applyCatalogue(stored, catalogueState, awaited, now());
315
+ setState(state);
316
+ }
317
+ const statusView = useMemo(() => catalogueView(catalogueState, awaited), [catalogueState, awaited]);
318
+ const retryCatalogue = useCallback(() => {
319
+ if (loadFailed(catalogue.getState())) catalogue.refresh();
320
+ }, [catalogue]);
321
+ /**
322
+ * What the handlers below read. It follows the last committed state, set in
323
+ * a layout effect so a render React throws away (a transition that
324
+ * suspends) never leaves its state here, and before any effect of the
325
+ * same commit runs. A layout effect of a child that calls a handler in the
326
+ * same commit would still see the previous state; the handlers are only
327
+ * called from events and the map's callbacks.
328
+ */
329
+ const stateRef = useRef(state);
330
+ useLayoutEffect(() => {
331
+ stateRef.current = state;
332
+ }, [state]);
333
+ const requests = useRef(/* @__PURE__ */ new Map());
334
+ /** The request key each layer last settled for, so a settled layer is not loaded again. */
335
+ const loadedKeys = useRef(/* @__PURE__ */ new Map());
336
+ /** The window each query layer last asked for, remembered once its request is committed. */
337
+ const queryWindows = useRef(/* @__PURE__ */ new Map());
338
+ const announcedStates = useRef(/* @__PURE__ */ new Map());
339
+ const detailRequest = useRef(null);
340
+ /** The tap in flight, if there is one. */
341
+ const identifyRun = useRef(null);
342
+ const byId = useMemo(() => new Map(definitions.map((definition) => [definition.id, definition])), [definitions]);
343
+ const wanted = wantedLoads({
344
+ enabled: state.enabled,
345
+ definitions: byId,
346
+ controls: state.controls,
347
+ retries: state.retries,
348
+ view: state.view,
349
+ windows: queryWindows.current,
350
+ now: now()
351
+ });
352
+ const signature = wanted.map(({ id, key }) => `${id} ${key}`).join("\n");
353
+ const limited = state.enabled.flatMap((id) => {
354
+ const definition = byId.get(id);
355
+ const limit = definition && viewZoomLimit(definition, state.view);
356
+ return definition && limit ? [{
357
+ definition,
358
+ limit
359
+ }] : [];
360
+ });
361
+ const limitedSignature = limited.map(({ definition, limit }) => `${definition.id} ${limit.kind}`).join("\n");
362
+ const identifiable = identifiableLayers({
363
+ definitions,
364
+ enabled: state.enabled,
365
+ controls: state.controls,
366
+ now: now()
367
+ });
368
+ const identifiableSignature = identifiable.map(({ definition, tiles }) => `${definition.id} ${tiles}`).join("\n");
369
+ useEffect(() => {
370
+ identifyRun.current?.abortStale(new Map(identifiable.map(({ definition, tiles }) => [definition.id, tiles])));
371
+ }, [identifiableSignature]);
372
+ useEffect(() => {
373
+ rememberWindows(queryWindows.current, wanted);
374
+ });
375
+ useEffect(() => {
376
+ reportZoomLimits(limited, announcedStates.current, announce);
377
+ }, [limitedSignature]);
378
+ useEffect(() => {
379
+ /** Starts one load, shows the layer as loading, and settles it when the source answers. */
380
+ const startLoad = (load) => {
381
+ const { id, key, definition } = load;
382
+ const controller = new AbortController();
383
+ requests.current.set(id, {
384
+ key,
385
+ controller
386
+ });
387
+ setState((current) => withLoading(current, load));
388
+ loadOutcome(layerSource, load, now, controller.signal, isOffline).then((outcome) => {
389
+ if (!outcome || requests.current.get(id)?.controller !== controller) return;
390
+ requests.current.delete(id);
391
+ loadedKeys.current.set(id, key);
392
+ setState((current) => ({
393
+ ...current,
394
+ results: {
395
+ ...current.results,
396
+ [id]: outcome.result
397
+ }
398
+ }));
399
+ reportLoad(definition, outcome.spoken, announcedStates.current, announce);
400
+ });
401
+ };
402
+ const plan = planLoads(wanted, requests.current, loadedKeys.current);
403
+ for (const id of plan.cancel) {
404
+ requests.current.get(id)?.controller.abort();
405
+ requests.current.delete(id);
406
+ }
407
+ for (const id of plan.forget) loadedKeys.current.delete(id);
408
+ for (const load of plan.start) startLoad(load);
409
+ }, [signature]);
410
+ const offer = state.undo;
411
+ const [undoHolds, setUndoHolds] = useState({
412
+ pointer: false,
413
+ focus: false
414
+ });
415
+ const undoHeld = undoHolds.pointer || undoHolds.focus;
416
+ useEffect(() => {
417
+ if (!offer || undoHeld) return;
418
+ const timer = setTimeout(() => setState((previous) => previous.undo === offer ? {
419
+ ...previous,
420
+ undo: null
421
+ } : previous), UNDO_TIMEOUT_MS);
422
+ return () => clearTimeout(timer);
423
+ }, [offer, undoHeld]);
424
+ useEffect(() => () => {
425
+ for (const request of requests.current.values()) request.controller.abort();
426
+ requests.current.clear();
427
+ detailRequest.current?.abort();
428
+ identifyRun.current?.cancel();
429
+ identifyRun.current = null;
430
+ }, []);
431
+ /** Drops what the hook holds outside the state for these layers: their open request for an affected area, and what they last said. */
432
+ const forgetLayers = useCallback((ids) => {
433
+ const detail = stateRef.current.detail;
434
+ if (detail && ids.has(detail.layerId)) detailRequest.current?.abort();
435
+ for (const id of ids) announcedStates.current.delete(id);
436
+ }, []);
437
+ const spokenNotice = useRef(null);
438
+ const notice = state.notice;
439
+ useEffect(() => {
440
+ if (!notice || spokenNotice.current === notice) return;
441
+ spokenNotice.current = notice;
442
+ if (stateRef.current.detail === null) detailRequest.current?.abort();
443
+ forgetLayers(new Set(notice.gone));
444
+ announce(notice.message, {
445
+ priority: notice.priority,
446
+ keep: notice.keep
447
+ });
448
+ }, [
449
+ notice,
450
+ forgetLayers,
451
+ announce
452
+ ]);
453
+ const setEnabled = useCallback((id, enabled) => {
454
+ const definition = byId.get(id);
455
+ const current = stateRef.current;
456
+ if (!definition || current.enabled.includes(id) === enabled) return;
457
+ const ids = /* @__PURE__ */ new Set([id]);
458
+ forgetLayers(ids);
459
+ setState((previous) => ({
460
+ ...withoutTraces(previous, ids),
461
+ enabled: enabled ? [...previous.enabled, id] : previous.enabled.filter((item) => item !== id)
462
+ }));
463
+ if (enabled && !loadsFeatures(definition)) announce(announceLayerOn(textOrMessage(definition.name)), {
464
+ priority: "polite",
465
+ keep: true
466
+ });
467
+ }, [
468
+ announce,
469
+ byId,
470
+ forgetLayers
471
+ ]);
472
+ const turnOff = useCallback((ids, offOptions = {}) => {
473
+ const current = stateRef.current;
474
+ const leaving = new Set(ids.filter((id) => byId.has(id) && current.enabled.includes(id)));
475
+ if (leaving.size === 0) return;
476
+ forgetLayers(leaving);
477
+ setState((previous) => ({
478
+ ...withoutTraces(previous, leaving),
479
+ enabled: previous.enabled.filter((id) => !leaving.has(id)),
480
+ undo: {
481
+ ids: [...leaving],
482
+ group: offOptions.group ?? null
483
+ }
484
+ }));
485
+ announce(announceLayersTurnedOff(leaving.size), {
486
+ priority: "polite",
487
+ keep: true
488
+ });
489
+ }, [
490
+ announce,
491
+ byId,
492
+ forgetLayers
493
+ ]);
494
+ const undoTurnOff = useCallback(() => {
495
+ const { undo, enabled } = stateRef.current;
496
+ if (!undo) return;
497
+ const returning = stillOff(undo, enabled, byId);
498
+ forgetLayers(new Set(returning));
499
+ setState((previous) => ({
500
+ ...previous,
501
+ enabled: [...previous.enabled, ...stillOff(undo, previous.enabled, byId)],
502
+ undo: null
503
+ }));
504
+ if (returning.length > 0) announce(announceLayersTurnedBackOn(returning.length), {
505
+ priority: "polite",
506
+ keep: true
507
+ });
508
+ }, [
509
+ announce,
510
+ byId,
511
+ forgetLayers
512
+ ]);
513
+ const holdUndo = useCallback((by) => setUndoHolds((holds) => ({
514
+ ...holds,
515
+ [by]: true
516
+ })), []);
517
+ const releaseUndo = useCallback((by) => setUndoHolds((holds) => ({
518
+ ...holds,
519
+ [by]: false
520
+ })), []);
521
+ const setControl = useCallback((id, controlId, value) => {
522
+ const definition = byId.get(id);
523
+ if (!definition) return;
524
+ setState((previous) => {
525
+ const controls = resolveControlValues(definition, {
526
+ ...previous.controls[id],
527
+ [controlId]: value
528
+ }, now());
529
+ const tiles = tilesOf(definition, controls, now());
530
+ return withoutStaleIdentified({
531
+ ...previous,
532
+ controls: {
533
+ ...previous.controls,
534
+ [id]: controls
535
+ },
536
+ tilesUnavailable: reportedTilesFor(previous.tilesUnavailable, id, tiles),
537
+ tilesSlow: reportedTilesFor(previous.tilesSlow, id, tiles)
538
+ }, id, tiles);
539
+ });
540
+ }, [byId, now]);
541
+ const reportTilesSlow = useCallback((id, tiles) => {
542
+ const definition = byId.get(id);
543
+ const current = stateRef.current;
544
+ if (!definition || !current.enabled.includes(id) || current.tilesSlow[id] === tiles || current.tilesUnavailable[id] === tiles) return;
545
+ if (tilesOf(definition, current.controls[id] ?? {}, now()) !== tiles) return;
546
+ setState((previous) => ({
547
+ ...previous,
548
+ tilesSlow: {
549
+ ...previous.tilesSlow,
550
+ [id]: tiles
551
+ }
552
+ }));
553
+ announce(announceTilesSlow(textOrMessage(definition.name)), {
554
+ priority: "polite",
555
+ keep: true
556
+ });
557
+ }, [
558
+ announce,
559
+ byId,
560
+ now
561
+ ]);
562
+ const reportTilesUnavailable = useCallback((id, tiles) => {
563
+ const definition = byId.get(id);
564
+ const current = stateRef.current;
565
+ if (!definition || !current.enabled.includes(id) || current.tilesUnavailable[id] === tiles) return;
566
+ const controls = current.controls[id] ?? {};
567
+ if (tilesOf(definition, controls, now()) !== tiles) return;
568
+ setState((previous) => ({
569
+ ...previous,
570
+ tilesUnavailable: {
571
+ ...previous.tilesUnavailable,
572
+ [id]: tiles
573
+ },
574
+ tilesSlow: reportedTilesFor(previous.tilesSlow, id, null)
575
+ }));
576
+ announce(announceTilesUnavailable(textOrMessage(definition.name), describeChosenTime(definition, controls)), { priority: "polite" });
577
+ }, [
578
+ announce,
579
+ byId,
580
+ now
581
+ ]);
582
+ const reportTilesRecovered = useCallback((id, tiles) => {
583
+ const definition = byId.get(id);
584
+ const current = stateRef.current;
585
+ if (!definition || current.tilesUnavailable[id] !== tiles && current.tilesSlow[id] !== tiles) return;
586
+ setState((previous) => ({
587
+ ...previous,
588
+ tilesUnavailable: reportedTilesFor(previous.tilesUnavailable, id, null),
589
+ tilesSlow: reportedTilesFor(previous.tilesSlow, id, null)
590
+ }));
591
+ announce(announceTilesRecovered(textOrMessage(definition.name)), { priority: "polite" });
592
+ }, [announce, byId]);
593
+ const setSort = useCallback((id, sortId) => {
594
+ setState((previous) => ({
595
+ ...previous,
596
+ sorts: {
597
+ ...previous.sorts,
598
+ [id]: sortId
599
+ }
600
+ }));
601
+ }, []);
602
+ const retry = useCallback((id) => {
603
+ setState((previous) => ({
604
+ ...previous,
605
+ retries: {
606
+ ...previous.retries,
607
+ [id]: (previous.retries[id] ?? 0) + 1
608
+ }
609
+ }));
610
+ }, []);
611
+ /** Cancels the tap in flight, and reports whether there was one. */
612
+ const cancelIdentify = useCallback(() => {
613
+ const run = identifyRun.current;
614
+ if (!run) return false;
615
+ identifyRun.current = null;
616
+ run.cancel();
617
+ setState((previous) => previous.identifying ? {
618
+ ...previous,
619
+ identifying: false
620
+ } : previous);
621
+ return true;
622
+ }, []);
623
+ const select = useCallback((layerId, featureId, selectOptions = {}) => {
624
+ if (featureId !== null) cancelIdentify();
625
+ setState((previous) => {
626
+ const snapshot = featureId === null ? void 0 : featuresFor(previous.identified, layerId, previous.results[layerId]?.features)?.find((item) => item.id === featureId);
627
+ return {
628
+ ...previous,
629
+ selection: featureId === null ? null : {
630
+ layerId,
631
+ featureId,
632
+ ...snapshot ? { snapshot } : {}
633
+ },
634
+ choices: featureId !== null && selectOptions.keepChoices ? previous.choices : null,
635
+ focusRequest: previous.focusRequest + (selectOptions.focus ? 1 : 0)
636
+ };
637
+ });
638
+ }, [cancelIdentify]);
639
+ const choose = useCallback((hits, chooseOptions = {}) => {
640
+ const { results } = stateRef.current;
641
+ const seen = /* @__PURE__ */ new Set();
642
+ const found = hits.filter((hit) => {
643
+ const key = `${hit.layerId}\u0000${hit.featureId}`;
644
+ if (seen.has(key) || !results[hit.layerId]?.features.some((item) => item.id === hit.featureId)) return false;
645
+ seen.add(key);
646
+ return true;
647
+ });
648
+ const [only] = found;
649
+ if (!only) return;
650
+ if (found.length === 1) {
651
+ select(only.layerId, only.featureId, chooseOptions);
652
+ return;
653
+ }
654
+ cancelIdentify();
655
+ setState((previous) => withOpened(previous, found, chooseOptions.focus === true));
656
+ announce(announceFeaturesFound(found.length), {
657
+ priority: "polite",
658
+ keep: true
659
+ });
660
+ }, [
661
+ announce,
662
+ cancelIdentify,
663
+ select
664
+ ]);
665
+ const identifyAt = useCallback(async (target, identifyOptions = {}) => {
666
+ cancelIdentify();
667
+ const current = stateRef.current;
668
+ const available = askableLayers(identifiableLayers({
669
+ definitions,
670
+ enabled: current.enabled,
671
+ controls: current.controls,
672
+ now: now()
673
+ }), current.tilesUnavailable, target.latlng);
674
+ const asking = available.slice(0, 4);
675
+ if (asking.length === 0) return {
676
+ asked: 0,
677
+ found: 0
678
+ };
679
+ const run = new IdentifyRun();
680
+ identifyRun.current = run;
681
+ setState((previous) => ({
682
+ ...previous,
683
+ identifying: true
684
+ }));
685
+ const answers = await Promise.all(asking.map((layer) => run.ask(layerSource, layer, target, now())));
686
+ if (identifyRun.current !== run) return null;
687
+ identifyRun.current = null;
688
+ const latest = stateRef.current;
689
+ const shown = new Map(identifiableLayers({
690
+ definitions,
691
+ enabled: latest.enabled,
692
+ controls: latest.controls,
693
+ now: now()
694
+ }).map(({ definition, tiles }) => [definition.id, tiles]));
695
+ const outcome = outcomeOf(stillCurrent(answers, shown), available.length);
696
+ if (!outcome) {
697
+ setState((previous) => ({
698
+ ...previous,
699
+ identifying: false
700
+ }));
701
+ return null;
702
+ }
703
+ setState((previous) => withIdentified(previous, outcome.entries, outcome.hits, identifyOptions.focus === true));
704
+ const said = announceIdentified(outcome.report);
705
+ if (said) announce(said.message, {
706
+ priority: said.priority,
707
+ keep: true
708
+ });
709
+ return {
710
+ asked: outcome.report.asked,
711
+ found: outcome.report.found
712
+ };
713
+ }, [
714
+ announce,
715
+ cancelIdentify,
716
+ definitions,
717
+ layerSource,
718
+ now
719
+ ]);
720
+ const backToChoices = useCallback((backOptions = {}) => {
721
+ setState((previous) => previous.choices ? {
722
+ ...previous,
723
+ selection: null,
724
+ detail: null,
725
+ focusRequest: previous.focusRequest + (backOptions.focus ? 1 : 0)
726
+ } : previous);
727
+ }, []);
728
+ const setView = useCallback((area, zoom) => {
729
+ setState((previous) => {
730
+ const last = previous.view;
731
+ return last && last.zoom === zoom && last.area.west === area.west && last.area.south === area.south && last.area.east === area.east && last.area.north === area.north ? previous : {
732
+ ...previous,
733
+ view: {
734
+ area,
735
+ zoom
736
+ }
737
+ };
738
+ });
739
+ }, []);
740
+ const consumeFocus = useCallback(() => {
741
+ setState((previous) => previous.focusHandled === previous.focusRequest ? previous : {
742
+ ...previous,
743
+ focusHandled: previous.focusRequest
744
+ });
745
+ }, []);
746
+ const hideDetail = useCallback(() => {
747
+ detailRequest.current?.abort();
748
+ detailRequest.current = null;
749
+ setState((previous) => ({
750
+ ...previous,
751
+ detail: null
752
+ }));
753
+ }, []);
754
+ const showDetail = useCallback((layerId, featureId) => {
755
+ const definition = byId.get(layerId);
756
+ const feature = stateRef.current.results[layerId]?.features.find((item) => item.id === featureId);
757
+ if (!definition || !feature) return;
758
+ detailRequest.current?.abort();
759
+ const controller = new AbortController();
760
+ detailRequest.current = controller;
761
+ const finish = (detail) => {
762
+ if (detailRequest.current !== controller) return;
763
+ setState((previous) => previous.detail ? {
764
+ ...previous,
765
+ detail: {
766
+ ...previous.detail,
767
+ ...detail
768
+ }
769
+ } : previous);
770
+ };
771
+ setState((previous) => ({
772
+ ...previous,
773
+ detail: {
774
+ layerId,
775
+ featureId,
776
+ status: "loading",
777
+ shapes: []
778
+ }
779
+ }));
780
+ layerSource.loadDetail({
781
+ definition,
782
+ feature,
783
+ signal: controller.signal
784
+ }).then((shapes) => {
785
+ finish({
786
+ status: "shown",
787
+ shapes
788
+ });
789
+ announce(announceDetailShown(String(feature.fields.title ?? "")), { priority: "polite" });
790
+ }, (error) => {
791
+ if (errorKind(error) === "aborted" || controller.signal.aborted) return;
792
+ finish({
793
+ status: "error",
794
+ shapes: []
795
+ });
796
+ announce(announceDetailError(), { priority: "assertive" });
797
+ });
798
+ }, [
799
+ announce,
800
+ byId,
801
+ layerSource
802
+ ]);
803
+ const layers = useMemo(() => definitions.map((definition) => {
804
+ const id = definition.id;
805
+ const enabled = state.enabled.includes(id);
806
+ let result = OFF;
807
+ const limit = enabled ? viewZoomLimit(definition, state.view) : null;
808
+ if (limit) result = {
809
+ status: limit,
810
+ features: []
811
+ };
812
+ else if (enabled) result = state.results[id] ?? (loadsFeatures(definition) ? {
813
+ status: { kind: "loading" },
814
+ features: []
815
+ } : {
816
+ status: { kind: tileStatusKind(state, id) },
817
+ features: []
818
+ });
819
+ const sortId = state.sorts[id] ?? (isFeedLayer(definition) ? definition.list.sorts[0]?.id ?? "" : "");
820
+ return {
821
+ definition,
822
+ enabled,
823
+ controls: state.controls[id] ?? {},
824
+ status: result.status,
825
+ features: result.features,
826
+ sortId,
827
+ sorted: sortFeatures(definition, result.features, sortId, collator)
828
+ };
829
+ }), [
830
+ collator,
831
+ definitions,
832
+ state
833
+ ]);
834
+ const selected = useMemo(() => {
835
+ const selection = state.selection;
836
+ const layer = layers.find((item) => item.definition.id === selection?.layerId);
837
+ const feature = featuresFor(state.identified, layer?.definition.id ?? "", layer?.features)?.find((item) => item.id === selection?.featureId) ?? (layer?.enabled && isQueryLayer(layer.definition) ? selection?.snapshot : void 0);
838
+ return layer && feature ? {
839
+ layer,
840
+ feature
841
+ } : null;
842
+ }, [
843
+ layers,
844
+ state.identified,
845
+ state.selection
846
+ ]);
847
+ const choices = useMemo(() => {
848
+ if (!state.choices) return null;
849
+ const found = state.choices.flatMap((choice) => {
850
+ const layer = layers.find((item) => item.definition.id === choice.layerId);
851
+ const feature = featuresFor(state.identified, choice.layerId, layer?.features)?.find((item) => item.id === choice.featureId);
852
+ return layer && feature ? [{
853
+ layer,
854
+ feature
855
+ }] : [];
856
+ });
857
+ return found.length > 0 ? found : null;
858
+ }, [
859
+ layers,
860
+ state.identified,
861
+ state.choices
862
+ ]);
863
+ const turnedOff = useMemo(() => {
864
+ const ids = offer ? stillOff(offer, state.enabled, byId) : [];
865
+ return offer && ids.length > 0 ? {
866
+ count: ids.length,
867
+ ids,
868
+ group: offer.group
869
+ } : null;
870
+ }, [
871
+ offer,
872
+ state.enabled,
873
+ byId
874
+ ]);
875
+ const urlValue = useMemo(() => {
876
+ const { waiting, controls: linked } = state.link;
877
+ return {
878
+ enabled: [...state.enabled, ...waiting],
879
+ controls: Object.fromEntries([...state.enabled.map((id) => [id, state.controls[id] ?? {}]), ...waiting.map((id) => [id, linked[id] ?? {}])])
880
+ };
881
+ }, [
882
+ state.enabled,
883
+ state.controls,
884
+ state.link
885
+ ]);
886
+ const year = String(new Date(now()).getUTCFullYear());
887
+ const credits = useMemo(() => {
888
+ const byText = /* @__PURE__ */ new Map();
889
+ for (const id of state.enabled) for (const credit of byId.get(id)?.attribution ?? []) {
890
+ const text = credit.text.replaceAll("{year}", year);
891
+ if (!byText.has(text)) byText.set(text, {
892
+ ...credit,
893
+ text
894
+ });
895
+ }
896
+ return [...byText.values()];
897
+ }, [
898
+ state.enabled,
899
+ byId,
900
+ year
901
+ ]);
902
+ return {
903
+ layers,
904
+ catalogue: statusView,
905
+ retryCatalogue,
906
+ selected,
907
+ choices,
908
+ detail: state.detail,
909
+ focusRequest: state.focusRequest,
910
+ focusPending: state.focusRequest > state.focusHandled,
911
+ consumeFocus,
912
+ urlValue,
913
+ credits,
914
+ now,
915
+ setEnabled,
916
+ turnOff,
917
+ turnedOff,
918
+ undoTurnOff,
919
+ holdUndo,
920
+ releaseUndo,
921
+ setControl,
922
+ setSort,
923
+ retry,
924
+ reportTilesSlow,
925
+ reportTilesUnavailable,
926
+ reportTilesRecovered,
927
+ select,
928
+ choose,
929
+ identifyAt,
930
+ cancelIdentify,
931
+ identifying: state.identifying,
932
+ backToChoices,
933
+ setView,
934
+ showDetail,
935
+ hideDetail
936
+ };
937
+ }
938
+ export { IDENTIFY_TIMEOUT_MS, MAX_IDENTIFY_LAYERS, UNDO_TIMEOUT_MS, useDataLayers };
939
+
940
+ //# sourceMappingURL=useDataLayers.js.map