@defra/interactive-map 0.0.3-alpha → 0.0.5-alpha

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 (407) hide show
  1. package/README.md +16 -57
  2. package/dist/css/index.css +1 -1
  3. package/dist/esm/im-core.js +1 -1
  4. package/dist/esm/index.js +1 -1
  5. package/dist/umd/im-core.js +1 -1
  6. package/dist/umd/index.js +1 -1
  7. package/docs/api/button-definition.md +176 -0
  8. package/docs/api/context.md +124 -0
  9. package/docs/api/control-definition.md +72 -0
  10. package/docs/api/icon-definition.md +28 -0
  11. package/docs/api/map-style-config.md +76 -0
  12. package/docs/api/marker-config.md +51 -0
  13. package/docs/api/panel-definition.md +117 -0
  14. package/docs/api/slots.md +25 -0
  15. package/docs/api.md +721 -0
  16. package/docs/architecture.md +139 -0
  17. package/docs/building-a-plugin.md +149 -0
  18. package/docs/getting-started.md +46 -0
  19. package/docs/govuk-prototype.md +0 -0
  20. package/docs/plugins/interact.md +205 -0
  21. package/docs/plugins/map-styles.md +84 -0
  22. package/docs/plugins/plugin-context.md +67 -0
  23. package/docs/plugins/plugin-descriptor.md +71 -0
  24. package/docs/plugins/plugin-manifest.md +118 -0
  25. package/docs/plugins/scale-bar.md +62 -0
  26. package/docs/plugins/search.md +162 -0
  27. package/docs/plugins.md +116 -0
  28. package/govuk-prototype-kit.config.json +7 -7
  29. package/package.json +16 -2
  30. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +2 -0
  31. package/plugins/beta/datasets/dist/esm/index.js +2 -0
  32. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +2 -0
  33. package/plugins/beta/datasets/dist/umd/index.js +2 -0
  34. package/plugins/beta/datasets/src/datasets.js +113 -0
  35. package/plugins/beta/datasets/src/fetch/createDynamicSource.js +206 -0
  36. package/plugins/beta/datasets/src/fetch/fetchGeoJSON.js +38 -0
  37. package/plugins/{datasets → beta/datasets}/src/handleSetMapStyle.js +8 -1
  38. package/plugins/{datasets → beta/datasets}/src/manifest.js +1 -1
  39. package/plugins/{datasets → beta/datasets}/src/mapLayers.js +42 -4
  40. package/plugins/{datasets → beta/datasets}/src/panels/Key.jsx +1 -1
  41. package/plugins/beta/datasets/src/utils/bbox.js +115 -0
  42. package/plugins/beta/draw-ml/dist/css/index.css +1 -0
  43. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -0
  44. package/plugins/beta/draw-ml/dist/esm/index.js +2 -0
  45. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -0
  46. package/plugins/beta/draw-ml/dist/umd/index.js +2 -0
  47. package/plugins/beta/draw-ml/src/api/addFeature.js +27 -0
  48. package/plugins/{draw-ml → beta/draw-ml}/src/api/editFeature.js +17 -6
  49. package/plugins/beta/draw-ml/src/api/merge.js +9 -0
  50. package/plugins/beta/draw-ml/src/api/newLine.js +68 -0
  51. package/plugins/beta/draw-ml/src/api/newPolygon.js +68 -0
  52. package/plugins/beta/draw-ml/src/api/split.js +81 -0
  53. package/plugins/{draw-ml → beta/draw-ml}/src/defaults.js +3 -0
  54. package/plugins/beta/draw-ml/src/draw.scss +32 -0
  55. package/plugins/beta/draw-ml/src/events.js +171 -0
  56. package/plugins/beta/draw-ml/src/manifest.js +132 -0
  57. package/plugins/{draw-ml → beta/draw-ml}/src/mapboxDraw.js +51 -2
  58. package/plugins/{draw-ml → beta/draw-ml}/src/mapboxSnap.js +18 -12
  59. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +497 -0
  60. package/plugins/beta/draw-ml/src/modes/drawLineMode.js +18 -0
  61. package/plugins/beta/draw-ml/src/modes/drawPolygonMode.js +16 -0
  62. package/plugins/beta/draw-ml/src/modes/editVertex/geometryHelpers.js +135 -0
  63. package/plugins/beta/draw-ml/src/modes/editVertex/helpers.js +2 -0
  64. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +134 -0
  65. package/plugins/beta/draw-ml/src/modes/editVertex/undoHandlers.js +133 -0
  66. package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +141 -0
  67. package/plugins/beta/draw-ml/src/modes/editVertex/vertexQueries.js +121 -0
  68. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +437 -0
  69. package/plugins/{draw-ml → beta/draw-ml}/src/reducer.js +30 -2
  70. package/plugins/{draw-ml → beta/draw-ml}/src/styles.js +66 -36
  71. package/plugins/beta/draw-ml/src/undoStack.js +50 -0
  72. package/plugins/beta/draw-ml/src/utils/debounce.js +16 -0
  73. package/plugins/beta/draw-ml/src/utils/flattenStyleProperties.js +49 -0
  74. package/plugins/beta/draw-ml/src/utils/spatial.js +258 -0
  75. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -0
  76. package/plugins/beta/frame/dist/esm/index.js +2 -0
  77. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -0
  78. package/plugins/beta/frame/dist/umd/index.js +2 -0
  79. package/plugins/{frame → beta/frame}/src/Frame.jsx +1 -1
  80. package/plugins/{map-styles → beta/map-styles}/dist/css/index.css +1 -1
  81. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -0
  82. package/plugins/beta/map-styles/dist/esm/index.js +2 -0
  83. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -0
  84. package/plugins/beta/map-styles/dist/umd/index.js +2 -0
  85. package/plugins/{map-styles → beta/map-styles}/src/MapStyles.jsx +1 -1
  86. package/plugins/{map-styles → beta/map-styles}/src/manifest.js +8 -10
  87. package/plugins/{map-styles → beta/map-styles}/src/mapStyles.scss +4 -1
  88. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -0
  89. package/plugins/beta/scale-bar/dist/esm/index.js +2 -0
  90. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -0
  91. package/plugins/beta/scale-bar/dist/umd/index.js +2 -0
  92. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -0
  93. package/plugins/beta/use-location/dist/esm/index.js +2 -0
  94. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -0
  95. package/plugins/beta/use-location/dist/umd/index.js +2 -0
  96. package/plugins/interact/dist/css/index.css +1 -1
  97. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  98. package/plugins/interact/dist/esm/index.js +1 -1
  99. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  100. package/plugins/interact/dist/umd/index.js +1 -1
  101. package/plugins/interact/src/InteractInit.jsx +1 -1
  102. package/plugins/interact/src/InteractInit.test.js +97 -0
  103. package/plugins/interact/src/api/clear.test.js +18 -0
  104. package/plugins/interact/src/api/disable.test.js +12 -0
  105. package/plugins/interact/src/api/enable.test.js +48 -0
  106. package/plugins/interact/src/api/selectFeature.test.js +33 -0
  107. package/plugins/interact/src/api/unselectFeature.test.js +33 -0
  108. package/plugins/interact/src/defaults.js +2 -0
  109. package/plugins/interact/src/events.js +37 -52
  110. package/plugins/interact/src/events.test.js +186 -0
  111. package/plugins/interact/src/hooks/useHighlightSync.js +1 -1
  112. package/plugins/interact/src/hooks/useHighlightSync.test.js +212 -0
  113. package/plugins/interact/src/hooks/useInteractionHandlers.js +80 -41
  114. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +316 -0
  115. package/plugins/interact/src/index.test.js +22 -0
  116. package/plugins/interact/src/interact.scss +6 -0
  117. package/plugins/interact/src/manifest.js +1 -1
  118. package/plugins/interact/src/manifest.test.js +94 -0
  119. package/plugins/interact/src/reducer.js +28 -21
  120. package/plugins/interact/src/reducer.test.js +155 -0
  121. package/plugins/interact/src/utils/buildStylesMap.test.js +57 -0
  122. package/plugins/interact/src/utils/featureQueries.js +2 -2
  123. package/plugins/interact/src/utils/featureQueries.test.js +56 -0
  124. package/plugins/interact/src/utils/spatial.js +95 -0
  125. package/plugins/interact/src/utils/spatial.test.js +93 -0
  126. package/plugins/search/dist/css/index.css +1 -1
  127. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  128. package/plugins/search/dist/esm/index.js +1 -1
  129. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  130. package/plugins/search/dist/umd/index.js +1 -1
  131. package/plugins/search/src/Search.jsx +2 -2
  132. package/plugins/search/src/components/Form/Form.jsx +1 -1
  133. package/plugins/search/src/components/Suggestions/Suggestions.jsx +5 -5
  134. package/plugins/search/src/datasets.js +1 -1
  135. package/plugins/search/src/defaults.js +3 -0
  136. package/plugins/search/src/events/fetchSuggestions.js +48 -53
  137. package/plugins/search/src/events/formHandlers.js +3 -2
  138. package/plugins/search/src/events/index.js +1 -1
  139. package/plugins/search/src/events/inputHandlers.js +3 -1
  140. package/plugins/search/src/events/suggestionHandlers.js +12 -3
  141. package/plugins/search/src/search.scss +4 -1
  142. package/plugins/search/src/utils/parseOsNamesResults.js +15 -19
  143. package/providers/{esri → beta/esri}/src/esriProvider.js +1 -1
  144. package/providers/{esri → beta/esri}/src/index.js +1 -1
  145. package/providers/{esri → beta/esri}/src/mapEvents.js +2 -2
  146. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +2 -0
  147. package/providers/beta/open-names/dist/esm/index.js +2 -0
  148. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +2 -0
  149. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js.LICENSE.txt +1 -0
  150. package/providers/beta/open-names/dist/umd/index.js +2 -0
  151. package/providers/beta/open-names/dist/umd/index.js.LICENSE.txt +1 -0
  152. package/providers/maplibre/dist/esm/im-maplibre-framework.js +1 -1
  153. package/providers/maplibre/dist/esm/im-maplibre-framework.js.LICENSE.txt +1 -1
  154. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  155. package/providers/maplibre/dist/esm/index.js +1 -1
  156. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  157. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +1 -1
  158. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  159. package/providers/maplibre/dist/umd/index.js +1 -1
  160. package/providers/maplibre/src/defaults.js +3 -2
  161. package/providers/maplibre/src/index.js +36 -20
  162. package/providers/maplibre/src/maplibreProvider.js +140 -11
  163. package/providers/maplibre/src/utils/detectWebgl.js +1 -2
  164. package/providers/maplibre/src/utils/highlightFeatures.js +78 -67
  165. package/providers/maplibre/src/utils/labels.js +174 -120
  166. package/providers/maplibre/src/utils/maplibreFixes.js +2 -2
  167. package/providers/maplibre/src/utils/queryFeatures.js +146 -0
  168. package/providers/maplibre/src/utils/spatial.js +14 -17
  169. package/sonar-project.properties +40 -3
  170. package/src/App/components/Actions/Actions.jsx +2 -2
  171. package/src/App/components/Actions/Actions.module.scss +2 -2
  172. package/src/App/components/KeyboardHelp/KeyboardHelp.jsx +3 -1
  173. package/src/App/components/KeyboardHelp/KeyboardHelp.test.jsx +9 -0
  174. package/src/App/components/Logo/Logo.jsx +1 -1
  175. package/src/App/components/MapButton/MapButton.jsx +217 -41
  176. package/src/App/components/MapButton/MapButton.module.scss +32 -21
  177. package/src/App/components/MapButton/MapButton.test.jsx +128 -84
  178. package/src/App/components/Markers/Markers.jsx +1 -1
  179. package/src/App/components/Markers/Markers.module.scss +0 -5
  180. package/src/App/components/Panel/Panel.jsx +75 -45
  181. package/src/App/components/Panel/Panel.module.scss +18 -24
  182. package/src/App/components/Panel/Panel.test.jsx +18 -0
  183. package/src/App/components/PopupMenu/PopupMenu.jsx +246 -0
  184. package/src/App/components/PopupMenu/PopupMenu.module.scss +70 -0
  185. package/src/App/components/PopupMenu/PopupMenu.test.jsx +304 -0
  186. package/src/App/components/Tooltip/Tooltip.jsx +4 -2
  187. package/src/App/components/Tooltip/getTooltipPosition.js +1 -1
  188. package/src/App/components/Viewport/MapController.jsx +1 -1
  189. package/src/App/components/Viewport/MapStatus.jsx +1 -1
  190. package/src/App/components/Viewport/Viewport.jsx +2 -2
  191. package/src/App/components/Viewport/Viewport.module.scss +2 -2
  192. package/src/App/controls/keyboardActions.js +3 -2
  193. package/src/App/controls/keyboardShortcuts.js +4 -2
  194. package/src/App/hooks/useButtonStateEvaluator.js +58 -45
  195. package/src/App/hooks/useButtonStateEvaluator.test.js +36 -3
  196. package/src/App/hooks/useCrossHairAPI.js +49 -47
  197. package/src/App/hooks/useFocusVisible.js +2 -2
  198. package/src/App/hooks/useInterfaceAPI.js +36 -1
  199. package/src/App/hooks/useKeyboardHint.js +1 -1
  200. package/src/App/hooks/useKeyboardShortcuts.js +4 -2
  201. package/src/App/hooks/useMapAnnouncements.js +34 -32
  202. package/src/App/hooks/useMapEvents.js +12 -1
  203. package/src/App/hooks/useMapProviderOverrides.js +3 -3
  204. package/src/App/hooks/useMapStateSync.js +7 -1
  205. package/src/App/hooks/useMapURLSync.js +6 -1
  206. package/src/App/hooks/useMarkersAPI.js +88 -50
  207. package/src/App/hooks/useMediaQueryDispatch.test.js +48 -0
  208. package/src/App/hooks/useModalPanelBehaviour.js +46 -40
  209. package/src/App/hooks/useResizeObserver.js +2 -2
  210. package/src/App/initialiseApp.js +45 -38
  211. package/src/App/layout/Layout.jsx +6 -4
  212. package/src/App/layout/layout.module.scss +13 -17
  213. package/src/App/registry/keyboardShortcutRegistry.js +12 -2
  214. package/src/App/registry/keyboardShortcutRegistry.test.js +28 -0
  215. package/src/App/registry/mergeManifests.js +1 -1
  216. package/src/App/registry/panelRegistry.js +1 -1
  217. package/src/App/registry/panelRegistry.test.js +30 -1
  218. package/src/App/registry/pluginRegistry.js +14 -51
  219. package/src/App/registry/pluginRegistry.test.js +54 -6
  220. package/src/App/renderer/HtmlElementHost.jsx +186 -0
  221. package/src/App/renderer/HtmlElementHost.test.jsx +231 -0
  222. package/src/App/renderer/mapButtons.js +12 -9
  223. package/src/App/renderer/mapButtons.test.js +6 -4
  224. package/src/App/renderer/mapControls.js +6 -0
  225. package/src/App/renderer/mapControls.test.js +10 -2
  226. package/src/App/renderer/mapPanels.js +39 -26
  227. package/src/App/renderer/mapPanels.test.js +29 -0
  228. package/src/App/renderer/pluginWrapper.test.js +28 -0
  229. package/src/App/renderer/slotHelpers.js +60 -0
  230. package/src/App/renderer/slotHelpers.test.js +82 -0
  231. package/src/App/store/AppProvider.jsx +3 -0
  232. package/src/App/store/AppProvider.test.jsx +40 -0
  233. package/src/App/store/PluginProvider.jsx +7 -5
  234. package/src/App/store/appActionsMap.js +46 -1
  235. package/src/App/store/appActionsMap.test.js +21 -0
  236. package/src/App/store/appReducer.js +1 -0
  237. package/src/App/store/mapActionsMap.js +12 -24
  238. package/src/App/store/mapReducer.js +1 -1
  239. package/src/InteractiveMap/InteractiveMap.js +194 -13
  240. package/src/InteractiveMap/InteractiveMap.test.js +164 -2
  241. package/src/InteractiveMap/behaviourController.js +12 -2
  242. package/src/InteractiveMap/behaviourController.test.js +82 -1
  243. package/src/InteractiveMap/deviceChecker.js +1 -1
  244. package/src/InteractiveMap/deviceChecker.test.js +2 -2
  245. package/src/InteractiveMap/historyManager.js +41 -5
  246. package/src/InteractiveMap/historyManager.test.js +37 -6
  247. package/src/InteractiveMap/polyfills.js +39 -0
  248. package/src/InteractiveMap/polyfills.test.js +127 -0
  249. package/src/config/appConfig.js +5 -5
  250. package/src/config/appConfig.test.js +107 -42
  251. package/src/config/defaults.js +30 -20
  252. package/src/config/events.js +110 -4
  253. package/src/index.js +5 -2
  254. package/src/index.umd.js +1 -1
  255. package/src/scss/main.scss +1 -0
  256. package/src/scss/settings/_dimensions.scss +6 -2
  257. package/src/scss/tools/_border-focus.scss +20 -4
  258. package/src/services/eventBus.test.js +24 -1
  259. package/src/test-utils.js +1 -0
  260. package/src/types.js +590 -0
  261. package/src/utils/detectBreakpoint.js +78 -77
  262. package/src/utils/detectBreakpoint.test.js +50 -4
  263. package/src/utils/detectInterfaceType.js +4 -4
  264. package/src/utils/getIsFullscreen.js +3 -1
  265. package/src/utils/getSafeZoneInset.js +23 -7
  266. package/src/utils/getSafeZoneInset.test.js +18 -0
  267. package/src/utils/mapStateSync.js +3 -3
  268. package/src/utils/queryString.js +1 -1
  269. package/src/utils/stringToKebab.js +1 -1
  270. package/src/utils/toggleInertElements.js +37 -12
  271. package/webpack.dev.mjs +3 -4
  272. package/webpack.esm.mjs +8 -8
  273. package/webpack.umd.mjs +8 -8
  274. package/plugins/datasets/dist/esm/im-datasets-plugin.js +0 -1
  275. package/plugins/datasets/dist/esm/index.js +0 -2
  276. package/plugins/datasets/dist/umd/im-datasets-plugin.js +0 -1
  277. package/plugins/datasets/dist/umd/index.js +0 -2
  278. package/plugins/datasets/src/datasets.js +0 -60
  279. package/plugins/datasets/src/utils/bbox.js +0 -4
  280. package/plugins/draw-ml/dist/css/index.css +0 -1
  281. package/plugins/draw-ml/dist/esm/im-draw-ml-plugin.js +0 -1
  282. package/plugins/draw-ml/dist/esm/index.js +0 -2
  283. package/plugins/draw-ml/dist/umd/im-draw-ml-plugin.js +0 -1
  284. package/plugins/draw-ml/dist/umd/index.js +0 -2
  285. package/plugins/draw-ml/src/api/addFeature.js +0 -15
  286. package/plugins/draw-ml/src/api/newPolygon.js +0 -43
  287. package/plugins/draw-ml/src/draw.scss +0 -9
  288. package/plugins/draw-ml/src/events.js +0 -127
  289. package/plugins/draw-ml/src/manifest.js +0 -100
  290. package/plugins/draw-ml/src/modes/drawVertexMode.js +0 -275
  291. package/plugins/draw-ml/src/modes/editVertexMode.js +0 -426
  292. package/plugins/draw-ml/src/utils.js +0 -102
  293. package/plugins/frame/dist/esm/im-frame-plugin.js +0 -1
  294. package/plugins/frame/dist/esm/index.js +0 -2
  295. package/plugins/frame/dist/umd/im-frame-plugin.js +0 -1
  296. package/plugins/frame/dist/umd/index.js +0 -2
  297. package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +0 -1
  298. package/plugins/map-styles/dist/esm/index.js +0 -2
  299. package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +0 -1
  300. package/plugins/map-styles/dist/umd/index.js +0 -2
  301. package/plugins/scale-bar/dist/esm/im-scale-bar-plugin.js +0 -1
  302. package/plugins/scale-bar/dist/esm/index.js +0 -2
  303. package/plugins/scale-bar/dist/umd/im-scale-bar-plugin.js +0 -1
  304. package/plugins/scale-bar/dist/umd/index.js +0 -2
  305. package/plugins/search/src/utils/fetchDataset.js +0 -23
  306. package/plugins/use-location/dist/esm/im-use-location-plugin.js +0 -1
  307. package/plugins/use-location/dist/esm/index.js +0 -2
  308. package/plugins/use-location/dist/umd/im-use-location-plugin.js +0 -1
  309. package/plugins/use-location/dist/umd/index.js +0 -2
  310. package/providers/maplibre/dist/esm/im-maplibre-legacy-framework.js +0 -1
  311. package/providers/maplibre/dist/umd/im-maplibre-legacy-framework.js +0 -1
  312. package/providers/open-names/dist/esm/im-reverse-geocode.js +0 -2
  313. package/providers/open-names/dist/esm/index.js +0 -2
  314. package/providers/open-names/dist/umd/im-reverse-geocode.js +0 -2
  315. package/providers/open-names/dist/umd/index.js +0 -2
  316. /package/docs/architecture/{ARCHITECTURE_DIAGRAMS.md → architecture-diagrams.md} +0 -0
  317. /package/plugins/{datasets → beta/datasets}/dist/css/index.css +0 -0
  318. /package/plugins/{datasets/dist/esm/index.js.LICENSE.txt → beta/datasets/dist/esm/im-datasets-plugin.js.LICENSE.txt} +0 -0
  319. /package/plugins/{datasets/dist/umd → beta/datasets/dist/esm}/index.js.LICENSE.txt +0 -0
  320. /package/plugins/{draw-ml/dist/esm/index.js.LICENSE.txt → beta/datasets/dist/umd/im-datasets-plugin.js.LICENSE.txt} +0 -0
  321. /package/plugins/{draw-ml → beta/datasets}/dist/umd/index.js.LICENSE.txt +0 -0
  322. /package/plugins/{datasets → beta/datasets}/src/DatasetsInit.jsx +0 -0
  323. /package/plugins/{datasets → beta/datasets}/src/api/addDataset.js +0 -0
  324. /package/plugins/{datasets → beta/datasets}/src/api/hideDataset.js +0 -0
  325. /package/plugins/{datasets → beta/datasets}/src/api/hideFeatures.js +0 -0
  326. /package/plugins/{datasets → beta/datasets}/src/api/removeDataset.js +0 -0
  327. /package/plugins/{datasets → beta/datasets}/src/api/showDataset.js +0 -0
  328. /package/plugins/{datasets → beta/datasets}/src/api/showFeatures.js +0 -0
  329. /package/plugins/{datasets → beta/datasets}/src/datasets.scss +0 -0
  330. /package/plugins/{datasets → beta/datasets}/src/defaults.js +0 -0
  331. /package/plugins/{datasets → beta/datasets}/src/index.js +0 -0
  332. /package/plugins/{datasets → beta/datasets}/src/panels/Key.module.scss +0 -0
  333. /package/plugins/{datasets → beta/datasets}/src/panels/Layers.jsx +0 -0
  334. /package/plugins/{datasets → beta/datasets}/src/panels/Layers.module.scss +0 -0
  335. /package/plugins/{datasets → beta/datasets}/src/reducer.js +0 -0
  336. /package/plugins/{datasets → beta/datasets}/src/utils/debounce.js +0 -0
  337. /package/plugins/{datasets → beta/datasets}/src/utils/filters.js +0 -0
  338. /package/plugins/{draw-es → beta/draw-es}/src/DrawInit.jsx +0 -0
  339. /package/plugins/{draw-es → beta/draw-es}/src/api/addFeature.js +0 -0
  340. /package/plugins/{draw-es → beta/draw-es}/src/api/deleteFeature.js +0 -0
  341. /package/plugins/{draw-es → beta/draw-es}/src/api/editFeature.js +0 -0
  342. /package/plugins/{draw-es → beta/draw-es}/src/api/newPolygon.js +0 -0
  343. /package/plugins/{draw-es → beta/draw-es}/src/events.js +0 -0
  344. /package/plugins/{draw-es → beta/draw-es}/src/graphic.js +0 -0
  345. /package/plugins/{draw-es → beta/draw-es}/src/index.js +0 -0
  346. /package/plugins/{draw-es → beta/draw-es}/src/manifest.js +0 -0
  347. /package/plugins/{draw-es → beta/draw-es}/src/reducer.js +0 -0
  348. /package/plugins/{draw-es → beta/draw-es}/src/sketchViewModel.js +0 -0
  349. /package/plugins/{frame → beta/draw-ml}/dist/esm/index.js.LICENSE.txt +0 -0
  350. /package/plugins/{frame → beta/draw-ml}/dist/umd/index.js.LICENSE.txt +0 -0
  351. /package/plugins/{draw-ml → beta/draw-ml}/src/DrawInit.jsx +0 -0
  352. /package/plugins/{draw-ml → beta/draw-ml}/src/api/deleteFeature.js +0 -0
  353. /package/plugins/{draw-ml → beta/draw-ml}/src/index.js +0 -0
  354. /package/plugins/{draw-ml → beta/draw-ml}/src/modes/disabledMode.js +0 -0
  355. /package/plugins/{draw-ml/src → beta/draw-ml/src/utils}/snapHelpers.js +0 -0
  356. /package/plugins/{frame → beta/frame}/dist/css/index.css +0 -0
  357. /package/plugins/{map-styles → beta/frame}/dist/esm/index.js.LICENSE.txt +0 -0
  358. /package/plugins/{map-styles → beta/frame}/dist/umd/index.js.LICENSE.txt +0 -0
  359. /package/plugins/{frame → beta/frame}/package.json +0 -0
  360. /package/plugins/{frame → beta/frame}/src/FrameInit.jsx +0 -0
  361. /package/plugins/{frame → beta/frame}/src/api/addFrame.js +0 -0
  362. /package/plugins/{frame → beta/frame}/src/api/editFeature.js +0 -0
  363. /package/plugins/{frame → beta/frame}/src/config.js +0 -0
  364. /package/plugins/{frame → beta/frame}/src/frame.scss +0 -0
  365. /package/plugins/{frame → beta/frame}/src/index.js +0 -0
  366. /package/plugins/{frame → beta/frame}/src/manifest.js +0 -0
  367. /package/plugins/{frame → beta/frame}/src/reducer.js +0 -0
  368. /package/plugins/{frame → beta/frame}/src/utils.js +0 -0
  369. /package/plugins/{scale-bar → beta/map-styles}/dist/esm/index.js.LICENSE.txt +0 -0
  370. /package/plugins/{scale-bar → beta/map-styles}/dist/umd/index.js.LICENSE.txt +0 -0
  371. /package/plugins/{map-styles → beta/map-styles}/src/MapStylesInit.jsx +0 -0
  372. /package/plugins/{map-styles → beta/map-styles}/src/config.js +0 -0
  373. /package/plugins/{map-styles → beta/map-styles}/src/index.js +0 -0
  374. /package/plugins/{scale-bar → beta/scale-bar}/dist/css/index.css +0 -0
  375. /package/plugins/{use-location → beta/scale-bar}/dist/esm/index.js.LICENSE.txt +0 -0
  376. /package/plugins/{use-location → beta/scale-bar}/dist/umd/index.js.LICENSE.txt +0 -0
  377. /package/plugins/{scale-bar → beta/scale-bar}/package.json +0 -0
  378. /package/plugins/{scale-bar → beta/scale-bar}/src/ScaleBar.jsx +0 -0
  379. /package/plugins/{scale-bar → beta/scale-bar}/src/ScaleBar.test.jsx +0 -0
  380. /package/plugins/{scale-bar → beta/scale-bar}/src/index.js +0 -0
  381. /package/plugins/{scale-bar → beta/scale-bar}/src/index.test.js +0 -0
  382. /package/plugins/{scale-bar → beta/scale-bar}/src/manifest.js +0 -0
  383. /package/plugins/{scale-bar → beta/scale-bar}/src/scaleBar.scss +0 -0
  384. /package/plugins/{scale-bar → beta/scale-bar}/src/utils.js +0 -0
  385. /package/plugins/{scale-bar → beta/scale-bar}/src/utils.test.js +0 -0
  386. /package/{providers/open-names → plugins/beta/use-location}/dist/esm/index.js.LICENSE.txt +0 -0
  387. /package/{providers/open-names → plugins/beta/use-location}/dist/umd/index.js.LICENSE.txt +0 -0
  388. /package/plugins/{use-location → beta/use-location}/src/UseLocation.jsx +0 -0
  389. /package/plugins/{use-location → beta/use-location}/src/UseLocationInit.jsx +0 -0
  390. /package/plugins/{use-location → beta/use-location}/src/defaults.js +0 -0
  391. /package/plugins/{use-location → beta/use-location}/src/events.js +0 -0
  392. /package/plugins/{use-location → beta/use-location}/src/index.js +0 -0
  393. /package/plugins/{use-location → beta/use-location}/src/manifest.js +0 -0
  394. /package/plugins/{use-location → beta/use-location}/src/reducer.js +0 -0
  395. /package/providers/{esri → beta/esri}/src/appEvents.js +0 -0
  396. /package/providers/{esri → beta/esri}/src/defaults.js +0 -0
  397. /package/providers/{esri → beta/esri}/src/esriProvider.scss +0 -0
  398. /package/providers/{esri → beta/esri}/src/utils/coords.js +0 -0
  399. /package/providers/{esri → beta/esri}/src/utils/detectWebGL.js +0 -0
  400. /package/providers/{esri → beta/esri}/src/utils/esriFixes.js +0 -0
  401. /package/providers/{esri → beta/esri}/src/utils/query.js +0 -0
  402. /package/providers/{esri → beta/esri}/src/utils/spatial.js +0 -0
  403. /package/providers/{open-names → beta/open-names}/dist/esm/im-reverse-geocode.js.LICENSE.txt +0 -0
  404. /package/providers/{open-names/dist/umd/im-reverse-geocode.js.LICENSE.txt → beta/open-names/dist/esm/index.js.LICENSE.txt} +0 -0
  405. /package/providers/{open-names → beta/open-names}/src/index.js +0 -0
  406. /package/providers/{open-names → beta/open-names}/src/reverseGeocode.js +0 -0
  407. /package/providers/{open-names → beta/open-names}/src/utils/mapToLocationModel.js +0 -0
@@ -0,0 +1,2 @@
1
+ /*! For license information please see index.js.LICENSE.txt */
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("defra",[],t):"object"==typeof exports?exports.defra=t():(e.defra=e.defra||{},e.defra.drawMLPlugin=t())}(this,()=>(()=>{"use strict";var e,t,r={738(e){e.exports=preactCompat}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce((t,r)=>(o.f[r](e,t),t),[])),o.u=e=>"im-draw-ml-plugin.js",o.miniCssF=e=>{},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="defra.drawMLPlugin:",o.l=(r,n,i,a)=>{if(e[r])e[r].push(n);else{var u,c;if(void 0!==i)for(var f=document.getElementsByTagName("script"),p=0;p<f.length;p++){var l=f[p];if(l.getAttribute("src")==r||l.getAttribute("data-webpack")==t+i){u=l;break}}u||(c=!0,(u=document.createElement("script")).charset="utf-8",o.nc&&u.setAttribute("nonce",o.nc),u.setAttribute("data-webpack",t+i),u.src=r),e[r]=[n];var s=(t,n)=>{u.onerror=u.onload=null,clearTimeout(d);var o=e[r];if(delete e[r],u.parentNode&&u.parentNode.removeChild(u),o&&o.forEach(e=>e(n)),t)return t(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:u}),12e4);u.onerror=s.bind(null,u.onerror),u.onload=s.bind(null,u.onload),c&&document.head.appendChild(u)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var t=o.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=r[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={57:0};o.f.j=(t,r)=>{var n=o.o(e,t)?e[t]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise((r,o)=>n=e[t]=[r,o]);r.push(n[2]=i);var a=o.p+o.u(t),u=new Error;o.l(a,r=>{if(o.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;u.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",u.name="ChunkLoadError",u.type=i,u.request=a,n[1](u)}},"chunk-"+t,t)}};var t=(t,r)=>{var n,i,[a,u,c]=r,f=0;if(a.some(t=>0!==e[t])){for(n in u)o.o(u,n)&&(o.m[n]=u[n]);c&&c(o)}for(t&&t(r);f<a.length;f++)i=a[f],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=this.webpackChunkdefra_DefraMap=this.webpackChunkdefra_DefraMap||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var i={};function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function u(){var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof f?n:f,p=Object.create(u.prototype);return c(p,"_invoke",function(r,n,o){var i,u,c,f=0,p=o||[],l=!1,s={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(t,r){return i=t,u=0,c=e,s.n=r,a}};function d(r,n){for(u=r,c=n,t=0;!l&&f&&!o&&t<p.length;t++){var o,i=p[t],d=s.p,b=i[2];r>3?(o=b===n)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(u=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,u=0))}if(o||r>1)return a;throw l=!0,n}return function(o,p,b){if(f>1)throw TypeError("Generator is already running");for(l&&1===p&&d(p,b),u=p,c=b;(t=u<2?e:c)||!l;){i||(u?u<3?(u>1&&(s.n=-1),d(u,c)):s.n=c:s.v=c);try{if(f=2,i){if(u||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=i.return)&&t.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=e}else if((t=(l=s.n<0)?c:r.call(n,s))!==a)break}catch(t){i=e,u=1,c=t}finally{f=1}}return{value:t,done:l}}}(r,o,i),!0),p}var a={};function f(){}function p(){}function l(){}t=Object.getPrototypeOf;var s=[][n]?t(t([][n]())):(c(t={},n,function(){return this}),t),d=l.prototype=f.prototype=Object.create(s);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return p.prototype=l,c(d,"constructor",l),c(l,"constructor",p),p.displayName="GeneratorFunction",c(l,o,"GeneratorFunction"),c(d),c(d,o,"Generator"),c(d,n,function(){return this}),c(d,"toString",function(){return"[object Generator]"}),(u=function(){return{w:i,m:b}})()}function c(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}c=function(e,t,r,n){function i(t,r){c(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},c(e,t,r,n)}function f(e,t,r,n,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function s(e,t,r){return(t=function(e){var t=function(e){if("object"!=a(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=a(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==a(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(){var e,t;return l(l({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(e=u().m(function e(){var t;return u().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.e(966).then(o.bind(o,133));case 1:return t=e.v.manifest,e.a(2,t)}},e)}),t=function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){f(i,n,o,a,u,"next",e)}function u(e){f(i,n,o,a,u,"throw",e)}a(void 0)})},function(){return t.apply(this,arguments)})})}return o.d(i,{default:()=>d}),i.default})());
@@ -0,0 +1,27 @@
1
+ import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
2
+
3
+ export const addFeature = ({ mapProvider, services }, feature) => {
4
+ const { draw } = mapProvider
5
+ const { eventBus } = services
6
+
7
+ if (!draw) {
8
+ return
9
+ }
10
+
11
+ // Extract style props from top level, flatten variants, merge with custom properties
12
+ const { stroke, fill, strokeWidth, properties, ...rest } = feature
13
+ const flatFeature = {
14
+ ...rest,
15
+ properties: {
16
+ ...properties,
17
+ ...flattenStyleProperties({ stroke, fill, strokeWidth })
18
+ }
19
+ }
20
+
21
+ // --- Add feature to draw instance
22
+ draw.add(flatFeature, {
23
+ userProperties: true
24
+ })
25
+
26
+ eventBus.emit('draw:add', flatFeature)
27
+ }
@@ -1,4 +1,4 @@
1
- import { getSnapInstance } from '../snapHelpers.js'
1
+ import { getSnapInstance } from '../utils/snapHelpers.js'
2
2
 
3
3
  /**
4
4
  * Programmatically edit a feature
@@ -6,7 +6,7 @@ import { getSnapInstance } from '../snapHelpers.js'
6
6
  * @param {string} featureId - ID of the feature to edit
7
7
  * @param {object} options - Options including snapLayers
8
8
  */
9
- export const editFeature = ({ appState, appConfig, mapState, pluginState, mapProvider }, featureId, options = {}) => {
9
+ export const editFeature = ({ appState, appConfig, mapState, pluginConfig, pluginState, mapProvider }, featureId, options = {}) => {
10
10
  const { dispatch } = pluginState
11
11
  const { draw, map } = mapProvider
12
12
 
@@ -14,24 +14,35 @@ export const editFeature = ({ appState, appConfig, mapState, pluginState, mapPro
14
14
  return
15
15
  }
16
16
 
17
+ // Determin snapLayers from pluginConfig or runtime config
18
+ let snapLayers = null
19
+ if (options.snapLayers !== undefined) {
20
+ snapLayers = options.snapLayers
21
+ } else if (pluginConfig.snapLayers !== undefined) {
22
+ snapLayers = pluginConfig.snapLayers
23
+ } else {
24
+ snapLayers = null
25
+ }
26
+
17
27
  // Set per-call snap layers if provided
18
28
  const snap = getSnapInstance(map)
19
29
  if (snap?.setSnapLayers) {
20
- snap.setSnapLayers(options.snapLayers || null)
21
- } else if (options.snapLayers) {
30
+ snap.setSnapLayers(snapLayers)
31
+ } else if (snapLayers) {
22
32
  // Snap instance not ready yet - store for later
23
- map._pendingSnapLayers = options.snapLayers
33
+ map._pendingSnapLayers = snapLayers
24
34
  } else {
25
35
  // No action
26
36
  }
27
37
 
28
38
  // Update state so UI can react to snap layer availability
29
- dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: options.snapLayers?.length > 0 })
39
+ dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: snapLayers?.length > 0 })
30
40
 
31
41
  // Change mode to edit_vertex
32
42
  draw.changeMode('edit_vertex', {
33
43
  container: appState.layoutRefs.viewportRef.current,
34
44
  deleteVertexButtonId: `${appConfig.id}-draw-delete-point`,
45
+ undoButtonId: `${appConfig.id}-draw-undo`,
35
46
  isPanEnabled: appState.interfaceType !== 'keyboard',
36
47
  interfaceType: appState.interfaceType,
37
48
  scale: { small: 1, medium: 1.5, large: 2 }[mapState.mapSize],
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Programmatically merge multiple polygons ia single polygon
3
+ * @param {object} context - plugin context
4
+ * @param {string} polygon[] - an a rray of polygons to merge
5
+ */
6
+ export const merge = ({ services }, polygons) => {
7
+ console.log('merge')
8
+ console.log(polygons)
9
+ }
@@ -0,0 +1,68 @@
1
+ import { getSnapInstance } from '../utils/snapHelpers.js'
2
+ import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
3
+ import { DEFAULTS } from '../defaults.js'
4
+
5
+ /**
6
+ * Programmatically create a new line
7
+ * @param {object} context - plugin context
8
+ * @param {string} featureId - ID for the new feature
9
+ * @param {object} options - Options including snapLayers, stroke, fill, strokeWidth, properties.
10
+ */
11
+ export const newLine = ({ appState, appConfig, pluginConfig, pluginState, mapProvider, services }, featureId, options = {}) => {
12
+ const { dispatch } = pluginState
13
+ const { draw, map } = mapProvider
14
+ const { eventBus } = services
15
+
16
+ if (!draw) {
17
+ return
18
+ }
19
+
20
+ // Emit draw:start
21
+ eventBus.emit('draw:start', { mode: 'draw_line' })
22
+
23
+ // Determin snapLayers from pluginConfig or runtime config
24
+ let snapLayers = null
25
+ if (options.snapLayers !== undefined) {
26
+ snapLayers = options.snapLayers
27
+ } else if (pluginConfig.snapLayers !== undefined) {
28
+ snapLayers = pluginConfig.snapLayers
29
+ } else {
30
+ snapLayers = null
31
+ }
32
+
33
+ // Set per-call snap layers if provided
34
+ const snap = getSnapInstance(map)
35
+ if (snap?.setSnapLayers) {
36
+ snap.setSnapLayers(snapLayers)
37
+ } else if (snapLayers) {
38
+ // Snap instance not ready yet - store for later
39
+ map._pendingSnapLayers = snapLayers
40
+ } else {
41
+ // No action
42
+ }
43
+
44
+ // Update state so UI can react to snap layer availability
45
+ dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: snapLayers?.length > 0 })
46
+
47
+ // Extract style props and flatten variants into properties
48
+ const { stroke, fill, strokeWidth, properties: customProperties, ...modeOptions } = options
49
+ const properties = {
50
+ ...customProperties,
51
+ ...flattenStyleProperties({ stroke, fill, strokeWidth })
52
+ }
53
+
54
+ // Change mode to draw_line
55
+ draw.changeMode('draw_line', {
56
+ container: appState.layoutRefs.viewportRef.current,
57
+ vertexMarkerId: `${appConfig.id}-cross-hair`,
58
+ addVertexButtonId: `${appConfig.id}-draw-add-point`,
59
+ interfaceType: appState.interfaceType,
60
+ getSnapEnabled: () => mapProvider.snapEnabled === true,
61
+ featureId,
62
+ ...modeOptions,
63
+ properties
64
+ })
65
+
66
+ // Set mode to draw_line
67
+ dispatch({ type: 'SET_MODE', payload: 'draw_line' })
68
+ }
@@ -0,0 +1,68 @@
1
+ import { getSnapInstance } from '../utils/snapHelpers.js'
2
+ import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
3
+ import { DEFAULTS } from '../defaults.js'
4
+
5
+ /**
6
+ * Programmatically create a new polygon
7
+ * @param {object} context - plugin context
8
+ * @param {string} featureId - ID for the new feature
9
+ * @param {object} options - Options including snapLayers, stroke, fill, strokeWidth, properties.
10
+ */
11
+ export const newPolygon = ({ appState, appConfig, pluginConfig, pluginState, mapProvider, services }, featureId, options = {}) => {
12
+ const { dispatch } = pluginState
13
+ const { draw, map } = mapProvider
14
+ const { eventBus } = services
15
+
16
+ if (!draw) {
17
+ return
18
+ }
19
+
20
+ // Emit draw:start
21
+ eventBus.emit('draw:start', { mode: 'draw_polygon' })
22
+
23
+ // Determin snapLayers from pluginConfig or runtime config
24
+ let snapLayers = null
25
+ if (options.snapLayers !== undefined) {
26
+ snapLayers = options.snapLayers
27
+ } else if (pluginConfig.snapLayers !== undefined) {
28
+ snapLayers = pluginConfig.snapLayers
29
+ } else {
30
+ snapLayers = null
31
+ }
32
+
33
+ // Set per-call snap layers if provided
34
+ const snap = getSnapInstance(map)
35
+ if (snap?.setSnapLayers) {
36
+ snap.setSnapLayers(snapLayers)
37
+ } else if (snapLayers) {
38
+ // Snap instance not ready yet - store for later
39
+ map._pendingSnapLayers = snapLayers
40
+ } else {
41
+ // No action
42
+ }
43
+
44
+ // Update state so UI can react to snap layer availability
45
+ dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: snapLayers?.length > 0 })
46
+
47
+ // Extract style props and flatten variants into properties
48
+ const { stroke, fill, strokeWidth, properties: customProperties, ...modeOptions } = options
49
+ const properties = {
50
+ ...customProperties,
51
+ ...flattenStyleProperties({ stroke, fill, strokeWidth })
52
+ }
53
+
54
+ // Change mode to draw_polygon
55
+ draw.changeMode('draw_polygon', {
56
+ container: appState.layoutRefs.viewportRef.current,
57
+ vertexMarkerId: `${appConfig.id}-cross-hair`,
58
+ addVertexButtonId: `${appConfig.id}-draw-add-point`,
59
+ interfaceType: appState.interfaceType,
60
+ getSnapEnabled: () => mapProvider.snapEnabled === true,
61
+ featureId,
62
+ ...modeOptions,
63
+ properties
64
+ })
65
+
66
+ // Set mode to draw_polygon
67
+ dispatch({ type: 'SET_MODE', payload: 'draw_polygon' })
68
+ }
@@ -0,0 +1,81 @@
1
+ import { getSnapInstance } from '../utils/snapHelpers.js'
2
+ import { splitPolygon } from '../utils/spatial.js'
3
+ import { debounce } from '../utils/debounce.js'
4
+
5
+ /**
6
+ * Programmatically split a polygon or line
7
+ * @param {object} context - plugin context
8
+ * @param {string} feature - the new feature to be split
9
+ * @param {object} options - Options including snapLayers.
10
+ */
11
+ export const split = ({ appState, appConfig, pluginState, mapProvider }, featureId, options = {}) => {
12
+ const { dispatch } = pluginState
13
+ const { draw, map } = mapProvider
14
+
15
+ if (!draw) {
16
+ return
17
+ }
18
+
19
+ // Get target polygon feature
20
+ const polygonFeature = draw.get(featureId)
21
+
22
+ // Always include 'stroke-inactive' in snap layers
23
+ const snapLayers = ['stroke-inactive.cold', ...(options.snapLayers || [])]
24
+
25
+ // Set per-call snap layers if provided
26
+ const snap = getSnapInstance(map)
27
+
28
+ if (snap?.setSnapLayers) {
29
+ snap.setSnapLayers(snapLayers)
30
+ } else if (options.snapLayers) {
31
+ // Snap instance not ready yet - store for later
32
+ map._pendingSnapLayers = snapLayers
33
+ } else {
34
+ // No action
35
+ }
36
+
37
+ // Update state so UI can react to snap layer availability
38
+ dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: true })
39
+
40
+ // Change mode to draw_line
41
+ draw.changeMode('draw_line', {
42
+ container: appState.layoutRefs.viewportRef.current,
43
+ vertexMarkerId: `${appConfig.id}-cross-hair`,
44
+ addVertexButtonId: `${appConfig.id}-draw-add-point`,
45
+ interfaceType: appState.interfaceType,
46
+ getSnapEnabled: () => mapProvider.snapEnabled === true,
47
+ featureId: '_splitter',
48
+ properties: { splitter: 'invalid' }
49
+ })
50
+
51
+ // Perform split
52
+ map.on('draw.create', (e) => {
53
+ const lineFeature = e.features[0]
54
+ const featureCollection = splitPolygon(polygonFeature, lineFeature)
55
+ draw.setFeatureProperty('_splitter', 'splitter', featureCollection ? 'valid' : 'invalid')
56
+ dispatch({ type: 'SET_ACTION', payload: { name: 'split', isValid: !!featureCollection }})
57
+ })
58
+
59
+ // Real time check for valid line
60
+ const DEBOUNCE_SPLIT_POLYGON = 50
61
+ const onGeometryChange = debounce((e) => {
62
+ if (e.coordinates.length < 2) {
63
+ return
64
+ }
65
+ const lineFeature = { id: '_splitter', geometry: { type: 'LineString', coordinates: e.coordinates }}
66
+ const featureCollection = splitPolygon(polygonFeature, lineFeature)
67
+ const isValid = !!featureCollection
68
+ e.properties.splitter = isValid ? 'valid' : 'invalid'
69
+ e.ctx.store.render()
70
+ if (draw.getMode() === 'edit_vertex') {
71
+ dispatch({ type: 'SET_ACTION', payload: { name: 'split', isValid }})
72
+ }
73
+ }, DEBOUNCE_SPLIT_POLYGON)
74
+ map.on('draw.geometrychange', onGeometryChange)
75
+
76
+ // Set mode to 'draw_line'
77
+ dispatch({ type: 'SET_MODE', payload: 'draw_line' })
78
+
79
+ // Set action to 'split'
80
+ dispatch({ type: 'SET_ACTION', payload: { name: 'split' }})
81
+ }
@@ -2,9 +2,12 @@ export const DEFAULTS = {
2
2
  editColorsForeground: { light: 'rgba(29,112,184,1)', dark: '#ffffff' },
3
3
  editColorsBackground: { light: '#ffffff', dark: 'rgba(11,12,12,1)' },
4
4
  editColorsHalo: { light: 'rgba(11,12,12,1)', dark: '#ffffff' },
5
+ splitInvalidColors: { light: 'rgba(29,112,184,1)', dark: 'rgba(29,112,184,1)' },
6
+ splitValidColors: { light: 'rgba(29,112,184,1)', dark: 'rgba(29,112,184,1)' },
5
7
  stroke: 'rgba(212,53,28,1)',
6
8
  strokeWidth: 2,
7
9
  fill: 'rgba(212,53,28,0.1)',
10
+ snapLayers: [],
8
11
  snapColors: {
9
12
  vertex: 'rgba(212,53,28,1)',
10
13
  midpoint: 'rgba(40,161,151,1)',
@@ -0,0 +1,32 @@
1
+ // Maplibre custom mode
2
+ .touch-vertex-target {
3
+ circle {
4
+ fill: var(--map-overlay-foreground-color);
5
+ }
6
+ path {
7
+ fill: var(--map-overlay-halo-color);
8
+ }
9
+ }
10
+
11
+ // Ensure action buttons take up same width
12
+ .im-c-actions {
13
+ .im-c-button-wrapper--draw-done,
14
+ .im-c-button-wrapper--draw-menu,
15
+ .im-c-button-wrapper--draw-cancel {
16
+ width: 33.33%;
17
+ }
18
+ }
19
+ .im-o-app--tablet .im-c-actions,
20
+ .im-o-app--desktop .im-c-actions {
21
+ .im-c-button-wrapper--draw-done,
22
+ .im-c-button-wrapper--draw-menu,
23
+ .im-c-button-wrapper--draw-cancel {
24
+ width: 100px;
25
+ }
26
+ }
27
+
28
+ // Position touch add point button
29
+ .im-c-button-wrapper--draw-add-point {
30
+ position: absolute;
31
+ bottom: calc(100% + var(--primary-gap));
32
+ }
@@ -0,0 +1,171 @@
1
+ import { clearSnapState, getSnapInstance } from './utils/snapHelpers.js'
2
+
3
+ export function attachEvents({ pluginState, mapProvider, buttonConfig, eventBus }) {
4
+ const { drawDone, drawAddPoint, drawUndo, drawDeletePoint, drawSnap, drawCancel } = buttonConfig
5
+ const { map, draw } = mapProvider
6
+ const { dispatch, feature, tempFeature } = pluginState
7
+
8
+ // --- Helper to disable snap
9
+ const disableSnap = () => {
10
+ mapProvider.snapEnabled = false
11
+ dispatch({ type: 'SET_SNAP', payload: false })
12
+ const snap = getSnapInstance(map)
13
+ if (snap) {
14
+ snap.setSnapStatus?.(false)
15
+ clearSnapState(snap)
16
+ }
17
+ if (map.getLayer('snap-helper-circle')) {
18
+ map.setLayoutProperty('snap-helper-circle', 'visibility', 'none')
19
+ }
20
+ }
21
+
22
+ // --- Helper to reset draw mode and feature (without touching snap)
23
+ const resetDrawModeAndFeature = () => {
24
+ mapProvider.undoStack?.clear()
25
+ dispatch({ type: 'SET_MODE', payload: null })
26
+ dispatch({ type: 'SET_FEATURE', payload: { feature: null, tempFeature: null }})
27
+ }
28
+
29
+ // --- Button handlers
30
+ const handleDone = () => {
31
+ const mode = draw.getMode()
32
+ const features = draw.getAll().features
33
+ const feature = features?.[0]
34
+
35
+ disableSnap()
36
+ mapProvider.undoStack?.clear()
37
+
38
+ if (mode === 'edit_vertex') {
39
+ map.fire('draw.editfinish', { features: [feature] })
40
+ return
41
+ }
42
+
43
+ if (!['draw_polygon', 'draw_line'].includes(mode) || features.length === 0) {
44
+ return
45
+ }
46
+
47
+ const geom = feature.geometry
48
+ if (geom.type === 'Polygon') {
49
+ const ring = geom.coordinates[0]
50
+ geom.coordinates[0] = [...ring.slice(0, -2), ring[0]]
51
+ } else {
52
+ geom.coordinates = geom.coordinates.slice(0, -1)
53
+ }
54
+
55
+ map.fire('draw.create', { features: [feature] })
56
+ }
57
+
58
+ const handleCancel = () => {
59
+ if (tempFeature?.id) {
60
+ draw.delete(tempFeature.id)
61
+ }
62
+ if (feature) {
63
+ draw.add(feature)
64
+ }
65
+ disableSnap()
66
+ draw.changeMode('disabled')
67
+ resetDrawModeAndFeature()
68
+ eventBus.emit('draw:cancel', { originalFeature: feature })
69
+ }
70
+
71
+ const handleUndo = () => {
72
+ if (draw.getMode() === 'edit_vertex') {
73
+ return
74
+ }
75
+ const undoStack = mapProvider.undoStack
76
+ if (!undoStack?.length) {
77
+ return
78
+ }
79
+ const operation = undoStack.pop()
80
+ map._undoInProgress = true
81
+ setTimeout(() => { map._undoInProgress = false }, 100)
82
+ map.fire('draw.undo', { operation })
83
+ }
84
+
85
+ let lastToggleTime = 0
86
+ const THROTTLE_MS = 300
87
+ const handleSnap = () => {
88
+ const now = Date.now()
89
+ if (now - lastToggleTime < THROTTLE_MS) {
90
+ return
91
+ }
92
+ lastToggleTime = now
93
+
94
+ const newSnapState = !pluginState.snap
95
+ dispatch({ type: 'TOGGLE_SNAP' })
96
+ mapProvider.snapEnabled = newSnapState
97
+
98
+ const snap = getSnapInstance(map)
99
+ if (snap?.setSnapStatus) {
100
+ snap.setSnapStatus(newSnapState)
101
+ }
102
+
103
+ if (!newSnapState && snap) {
104
+ clearSnapState(snap)
105
+ if (map.getLayer('snap-helper-circle')) {
106
+ map.setLayoutProperty('snap-helper-circle', 'visibility', 'none')
107
+ }
108
+ }
109
+ }
110
+
111
+ // --- Map style update
112
+ const handleStyleData = () => {
113
+ const layers = map.getStyle().layers || []
114
+ if (!layers.length || layers[layers.length - 1].source?.startsWith('mapbox-gl-draw')) {
115
+ return
116
+ }
117
+ layers.filter(l => l.source?.startsWith('mapbox-gl-draw')).forEach(l => map.moveLayer(l.id))
118
+ }
119
+
120
+ // --- Draw completion handlers (create / edit)
121
+ const handleDrawCompletion = (eventName) => (e) => {
122
+ const newFeature = e.features[0]
123
+ resetDrawModeAndFeature()
124
+ setTimeout(() => draw.changeMode('disabled'), 0)
125
+ eventBus.emit(eventName, { newFeature })
126
+ }
127
+
128
+ const onCreate = handleDrawCompletion('draw:create')
129
+ const onEditFinish = handleDrawCompletion('draw:edit')
130
+
131
+ // --- Other map events
132
+ const onUpdate = (e) => eventBus.emit('draw:update', e)
133
+ const onVertexSelection = (e) => {
134
+ dispatch({ type: 'SET_SELECTED_VERTEX_INDEX', payload: e })
135
+ eventBus.emit('draw:vertexselection', e)
136
+ }
137
+ const onVertexChange = (e) => {
138
+ dispatch({ type: 'SET_SELECTED_VERTEX_INDEX', payload: { index: -1, numVertecies: e.numVertecies } })
139
+ }
140
+ const onUndoChange = (e) => {
141
+ dispatch({ type: 'SET_UNDO_STACK_LENGTH', payload: e.length })
142
+ }
143
+
144
+ // --- Register events
145
+ drawDone.onClick = handleDone
146
+ drawCancel.onClick = handleCancel
147
+ drawUndo.onClick = handleUndo
148
+ drawSnap.onClick = handleSnap
149
+
150
+ map.on('styledata', handleStyleData)
151
+ map.on('draw.create', onCreate)
152
+ map.on('draw.editfinish', onEditFinish)
153
+ map.on('draw.update', onUpdate)
154
+ map.on('draw.vertexselection', onVertexSelection)
155
+ map.on('draw.vertexchange', onVertexChange)
156
+ map.on('draw.undochange', onUndoChange)
157
+
158
+ // --- Cleanup
159
+ return () => {
160
+ [drawDone, drawAddPoint, drawUndo, drawDeletePoint, drawSnap, drawCancel].forEach(btn => { if (btn) {
161
+ btn.onClick = null
162
+ }})
163
+ map.off('styledata', handleStyleData)
164
+ map.off('draw.create', onCreate)
165
+ map.off('draw.editfinish', onEditFinish)
166
+ map.off('draw.update', onUpdate)
167
+ map.off('draw.vertexselection', onVertexSelection)
168
+ map.off('draw.vertexchange', onVertexChange)
169
+ map.off('draw.undochange', onUndoChange)
170
+ }
171
+ }
@@ -0,0 +1,132 @@
1
+ // /plugins/draw-ml/manifest.js
2
+ import { initialState, actions } from './reducer.js'
3
+ import { DrawInit } from './DrawInit.jsx'
4
+ import { newPolygon } from './api/newPolygon.js'
5
+ import { newLine } from './api/newLine.js'
6
+ import { editFeature } from './api/editFeature.js'
7
+ import { addFeature } from './api/addFeature.js'
8
+ import { deleteFeature } from './api/deleteFeature.js'
9
+ import { split } from './api/split.js'
10
+ import { merge } from './api/merge.js'
11
+
12
+ const createButtonSlots = (showLabel) => ({
13
+ mobile: { slot: 'actions', showLabel },
14
+ tablet: { slot: 'actions', showLabel },
15
+ desktop: { slot: 'actions', showLabel }
16
+ })
17
+
18
+ export const manifest = {
19
+ reducer: {
20
+ initialState,
21
+ actions
22
+ },
23
+
24
+ InitComponent: DrawInit,
25
+
26
+ buttons: [{
27
+ id: 'drawAddPoint',
28
+ label: 'Add point',
29
+ variant: 'primary',
30
+ hiddenWhen: ({ appState, pluginState }) => !['draw_polygon', 'draw_line'].includes(pluginState.mode) || appState.interfaceType === 'mouse',
31
+ ...createButtonSlots(true)
32
+ },{
33
+ id: 'drawDone',
34
+ label: 'Done',
35
+ variant: 'primary',
36
+ hiddenWhen: ({ pluginState }) => !['draw_polygon', 'draw_line', 'edit_vertex'].includes(pluginState.mode),
37
+ enableWhen: ({ pluginState }) => pluginState.numVertecies >= (pluginState.mode === 'draw_polygon' ? 3 : 2),
38
+ ...createButtonSlots(true)
39
+ },{
40
+ id: 'drawMenu',
41
+ label: 'Menu',
42
+ iconId: 'menu',
43
+ variant: 'tertiary',
44
+ hiddenWhen: ({ pluginState }) => !['draw_polygon', 'draw_line', 'edit_vertex'].includes(pluginState.mode),
45
+ menuItems: [{
46
+ id: 'drawUndo',
47
+ label: 'Undo',
48
+ iconId: 'undo',
49
+ hiddenWhen: ({ pluginState }) => !['draw_polygon', 'draw_line', 'edit_vertex'].includes(pluginState.mode),
50
+ enableWhen: ({ pluginState }) => pluginState.undoStackLength > 0,
51
+ },{
52
+ id: 'drawSnap',
53
+ label: 'Snap to feature',
54
+ iconId: 'magnet',
55
+ hiddenWhen: ({ pluginState }) => !pluginState.mode || !pluginState.hasSnapLayers,
56
+ pressedWhen: ({ pluginState }) => !!pluginState.snap,
57
+ },{
58
+ id: 'drawDeletePoint',
59
+ label: 'Delete point',
60
+ iconId: 'trash',
61
+ enableWhen: ({ pluginState }) => pluginState.selectedVertexIndex >= 0 && pluginState.numVertecies > (pluginState.tempFeature?.geometry?.type === 'Polygon' ? 3 : 2),
62
+ hiddenWhen: ({ pluginState }) => !(['simple_select', 'edit_vertex'].includes(pluginState.mode)),
63
+ }],
64
+ ...createButtonSlots(true)
65
+ },
66
+ // {
67
+ // id: 'drawUndo',
68
+ // label: 'Undo',
69
+ // iconId: 'undo',
70
+ // variant: 'tertiary',
71
+ // hiddenWhen: ({ pluginState }) => !['draw_polygon', 'draw_line', 'edit_vertex'].includes(pluginState.mode),
72
+ // enableWhen: ({ pluginState }) => pluginState.undoStackLength > 0,
73
+ // excludeWhen: () => true,
74
+ // ...createButtonSlots(false)
75
+ // },{
76
+ // id: 'drawDeletePoint',
77
+ // label: 'Delete point',
78
+ // iconId: 'trash',
79
+ // variant: 'tertiary',
80
+ // enableWhen: ({ pluginState }) => pluginState.selectedVertexIndex >= 0 && pluginState.numVertecies > (pluginState.tempFeature?.geometry?.type === 'Polygon' ? 3 : 2),
81
+ // hiddenWhen: ({ pluginState }) => !(['simple_select', 'edit_vertex'].includes(pluginState.mode)),
82
+ // excludeWhen: () => true,
83
+ // ...createButtonSlots(false)
84
+ // },{
85
+ // id: 'drawSnap',
86
+ // label: 'Snap to line',
87
+ // iconId: 'magnet',
88
+ // variant: 'tertiary',
89
+ // hiddenWhen: ({ pluginState }) => !pluginState.mode || !pluginState.hasSnapLayers,
90
+ // pressedWhen: ({ pluginState }) => !!pluginState.snap,
91
+ // excludeWhen: () => true,
92
+ // ...createButtonSlots(false)
93
+ // },
94
+ {
95
+ id: 'drawCancel',
96
+ label: 'Cancel',
97
+ variant: 'tertiary',
98
+ hiddenWhen: ({ pluginState }) => !pluginState.mode,
99
+ ...createButtonSlots(true)
100
+ }],
101
+
102
+ keyboardShortcuts: [{
103
+ id: 'drawStart',
104
+ group: 'Drawing',
105
+ title: 'Edit vertex',
106
+ command: '<kbd>Spacebar</kbd></dd>'
107
+ }],
108
+
109
+ icons: [{
110
+ id: 'menu',
111
+ svgContent: '<circle cx="12" cy="12" r="10"/><path d="m16 10-4 4-4-4"/>'
112
+ },{
113
+ id: 'undo',
114
+ svgContent: '<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'
115
+ },{
116
+ id: 'magnet',
117
+ svgContent: '<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'
118
+ },{
119
+ id: 'trash',
120
+ svgContent: '<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'
121
+ }],
122
+
123
+ api: {
124
+ newPolygon,
125
+ newLine,
126
+ editFeature,
127
+ addFeature,
128
+ deleteFeature,
129
+ split,
130
+ merge
131
+ }
132
+ }