@defra/interactive-map 0.0.55-alpha → 0.0.56-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 (394) hide show
  1. package/assets/templates/style-switcher.njk +2 -2
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/context.md +2 -0
  7. package/docs/api.md +17 -1
  8. package/docs/architecture/interactive-map.likec4 +4 -4
  9. package/docs/plugins/datasets.md +11 -0
  10. package/docs/plugins/draw.md +8 -2
  11. package/docs/plugins/interact.md +24 -1
  12. package/docs/plugins/search.md +2 -2
  13. package/docusaurus.config.cjs +25 -3
  14. package/govuk-prototype-kit.config.json +6 -7
  15. package/package.json +20 -23
  16. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  17. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  18. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  19. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  20. package/plugins/datasets/dist/esm/index.js +1 -1
  21. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  22. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  23. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  24. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  25. package/plugins/datasets/dist/umd/index.js +1 -1
  26. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +18 -16
  27. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.test.js +2 -2
  28. package/plugins/datasets/src/adapters/esri/registry/esriDataset.js +2 -3
  29. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  30. package/plugins/datasets/src/adapters/loadLayerAdapter.js +2 -20
  31. package/plugins/datasets/src/adapters/loadLayerAdapter.test.js +9 -9
  32. package/plugins/datasets/src/adapters/mapboxStyleLayerAdapter.js +7 -7
  33. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +19 -19
  34. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +1 -1
  35. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
  36. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +2 -2
  37. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +1 -1
  38. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +21 -21
  39. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +5 -5
  40. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +2 -3
  41. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +2 -2
  42. package/plugins/datasets/src/api/getOpacity.js +1 -2
  43. package/plugins/datasets/src/api/getOpacity.test.js +9 -12
  44. package/plugins/datasets/src/api/getStyle.js +1 -2
  45. package/plugins/datasets/src/api/getStyle.test.js +5 -8
  46. package/plugins/datasets/src/api/removeDataset.js +2 -4
  47. package/plugins/datasets/src/api/removeDataset.test.js +5 -10
  48. package/plugins/datasets/src/api/setData.js +2 -4
  49. package/plugins/datasets/src/api/setData.test.js +6 -14
  50. package/plugins/datasets/src/api/setFeatureVisibility.js +1 -2
  51. package/plugins/datasets/src/api/setFeatureVisibility.test.js +8 -11
  52. package/plugins/datasets/src/components/LayersMenu/LayersMenu.jsx +1 -0
  53. package/plugins/datasets/src/components/LayersMenu/LayersMenuCheckbox.jsx +1 -3
  54. package/plugins/datasets/src/components/LayersMenu/LayersMenuCheckbox.test.jsx +13 -18
  55. package/plugins/datasets/src/index.js +2 -2
  56. package/plugins/datasets/src/index.test.js +8 -1
  57. package/plugins/datasets/src/initialise/DatasetsInit.jsx +48 -26
  58. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +160 -89
  59. package/plugins/datasets/src/initialise/initialiseDatasets.js +2 -3
  60. package/plugins/datasets/src/initialise/initialiseDatasets.test.js +23 -10
  61. package/plugins/datasets/src/manifest.js +53 -44
  62. package/plugins/datasets/src/manifest.test.js +36 -4
  63. package/plugins/datasets/src/reducers/pluginState.js +5 -5
  64. package/plugins/datasets/src/reducers/pluginState.test.js +21 -20
  65. package/plugins/datasets/src/registry/__mocks__/datasetRegistry.js +7 -6
  66. package/plugins/datasets/src/registry/createDataset.js +2 -2
  67. package/plugins/datasets/src/registry/dataset.js +9 -10
  68. package/plugins/datasets/src/registry/dataset.test.js +63 -64
  69. package/plugins/datasets/src/registry/datasetRegistry.js +39 -10
  70. package/plugins/datasets/src/registry/datasetRegistry.test.js +83 -1
  71. package/plugins/datasets/src/registry/globalDataset.js +9 -17
  72. package/plugins/datasets/src/registry/isVisibleWhen.js +9 -17
  73. package/plugins/datasets/src/registry/isVisibleWhen.test.js +27 -20
  74. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +26 -27
  75. package/plugins/datasets/src/utils/hasLayersMenu.js +13 -0
  76. package/plugins/datasets/src/utils/hasLayersMenu.test.js +25 -0
  77. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  78. package/plugins/draw/dist/esm/index.js +1 -1
  79. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  80. package/plugins/draw/dist/umd/index.js +1 -1
  81. package/plugins/draw/src/DrawInit.jsx +47 -26
  82. package/plugins/draw/src/DrawInit.test.jsx +90 -2
  83. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +1 -1
  84. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +1 -1
  85. package/plugins/draw/src/manifest.js +3 -2
  86. package/plugins/draw/src/manifest.test.js +13 -1
  87. package/plugins/draw/src/utils/needsDrawTarget.js +22 -0
  88. package/plugins/draw/src/utils/needsDrawTarget.test.js +42 -0
  89. package/plugins/draw-es/dist/esm/index.js +1 -0
  90. package/plugins/{beta/draw-es → draw-es}/src/DrawInit.jsx +1 -1
  91. package/plugins/{beta/draw-es → draw-es}/src/events.test.js +1 -1
  92. package/plugins/{beta/draw-es → draw-es}/src/graphic.js +1 -1
  93. package/plugins/frame/dist/esm/index.js +1 -0
  94. package/plugins/{beta/frame → frame}/dist/umd/im-frame-plugin.js +1 -1
  95. package/plugins/{beta/frame → frame}/dist/umd/index.js +1 -1
  96. package/plugins/{beta/frame → frame}/package.json +2 -2
  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 +3 -3
  102. package/plugins/interact/src/api/enable.test.js +13 -0
  103. package/plugins/interact/src/defaults.js +1 -0
  104. package/plugins/interact/src/hooks/useCrossHairVisibility.js +27 -17
  105. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +72 -7
  106. package/plugins/interact/src/manifest.js +4 -4
  107. package/plugins/interact/src/manifest.test.js +29 -0
  108. package/plugins/interact/src/reducer.js +7 -2
  109. package/plugins/interact/src/reducer.test.js +12 -2
  110. package/plugins/interact/src/utils/needsTarget.js +20 -0
  111. package/plugins/interact/src/utils/needsTarget.test.js +36 -0
  112. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  113. package/plugins/map-key/dist/esm/index.js +1 -1
  114. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  115. package/plugins/map-key/dist/umd/index.js +1 -1
  116. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +4 -0
  117. package/plugins/map-key/src/components/Key/MapKey.jsx +15 -15
  118. package/plugins/map-key/src/components/Key/MapKey.test.jsx +29 -15
  119. package/plugins/map-key/src/initialise/MapKeyInit.jsx +5 -8
  120. package/plugins/map-key/src/initialise/MapKeyInit.test.jsx +9 -7
  121. package/plugins/map-key/src/manifest.test.js +0 -1
  122. package/plugins/map-key/src/reducers/mergeKeyGroupItems.js +14 -33
  123. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +34 -50
  124. package/plugins/map-key/src/reducers/pluginState.js +6 -1
  125. package/plugins/map-key/src/reducers/pluginState.test.js +13 -4
  126. package/plugins/map-styles/dist/esm/index.js +1 -0
  127. package/plugins/{beta/map-styles → map-styles}/dist/umd/im-map-styles-plugin.js +1 -1
  128. package/plugins/{beta/map-styles → map-styles}/dist/umd/index.js +1 -1
  129. package/plugins/{beta/map-styles → map-styles}/src/MapStyles.jsx +2 -2
  130. package/plugins/{beta/map-styles → map-styles}/src/MapStylesInit.jsx +1 -1
  131. package/plugins/menu/dist/esm/index.js +1 -1
  132. package/plugins/scale-bar/dist/esm/index.js +1 -0
  133. package/plugins/{beta/scale-bar → scale-bar}/dist/umd/im-scale-bar-plugin.js +1 -1
  134. package/plugins/{beta/scale-bar → scale-bar}/dist/umd/index.js +1 -1
  135. package/plugins/{beta/scale-bar → scale-bar}/package.json +2 -2
  136. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  137. package/plugins/search/dist/esm/index.js +1 -1
  138. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  139. package/plugins/search/dist/umd/index.js +1 -1
  140. package/plugins/search/src/components/Suggestions/Suggestions.jsx +3 -1
  141. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +11 -0
  142. package/plugins/search/src/utils/markedToElements.jsx +25 -0
  143. package/plugins/search/src/utils/markedToElements.test.jsx +49 -0
  144. package/plugins/search/src/utils/parseOsNamesResults.js +6 -4
  145. package/plugins/search/src/utils/parseOsNamesResults.test.js +18 -0
  146. package/plugins/use-location/dist/esm/index.js +1 -0
  147. package/plugins/{beta/use-location → use-location}/dist/umd/im-use-location-plugin.js +1 -1
  148. package/plugins/{beta/use-location → use-location}/dist/umd/index.js +1 -1
  149. package/providers/esri/dist/esm/index.js +1 -0
  150. package/providers/{beta/esri → esri}/src/esriProvider.js +1 -1
  151. package/providers/{beta/esri → esri}/src/mapEvents.js +2 -2
  152. package/providers/maplibre/dist/esm/index.js +1 -1
  153. package/providers/open-names/dist/esm/index.js +1 -0
  154. package/providers/{beta/open-names → open-names}/dist/umd/im-reverse-geocode.js +1 -1
  155. package/providers/{beta/open-names → open-names}/dist/umd/index.js +1 -1
  156. package/providers/openlayers/dist/esm/index.js +1 -0
  157. package/providers/openlayers/dist/umd/im-openlayers-provider.js +2 -0
  158. package/providers/{beta/openlayers → openlayers}/dist/umd/index.js +1 -1
  159. package/providers/{beta/openlayers → openlayers}/src/index.js +4 -4
  160. package/providers/{beta/openlayers → openlayers}/src/mapEvents.js +2 -2
  161. package/providers/{beta/openlayers → openlayers}/src/mapEvents.test.js +2 -2
  162. package/providers/{beta/openlayers → openlayers}/src/openlayersProvider.js +3 -3
  163. package/providers/{beta/openlayers → openlayers}/src/utils/highlightFeatures.js +1 -1
  164. package/providers/{beta/openlayers → openlayers}/src/utils/patternImages.js +1 -1
  165. package/providers/{beta/openlayers → openlayers}/src/utils/symbolImages.js +1 -1
  166. package/rollup.esm.mjs +43 -47
  167. package/sonar-project.properties +1 -1
  168. package/src/App/App.jsx +4 -1
  169. package/src/App/App.test.jsx +6 -0
  170. package/src/App/renderer/PluginInits.jsx +8 -7
  171. package/src/App/renderer/PluginInits.test.jsx +20 -5
  172. package/src/App/renderer/SlotItemsProvider.jsx +33 -0
  173. package/src/App/renderer/SlotItemsProvider.test.jsx +59 -0
  174. package/src/App/renderer/SlotRenderer.jsx +3 -14
  175. package/src/App/renderer/SlotRenderer.test.jsx +11 -44
  176. package/src/App/renderer/mapButtons.js +22 -11
  177. package/src/App/renderer/mapButtons.test.js +23 -1
  178. package/src/App/renderer/mapControls.js +6 -8
  179. package/src/App/renderer/mapControls.test.js +10 -0
  180. package/src/App/renderer/mapPanels.js +16 -19
  181. package/src/App/renderer/mapPanels.test.js +37 -9
  182. package/src/App/renderer/pluginWrapper.js +10 -8
  183. package/src/App/renderer/pluginWrapper.test.js +23 -9
  184. package/src/App/renderer/slotAggregator.js +18 -5
  185. package/src/App/renderer/slotAggregator.test.js +68 -25
  186. package/src/App/renderer/slotHelpers.js +13 -0
  187. package/src/App/renderer/slotHelpers.test.js +16 -1
  188. package/src/App/store/AppProvider.jsx +19 -1
  189. package/src/App/store/AppProvider.test.jsx +41 -0
  190. package/src/App/store/appActionsMap.js +10 -1
  191. package/src/App/store/appActionsMap.test.js +21 -0
  192. package/src/App/store/appDispatchMiddleware.js +29 -17
  193. package/src/App/store/appDispatchMiddleware.test.js +31 -0
  194. package/src/InteractiveMap/parseDataProperties.js +4 -4
  195. package/src/InteractiveMap/parseDataProperties.test.js +62 -6
  196. package/src/config/events.js +4 -2
  197. package/src/scss/tools/_govuk-content.scss +4 -3
  198. package/webpack.dev.mjs +9 -3
  199. package/webpack.prod.mjs +11 -4
  200. package/webpack.umd.mjs +6 -7
  201. package/plugins/beta/draw-es/dist/esm/index.js +0 -1
  202. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +0 -1
  203. package/plugins/beta/draw-ml/dist/esm/index.js +0 -1
  204. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +0 -1
  205. package/plugins/beta/draw-ml/dist/umd/index.js +0 -2
  206. package/plugins/beta/draw-ml/src/DrawInit.jsx +0 -85
  207. package/plugins/beta/draw-ml/src/api/addFeature.js +0 -27
  208. package/plugins/beta/draw-ml/src/api/deleteFeature.js +0 -13
  209. package/plugins/beta/draw-ml/src/api/editFeature.js +0 -75
  210. package/plugins/beta/draw-ml/src/api/merge.js +0 -9
  211. package/plugins/beta/draw-ml/src/api/newLine.js +0 -68
  212. package/plugins/beta/draw-ml/src/api/newPolygon.js +0 -68
  213. package/plugins/beta/draw-ml/src/api/split.js +0 -81
  214. package/plugins/beta/draw-ml/src/defaults.js +0 -17
  215. package/plugins/beta/draw-ml/src/draw.scss +0 -26
  216. package/plugins/beta/draw-ml/src/events.js +0 -185
  217. package/plugins/beta/draw-ml/src/index.js +0 -13
  218. package/plugins/beta/draw-ml/src/manifest.js +0 -110
  219. package/plugins/beta/draw-ml/src/mapboxDraw.js +0 -143
  220. package/plugins/beta/draw-ml/src/mapboxSnap.js +0 -321
  221. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +0 -552
  222. package/plugins/beta/draw-ml/src/modes/disabledMode.js +0 -23
  223. package/plugins/beta/draw-ml/src/modes/drawLineMode.js +0 -18
  224. package/plugins/beta/draw-ml/src/modes/drawPolygonMode.js +0 -16
  225. package/plugins/beta/draw-ml/src/modes/editVertex/geometryHelpers.js +0 -135
  226. package/plugins/beta/draw-ml/src/modes/editVertex/helpers.js +0 -2
  227. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +0 -142
  228. package/plugins/beta/draw-ml/src/modes/editVertex/undoHandlers.js +0 -133
  229. package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +0 -142
  230. package/plugins/beta/draw-ml/src/modes/editVertex/vertexQueries.js +0 -121
  231. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +0 -495
  232. package/plugins/beta/draw-ml/src/reducer.js +0 -90
  233. package/plugins/beta/draw-ml/src/styles.js +0 -190
  234. package/plugins/beta/draw-ml/src/undoStack.js +0 -50
  235. package/plugins/beta/draw-ml/src/utils/debounce.js +0 -16
  236. package/plugins/beta/draw-ml/src/utils/flattenStyleProperties.js +0 -49
  237. package/plugins/beta/draw-ml/src/utils/snapHelpers.js +0 -200
  238. package/plugins/beta/draw-ml/src/utils/spatial.js +0 -258
  239. package/plugins/beta/draw-ol/dist/css/index.css +0 -1
  240. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +0 -1
  241. package/plugins/beta/draw-ol/dist/esm/EditMode.js +0 -1
  242. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +0 -1
  243. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +0 -1
  244. package/plugins/beta/draw-ol/dist/esm/index.js +0 -1
  245. package/plugins/beta/draw-ol/src/DrawInit.jsx +0 -65
  246. package/plugins/beta/draw-ol/src/api/addFeature.js +0 -29
  247. package/plugins/beta/draw-ol/src/api/deleteFeature.js +0 -11
  248. package/plugins/beta/draw-ol/src/api/editFeature.js +0 -50
  249. package/plugins/beta/draw-ol/src/api/newLine.js +0 -44
  250. package/plugins/beta/draw-ol/src/api/newPolygon.js +0 -44
  251. package/plugins/beta/draw-ol/src/core/OLDrawManager.js +0 -153
  252. package/plugins/beta/draw-ol/src/core/featureStore.js +0 -65
  253. package/plugins/beta/draw-ol/src/core/styles.js +0 -98
  254. package/plugins/beta/draw-ol/src/core/undoStack.js +0 -31
  255. package/plugins/beta/draw-ol/src/defaults.js +0 -16
  256. package/plugins/beta/draw-ol/src/draw/DrawMode.js +0 -121
  257. package/plugins/beta/draw-ol/src/draw/drawInput.js +0 -243
  258. package/plugins/beta/draw-ol/src/draw.scss +0 -17
  259. package/plugins/beta/draw-ol/src/edit/EditMode.js +0 -424
  260. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +0 -229
  261. package/plugins/beta/draw-ol/src/edit/midpointLayer.js +0 -57
  262. package/plugins/beta/draw-ol/src/edit/touchHandler.js +0 -171
  263. package/plugins/beta/draw-ol/src/edit/undoOps.js +0 -95
  264. package/plugins/beta/draw-ol/src/edit/vertexHitTest.js +0 -72
  265. package/plugins/beta/draw-ol/src/edit/vertexLayer.js +0 -49
  266. package/plugins/beta/draw-ol/src/edit/vertexOps.js +0 -99
  267. package/plugins/beta/draw-ol/src/events.js +0 -114
  268. package/plugins/beta/draw-ol/src/index.js +0 -12
  269. package/plugins/beta/draw-ol/src/manifest.js +0 -125
  270. package/plugins/beta/draw-ol/src/olDraw.js +0 -38
  271. package/plugins/beta/draw-ol/src/reducer.js +0 -41
  272. package/plugins/beta/draw-ol/src/snap/snapEngine.js +0 -153
  273. package/plugins/beta/draw-ol/src/snap/snapGeometry.js +0 -177
  274. package/plugins/beta/draw-ol/src/snap/snapIndicator.js +0 -81
  275. package/plugins/beta/draw-ol/src/snap/snapInteraction.js +0 -57
  276. package/plugins/beta/draw-ol/src/snap/snapManager.js +0 -99
  277. package/plugins/beta/draw-ol/src/utils/flattenStyleProperties.js +0 -47
  278. package/plugins/beta/draw-ol/src/utils/geometryHelpers.js +0 -103
  279. package/plugins/beta/draw-ol/src/utils/olCoords.js +0 -35
  280. package/plugins/beta/draw-ol/src/utils/resolveColors.js +0 -39
  281. package/plugins/beta/draw-ol/src/utils/spatial.js +0 -24
  282. package/plugins/beta/draw-ol/src/utils/touchTarget.js +0 -61
  283. package/plugins/beta/frame/dist/esm/index.js +0 -1
  284. package/plugins/beta/map-styles/dist/esm/index.js +0 -1
  285. package/plugins/beta/scale-bar/dist/esm/index.js +0 -1
  286. package/plugins/beta/use-location/dist/esm/index.js +0 -1
  287. package/plugins/map-key/src/registry/getDatasetRegistry.js +0 -6
  288. package/plugins/map-key/src/registry/getDatasetRegistry.test.js +0 -23
  289. package/plugins/map-key/src/registry/index.js +0 -1
  290. package/plugins/map-key/src/registry/index.test.js +0 -7
  291. package/providers/beta/esri/dist/esm/index.js +0 -1
  292. package/providers/beta/open-names/dist/esm/index.js +0 -1
  293. package/providers/beta/openlayers/dist/esm/index.js +0 -1
  294. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +0 -2
  295. package/providers/beta/openlayers/dist/umd/index.js.LICENSE.txt +0 -1
  296. /package/plugins/{beta/draw-es → draw-es}/dist/esm/im-draw-es-plugin.js +0 -0
  297. /package/plugins/{beta/draw-es → draw-es}/src/api/addFeature.js +0 -0
  298. /package/plugins/{beta/draw-es → draw-es}/src/api/deleteFeature.js +0 -0
  299. /package/plugins/{beta/draw-es → draw-es}/src/api/editFeature.js +0 -0
  300. /package/plugins/{beta/draw-es → draw-es}/src/api/newPolygon.js +0 -0
  301. /package/plugins/{beta/draw-es → draw-es}/src/api/removeSafeZone.js +0 -0
  302. /package/plugins/{beta/draw-es → draw-es}/src/events.js +0 -0
  303. /package/plugins/{beta/draw-es → draw-es}/src/index.js +0 -0
  304. /package/plugins/{beta/draw-es → draw-es}/src/manifest.js +0 -0
  305. /package/plugins/{beta/draw-es → draw-es}/src/reducer.js +0 -0
  306. /package/plugins/{beta/draw-es → draw-es}/src/sketchViewModel.js +0 -0
  307. /package/plugins/{beta/frame → frame}/dist/css/index.css +0 -0
  308. /package/plugins/{beta/frame → frame}/dist/esm/im-frame-plugin.js +0 -0
  309. /package/plugins/{beta/draw-ml → frame}/dist/umd/index.js.LICENSE.txt +0 -0
  310. /package/plugins/{beta/frame → frame}/src/Frame.jsx +0 -0
  311. /package/plugins/{beta/frame → frame}/src/FrameInit.jsx +0 -0
  312. /package/plugins/{beta/frame → frame}/src/api/addFrame.js +0 -0
  313. /package/plugins/{beta/frame → frame}/src/api/editFeature.js +0 -0
  314. /package/plugins/{beta/frame → frame}/src/config.js +0 -0
  315. /package/plugins/{beta/frame → frame}/src/frame.scss +0 -0
  316. /package/plugins/{beta/frame → frame}/src/index.js +0 -0
  317. /package/plugins/{beta/frame → frame}/src/manifest.js +0 -0
  318. /package/plugins/{beta/frame → frame}/src/reducer.js +0 -0
  319. /package/plugins/{beta/frame → frame}/src/utils.js +0 -0
  320. /package/plugins/{beta/map-styles → map-styles}/dist/css/index.css +0 -0
  321. /package/plugins/{beta/map-styles → map-styles}/dist/esm/im-map-styles-plugin.js +0 -0
  322. /package/plugins/{beta/frame → map-styles}/dist/umd/index.js.LICENSE.txt +0 -0
  323. /package/plugins/{beta/map-styles → map-styles}/src/config.js +0 -0
  324. /package/plugins/{beta/map-styles → map-styles}/src/index.js +0 -0
  325. /package/plugins/{beta/map-styles → map-styles}/src/manifest.js +0 -0
  326. /package/plugins/{beta/map-styles → map-styles}/src/mapStyles.scss +0 -0
  327. /package/plugins/{beta/scale-bar → scale-bar}/dist/css/index.css +0 -0
  328. /package/plugins/{beta/scale-bar → scale-bar}/dist/esm/im-scale-bar-plugin.js +0 -0
  329. /package/plugins/{beta/map-styles → scale-bar}/dist/umd/index.js.LICENSE.txt +0 -0
  330. /package/plugins/{beta/scale-bar → scale-bar}/src/ScaleBar.jsx +0 -0
  331. /package/plugins/{beta/scale-bar → scale-bar}/src/ScaleBar.test.jsx +0 -0
  332. /package/plugins/{beta/scale-bar → scale-bar}/src/index.js +0 -0
  333. /package/plugins/{beta/scale-bar → scale-bar}/src/index.test.js +0 -0
  334. /package/plugins/{beta/scale-bar → scale-bar}/src/manifest.js +0 -0
  335. /package/plugins/{beta/scale-bar → scale-bar}/src/scaleBar.scss +0 -0
  336. /package/plugins/{beta/scale-bar → scale-bar}/src/utils.js +0 -0
  337. /package/plugins/{beta/scale-bar → scale-bar}/src/utils.test.js +0 -0
  338. /package/plugins/{beta/use-location → use-location}/dist/esm/im-use-location-plugin.js +0 -0
  339. /package/plugins/{beta/scale-bar → use-location}/dist/umd/index.js.LICENSE.txt +0 -0
  340. /package/plugins/{beta/use-location → use-location}/src/UseLocation.jsx +0 -0
  341. /package/plugins/{beta/use-location → use-location}/src/UseLocationInit.jsx +0 -0
  342. /package/plugins/{beta/use-location → use-location}/src/defaults.js +0 -0
  343. /package/plugins/{beta/use-location → use-location}/src/events.js +0 -0
  344. /package/plugins/{beta/use-location → use-location}/src/index.js +0 -0
  345. /package/plugins/{beta/use-location → use-location}/src/manifest.js +0 -0
  346. /package/plugins/{beta/use-location → use-location}/src/reducer.js +0 -0
  347. /package/providers/{beta/esri → esri}/dist/css/index.css +0 -0
  348. /package/providers/{beta/esri → esri}/dist/esm/im-esri-provider.js +0 -0
  349. /package/providers/{beta/esri → esri}/src/appEvents.js +0 -0
  350. /package/providers/{beta/esri → esri}/src/defaults.js +0 -0
  351. /package/providers/{beta/esri → esri}/src/esriProvider.scss +0 -0
  352. /package/providers/{beta/esri → esri}/src/index.js +0 -0
  353. /package/providers/{beta/esri → esri}/src/utils/coords.js +0 -0
  354. /package/providers/{beta/esri → esri}/src/utils/coords.test.js +0 -0
  355. /package/providers/{beta/esri → esri}/src/utils/detectWebGL.js +0 -0
  356. /package/providers/{beta/esri → esri}/src/utils/esriFixes.js +0 -0
  357. /package/providers/{beta/esri → esri}/src/utils/query.js +0 -0
  358. /package/providers/{beta/esri → esri}/src/utils/spatial.js +0 -0
  359. /package/providers/{beta/esri → esri}/src/utils/spatial.test.js +0 -0
  360. /package/providers/{beta/open-names → open-names}/dist/esm/im-reverse-geocode.js +0 -0
  361. /package/providers/{beta/open-names → open-names}/dist/umd/im-reverse-geocode.js.LICENSE.txt +0 -0
  362. /package/{plugins/beta/use-location → providers/open-names}/dist/umd/index.js.LICENSE.txt +0 -0
  363. /package/providers/{beta/open-names → open-names}/src/index.js +0 -0
  364. /package/providers/{beta/open-names → open-names}/src/reverseGeocode.js +0 -0
  365. /package/providers/{beta/open-names → open-names}/src/utils/mapToLocationModel.js +0 -0
  366. /package/providers/{beta/open-names → open-names}/src/utils/mapToLocationModel.test.js +0 -0
  367. /package/providers/{beta/openlayers → openlayers}/dist/esm/im-openlayers-provider.js +0 -0
  368. /package/providers/{beta/openlayers → openlayers}/dist/umd/im-openlayers-provider.js.LICENSE.txt +0 -0
  369. /package/providers/{beta/open-names → openlayers}/dist/umd/index.js.LICENSE.txt +0 -0
  370. /package/providers/{beta/openlayers → openlayers}/src/appEvents.js +0 -0
  371. /package/providers/{beta/openlayers → openlayers}/src/appEvents.test.js +0 -0
  372. /package/providers/{beta/openlayers → openlayers}/src/defaults.js +0 -0
  373. /package/providers/{beta/openlayers → openlayers}/src/index.test.js +0 -0
  374. /package/providers/{beta/openlayers → openlayers}/src/openlayersProvider.test.js +0 -0
  375. /package/providers/{beta/openlayers → openlayers}/src/utils/bngProjection.js +0 -0
  376. /package/providers/{beta/openlayers → openlayers}/src/utils/filterEvaluator.js +0 -0
  377. /package/providers/{beta/openlayers → openlayers}/src/utils/filterEvaluator.test.js +0 -0
  378. /package/providers/{beta/openlayers → openlayers}/src/utils/highlightFeatures.test.js +0 -0
  379. /package/providers/{beta/openlayers → openlayers}/src/utils/hoverCursor.js +0 -0
  380. /package/providers/{beta/openlayers → openlayers}/src/utils/hoverCursor.test.js +0 -0
  381. /package/providers/{beta/openlayers → openlayers}/src/utils/openLayersFixes.js +0 -0
  382. /package/providers/{beta/openlayers → openlayers}/src/utils/openLayersFixes.test.js +0 -0
  383. /package/providers/{beta/openlayers → openlayers}/src/utils/patternImages.test.js +0 -0
  384. /package/providers/{beta/openlayers → openlayers}/src/utils/queryFeatures.js +0 -0
  385. /package/providers/{beta/openlayers → openlayers}/src/utils/queryFeatures.test.js +0 -0
  386. /package/providers/{beta/openlayers → openlayers}/src/utils/spatial.js +0 -0
  387. /package/providers/{beta/openlayers → openlayers}/src/utils/spatial.test.js +0 -0
  388. /package/providers/{beta/openlayers → openlayers}/src/utils/symbolImages.test.js +0 -0
  389. /package/providers/{beta/openlayers → openlayers}/src/utils/tileLayers.js +0 -0
  390. /package/providers/{beta/openlayers → openlayers}/src/utils/tileLayers.test.js +0 -0
  391. /package/providers/{beta/openlayers → openlayers}/src/utils/vtTileFragments.js +0 -0
  392. /package/providers/{beta/openlayers → openlayers}/src/utils/vtTileFragments.test.js +0 -0
  393. /package/providers/{beta/openlayers → openlayers}/src/utils/zoom.js +0 -0
  394. /package/providers/{beta/openlayers → openlayers}/src/utils/zoom.test.js +0 -0
@@ -1,258 +0,0 @@
1
- import polygonSplitter from 'polygon-splitter'
2
- import turfBearing from '@turf/bearing'
3
- import turfDestination from '@turf/destination'
4
- import turfBooleanValid from '@turf/boolean-valid'
5
- import turfArea from '@turf/area'
6
- import {
7
- featureCollection as turfFeatureCollection,
8
- polygon as turfPolygon,
9
- multiPolygon as turfMultiPolygon,
10
- lineString as turfLineString,
11
- multiLineString as turfMultiLineString,
12
- point as turfPoint,
13
- multiPoint as turfMultiPoint
14
- } from '@turf/helpers'
15
-
16
- /**
17
- * @typedef {import('geojson').Feature<import('geojson').Polygon>} Polygon
18
- * @typedef {import('geojson').Feature<import('geojson').LineString>} Line
19
- * @typedef {import('geojson').Feature<import('geojson').Feature>} Feature
20
- * @typedef {import('geojson').FeatureCollection<import('geojson').FeatureCollection>} FeatureCollection
21
- */
22
-
23
- /**
24
- * Extend a LineString at endpoints AND intermediate vertices.
25
- * For intermediate vertices on the polygon boundary, this creates small
26
- * extensions that ensure polygon-splitter recognizes them as crossing points.
27
- *
28
- * @param {Feature<LineString>} line
29
- * @param {number} extendDist (distance to extend in Turf units)
30
- */
31
- function extendLine (line, extendDist = 1, units = 'meters') {
32
- const coords = line.geometry.coordinates
33
- const result = []
34
-
35
- // Extend start point backward
36
- const startBearing = turfBearing(coords[1], coords[0])
37
- const newStart = turfDestination(coords[0], extendDist, startBearing, { units })
38
- result.push(newStart.geometry.coordinates)
39
-
40
- // Process each vertex
41
- for (let i = 0; i < coords.length; i++) {
42
- if (i > 0 && i < coords.length - 1) {
43
- // Intermediate vertex: add extension past it (creates spike for boundary crossing)
44
- const incomingBearing = turfBearing(coords[i - 1], coords[i])
45
- const pastPt = turfDestination(coords[i], extendDist, incomingBearing, { units })
46
- result.push(pastPt.geometry.coordinates)
47
- }
48
-
49
- result.push(coords[i])
50
- }
51
-
52
- // Extend end point forward
53
- const endBearing = turfBearing(coords[coords.length - 2], coords[coords.length - 1])
54
- const newEnd = turfDestination(coords[coords.length - 1], extendDist, endBearing, { units })
55
- result.push(newEnd.geometry.coordinates)
56
-
57
- return turfLineString(result)
58
- }
59
-
60
- /**
61
- * Split a polygon using a line.
62
- * Only accepts splits that result in exactly two polygons.
63
- *
64
- * @param {Feature<Polygon>} polygon
65
- * @param {Feature<LineString>} line
66
- * @returns {FeatureCollection<Polygon>|null}
67
- */
68
- const splitPolygon = (polygon, line) => {
69
- // Extend only start and end vertices
70
- const extended = extendLine(line) // assume extendLine only touches start/end now
71
-
72
- let result
73
- try {
74
- result = polygonSplitter(polygon, extended)
75
- } catch {
76
- return null
77
- }
78
-
79
- // Must result in exactly 2 polygons
80
- let polygons = []
81
- if (result.geometry.type === 'MultiPolygon') {
82
- if (result.geometry.coordinates.length !== 2) {
83
- return null
84
- }
85
- polygons = result.geometry.coordinates.map(coords => turfPolygon(coords, polygon.properties))
86
- } else {
87
- return null
88
- }
89
-
90
- // Assign IDs & properties
91
- const baseId = polygon.id ?? polygon.properties?.id ?? 'poly'
92
- const features = polygons.map((poly, i) =>
93
- turfPolygon(
94
- poly.geometry.coordinates,
95
- { ...polygon.properties, id: baseId },
96
- { id: `${baseId}-${i + 1}` }
97
- )
98
- )
99
-
100
- return turfFeatureCollection(features)
101
- }
102
-
103
- /**
104
- * Convert a GeoJSON Feature or geometry-like object into a Turf geometry.
105
- *
106
- * @param {Object} featureOrGeom - Either a Feature with a `.geometry` property or a raw GeoJSON geometry object.
107
- * @returns {Object} Turf geometry (Polygon, LineString, Point, etc.)
108
- *
109
- * @throws Will throw if the geometry type is not supported.
110
- */
111
- const toTurfGeometry = (featureOrGeom) => {
112
- const geom = featureOrGeom.geometry || featureOrGeom
113
-
114
- switch (geom.type) {
115
- case 'Polygon':
116
- return turfPolygon(geom.coordinates)
117
- case 'MultiPolygon':
118
- return turfMultiPolygon(geom.coordinates)
119
- case 'LineString':
120
- return turfLineString(geom.coordinates)
121
- case 'MultiLineString':
122
- return turfMultiLineString(geom.coordinates)
123
- case 'Point':
124
- return turfPoint(geom.coordinates)
125
- case 'MultiPoint':
126
- return turfMultiPoint(geom.coordinates)
127
- default:
128
- throw new Error(`Unsupported geometry type: ${geom.type}`)
129
- }
130
- }
131
-
132
- const haversine = ([lon1, lat1], [lon2, lat2]) => {
133
- const toRad = deg => deg * Math.PI / 180
134
- const R = 6371000 // meters
135
- const dLat = toRad(lat2 - lat1)
136
- const dLon = toRad(lon2 - lon1)
137
- const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2
138
- return 2 * R * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
139
- }
140
-
141
- const isNewCoordinate = (coords, tolerance = 0.01) => {
142
- // First coord
143
- if (coords[0].length <= 1) {
144
- return true
145
- }
146
- // Subsequent coordsmust be different
147
- if (coords[0].length <= 3) {
148
- for (let i = 0; i < coords[0].length; i++) {
149
- for (let j = i + 1; j < coords[0].length; j++) {
150
- if (haversine(coords[0][i], coords[0][j]) < tolerance) {
151
- return false
152
- }
153
- }
154
- }
155
- }
156
- return true
157
- }
158
-
159
- const isNewLineCoordinate = (coords, tolerance = 0.01) => {
160
- // First coord is always valid
161
- if (coords.length <= 1) {
162
- return true
163
- }
164
- // Check last two coords are different
165
- if (coords.length >= 2) {
166
- const last = coords[coords.length - 1]
167
- const secondLast = coords[coords.length - 2]
168
- if (haversine(last, secondLast) < tolerance) {
169
- return false
170
- }
171
- }
172
- return true
173
- }
174
-
175
- const isValidLineClick = (coords) => {
176
- // First coord is always valid
177
- if (coords.length <= 1) {
178
- return true
179
- }
180
- // Check that the new coordinate is different from the previous one
181
- return isNewLineCoordinate(coords)
182
- }
183
-
184
- const isValidClick = (coords) => {
185
- // Less than 4 and new coordinates
186
- if (coords[0].length <= 1 || isNewCoordinate(coords)) {
187
- return true
188
- }
189
-
190
- // Basic checks
191
- if (!Array.isArray(coords) || coords.length < 4) {
192
- return false
193
- }
194
-
195
- // Check if ring is closed
196
- const first = coords[0]
197
- const last = coords[coords.length - 1]
198
- const isClosed = first[0] === last[0] && first[1] === last[1]
199
- if (!isClosed) {
200
- return false
201
- }
202
-
203
- // Create a turf polygon
204
- const turfPoly = turfPolygon([coords])
205
-
206
- // Check if geometry is valid (non-self-intersecting)
207
- const valid = turfBooleanValid(turfPoly)
208
- if (!valid) {
209
- return false
210
- }
211
-
212
- // Check if area is positive
213
- const polyArea = turfArea(turfPoly)
214
- if (polyArea <= 0) {
215
- return false
216
- }
217
-
218
- return true
219
- }
220
-
221
- const spatialNavigate = (start, pixels, direction) => {
222
- const quadrant = pixels.filter((p, i) => {
223
- const offsetX = Math.abs(p[0] - start[0])
224
- const offsetY = Math.abs(p[1] - start[1])
225
- let isQuadrant = false
226
- if (direction === 'ArrowUp') {
227
- isQuadrant = p[1] <= start[1] && offsetY >= offsetX
228
- } else if (direction === 'ArrowDown') {
229
- isQuadrant = p[1] > start[1] && offsetY >= offsetX
230
- } else if (direction === 'ArrowLeft') {
231
- isQuadrant = p[0] <= start[0] && offsetY < offsetX
232
- } else if (direction === 'ArrowRight') {
233
- isQuadrant = p[0] > start[0] && offsetY < offsetX
234
- } else {
235
- isQuadrant = true
236
- }
237
- return isQuadrant && (JSON.stringify(p) !== JSON.stringify(start))
238
- })
239
-
240
- if (!quadrant.length) {
241
- quadrant.push(start)
242
- }
243
-
244
- const pythagorean = (a, b) => Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2))
245
- const distances = quadrant.map(p => pythagorean(Math.abs(start[0] - p[0]), Math.abs(start[1] - p[1])))
246
- const closest = quadrant[distances.indexOf(Math.min(...distances))]
247
- return pixels.findIndex(i => JSON.stringify(i) === JSON.stringify(closest))
248
- }
249
-
250
- export {
251
- toTurfGeometry,
252
- splitPolygon,
253
- extendLine,
254
- isNewCoordinate,
255
- isValidClick,
256
- isValidLineClick,
257
- spatialNavigate
258
- }
@@ -1 +0,0 @@
1
- .im-draw-touch-target{color:#3b82f6;cursor:grab;filter:drop-shadow(0 2px 4px rgba(0,0,0,.15))}.im-draw-touch-target:active{cursor:grabbing}.im-draw-button:focus-visible{outline:2px solid #3b82f6;outline-offset:2px}
@@ -1 +0,0 @@
1
- import e from"ol/interaction/Draw.js";import{noModifierKeys as t}from"ol/events/condition.js";import{c as n,p as o,g as r}from"./geometryHelpers.js";const a=4,i=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),s=({drawInteraction:e,options:t})=>{const{container:r,addVertexButtonId:s,mapProvider:d,snap:l,onUndo:c,canFinish:g}=t;let u=t.interfaceType??"mouse",p=null,y=null;e.on("drawstart",e=>{p=e.feature,y=null}),e.on("drawend",()=>{p=null,y=null}),e.on("drawabort",()=>{p=null,y=null});const m=()=>{if(!p)return void("mouse"!==u&&l&&l.apply(d.getCenter()));const e=p.getGeometry();if(!e.getCoordinates().length)return;const t=d.getCenter();((e,t)=>{if("LineString"===e.getType()){const n=[...e.getCoordinates()];n[n.length-1]=t,e.setCoordinates(n)}else if("Polygon"===e.getType()){const n=e.getCoordinates().map((e,n)=>{if(0!==n)return e;const o=[...e];return o[o.length-1]=t,o});e.setCoordinates(n)}})(e,"mouse"!==u&&l?l.apply(t):t)},f=(t,r,i)=>{if(y&&y[0]===i[0]&&y[1]===i[1])return g?.()&&e.finishDrawing(),y=null,!0;if(((e,t,r,i)=>{if("Polygon"!==i||r.length<a)return!1;const s=r[0],d=n(e,t),l=n(e,s);return!(!d||!l)&&o(d,l)<12})(e.getMap(),i,r,t.getType()))return e.finishDrawing(),!0;const s=e.getMap(),d=(e=>{if("Polygon"===e.getType()){const t=e.getCoordinates()[0]||[];return t.length>=3?t[t.length-3]:null}const t=e.getCoordinates();return t.length>=2?t[t.length-2]:null})(t);if(d){const e=s.getPixelFromCoordinate(d),t=s.getPixelFromCoordinate(i);if(e&&t){const n=e[0]-t[0],o=e[1]-t[1];if(n*n+o*o<4)return y=i,!0}}return!1},h=e.getMap(),v=h?.getView(),w=(({container:e,addVertexButtonId:t,olView:n,onUndo:o,getInterfaceType:r,setInterfaceType:a,clearLastCoord:s,updateRubberbanding:d,placeVertex:l})=>{const c=()=>{"mouse"!==r()&&d()};n?.on("change:center",c);const g=t=>{e.contains(document.activeElement)&&(i.has(t.key)?a("keyboard"):("Enter"===t.key&&(t.preventDefault(),a("keyboard"),l()),"z"===t.key&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),o?.())))},u=e=>{t&&e.target.closest(`#${t}`)&&l()},p=e=>{"touch"!==e.pointerType&&(a("mouse"),s())},y=()=>{a("touch")},m=()=>{"mouse"!==r()&&d()};return globalThis.addEventListener("keydown",g),globalThis.addEventListener("click",u),e.addEventListener("pointerdown",p),e.addEventListener("touchstart",y,{passive:!0}),e.addEventListener("pointermove",m),{destroy(){n?.un("change:center",c),globalThis.removeEventListener("keydown",g),globalThis.removeEventListener("click",u),e.removeEventListener("pointerdown",p),e.removeEventListener("touchstart",y),e.removeEventListener("pointermove",m)}}})({container:r,addVertexButtonId:s,olView:v,onUndo:c,getInterfaceType:()=>u,setInterfaceType:e=>{u=e},clearLastCoord:()=>{y=null},updateRubberbanding:m,placeVertex:()=>{const t=d.getCenter(),n="mouse"!==u&&l?l.apply(t):t;if(l?.hideIndicator(),p){const e=p.getGeometry(),t=e.getCoordinates(),o="Polygon"===e.getType()?t[0]||[]:t;if(f(e,o,n))return}e.appendCoordinates([n]),y=n}}),C=()=>{"mouse"!==u&&v?.getAnimating()&&m()};return h?.on("postrender",C),{getInterfaceType:()=>u,destroy(){w.destroy(),h?.un("postrender",C)}}},d={Polygon:3,LineString:2},l=(e,t)=>{if(!t)return!1;const n=t.getGeometry();return r({type:e,coordinates:n.getCoordinates()}).length-1>=d[e]},c=(e,n,o)=>r=>{if(!t(r))return!1;const a=o();if(!a||l(n,a))return!0;const i=(e=>{if("Polygon"===e.getType()){const t=e.getCoordinates()[0]||[];return t.length>=3?t[t.length-3]:null}const t=e.getCoordinates();return t.length>=2?t[t.length-2]:null})(a.getGeometry());if(!i)return!0;const s=e.getPixelFromCoordinate(i);if(!s)return!0;const d=r.pixel[0]-s[0],c=r.pixel[1]-s[1];return d*d+c*c>4},g=({map:t,manager:n,options:o})=>{const{geometryType:a,featureId:i,properties:d={},container:g,interfaceType:u,addVertexButtonId:p,mapProvider:y,snap:m}=o;let f=null;const h=new e({type:a,style:n.styles.createSketchStyle(),stopClick:!0,snapTolerance:12,condition:c(t,a,()=>f)});t.addInteraction(h),h.overlay_.updateWhileAnimating_=!0;const v=()=>{if(!f)return;const e=f.getGeometry(),t=r({type:a,coordinates:e.getCoordinates()});n.emit("vertexchange",{numVertices:Math.max(0,t.length-1)})};h.on("drawstart",e=>{f=e.feature,f.getGeometry().on("change",v)}),h.on("drawend",e=>{const t=e.feature;t.setId(String(i)),t.setProperties(d),n.store.source.addFeature(t),n.emit("create",n.store.toGeoJSON(t))}),h.on("drawabort",()=>{n.emit("cancel")});const w=s({drawInteraction:h,options:{container:g,interfaceType:u,addVertexButtonId:p,mapProvider:y,snap:m,onUndo:()=>{h.removeLastPoint(),v()},canFinish:()=>l(a,f)}});return{done(){l(a,f)&&h.finishDrawing()},cancel(){h.abortDrawing()},undo(){h.removeLastPoint(),v()},destroy(){w.destroy(),t.removeInteraction(h),f=null}}};export{g as createDrawMode};
@@ -1 +0,0 @@
1
- import e from"ol/interaction/Modify.js";import t from"ol/Collection.js";import n from"ol/source/Vector.js";import r from"ol/layer/Vector.js";import o from"ol/Feature.js";import s from"ol/geom/Point.js";import{a as d,g as i,b as l,d as c,e as a,c as p,p as x,f as u,n as y}from"./geometryHelpers.js";const v=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},g=(e,t)=>{t&&e&&(e.style.left=`${t.x}px`,e.style.top=`${t.y}px`,e.style.display="block")},m=e=>{e&&(e.style.display="none")},f=e=>{if(!e)return!1;const t=e.parentNode;return t instanceof globalThis.SVGElement||null!=t?.ownerSVGElement},h=(e,t,n,r)=>{const o=n-r,s=t[o];if(!s)return null;const d=e.getGeometry(),i={type:d.getType(),coordinates:d.getCoordinates()},c=l(i);let p=0;for(const e of c){const t=e.closed?e.length:e.length-1;if(o<p+t){const t=o-p+1,n=e.start+t;return a(i,e.path).splice(t,0,[...s]),d.setCoordinates(i.coordinates),{insertedIndex:n}}p+=t}return null},I=(e,t,n)=>{const r=e.getGeometry(),o={type:r.getType(),coordinates:r.getCoordinates()},s=l(o),d=c(s,t);if(!d)return;const i=a(o,d.segment.path);i[d.localIdx]=[...n],d.segment.closed&&0===d.localIdx&&(i[i.length-1]=[...n]),r.setCoordinates(o.coordinates)},T=(e,t,n,r,o=12)=>((e,t,n,r=12)=>{let o=-1,s=r;return t.forEach((t,r)=>{const d=p(e,t);if(!d)return;const i=x(d,n);i<s&&(s=i,o=r)}),o>=0?{index:o,type:"vertex"}:null})(e,t,r,o)??((e,t,n,r,o=12)=>{let s=-1,d=o;return t.forEach((t,r)=>{const o=p(e,t);if(!o)return;const i=x(o,n);i<d&&(d=i,s=r)}),s>=0?{index:r+s,type:"midpoint"}:null})(e,n,r,t.length,o),V=({map:e,container:t,getState:n,setState:r,onVertexMoved:o,onTap:s,colors:d,snap:i})=>{const l=(e=>{let t=e.querySelector("[data-im-draw-touch-target]");return t||(e.insertAdjacentHTML("beforeend","\n <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:24px 0 0 -24px;cursor:grab'\n class='im-draw-touch-target' data-im-draw-touch-target>\n <circle cx='24' cy='24' r='24' fill='var(--draw-halo, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--draw-bg, #fff)'/>\n </svg>\n"),t=e.querySelector("[data-im-draw-touch-target]")),t})(t);v(l,d);const c={scale:1,ox:0,oy:0},a=e=>({x:e.x*c.scale+c.ox,y:e.y*c.scale+c.oy}),x=()=>{const n=e.getViewport(),r=n.getBoundingClientRect(),o=t.getBoundingClientRect(),s=n.offsetWidth>0?r.width/n.offsetWidth:1,d=t.offsetWidth>0?o.width/t.offsetWidth:1;Object.assign(c,{scale:s/d,ox:(r.left-o.left)/d,oy:(r.top-o.top)/d})},y=(({container:e,map:t,targetEl:n,olToCSS:r,cssToOl:o,getState:s,setState:d,onVertexMoved:i,onTap:l,snap:c})=>{let a=null,x=null,y=null,v=null,m=null;const h=e=>{const r=e.touches[0],d=f(e.target);if(m={x:r.clientX,y:r.clientY,time:Date.now(),onTarget:d},!d)return;const{selectedVertexIndex:i,vertices:l}=s(),c=l[i];if(!c)return;const u=t.getEventPixel({clientX:r.clientX,clientY:r.clientY}),g=p(t,c),h=getComputedStyle(n),I=o({x:Number.parseFloat(h.left),y:Number.parseFloat(h.top)});a=[...c],x=i,y={x:u[0]-g.x,y:u[1]-g.y},v={x:u[0]-I.x,y:u[1]-I.y},e.preventDefault()},V=e=>{if(!f(e.target)||null==x)return;e.preventDefault();const o=t.getEventPixel({clientX:e.touches[0].clientX,clientY:e.touches[0].clientY}),i=u(t,{x:o[0]-y.x,y:o[1]-y.y}),l=c?c.apply(i):i;c?.hideIndicator();const{olFeature:a,vertices:p}=s();a&&(I(a,x,l),d({vertices:p.map((e,t)=>t===x?l:e)}),g(n,r({x:o[0]-v.x,y:o[1]-v.y})))},w=e=>{if(null==x){if(m&&!m.onTarget&&e.changedTouches.length>0){const n=e.changedTouches[0],r=Date.now()-m.time;if(Math.hypot(n.clientX-m.x,n.clientY-m.y)<10&&r<400){const r=t.getEventPixel({clientX:n.clientX,clientY:n.clientY}),o=s();l?.(T(t,o.vertices,o.midpoints,{x:r[0],y:r[1]},24)),e.preventDefault()}}return void(m=null)}m=null;const{vertices:n}=s();n[x]&&a&&i({vertexIndex:x,previousCoord:a}),c?.hideIndicator(),a=null,x=null,y=null,v=null,e.preventDefault()};return e.addEventListener("touchstart",h,{passive:!1}),e.addEventListener("touchmove",V,{passive:!1}),e.addEventListener("touchend",w,{passive:!1}),{isDragging:()=>null!=x,destroy(){e.removeEventListener("touchstart",h),e.removeEventListener("touchmove",V),e.removeEventListener("touchend",w)}}})({container:t,map:e,targetEl:l,olToCSS:a,cssToOl:e=>({x:(e.x-c.ox)/c.scale,y:(e.y-c.oy)/c.scale}),getState:n,setState:r,onVertexMoved:o,onTap:s,snap:i}),h=()=>{const{selectedVertexIndex:t,vertices:r,interfaceType:o}=n();if(t<0||!r[t]||"touch"!==o)return void m(l);const s=p(e,r[t]);s?g(l,a(s)):m(l)},V=()=>{const{selectedVertexIndex:e,interfaceType:t}=n();e>=0&&!y.isDragging()&&"touch"===t&&h()};e.on("postrender",V);const w=()=>{x(),e.once("postrender",h)};return e.on("change:size",w),x(),{updateTargetPosition:h,updateColors(e){v(l,e)},hide(){m(l)},destroy(){e.un("change:size",w),e.un("postrender",V),y.destroy(),m(l)}}},w=(e,t,n)=>{const r=t.filter(t=>{const r=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);let s=!1;return s="ArrowUp"===n?t[1]<=e[1]&&o>=r:"ArrowDown"===n?t[1]>e[1]&&o>=r:"ArrowLeft"===n?t[0]<=e[0]&&o<r:"ArrowRight"!==n||t[0]>e[0]&&o<r,s&&JSON.stringify(t)!==JSON.stringify(e)});r.length||r.push(e);const o=t=>Math.hypot(e[0]-t[0],e[1]-t[1]),s=r.reduce((e,t)=>o(t)<o(e)?t:e,r[0]);return t.findIndex(e=>JSON.stringify(e)===JSON.stringify(s))},S=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),C=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),E=({map:e,snap:t,getState:n,setState:r,onInserted:o})=>{const s={start:null,index:null};return{nudge:d=>{const{selectedVertexIndex:i,selectedVertexType:l,vertices:c,midpoints:a,olFeature:p}=n();if(!p)return;const x=d.shiftKey?1:5,u={ArrowUp:[0,-x],ArrowDown:[0,x],ArrowLeft:[-x,0],ArrowRight:[x,0]},[v,g]=u[d.key];if("midpoint"===l)return void((d,i,l,c,a,p)=>{const x=h(d,i,l,c.length);if(!x)return;o({insertedIndex:x.insertedIndex});const u=n().vertices,v=u[x.insertedIndex];if(!v)return;s.start=[...v],s.index=x.insertedIndex;const g=y(e,v,a,p),m=t?t.apply(g):g;I(d,x.insertedIndex,m),r({selectedVertexIndex:x.insertedIndex,selectedVertexType:"vertex",vertices:u.map((e,t)=>t===x.insertedIndex?m:e)})})(p,a,i,c,v,g);if(i<0||!c[i])return;const m=c[i];s.start||(s.start=[...m],s.index=i);const f=y(e,m,v,g),T=t?t.apply(f):f;t?.hideIndicator();const V=((e,t,n,r,o,s,d)=>{if(!e)return o;const i=[r[0]-n[0],r[1]-n[1]],l=[o[0]-n[0],o[1]-n[1]],c=i[0]**2+i[1]**2;if(c>0&&(l[0]*i[0]+l[1]*i[1])/c<.5){const r=e.snapRadius+1;return y(t,n,0===s?0:Math.sign(s)*r,0===d?0:Math.sign(d)*r)}return o})(t,e,m,f,T,v,g);I(p,i,V),r({vertices:c.map((e,t)=>t===i?V:e)})},keyMove:s}},L=({map:e,snap:t,getState:n,setState:r,onVertexMoved:o,onInserted:s,onDeleted:d,onUndo:i,onKeyboardActive:l})=>{const{nudge:c,keyMove:a}=E({map:e,snap:t,getState:n,setState:r,onInserted:s}),x=e.getViewport().closest('[role="application"]')??e.getViewport(),u=()=>(e=>{const t=document.activeElement;if(!t||t===document.body)return!1;if(e.contains(t))return!1;const n=t.tagName;return C.has(n)||t.isContentEditable||t.hasAttribute("tabindex")})(x),y=t=>{t.altKey?(t.preventDefault(),t.stopPropagation(),((e,t,n,r)=>{const{selectedVertexIndex:o,vertices:s,midpoints:d}=n();if(!s.length)return;const i=[...s,...d].map(e=>p(t,e)).filter(Boolean).map(e=>[e.x,e.y]),l=o>=0?i[o]:(()=>{const e=p(t,t.getView().getCenter());return e?[e.x,e.y]:null})();if(!l)return;const c=w(l,i,e);r({selectedVertexIndex:c,selectedVertexType:c<s.length?"vertex":"midpoint"})})(t.key,e,n,r)):n().selectedVertexIndex>=0&&(t.preventDefault(),t.stopPropagation(),c(t))},v=t=>{if(l?.()," "===t.key)t.preventDefault(),n().selectedVertexIndex<0&&((e,t,n)=>{const{vertices:r,midpoints:o}=t();if(!r.length)return;const s=e.getView().getCenter(),d=p(e,s);if(!d)return;const i=[...r.map(t=>p(e,t)),...o.map(t=>p(e,t))].filter(Boolean).map(e=>[e.x,e.y]),l=w([d.x,d.y],i,void 0);n({selectedVertexIndex:l,selectedVertexType:l<r.length?"vertex":"midpoint"})})(e,n,r);else if(S.has(t.key))y(t);else if("z"===t.key&&(t.metaKey||t.ctrlKey)){const e=document.activeElement?.tagName;C.has(e)||(t.preventDefault(),t.stopPropagation(),i())}},g=e=>{u()||("Escape"===e.key&&n().selectedVertexIndex>=0?(e.preventDefault(),a.start=null,a.index=null,r({selectedVertexIndex:-1,selectedVertexType:null})):v(e))},m=e=>{u()||(S.has(e.key)&&a.start&&null!=a.index&&(t?.hideIndicator(),o({vertexIndex:a.index,previousCoord:a.start}),a.start=null,a.index=null),"Delete"===e.key&&d())};return window.addEventListener("keydown",g,{capture:!0}),window.addEventListener("keyup",m,{capture:!0}),{destroy(){window.removeEventListener("keydown",g,{capture:!0}),window.removeEventListener("keyup",m,{capture:!0})}}},b=(e,t)=>{switch(t.type){case"move_vertex":return((e,t)=>{const{vertexIndex:n,previousCoord:r}=t,o=e.getGeometry(),s={type:o.getType(),coordinates:o.getCoordinates()},d=l(s),i=c(d,n);if(!i)return-1;const p=a(s,i.segment.path);return p[i.localIdx]=[...r],i.segment.closed&&0===i.localIdx&&(p[p.length-1]=[...r]),o.setCoordinates(s.coordinates),n})(e,t);case"insert_vertex":return((e,t)=>{const{vertexIndex:n}=t,r=e.getGeometry(),o={type:r.getType(),coordinates:r.getCoordinates()},s=l(o),d=c(s,n);if(!d)return-1;const i=a(o,d.segment.path);return i.splice(d.localIdx,1),d.segment.closed&&(i[i.length-1]=[...i[0]]),r.setCoordinates(o.coordinates),-1})(e,t);case"delete_vertex":return((e,t)=>{const{vertexIndex:n,deletedCoord:r}=t,o=e.getGeometry(),s={type:o.getType(),coordinates:o.getCoordinates()},d=l(s);let i=c(d,n);if(!i)for(const e of d)if(n===e.start+e.length){i={segment:e,localIdx:e.length};break}if(!i)return-1;const p=a(s,i.segment.path);return p.splice(i.localIdx,0,[...r]),i.segment.closed&&(p[p.length-1]=[...p[0]]),o.setCoordinates(s.coordinates),n})(e,t);default:return-1}},k=({map:p,manager:x,options:u})=>{const{featureId:y,container:v,interfaceType:g,deleteVertexButtonId:m,snap:f}=u,{store:I,undoStack:w}=x,S=I.getOL(y);if(!S)return null;const C=S.getStyle();S.setStyle(x.styles.editFeatureStyle);const E={olFeature:S,selectedVertexIndex:-1,selectedVertexType:null,vertices:[],midpoints:[],interfaceType:g??"mouse"},k=()=>E;let A=null,M=null;const P=e=>{if(Object.assign(E,e),void 0!==e.selectedVertexIndex&&(_.setSelected("vertex"===E.selectedVertexType?E.selectedVertexIndex:-1),j.setSelected("midpoint"===E.selectedVertexType?E.selectedVertexIndex-E.vertices.length:-1),E.selectedVertexIndex<0&&A?.(),B(),x.emit("vertexselection",{index:"vertex"===E.selectedVertexType?E.selectedVertexIndex:-1,numVertices:E.vertices.length})),void 0!==e.vertices){const e={type:S.getGeometry().getType(),coordinates:S.getGeometry().getCoordinates()};j.update(e),_.update(e),E.midpoints=j.getCoords(),B(),M?.(),p.render()}},D=()=>{const e=S.getGeometry(),t={type:e.getType(),coordinates:e.getCoordinates()};E.vertices=i(t),E.midpoints=d(t),j.update(t),_.update(t),B()},G=()=>{D(),x.emit("vertexchange",{numVertices:E.vertices.length}),x.emit("update",I.toGeoJSON(S))},z=()=>D();S.getGeometry().on("change",z);const N=new t([S]),F=new e({features:N,style:()=>[],pixelTolerance:12,condition:e=>{if("touch"===E.interfaceType)return!1;const t=p.getEventPixel(e.originalEvent);return null!==T(p,E.vertices,E.midpoints,{x:t[0],y:t[1]})}});p.addInteraction(F);let O=null;F.on("modifystart",()=>{"touch"!==E.interfaceType&&(O=E.vertices.map(e=>[...e]))}),F.on("modifyend",()=>{if("touch"===E.interfaceType)return;const e=O;if(G(),!e)return;const t=E.vertices;if(t.length>e.length){const n=t.findIndex((t,n)=>!e[n]||t[0]!==e[n][0]),r=Math.max(0,n);w.push({type:"insert_vertex",vertexIndex:r}),P({selectedVertexIndex:r,selectedVertexType:"vertex"})}else if(t.length===e.length){const n=t.findIndex((t,n)=>t[0]!==e[n][0]||t[1]!==e[n][1]);n>=0&&(w.push({type:"move_vertex",vertexIndex:n,previousCoord:e[n]}),P({selectedVertexIndex:n,selectedVertexType:"vertex"}))}O=null});const j=((e,t)=>{let i=t,l=-1;const c=new n,a=new r({source:c,style:e=>e.get("midpointIndex")===l?null:[i],zIndex:101});return e.addLayer(a),{update(e){c.clear();const t=d(e).map((e,t)=>{const n=new o({geometry:new s(e)});return n.set("midpointIndex",t),n});c.addFeatures(t)},setSelected(e){l=e,c.changed()},updateStyle(e){i=e,c.changed()},getCoords:()=>c.getFeatures().sort((e,t)=>e.get("midpointIndex")-t.get("midpointIndex")).map(e=>e.getGeometry().getCoordinates()),remove(){c.clear(),e.removeLayer(a)}}})(p,x.styles.midpointStyle),_=((e,t)=>{let d=t,l=-1;const c=new n,a=new r({source:c,style:e=>e.get("vertexIndex")===l?null:[d],zIndex:102});return e.addLayer(a),{update(e){c.clear(),i(e).forEach((e,t)=>{const n=new o({geometry:new s(e)});n.set("vertexIndex",t),c.addFeature(n)})},setSelected(e){l=e,c.changed()},updateStyle(e){d=e,c.changed()},remove(){c.clear(),e.removeLayer(a)}}})(p,x.styles.vertexStyle),X=new n,Y=new r({source:X,zIndex:103});p.addLayer(Y);const B=()=>{X.clear();const{selectedVertexIndex:e,selectedVertexType:t,vertices:n,midpoints:r}=E;if(e<0)return;let d,i;if("vertex"===t)d=n[e],i=x.styles.selectedVertexStyle;else{if("midpoint"!==t)return;d=r[e-n.length],i=x.styles.selectedMidpointStyle}if(!d)return;const l=new o({geometry:new s(d)});l.setStyle(i),X.addFeature(l)};G();const R=e=>{S.setStyle(e.editFeatureStyle),_.updateStyle(e.vertexStyle),j.updateStyle(e.midpointStyle),B(),q.updateColors(x.colors)};x.on("styleschanged",R);const U=e=>{if("touch"===e.pointerType)return E.interfaceType="touch",void q.updateTargetPosition();E.interfaceType="mouse";const t=p.getEventPixel(e),n={x:t[0],y:t[1]},r=T(p,E.vertices,E.midpoints,n);"vertex"===r?.type&&P({selectedVertexIndex:r.index,selectedVertexType:"vertex"})},J=e=>{if("touch"===E.interfaceType)return;const t=p.getEventPixel(e),n={x:t[0],y:t[1]},r=T(p,E.vertices,E.midpoints,n);"vertex"===r?.type?P({selectedVertexIndex:r.index,selectedVertexType:"vertex"}):"midpoint"===r?.type||P({selectedVertexIndex:-1,selectedVertexType:null})},K=e=>{"mouse"===e.pointerType&&"mouse"!==E.interfaceType&&(E.interfaceType="mouse",q.hide())};v.addEventListener("pointerdown",U),v.addEventListener("pointerenter",K),v.addEventListener("pointermove",K),v.addEventListener("click",J);const H=e=>{m&&e.target.closest(`#${m}`)&&W()};globalThis.addEventListener("click",H);const W=()=>{if("vertex"!==E.selectedVertexType||E.selectedVertexIndex<0)return;const e=((e,t)=>{const n=e.getGeometry(),r={type:n.getType(),coordinates:n.getCoordinates()},o=i(r),s=l(r),d=c(s,t);if(!d)return null;const{segment:p}=d,x=p.closed?3:2;if(p.length<=x)return null;const u=[...o[t]],y=a(r,p.path);return y.splice(d.localIdx,1),p.closed&&(y[y.length-1]=[...y[0]]),n.setCoordinates(r.coordinates),{deletedIndex:t,deletedCoord:u}})(S,E.selectedVertexIndex);e&&(w.push({type:"delete_vertex",vertexIndex:e.deletedIndex,deletedCoord:e.deletedCoord}),G(),P({selectedVertexIndex:-1,selectedVertexType:null}))},$=()=>{const e=w.pop();if(!e)return;const t=E.selectedVertexIndex,n=b(S,e);G();const r=t>=0?n:-1;P({selectedVertexIndex:r,selectedVertexType:r>=0?"vertex":null}),t>=0&&r>=0&&M?.()},q=V({map:p,container:v,getState:k,setState:P,colors:x.colors,snap:f,onVertexMoved({vertexIndex:e,previousCoord:t}){w.push({type:"move_vertex",vertexIndex:e,previousCoord:t}),G(),P({selectedVertexIndex:e,selectedVertexType:"vertex"}),q.updateTargetPosition()},onTap(e){if(e){if("vertex"===e.type)return P({selectedVertexIndex:e.index,selectedVertexType:"vertex"}),void q.updateTargetPosition();if("midpoint"===e.type){const t=h(S,E.midpoints,e.index,E.vertices.length);if(!t)return;w.push({type:"insert_vertex",vertexIndex:t.insertedIndex}),G(),P({selectedVertexIndex:t.insertedIndex,selectedVertexType:"vertex"}),q.updateTargetPosition()}}else P({selectedVertexIndex:-1,selectedVertexType:null})}});A=()=>q.hide(),M=()=>{"touch"===E.interfaceType&&q.updateTargetPosition()};const Q=()=>{"touch"!==E.interfaceType||E.selectedVertexIndex<0||p.once("postrender",()=>q.updateTargetPosition())};p.on("change:size",Q);const Z=(e=>L(e))({map:p,getState:k,setState:P,snap:f,onVertexMoved({vertexIndex:e,previousCoord:t}){w.push({type:"move_vertex",vertexIndex:e,previousCoord:t}),G(),P({selectedVertexIndex:e,selectedVertexType:"vertex"})},onInserted({insertedIndex:e}){w.push({type:"insert_vertex",vertexIndex:e}),G()},onDeleted:W,onUndo:$,onKeyboardActive(){"keyboard"!==E.interfaceType&&(E.interfaceType="keyboard",q.hide(),v.focus({preventScroll:!0}))}});return{setInterfaceType(e){e!==E.interfaceType&&(E.interfaceType=e,"touch"===e?q.updateTargetPosition():q.hide())},done(){x.emit("editfinish",I.toGeoJSON(S))},cancel(){},undo:$,deleteVertex:W,destroy(){S.setStyle(C),S.getGeometry().un("change",z),x.off("styleschanged",R),v.removeEventListener("pointerdown",U),v.removeEventListener("pointerenter",K),v.removeEventListener("pointermove",K),v.removeEventListener("click",J),globalThis.removeEventListener("click",H),p.un("change:size",Q),p.removeInteraction(F),X.clear(),p.removeLayer(Y),j.remove(),_.remove(),q.destroy(),Z.destroy()}}};export{k as createEditMode};
@@ -1 +0,0 @@
1
- const t=(t,e)=>{const r=t.getPixelFromCoordinate(e);return r?{x:r[0],y:r[1]}:null},e=(t,e)=>t.getCoordinateFromPixel([e.x,e.y]),r=(t,e)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2),n=(t,e,r,n)=>{const o=t.getPixelFromCoordinate(e);return o?t.getCoordinateFromPixel([o[0]+r,o[1]+n]):e},o=t=>{if(!t?.coordinates)return[];switch(t.type){case"LineString":return t.coordinates;case"Polygon":return t.coordinates.flatMap(t=>t.slice(0,-1));case"MultiLineString":return t.coordinates.flat(1);case"MultiPolygon":return t.coordinates.flatMap(t=>t.flatMap(t=>t.slice(0,-1)));default:return[]}},s=t=>{if(!t?.coordinates)return[];const e=[];let r=0;switch(t.type){case"LineString":e.push({start:0,length:t.coordinates.length,path:[],closed:!1});break;case"Polygon":t.coordinates.forEach((t,n)=>{const o=t.length-1;e.push({start:r,length:o,path:[n],closed:!0}),r+=o});break;case"MultiLineString":t.coordinates.forEach((t,n)=>{e.push({start:r,length:t.length,path:[n],closed:!1}),r+=t.length});break;case"MultiPolygon":t.coordinates.forEach((t,n)=>{t.forEach((t,o)=>{const s=t.length-1;e.push({start:r,length:s,path:[n,o],closed:!0}),r+=s})})}return e},a=(t,e)=>{for(const r of t)if(e>=r.start&&e<r.start+r.length)return{segment:r,localIdx:e-r.start};return null},l=(t,e)=>{let r=t.coordinates;for(const t of e)r=r[t];return r},c=t=>{const e=o(t),r=s(t);if(!e.length||!r.length)return[];const n=[];for(const t of r){const r=t.closed?t.length:t.length-1;for(let o=0;o<r;o++){const r=t.start+o,s=t.start+(o+1)%t.length,[a,l]=e[r],[c,i]=e[s];n.push([(a+c)/2,(l+i)/2])}}return n};export{c as a,s as b,t as c,a as d,l as e,e as f,o as g,n,r as p};
@@ -1 +0,0 @@
1
- import{useEffect as e}from"preact/compat";import t from"ol/layer/Vector.js";import r from"ol/source/Vector.js";import n from"ol/format/GeoJSON.js";import o from"ol/style/Style.js";import i from"ol/style/Fill.js";import a from"ol/style/Stroke.js";import s from"ol/style/Circle.js";import{transform as d}from"ol/proj.js";import l from"ol/layer/VectorTile.js";import c from"ol/Feature.js";import p from"ol/geom/Point.js";import{Style as u}from"ol/style.js";import h from"ol/interaction/Interaction.js";const g={SET_MODE:(e,t)=>({...e,mode:t,numVertices:null}),SET_FEATURE:(e,t)=>({...e,feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>({...e,selectedVertexIndex:t.index,numVertices:t.numVertices}),SET_UNDO_STACK_LENGTH:(e,t)=>({...e,undoStackLength:t}),TOGGLE_SNAP:e=>({...e,snap:!e.snap}),SET_HAS_SNAP_LAYERS:(e,t)=>({...e,hasSnapLayers:!!t})},f={MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize"},m="EPSG:27700",y=new n({dataProjection:m,featureProjection:m}),S=()=>{const e=new r;return{source:e,getOL:t=>e.getFeatureById(String(t))??null,add(t){const r=this.getOL(t.id);r&&e.removeFeature(r);const n=y.readFeature(t);return e.addFeature(n),n},get(e){const t=this.getOL(e);return t?y.writeFeatureObject(t):null},remove(t){const r=this.getOL(t);r&&e.removeFeature(r)},clear(){e.clear()},toGeoJSON:e=>y.writeFeatureObject(e),fromGeoJSON:e=>y.readFeature(e)}},w={outer:11,mid:8,inner:6},_={outer:9,mid:6,inner:4},v=(e,t,r,n,o)=>{e.beginPath(),e.arc(t,r,n,0,2*Math.PI),e.fillStyle=o,e.fill()},E=({outer:e,mid:t,inner:r},n,o)=>(i,a)=>{const s=a.context,d=a.pixelRatio,[l,c]=i;s.save(),v(s,l,c,e*d,n.editActive),v(s,l,c,t*d,n.editHalo),v(s,l,c,r*d,n[o]),s.restore()},x=e=>e.charAt(0).toUpperCase()+e.slice(1),T=e=>{const t=new o({image:new s({radius:6,fill:new i({color:e.editVertex})})}),r=new o({renderer:E(w,e,"editVertex")}),n=new o({image:new s({radius:4,fill:new i({color:e.editMidpoint})})}),d=new o({renderer:E(_,e,"editMidpoint")}),l=new o({stroke:new a({color:e.editStroke,width:2}),fill:new i({color:e.shapeFill})}),c=new o({stroke:new a({color:e.editStroke,width:2}),fill:new i({color:e.shapeFill})}),p=new o({image:new s({radius:5,fill:new i({color:e.editVertex})})});return{vertexStyle:t,selectedVertexStyle:r,midpointStyle:n,selectedMidpointStyle:d,editFeatureStyle:l,createSketchStyle:()=>e=>"Point"===e.getGeometry().getType()?[p]:[c],createFeatureStyle:()=>t=>{const r=t.getProperties(),n=e.mapStyleId,s=n&&r[`stroke${x(n)}`]||r.stroke||e.shapeStroke,d=n&&r[`fill${x(n)}`]||r.fill||e.shapeFill,l=r.strokeWidth||e.strokeWidth;return[new o({stroke:new a({color:s,width:l}),fill:new i({color:d})})]}}},k={editStroke:{light:"#1a65a6",dark:"#ffffff"},editVertex:{light:"#1a65a6",dark:"#ffffff"},editMidpoint:{light:"#1a65a6",dark:"#ffffff"},editHalo:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editActive:{light:"#000000",dark:"#ffffff"},splitInvalid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},shapeStroke:"#1a65a6",shapeFill:"rgba(26,101,166,0.1)",strokeWidth:2,snapVertex:"rgba(212,53,28,0.5)",snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)",snapRadius:10},M=(e,t={})=>{const r=e?.mapColorScheme??"light",n=e?.id??null,o=e=>((e,t,r)=>"object"!=typeof e||null===e?e:r&&void 0!==e[r]?e[r]:void 0!==e[t]?e[t]:void 0!==e.light?e.light:Object.values(e)[0])(t[e]??k[e],r,n);return{editStroke:o("editStroke"),editVertex:o("editVertex"),editMidpoint:o("editMidpoint"),editActive:o("editActive"),editHalo:o("editHalo"),shapeStroke:o("shapeStroke"),strokeWidth:t.strokeWidth??k.strokeWidth,shapeFill:o("shapeFill"),snapVertex:o("snapVertex"),snapEdge:o("snapEdge"),mapStyleId:n}},C=(e,t)=>{const r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n},b=(e,t,r)=>{const n=r[0]-t[0],o=r[1]-t[1],i=n*n+o*o;if(0===i)return[t[0],t[1]];const a=Math.max(0,Math.min(1,((e[0]-t[0])*n+(e[1]-t[1])*o)/i));return[t[0]+a*n,t[1]+a*o]},I=(e,t)=>P(e,t)?t:e,P=(e,t)=>e?!!t&&("edge"===e.type&&"vertex"===t.type||("vertex"!==e.type||"edge"!==t.type)&&t.distSq<e.distSq):!!t,L=(e,t,r,n)=>{let o=null;const i=n&&e.length>1?e.length-1:e.length,a=n?i:i-1;for(let n=0;n<i;n++){const i=e[n],a=C(t,i);a<=r&&(o=I(o,{type:"vertex",coord:[i[0],i[1]],distSq:a}))}for(let n=0;n<a;n++){const a=e[n],s=e[(n+1)%i],d=b(t,a,s),l=C(t,d);l<=r&&(o=I(o,{type:"edge",coord:d,distSq:l}))}return o},F=(e,t,r,n,o,i)=>I(((e,t,r,n,o)=>{let i=null;for(let a=0;a<r;a++){const r=t+2*a,s=[e[r],e[r+1]],d=C(n,s);d<=o&&(i=I(i,{type:"vertex",coord:s,distSq:d}))}return i})(e,t,r,o,i),((e,t,r,n,o,i)=>{let a=null;for(let s=0;s<n;s++){const n=t+2*s,d=t+(s+1)%r*2,l=[e[n],e[n+1]],c=[e[d],e[d+1]],p=b(o,l,c),u=C(o,p);u<=i&&(a=I(a,{type:"edge",coord:p,distSq:u}))}return a})(e,t,r,n,o,i)),A=(e,t,r,n,o,i)=>{const a=(r-t)/2;return F(e,t,a,i?a:a-1,n,o)},V={point:(e,t,r)=>{const n=e.getCoordinates(),o=C(t,n);return o<=r?{type:"vertex",coord:[n[0],n[1]],distSq:o}:null},lineString:(e,t,r)=>L(e.getCoordinates(),t,r,!1),linearRing:(e,t,r)=>L(e.getCoordinates(),t,r,!0),polygon:(e,t,r)=>{let n=null;for(const o of e.getCoordinates())n=I(n,L(o,t,r,!0));return n},multiLineString:(e,t,r)=>{let n=null;for(const o of e.getCoordinates())n=I(n,L(o,t,r,!1));return n},multiPolygon:(e,t,r)=>{let n=null;for(const o of e.getCoordinates())for(const e of o)n=I(n,L(e,t,r,!0));return n}},j=(e,t,r)=>{const n=e.getGeometry();if(!n)return null;const o=n.getType(),i=V[o[0].toLowerCase()+o.slice(1)];return i?i(n,t,r):null},R=(e,t)=>t?e?"vertex"===e.type&&"edge"===t.type?e:"edge"===e.type&&"vertex"===t.type||t.distSq<e.distSq?t:e:t:e,W=(e,r=[])=>{let n=new Set,o=[];const i=e=>{n=new Set,o=[];for(const r of e??[])"string"==typeof r?n.add(r):r instanceof t&&o.push(r)};i(r);return{query:(t,r)=>{const i=e.getView().getResolution();if(!i)return null;const a=r*i,s=a*a,c=[t[0]-a,t[1]-a,t[0]+a,t[1]+a];let p=null;for(const e of o){const r=e.getSource();if(r)for(const e of r.getFeaturesInExtent(c))p=R(p,j(e,t,s))}if(n.size>0){const o=(e=>{const t=[];return e.getLayers().forEach(e=>{e instanceof l&&t.push(e)}),t})(e),a=o.length>0?e.getPixelFromCoordinate(t):null;if(a){const l=new Map;e.forEachFeatureAtPixel(a,(r,a)=>{const c=r.get("mapbox-layer");if(!n.has(c?.id))return;const u=((e,t,r)=>{const n=e.getType(),o=e.getFlatCoordinates();let i=null;if("Point"===n){const e=C(t,o);e<=r&&(i={type:"vertex",coord:[o[0],o[1]],distSq:e})}else if("LineString"===n)i=A(o,0,o.length,t,r,!1);else if("Polygon"===n||"MultiLineString"===n){const a=e.getEnds();let s=0;const d="Polygon"===n;for(const e of a)i=I(i,A(o,s,e,t,r,d)),s=e}return i})(r,t,s);u&&(l.has(a)||l.set(a,((e,t)=>{const r=e.getSource(),n=r?.getTileGrid();if(!n)return null;const o=t.getView().getProjection(),i=r.getProjection()??o,a=n.getZForResolution(t.getView().getResolution(),0);return{tileGrid:n,viewProj:o,sourceProj:i,zoom:a}})(a,e)),((e,t)=>{if(!e)return!1;const{tileGrid:r,viewProj:n,sourceProj:o,zoom:i}=e,a=d(t,n,o),s=r.getTileCoordForCoordAndZ(a,i),[l,c,p,u]=r.getTileCoordExtent(s),h=.03125*(p-l)+1;return Math.abs(a[0]-l)<h||Math.abs(a[0]-p)<h||Math.abs(a[1]-c)<h||Math.abs(a[1]-u)<h})(l.get(a),u.coord)||"edge"===u.type&&"fill"===c?.type&&((e,t,r,n,o,i)=>{const a=e[0]-t[0],s=e[1]-t[1],d=a*a+s*s;if(d<1)return!1;const l=Math.sqrt(d),c=4*i,p=[e[0]+a/l*c,e[1]+s/l*c],u=n.getPixelFromCoordinate(p);return!!u&&!!n.forEachFeatureAtPixel(u,e=>e.get("mapbox-layer")?.id===r,{hitTolerance:2,layerFilter:e=>o.includes(e)})})(u.coord,t,c.id,e,o,i)||(p=R(p,u)))},{hitTolerance:r,layerFilter:e=>o.includes(e)})}}return p?{type:p.type,coord:p.coord}:null},setLayers:i}},D=e=>(t,r)=>{const n=r.context,[o,i]=t;n.beginPath(),n.arc(o,i,10*r.pixelRatio,0,2*Math.PI),n.fillStyle=e,n.fill()},O=e=>({vertex:new u({renderer:D(e.snapVertex)}),edge:new u({renderer:D(e.snapEdge)})}),G=new Set(["pointermove","pointerdrag","pointerdown","pointerup","singleclick","click"]),H=(e,t,r,n)=>{const o=new h({handleEvent:i=>(o.getActive()&&((e,t,r,n,o)=>{const{type:i}=e;if("pointerout"===i||"pointerleave"===i)return void r.hide();if(!G.has(i))return;const a=t.query(e.coordinate,n);a&&(e.coordinate=a.coord.slice()),"pointermove"===i&&o()?a?r.show(a.coord,a.type):r.hide():"pointerdrag"===i&&r.hide()})(i,e,t,r,n),!0)});return o},N=(e,n,o,i)=>{if(!n?.length)return null;const a=W(e,n),s=((e,n)=>{let o=O(n);const i=new r,a=new t({source:i,style:e=>o[e.get("snapType")]??null,zIndex:200,updateWhileAnimating:!0,updateWhileInteracting:!0});e.addLayer(a);const s=new c;let d=!1;return{show(e,t){s.setGeometry(new p(e)),s.set("snapType",t,!0),d?i.changed():(i.addFeature(s),d=!0)},hide(){d&&(i.clear(),d=!1)},updateColors(e){o=O(e),d&&i.changed()},remove(){i.clear(),e.removeLayer(a)}}})(e,o);let d=!1;const l=H(a,s,i,()=>d);e.addInteraction(l),l.setActive(!1);let u=!1;return{snapRadius:i,apply(e){if(!u)return e;const t=a.query(e,i);return t?(s.show(t.coord,t.type),t.coord):(s.hide(),e)},hideIndicator(){s.hide()},setIndicatorActive(e){d=e,e||s.hide()},setActive(e){u=e,l.setActive(e),e||s.hide()},setSnapLayers(e){a.setLayers(null==e?n??[]:e)},reattach(){e.removeInteraction(l),e.addInteraction(l)},updateColors(e){s.updateColors(e)},destroy(){e.removeInteraction(l),s.remove()}}};class q{constructor(e,r={}){this._map=e,this._pluginConfig=r,this._mode="disabled",this._modeInstance=null,this._listeners=new Map,this.store=S(),this.undoStack=(e=>{const t=[];return{push(r){t.push(r),e(t.length)},pop(){const r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}})(e=>this.emit("undochange",e)),this.colors=M(null,r),this.styles=T(this.colors),this.snap=N(e,r.snapLayers??null,this.colors,r.snapRadius??k.snapRadius),this._layer=new t({source:this.store.source,style:this.styles.createFeatureStyle(),zIndex:100}),this._layer.set("layerId","draw"),e.addLayer(this._layer)}setMapStyle(e){this.colors=M(e,this._pluginConfig),this.styles=T(this.colors),this._layer.setStyle(this.styles.createFeatureStyle()),this.store.source.changed(),this.snap?.updateColors(this.colors),this.emit("styleschanged",this.styles)}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}off(e,t){this._listeners.get(e)?.delete(t)}emit(e,t){this._listeners.get(e)?.forEach(e=>e(t))}async changeMode(e,t={}){this._modeInstance?.destroy(),this._modeInstance=null,this._mode=e;const r="draw_polygon"===e||"draw_line"===e||"edit_vertex"===e;this.snap?.setIndicatorActive(r);const n={...t,snap:this.snap};if("draw_polygon"===e||"draw_line"===e){const{createDrawMode:e}=await import(/* webpackChunkName: "DrawMode" */ "./DrawMode.js");this._modeInstance=e({map:this._map,manager:this,options:n})}else if("edit_vertex"===e){const{createEditMode:e}=await import(/* webpackChunkName: "EditMode" */ "./EditMode.js");this._modeInstance=e({map:this._map,manager:this,options:n})}this.snap?.reattach()}getMode(){return this._mode}done(){this._modeInstance?.done()}cancel(){this._modeInstance?.cancel(),this.changeMode("disabled")}undo(){this._modeInstance?.undo()}deleteVertex(){this._modeInstance?.deleteVertex()}setInterfaceType(e){this._modeInstance?.setInterfaceType?.(e)}get(e){return this.store.get(e)}add(e){return this.store.add(e)}delete(e){return this.store.remove(e)}deleteAll(){return this.store.clear()}remove(){this._modeInstance?.destroy(),this._modeInstance=null,this.snap?.destroy(),this.snap=null,this.store.clear(),this._map.removeLayer(this._layer),this._listeners.clear()}}const B=["stroke","fill","strokeWidth"],U=e=>{if(!e)return{};const t={};for(const[r,n]of Object.entries(e))if(B.includes(r)&&"object"==typeof n&&null!==n){const e=Object.entries(n);e.length>0&&(t[r]=e[0][1]);for(const[n,o]of e)t[`${r}${n.charAt(0).toUpperCase()+n.slice(1)}`]=o}else t[r]=n;return t},z=e=>({mobile:{slot:"actions",showLabel:e},tablet:{slot:"actions",showLabel:e},desktop:{slot:"actions",showLabel:e}}),$={reducer:{initialState:{mode:null,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertices:null,undoStackLength:0,snap:!1,hasSnapLayers:!1},actions:g},InitComponent:({appState:t,appConfig:r,mapState:n,pluginConfig:o,pluginState:i,services:a,mapProvider:s,buttonConfig:d})=>{const{eventBus:l}=a,{crossHair:c}=n,p=["touch","keyboard"].includes(t.interfaceType);e(()=>{if(!n.isMapReady)return;const{remove:e}=(({mapProvider:e,events:t,eventBus:r,pluginConfig:n={},mapStyle:o=null})=>{const{map:i}=e,a=new q(i,n);o&&a.setMapStyle(o),e.draw=a;const s=t=>{e.drawScale={small:1,medium:1.5,large:2}[t]??1};r.on(t.MAP_SET_SIZE,s);const d=e=>{a.setMapStyle(e)};return r.on(t.MAP_SET_STYLE,d),{remove(){r.off(t.MAP_SET_SIZE,s),r.off(t.MAP_SET_STYLE,d),a.remove(),e.draw=null}}})({mapProvider:s,events:f,eventBus:l,pluginConfig:o,mapStyle:n.mapStyle});return i.dispatch({type:"SET_MODE",payload:null}),i.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:o.snapLayers?.length>0}),l.emit("draw:ready"),()=>e()},[n.isMapReady]),e(()=>{if(!["draw_polygon","draw_line"].includes(i.mode)||!p)return;const e=c.isVisible;return c.fixAtCenter(),()=>{e||c.hide()}},[i.mode,t.interfaceType]),e(()=>{"edit_vertex"===i.mode&&s.draw&&s.draw.setInterfaceType(t.interfaceType)},[t.interfaceType,i.mode]),e(()=>{if(s.draw)return function({pluginState:e,mapProvider:t,buttonConfig:r,eventBus:n}){const{drawDone:o,drawCancel:i,drawUndo:a,drawDeletePoint:s,drawSnap:d}=r,{draw:l}=t,{dispatch:c,feature:p,tempFeature:u}=e,h=()=>{l.undoStack.clear(),c({type:"SET_MODE",payload:null}),c({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},g=e=>{h(),l.changeMode("disabled"),n.emit("draw:created",e)},f=e=>{h(),l.changeMode("disabled"),n.emit("draw:edited",e)},m=()=>{},y=e=>{c({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),n.emit("draw:vertexselection",e)},S=e=>{c({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertices:e.numVertices}})},w=e=>{c({type:"SET_UNDO_STACK_LENGTH",payload:e})},_=e=>{n.emit("draw:updated",e)};return o.onClick=()=>{l.undoStack.clear(),l.done()},i.onClick=()=>{"edit_vertex"===l.getMode()&&u?.id&&l.add(p),l.cancel(),h(),n.emit("draw:cancelled",p)},a.onClick=()=>{l.undo()},s&&(s.onClick=()=>{l.deleteVertex()}),d&&(d.onClick=()=>{const t=!e.snap;c({type:"TOGGLE_SNAP"}),l.snap?.setActive(t)}),l.on("create",g),l.on("editfinish",f),l.on("cancel",m),l.on("vertexselection",y),l.on("vertexchange",S),l.on("undochange",w),l.on("update",_),()=>{o.onClick=null,i.onClick=null,a.onClick=null,s&&(s.onClick=null),d&&(d.onClick=null),l.off("create",g),l.off("editfinish",f),l.off("cancel",m),l.off("vertexselection",y),l.off("vertexchange",S),l.off("undochange",w),l.off("update",_)}}({mapProvider:s,buttonConfig:d,pluginState:i,eventBus:l})},[s,t,i])},buttons:[{id:"drawCancel",label:"Cancel",variant:"tertiary",hiddenWhen:({pluginState:e})=>!e.mode,...z(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",hiddenWhen:({appState:e,pluginState:t})=>!["draw_polygon","draw_line"].includes(t.mode)||"touch"!==e.interfaceType,...z(!0)},{id:"drawDone",label:"Done",variant:"primary",hiddenWhen:({pluginState:e})=>!["draw_polygon","draw_line","edit_vertex"].includes(e.mode),enableWhen:({pluginState:e})=>"draw_polygon"===e.mode?e.numVertices>=3:"draw_line"===e.mode?e.numVertices>=2:"edit_vertex"===e.mode,...z(!0)},{id:"drawMenu",label:"Menu",iconId:"menu",hiddenWhen:({pluginState:e})=>!["draw_polygon","draw_line","edit_vertex"].includes(e.mode),menuItems:[{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:({pluginState:e})=>!["draw_polygon","draw_line","edit_vertex"].includes(e.mode),enableWhen:({pluginState:e})=>["draw_polygon","draw_line"].includes(e.mode)?e.numVertices>0:e.undoStackLength>0},{id:"drawSnap",label:"Snap to feature",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,pressedWhen:({pluginState:e})=>!!e.snap},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:({pluginState:e})=>{if(e.selectedVertexIndex<0)return!1;return"Polygon"===e.feature?.geometry?.type?e.numVertices>3:e.numVertices>2},hiddenWhen:({pluginState:e})=>"edit_vertex"!==e.mode}],mobile:{slot:"bottom-right"},tablet:{slot:"top-middle"},desktop:{slot:"top-middle"}}],keyboardShortcuts:[{id:"drawStart",group:"Drawing",title:"Edit vertex",command:"<kbd>Spacebar</kbd></dd>"}],icons:[{id:"menu",svgContent:'<path d="m6 9 6 6 6-6"/>'},{id:"undo",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"/>'},{id:"magnet",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"/>'},{id:"trash",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"/>'}],api:{newPolygon:({appState:e,appConfig:t,mapState:r,pluginState:n,mapProvider:o,services:i},a,s={})=>{const{dispatch:d}=n,{draw:l}=o,{eventBus:c}=i;if(!l)return;c.emit("draw:started",{mode:"draw_polygon"});const{stroke:p,fill:u,strokeWidth:h,properties:g,...f}=s,m={...g,...U({stroke:p,fill:u,strokeWidth:h})};l.changeMode("draw_polygon",{container:e.layoutRefs.viewportRef.current,interfaceType:e.interfaceType,addVertexButtonId:`${t.id}-draw-add-point`,featureId:a,geometryType:"Polygon",properties:m,mapProvider:o,crossHair:r.crossHair,...f}),d({type:"SET_MODE",payload:"draw_polygon"})},newLine:({appState:e,appConfig:t,mapState:r,pluginState:n,mapProvider:o,services:i},a,s={})=>{const{dispatch:d}=n,{draw:l}=o,{eventBus:c}=i;if(!l)return;c.emit("draw:started",{mode:"draw_line"});const{stroke:p,fill:u,strokeWidth:h,properties:g,...f}=s,m={...g,...U({stroke:p,fill:u,strokeWidth:h})};l.changeMode("draw_line",{container:e.layoutRefs.viewportRef.current,interfaceType:e.interfaceType,addVertexButtonId:`${t.id}-draw-add-point`,featureId:a,geometryType:"LineString",properties:m,mapProvider:o,crossHair:r.crossHair,...f}),d({type:"SET_MODE",payload:"draw_line"})},editFeature:({appState:e,appConfig:t,pluginConfig:r,pluginState:n,mapProvider:o,services:i},a,s={})=>{const{dispatch:d}=n,{draw:l}=o,{eventBus:c}=i;if(!l)return!1;const p=l.get(a);if(!p)return!1;c.emit("draw:editstart",{mode:"edit_vertex"});const u=void 0===s.snapLayers?r.snapLayers??null:s.snapLayers;return l.snap?.setSnapLayers(u),d({type:"SET_HAS_SNAP_LAYERS",payload:u?.length>0}),l.changeMode("edit_vertex",{container:e.layoutRefs.viewportRef.current,deleteVertexButtonId:`${t.id}-draw-delete-point`,interfaceType:e.interfaceType,featureId:a}),d({type:"SET_FEATURE",payload:{feature:p,tempFeature:p}}),d({type:"SET_MODE",payload:"edit_vertex"}),!0},addFeature:({mapProvider:e,services:t},r)=>{const{draw:n}=e,{eventBus:o}=t;if(!n)return;const{stroke:i,fill:a,strokeWidth:s,properties:d,...l}=r,c={...l,properties:{...d,...U({stroke:i,fill:a,strokeWidth:s})}};n.add(c),o.emit("draw:add",c)},deleteFeature:({mapProvider:e},t)=>{const{draw:r}=e;r&&r.delete(t)}}};export{$ as manifest};
@@ -1 +0,0 @@
1
- import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/regenerator";function n(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})),t.push.apply(t,n)}return t}function o(r){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach(function(t){e(r,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function i(){var e;return o(o({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(e=r(t.mark(function r(){var e;return t.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=1,import(/* webpackChunkName: "im-draw-ol-plugin" */ "./im-draw-ol-plugin.js");case 1:return e=r.sent.manifest,r.abrupt("return",e);case 2:case"end":return r.stop()}},r)})),function(){return e.apply(this,arguments)})})}export{i as default};
@@ -1,65 +0,0 @@
1
- import { useEffect } from 'react'
2
- import { EVENTS } from '../../../../src/config/events.js'
3
- import { createOLDraw } from './olDraw.js'
4
- import { attachEvents } from './events.js'
5
-
6
- export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginState, services, mapProvider, buttonConfig }) => {
7
- const { eventBus } = services
8
- const { crossHair } = mapState
9
- const isTouchOrKeyboard = ['touch', 'keyboard'].includes(appState.interfaceType)
10
-
11
- // Create the OLDrawManager once when the map is ready
12
- useEffect(() => {
13
- if (!mapState.isMapReady) {
14
- return undefined
15
- }
16
-
17
- const { remove } = createOLDraw({ mapProvider, events: EVENTS, eventBus, pluginConfig, mapStyle: mapState.mapStyle })
18
-
19
- pluginState.dispatch({ type: 'SET_MODE', payload: null })
20
- pluginState.dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: pluginConfig.snapLayers?.length > 0 })
21
- eventBus.emit('draw:ready')
22
-
23
- return () => remove()
24
- }, [mapState.isMapReady])
25
-
26
- // Show crosshair when entering draw mode on touch/keyboard
27
- useEffect(() => {
28
- if (!['draw_polygon', 'draw_line'].includes(pluginState.mode) || !isTouchOrKeyboard) {
29
- return undefined
30
- }
31
- const wasVisible = crossHair.isVisible
32
- crossHair.fixAtCenter()
33
- return () => {
34
- if (!wasVisible) { crossHair.hide() }
35
- }
36
- }, [pluginState.mode, appState.interfaceType])
37
-
38
- // Keep edit mode in sync with the global interface type so the touch
39
- // offset target hides immediately when the user switches to mouse/keyboard.
40
- useEffect(() => {
41
- if (pluginState.mode !== 'edit_vertex' || !mapProvider.draw) {
42
- return undefined
43
- }
44
- mapProvider.draw.setInterfaceType(appState.interfaceType)
45
- return undefined
46
- }, [appState.interfaceType, pluginState.mode])
47
-
48
- // Re-attach events when state changes
49
- useEffect(() => {
50
- if (!mapProvider.draw) {
51
- return undefined
52
- }
53
-
54
- return attachEvents({
55
- appState,
56
- appConfig,
57
- mapState,
58
- mapProvider,
59
- buttonConfig,
60
- pluginState,
61
- events: EVENTS,
62
- eventBus
63
- })
64
- }, [mapProvider, appState, pluginState])
65
- }
@@ -1,29 +0,0 @@
1
- import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
2
-
3
- /**
4
- * Add a pre-drawn feature (GeoJSON) to the draw layer.
5
- * The feature will be stored and available for editing.
6
- *
7
- * @param {object} context - plugin context
8
- * @param {object} feature - GeoJSON feature with id, geometry, properties
9
- */
10
- export const addFeature = ({ mapProvider, services }, feature) => {
11
- const { draw } = mapProvider
12
- const { eventBus } = services
13
-
14
- if (!draw) {
15
- return
16
- }
17
-
18
- const { stroke, fill, strokeWidth, properties, ...featureRest } = feature
19
- const flatFeature = {
20
- ...featureRest,
21
- properties: {
22
- ...properties,
23
- ...flattenStyleProperties({ stroke, fill, strokeWidth })
24
- }
25
- }
26
-
27
- draw.add(flatFeature)
28
- eventBus.emit('draw:add', flatFeature)
29
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Delete a feature from the draw layer by ID.
3
- *
4
- * @param {object} context - plugin context
5
- * @param {string} featureId - ID of the feature to delete
6
- */
7
- export const deleteFeature = ({ mapProvider }, featureId) => {
8
- const { draw } = mapProvider
9
- if (!draw) return
10
- draw.delete(featureId)
11
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Programmatically start editing a feature.
3
- *
4
- * @param {object} context - plugin context
5
- * @param {string} featureId - ID of the feature to edit
6
- * @param {object} options - { snapLayers }
7
- * @returns {boolean} true if edit mode entered, false if feature not found
8
- */
9
- export const editFeature = (
10
- { appState, appConfig, pluginConfig, pluginState, mapProvider, services },
11
- featureId,
12
- options = {}
13
- ) => {
14
- const { dispatch } = pluginState
15
- const { draw } = mapProvider
16
- const { eventBus } = services
17
-
18
- if (!draw) {
19
- return false
20
- }
21
-
22
- const existingFeature = draw.get(featureId)
23
- if (!existingFeature) {
24
- return false
25
- }
26
-
27
- eventBus.emit('draw:editstart', { mode: 'edit_vertex' })
28
-
29
- const snapLayers = options.snapLayers === undefined
30
- ? (pluginConfig.snapLayers ?? null)
31
- : options.snapLayers
32
-
33
- draw.snap?.setSnapLayers(snapLayers)
34
- dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: snapLayers?.length > 0 })
35
-
36
- draw.changeMode('edit_vertex', {
37
- container: appState.layoutRefs.viewportRef.current,
38
- deleteVertexButtonId: `${appConfig.id}-draw-delete-point`,
39
- interfaceType: appState.interfaceType,
40
- featureId
41
- })
42
-
43
- dispatch({
44
- type: 'SET_FEATURE',
45
- payload: { feature: existingFeature, tempFeature: existingFeature }
46
- })
47
-
48
- dispatch({ type: 'SET_MODE', payload: 'edit_vertex' })
49
- return true
50
- }
@@ -1,44 +0,0 @@
1
- import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
2
-
3
- /**
4
- * Programmatically start drawing a new line.
5
- *
6
- * @param {object} context - plugin context
7
- * @param {string} featureId - unique ID for this feature
8
- * @param {object} options - { snapLayers, stroke, fill, strokeWidth, properties }
9
- */
10
- export const newLine = (
11
- { appState, appConfig, mapState, pluginState, mapProvider, services },
12
- featureId,
13
- options = {}
14
- ) => {
15
- const { dispatch } = pluginState
16
- const { draw } = mapProvider
17
- const { eventBus } = services
18
-
19
- if (!draw) {
20
- return
21
- }
22
-
23
- eventBus.emit('draw:started', { mode: 'draw_line' })
24
-
25
- const { stroke, fill, strokeWidth, properties: customProperties, ...modeOptions } = options
26
- const properties = {
27
- ...customProperties,
28
- ...flattenStyleProperties({ stroke, fill, strokeWidth })
29
- }
30
-
31
- draw.changeMode('draw_line', {
32
- container: appState.layoutRefs.viewportRef.current,
33
- interfaceType: appState.interfaceType,
34
- addVertexButtonId: `${appConfig.id}-draw-add-point`,
35
- featureId,
36
- geometryType: 'LineString',
37
- properties,
38
- mapProvider,
39
- crossHair: mapState.crossHair,
40
- ...modeOptions
41
- })
42
-
43
- dispatch({ type: 'SET_MODE', payload: 'draw_line' })
44
- }
@@ -1,44 +0,0 @@
1
- import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
2
-
3
- /**
4
- * Programmatically start drawing a new polygon.
5
- *
6
- * @param {object} context - plugin context
7
- * @param {string} featureId - unique ID for this feature
8
- * @param {object} options - { snapLayers, stroke, fill, strokeWidth, properties }
9
- */
10
- export const newPolygon = (
11
- { appState, appConfig, mapState, pluginState, mapProvider, services },
12
- featureId,
13
- options = {}
14
- ) => {
15
- const { dispatch } = pluginState
16
- const { draw } = mapProvider
17
- const { eventBus } = services
18
-
19
- if (!draw) {
20
- return
21
- }
22
-
23
- eventBus.emit('draw:started', { mode: 'draw_polygon' })
24
-
25
- const { stroke, fill, strokeWidth, properties: customProperties, ...modeOptions } = options
26
- const properties = {
27
- ...customProperties,
28
- ...flattenStyleProperties({ stroke, fill, strokeWidth })
29
- }
30
-
31
- draw.changeMode('draw_polygon', {
32
- container: appState.layoutRefs.viewportRef.current,
33
- interfaceType: appState.interfaceType,
34
- addVertexButtonId: `${appConfig.id}-draw-add-point`,
35
- featureId,
36
- geometryType: 'Polygon',
37
- properties,
38
- mapProvider,
39
- crossHair: mapState.crossHair,
40
- ...modeOptions
41
- })
42
-
43
- dispatch({ type: 'SET_MODE', payload: 'draw_polygon' })
44
- }