@defra/interactive-map 0.0.3-alpha → 0.0.4-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 (268) hide show
  1. package/README.md +16 -57
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/index.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/button-definition.md +176 -0
  7. package/docs/api/context.md +124 -0
  8. package/docs/api/control-definition.md +72 -0
  9. package/docs/api/icon-definition.md +28 -0
  10. package/docs/api/map-style-config.md +76 -0
  11. package/docs/api/marker-config.md +51 -0
  12. package/docs/api/panel-definition.md +117 -0
  13. package/docs/api/slots.md +25 -0
  14. package/docs/api.md +713 -0
  15. package/docs/architecture.md +139 -0
  16. package/docs/building-a-plugin.md +149 -0
  17. package/docs/getting-started.md +46 -0
  18. package/docs/govuk-prototype.md +0 -0
  19. package/docs/plugins/interact.md +205 -0
  20. package/docs/plugins/map-styles.md +84 -0
  21. package/docs/plugins/plugin-context.md +67 -0
  22. package/docs/plugins/plugin-descriptor.md +71 -0
  23. package/docs/plugins/plugin-manifest.md +118 -0
  24. package/docs/plugins/scale-bar.md +62 -0
  25. package/docs/plugins/search.md +162 -0
  26. package/docs/plugins.md +116 -0
  27. package/govuk-prototype-kit.config.json +7 -7
  28. package/package.json +14 -1
  29. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -0
  30. package/plugins/beta/datasets/dist/esm/index.js +2 -0
  31. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -0
  32. package/plugins/beta/datasets/dist/umd/index.js +2 -0
  33. package/plugins/{datasets → beta/datasets}/src/manifest.js +1 -1
  34. package/plugins/{datasets → beta/datasets}/src/mapLayers.js +1 -1
  35. package/plugins/{datasets → beta/datasets}/src/panels/Key.jsx +1 -1
  36. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -0
  37. package/plugins/beta/draw-ml/dist/esm/index.js +2 -0
  38. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -0
  39. package/plugins/beta/draw-ml/dist/umd/index.js +2 -0
  40. package/plugins/{draw-ml → beta/draw-ml}/src/api/editFeature.js +1 -1
  41. package/plugins/beta/draw-ml/src/api/merge.js +9 -0
  42. package/plugins/beta/draw-ml/src/api/newLine.js +43 -0
  43. package/plugins/{draw-ml → beta/draw-ml}/src/api/newPolygon.js +5 -5
  44. package/plugins/beta/draw-ml/src/api/split.js +81 -0
  45. package/plugins/{draw-ml → beta/draw-ml}/src/defaults.js +2 -0
  46. package/plugins/{draw-ml → beta/draw-ml}/src/events.js +105 -3
  47. package/plugins/{draw-ml → beta/draw-ml}/src/manifest.js +17 -11
  48. package/plugins/{draw-ml → beta/draw-ml}/src/mapboxDraw.js +51 -2
  49. package/plugins/{draw-ml → beta/draw-ml}/src/mapboxSnap.js +2 -0
  50. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +496 -0
  51. package/plugins/beta/draw-ml/src/modes/drawLineMode.js +18 -0
  52. package/plugins/beta/draw-ml/src/modes/drawPolygonMode.js +16 -0
  53. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +792 -0
  54. package/plugins/{draw-ml → beta/draw-ml}/src/reducer.js +30 -2
  55. package/plugins/{draw-ml → beta/draw-ml}/src/styles.js +66 -36
  56. package/plugins/beta/draw-ml/src/undoStack.js +50 -0
  57. package/plugins/beta/draw-ml/src/utils/debounce.js +16 -0
  58. package/plugins/beta/draw-ml/src/utils/spatial.js +258 -0
  59. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -0
  60. package/plugins/beta/frame/dist/esm/index.js +2 -0
  61. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -0
  62. package/plugins/beta/frame/dist/umd/index.js +2 -0
  63. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -0
  64. package/plugins/beta/map-styles/dist/esm/index.js +2 -0
  65. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -0
  66. package/plugins/beta/map-styles/dist/umd/index.js +2 -0
  67. package/plugins/{map-styles → beta/map-styles}/src/MapStyles.jsx +1 -1
  68. package/plugins/{map-styles → beta/map-styles}/src/manifest.js +8 -10
  69. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -0
  70. package/plugins/beta/scale-bar/dist/esm/index.js +2 -0
  71. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -0
  72. package/plugins/beta/scale-bar/dist/umd/index.js +2 -0
  73. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -0
  74. package/plugins/beta/use-location/dist/esm/index.js +2 -0
  75. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -0
  76. package/plugins/beta/use-location/dist/umd/index.js +2 -0
  77. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  78. package/plugins/interact/dist/esm/index.js +1 -1
  79. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  80. package/plugins/interact/dist/umd/index.js +1 -1
  81. package/plugins/interact/src/InteractInit.test.js +97 -0
  82. package/plugins/interact/src/api/clear.test.js +18 -0
  83. package/plugins/interact/src/api/disable.test.js +12 -0
  84. package/plugins/interact/src/api/enable.test.js +48 -0
  85. package/plugins/interact/src/api/selectFeature.test.js +33 -0
  86. package/plugins/interact/src/api/unselectFeature.test.js +33 -0
  87. package/plugins/interact/src/defaults.js +1 -0
  88. package/plugins/interact/src/events.test.js +151 -0
  89. package/plugins/interact/src/hooks/useHighlightSync.test.js +212 -0
  90. package/plugins/interact/src/hooks/useInteractionHandlers.js +14 -7
  91. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +260 -0
  92. package/plugins/interact/src/index.test.js +22 -0
  93. package/plugins/interact/src/manifest.js +1 -1
  94. package/plugins/interact/src/manifest.test.js +94 -0
  95. package/plugins/interact/src/reducer.js +10 -1
  96. package/plugins/interact/src/reducer.test.js +142 -0
  97. package/plugins/interact/src/utils/buildStylesMap.test.js +57 -0
  98. package/plugins/interact/src/utils/featureQueries.test.js +56 -0
  99. package/plugins/interact/src/utils/turfHelpers.js +30 -0
  100. package/plugins/interact/src/utils/turfHelpers.test.js +30 -0
  101. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  102. package/plugins/search/dist/esm/index.js +1 -1
  103. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  104. package/plugins/search/dist/umd/index.js +1 -1
  105. package/plugins/search/src/utils/parseOsNamesResults.js +3 -7
  106. package/providers/{esri → beta/esri}/src/mapEvents.js +2 -2
  107. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +2 -0
  108. package/providers/beta/open-names/dist/esm/index.js +2 -0
  109. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +2 -0
  110. package/providers/beta/open-names/dist/umd/index.js +2 -0
  111. package/providers/maplibre/dist/esm/im-maplibre-framework.js +1 -1
  112. package/providers/maplibre/dist/esm/im-maplibre-framework.js.LICENSE.txt +1 -1
  113. package/providers/maplibre/dist/esm/im-maplibre-legacy-framework.js +1 -1
  114. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  115. package/providers/maplibre/dist/esm/index.js +1 -1
  116. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  117. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +1 -1
  118. package/providers/maplibre/dist/umd/im-maplibre-legacy-framework.js +1 -1
  119. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  120. package/providers/maplibre/dist/umd/index.js +1 -1
  121. package/providers/maplibre/src/index.js +14 -1
  122. package/providers/maplibre/src/maplibreProvider.js +127 -0
  123. package/sonar-project.properties +1 -1
  124. package/src/App/hooks/useInterfaceAPI.js +24 -1
  125. package/src/App/renderer/mapButtons.js +1 -1
  126. package/src/App/store/appActionsMap.js +22 -1
  127. package/src/InteractiveMap/InteractiveMap.js +114 -6
  128. package/src/config/defaults.js +29 -20
  129. package/src/config/events.js +110 -4
  130. package/src/index.js +5 -2
  131. package/src/scss/tools/_border-focus.scss +20 -4
  132. package/src/types.js +585 -0
  133. package/webpack.esm.mjs +8 -8
  134. package/webpack.umd.mjs +8 -8
  135. package/plugins/datasets/dist/esm/im-datasets-plugin.js +0 -1
  136. package/plugins/datasets/dist/esm/index.js +0 -2
  137. package/plugins/datasets/dist/umd/im-datasets-plugin.js +0 -1
  138. package/plugins/datasets/dist/umd/index.js +0 -2
  139. package/plugins/draw-ml/dist/esm/im-draw-ml-plugin.js +0 -1
  140. package/plugins/draw-ml/dist/esm/index.js +0 -2
  141. package/plugins/draw-ml/dist/umd/im-draw-ml-plugin.js +0 -1
  142. package/plugins/draw-ml/dist/umd/index.js +0 -2
  143. package/plugins/draw-ml/src/modes/drawVertexMode.js +0 -275
  144. package/plugins/draw-ml/src/modes/editVertexMode.js +0 -426
  145. package/plugins/draw-ml/src/utils.js +0 -102
  146. package/plugins/frame/dist/esm/im-frame-plugin.js +0 -1
  147. package/plugins/frame/dist/esm/index.js +0 -2
  148. package/plugins/frame/dist/umd/im-frame-plugin.js +0 -1
  149. package/plugins/frame/dist/umd/index.js +0 -2
  150. package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +0 -1
  151. package/plugins/map-styles/dist/esm/index.js +0 -2
  152. package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +0 -1
  153. package/plugins/map-styles/dist/umd/index.js +0 -2
  154. package/plugins/scale-bar/dist/esm/im-scale-bar-plugin.js +0 -1
  155. package/plugins/scale-bar/dist/esm/index.js +0 -2
  156. package/plugins/scale-bar/dist/umd/im-scale-bar-plugin.js +0 -1
  157. package/plugins/scale-bar/dist/umd/index.js +0 -2
  158. package/plugins/use-location/dist/esm/im-use-location-plugin.js +0 -1
  159. package/plugins/use-location/dist/esm/index.js +0 -2
  160. package/plugins/use-location/dist/umd/im-use-location-plugin.js +0 -1
  161. package/plugins/use-location/dist/umd/index.js +0 -2
  162. package/providers/open-names/dist/esm/im-reverse-geocode.js +0 -2
  163. package/providers/open-names/dist/esm/index.js +0 -2
  164. package/providers/open-names/dist/umd/im-reverse-geocode.js +0 -2
  165. package/providers/open-names/dist/umd/index.js +0 -2
  166. /package/docs/architecture/{ARCHITECTURE_DIAGRAMS.md → architecture-diagrams.md} +0 -0
  167. /package/plugins/{datasets → beta/datasets}/dist/css/index.css +0 -0
  168. /package/plugins/{datasets → beta/datasets}/dist/esm/index.js.LICENSE.txt +0 -0
  169. /package/plugins/{datasets → beta/datasets}/dist/umd/index.js.LICENSE.txt +0 -0
  170. /package/plugins/{datasets → beta/datasets}/src/DatasetsInit.jsx +0 -0
  171. /package/plugins/{datasets → beta/datasets}/src/api/addDataset.js +0 -0
  172. /package/plugins/{datasets → beta/datasets}/src/api/hideDataset.js +0 -0
  173. /package/plugins/{datasets → beta/datasets}/src/api/hideFeatures.js +0 -0
  174. /package/plugins/{datasets → beta/datasets}/src/api/removeDataset.js +0 -0
  175. /package/plugins/{datasets → beta/datasets}/src/api/showDataset.js +0 -0
  176. /package/plugins/{datasets → beta/datasets}/src/api/showFeatures.js +0 -0
  177. /package/plugins/{datasets → beta/datasets}/src/datasets.js +0 -0
  178. /package/plugins/{datasets → beta/datasets}/src/datasets.scss +0 -0
  179. /package/plugins/{datasets → beta/datasets}/src/defaults.js +0 -0
  180. /package/plugins/{datasets → beta/datasets}/src/handleSetMapStyle.js +0 -0
  181. /package/plugins/{datasets → beta/datasets}/src/index.js +0 -0
  182. /package/plugins/{datasets → beta/datasets}/src/panels/Key.module.scss +0 -0
  183. /package/plugins/{datasets → beta/datasets}/src/panels/Layers.jsx +0 -0
  184. /package/plugins/{datasets → beta/datasets}/src/panels/Layers.module.scss +0 -0
  185. /package/plugins/{datasets → beta/datasets}/src/reducer.js +0 -0
  186. /package/plugins/{datasets → beta/datasets}/src/utils/bbox.js +0 -0
  187. /package/plugins/{datasets → beta/datasets}/src/utils/debounce.js +0 -0
  188. /package/plugins/{datasets → beta/datasets}/src/utils/filters.js +0 -0
  189. /package/plugins/{draw-es → beta/draw-es}/src/DrawInit.jsx +0 -0
  190. /package/plugins/{draw-es → beta/draw-es}/src/api/addFeature.js +0 -0
  191. /package/plugins/{draw-es → beta/draw-es}/src/api/deleteFeature.js +0 -0
  192. /package/plugins/{draw-es → beta/draw-es}/src/api/editFeature.js +0 -0
  193. /package/plugins/{draw-es → beta/draw-es}/src/api/newPolygon.js +0 -0
  194. /package/plugins/{draw-es → beta/draw-es}/src/events.js +0 -0
  195. /package/plugins/{draw-es → beta/draw-es}/src/graphic.js +0 -0
  196. /package/plugins/{draw-es → beta/draw-es}/src/index.js +0 -0
  197. /package/plugins/{draw-es → beta/draw-es}/src/manifest.js +0 -0
  198. /package/plugins/{draw-es → beta/draw-es}/src/reducer.js +0 -0
  199. /package/plugins/{draw-es → beta/draw-es}/src/sketchViewModel.js +0 -0
  200. /package/plugins/{draw-ml → beta/draw-ml}/dist/css/index.css +0 -0
  201. /package/plugins/{draw-ml → beta/draw-ml}/dist/esm/index.js.LICENSE.txt +0 -0
  202. /package/plugins/{draw-ml → beta/draw-ml}/dist/umd/index.js.LICENSE.txt +0 -0
  203. /package/plugins/{draw-ml → beta/draw-ml}/src/DrawInit.jsx +0 -0
  204. /package/plugins/{draw-ml → beta/draw-ml}/src/api/addFeature.js +0 -0
  205. /package/plugins/{draw-ml → beta/draw-ml}/src/api/deleteFeature.js +0 -0
  206. /package/plugins/{draw-ml → beta/draw-ml}/src/draw.scss +0 -0
  207. /package/plugins/{draw-ml → beta/draw-ml}/src/index.js +0 -0
  208. /package/plugins/{draw-ml → beta/draw-ml}/src/modes/disabledMode.js +0 -0
  209. /package/plugins/{draw-ml/src → beta/draw-ml/src/utils}/snapHelpers.js +0 -0
  210. /package/plugins/{frame → beta/frame}/dist/css/index.css +0 -0
  211. /package/plugins/{frame → beta/frame}/dist/esm/index.js.LICENSE.txt +0 -0
  212. /package/plugins/{frame → beta/frame}/dist/umd/index.js.LICENSE.txt +0 -0
  213. /package/plugins/{frame → beta/frame}/package.json +0 -0
  214. /package/plugins/{frame → beta/frame}/src/Frame.jsx +0 -0
  215. /package/plugins/{frame → beta/frame}/src/FrameInit.jsx +0 -0
  216. /package/plugins/{frame → beta/frame}/src/api/addFrame.js +0 -0
  217. /package/plugins/{frame → beta/frame}/src/api/editFeature.js +0 -0
  218. /package/plugins/{frame → beta/frame}/src/config.js +0 -0
  219. /package/plugins/{frame → beta/frame}/src/frame.scss +0 -0
  220. /package/plugins/{frame → beta/frame}/src/index.js +0 -0
  221. /package/plugins/{frame → beta/frame}/src/manifest.js +0 -0
  222. /package/plugins/{frame → beta/frame}/src/reducer.js +0 -0
  223. /package/plugins/{frame → beta/frame}/src/utils.js +0 -0
  224. /package/plugins/{map-styles → beta/map-styles}/dist/css/index.css +0 -0
  225. /package/plugins/{map-styles → beta/map-styles}/dist/esm/index.js.LICENSE.txt +0 -0
  226. /package/plugins/{map-styles → beta/map-styles}/dist/umd/index.js.LICENSE.txt +0 -0
  227. /package/plugins/{map-styles → beta/map-styles}/src/MapStylesInit.jsx +0 -0
  228. /package/plugins/{map-styles → beta/map-styles}/src/config.js +0 -0
  229. /package/plugins/{map-styles → beta/map-styles}/src/index.js +0 -0
  230. /package/plugins/{map-styles → beta/map-styles}/src/mapStyles.scss +0 -0
  231. /package/plugins/{scale-bar → beta/scale-bar}/dist/css/index.css +0 -0
  232. /package/plugins/{scale-bar → beta/scale-bar}/dist/esm/index.js.LICENSE.txt +0 -0
  233. /package/plugins/{scale-bar → beta/scale-bar}/dist/umd/index.js.LICENSE.txt +0 -0
  234. /package/plugins/{scale-bar → beta/scale-bar}/package.json +0 -0
  235. /package/plugins/{scale-bar → beta/scale-bar}/src/ScaleBar.jsx +0 -0
  236. /package/plugins/{scale-bar → beta/scale-bar}/src/ScaleBar.test.jsx +0 -0
  237. /package/plugins/{scale-bar → beta/scale-bar}/src/index.js +0 -0
  238. /package/plugins/{scale-bar → beta/scale-bar}/src/index.test.js +0 -0
  239. /package/plugins/{scale-bar → beta/scale-bar}/src/manifest.js +0 -0
  240. /package/plugins/{scale-bar → beta/scale-bar}/src/scaleBar.scss +0 -0
  241. /package/plugins/{scale-bar → beta/scale-bar}/src/utils.js +0 -0
  242. /package/plugins/{scale-bar → beta/scale-bar}/src/utils.test.js +0 -0
  243. /package/plugins/{use-location → beta/use-location}/dist/esm/index.js.LICENSE.txt +0 -0
  244. /package/plugins/{use-location → beta/use-location}/dist/umd/index.js.LICENSE.txt +0 -0
  245. /package/plugins/{use-location → beta/use-location}/src/UseLocation.jsx +0 -0
  246. /package/plugins/{use-location → beta/use-location}/src/UseLocationInit.jsx +0 -0
  247. /package/plugins/{use-location → beta/use-location}/src/defaults.js +0 -0
  248. /package/plugins/{use-location → beta/use-location}/src/events.js +0 -0
  249. /package/plugins/{use-location → beta/use-location}/src/index.js +0 -0
  250. /package/plugins/{use-location → beta/use-location}/src/manifest.js +0 -0
  251. /package/plugins/{use-location → beta/use-location}/src/reducer.js +0 -0
  252. /package/providers/{esri → beta/esri}/src/appEvents.js +0 -0
  253. /package/providers/{esri → beta/esri}/src/defaults.js +0 -0
  254. /package/providers/{esri → beta/esri}/src/esriProvider.js +0 -0
  255. /package/providers/{esri → beta/esri}/src/esriProvider.scss +0 -0
  256. /package/providers/{esri → beta/esri}/src/index.js +0 -0
  257. /package/providers/{esri → beta/esri}/src/utils/coords.js +0 -0
  258. /package/providers/{esri → beta/esri}/src/utils/detectWebGL.js +0 -0
  259. /package/providers/{esri → beta/esri}/src/utils/esriFixes.js +0 -0
  260. /package/providers/{esri → beta/esri}/src/utils/query.js +0 -0
  261. /package/providers/{esri → beta/esri}/src/utils/spatial.js +0 -0
  262. /package/providers/{open-names → beta/open-names}/dist/esm/im-reverse-geocode.js.LICENSE.txt +0 -0
  263. /package/providers/{open-names → beta/open-names}/dist/esm/index.js.LICENSE.txt +0 -0
  264. /package/providers/{open-names → beta/open-names}/dist/umd/im-reverse-geocode.js.LICENSE.txt +0 -0
  265. /package/providers/{open-names → beta/open-names}/dist/umd/index.js.LICENSE.txt +0 -0
  266. /package/providers/{open-names → beta/open-names}/src/index.js +0 -0
  267. /package/providers/{open-names → beta/open-names}/src/reverseGeocode.js +0 -0
  268. /package/providers/{open-names → beta/open-names}/src/utils/mapToLocationModel.js +0 -0
@@ -1,4 +1,13 @@
1
1
  // src/InteractiveMap/InteractiveMap.js
2
+
3
+ /**
4
+ * @typedef {import('../types.js').ButtonDefinition} ButtonDefinition
5
+ * @typedef {import('../types.js').ControlDefinition} ControlDefinition
6
+ * @typedef {import('../types.js').InteractiveMapConfig} InteractiveMapConfig
7
+ * @typedef {import('../types.js').MarkerOptions} MarkerOptions
8
+ * @typedef {import('../types.js').PanelDefinition} PanelDefinition
9
+ */
10
+
2
11
  import '../scss/main.scss'
3
12
  import historyManager from './historyManager.js'
4
13
  import { parseDataProperties } from './parseDataProperties.js'
@@ -14,6 +23,10 @@ import { createReverseGeocode } from '../services/reverseGeocode.js'
14
23
  import { EVENTS as events } from '../config/events.js'
15
24
  import { createEventBus } from '../services/eventBus.js'
16
25
 
26
+ /**
27
+ * Main entry point for the Interactive Map component.
28
+ * Handles initialization, lifecycle, and public API methods.
29
+ */
17
30
  export default class InteractiveMap {
18
31
  _openButton = null
19
32
  _root = null // keep react root internally
@@ -21,6 +34,12 @@ export default class InteractiveMap {
21
34
  _interfaceDetectorCleanup = null
22
35
  _hybridBehaviourCleanup = null
23
36
 
37
+ /**
38
+ * Create a new InteractiveMap instance.
39
+ *
40
+ * @param {string} id - The DOM element ID to mount the map into.
41
+ * @param {Partial<InteractiveMapConfig>} [props={}] - Configuration options.
42
+ */
24
43
  constructor (id, props = {}) {
25
44
  this.id = id
26
45
  this.rootEl = document.getElementById(id)
@@ -62,7 +81,6 @@ export default class InteractiveMap {
62
81
  })
63
82
  }
64
83
 
65
- // Private methods
66
84
  _initialize () {
67
85
  if (['buttonFirst', 'hybrid'].includes(this.config.behaviour)) {
68
86
  this._openButton = createButton(this.config, this.rootEl, (e) => {
@@ -93,7 +111,12 @@ export default class InteractiveMap {
93
111
  history.replaceState(history.state, '', newUrl)
94
112
  }
95
113
 
96
- // Public methods
114
+ /**
115
+ * Load and initialize the map application.
116
+ *
117
+ * @internal Not intended for end-user use.
118
+ * @returns {Promise<void>}
119
+ */
97
120
  async loadApp () {
98
121
  if (this._openButton) {
99
122
  this._openButton.style.display = 'none'
@@ -146,6 +169,11 @@ export default class InteractiveMap {
146
169
  }
147
170
  }
148
171
 
172
+ /**
173
+ * Remove the map application and restore the initial state.
174
+ *
175
+ * @internal Not intended for end-user use.
176
+ */
149
177
  removeApp () {
150
178
  if (this._root && typeof this.unmount === 'function') {
151
179
  this.unmount()
@@ -162,6 +190,11 @@ export default class InteractiveMap {
162
190
  this.eventBus.emit(events.MAP_DESTROY, { mapId: this.id })
163
191
  }
164
192
 
193
+ /**
194
+ * Destroy the map instance and clean up all resources.
195
+ *
196
+ * @internal Not intended for end-user use.
197
+ */
165
198
  destroy () {
166
199
  this.removeApp()
167
200
  this._breakpointDetector?.destroy()
@@ -171,54 +204,129 @@ export default class InteractiveMap {
171
204
  this.eventBus.destroy()
172
205
  }
173
206
 
174
- // API - EventBus methods
207
+ /**
208
+ * Subscribe to an event.
209
+ *
210
+ * @param {string} event - Event name.
211
+ * @param {Function} callback - Event handler.
212
+ */
175
213
  on (...args) {
176
214
  this.eventBus.on(...args)
177
215
  }
178
216
 
217
+ /**
218
+ * Unsubscribe from an event.
219
+ *
220
+ * @param {string} event - Event name.
221
+ * @param {Function} callback - Event handler to remove.
222
+ */
179
223
  off (...args) {
180
224
  this.eventBus.off(...args)
181
225
  }
182
226
 
227
+ /**
228
+ * Emit an event.
229
+ *
230
+ * @param {string} event - Event name.
231
+ * @param {any} [data] - Event data.
232
+ */
183
233
  emit (...args) {
184
234
  this.eventBus.emit(...args)
185
235
  }
186
236
 
187
- // API - location markers
237
+ /**
238
+ * Add a marker to the map.
239
+ *
240
+ * @param {string} id - Unique marker identifier.
241
+ * @param {[number, number]} coords - Coordinates [lng, lat] or [easting, northing] depending on crs.
242
+ * @param {MarkerOptions} [options] - Optional marker appearance options.
243
+ */
188
244
  addMarker (id, coords, options) {
189
245
  this.eventBus.emit(events.APP_ADD_MARKER, { id, coords, options })
190
246
  }
191
247
 
248
+ /**
249
+ * Remove a marker from the map.
250
+ *
251
+ * @param {string} id - Marker identifier to remove.
252
+ */
192
253
  removeMarker (id) {
193
254
  this.eventBus.emit(events.APP_REMOVE_MARKER, id)
194
255
  }
195
256
 
196
- // API - change app mode
257
+ /**
258
+ * Set the application mode.
259
+ *
260
+ * @param {string} mode - Mode identifier.
261
+ */
197
262
  setMode (mode) {
198
263
  this.eventBus.emit(events.APP_SET_MODE, mode)
199
264
  }
200
265
 
201
- // Interface API add button/panel/control, remove panel
266
+ /**
267
+ * Add a button to the UI.
268
+ *
269
+ * @param {string} id - Unique button identifier.
270
+ * @param {ButtonDefinition} config - Button configuration.
271
+ */
202
272
  addButton (id, config) {
203
273
  this.eventBus.emit(events.APP_ADD_BUTTON, { id, config })
204
274
  }
205
275
 
276
+ /**
277
+ * Set or toggle a button state.
278
+ *
279
+ * @param {string} id - Button identifier.
280
+ * @param {'hidden'|'pressed'|'disabled'} prop - The button state to change.
281
+ * @param {boolean} [value] - Optional boolean. If provided, sets state explicitly; otherwise toggles.
282
+ */
283
+ toggleButtonState (id, prop, value) {
284
+ this.eventBus.emit(events.APP_TOGGLE_BUTTON_STATE, { id, prop, value })
285
+ }
286
+
287
+ /**
288
+ * Add a panel to the UI.
289
+ *
290
+ * @param {string} id - Unique panel identifier.
291
+ * @param {PanelDefinition} config - Panel configuration.
292
+ */
206
293
  addPanel (id, config) {
207
294
  this.eventBus.emit(events.APP_ADD_PANEL, { id, config })
208
295
  }
209
296
 
297
+ /**
298
+ * Remove a panel from the UI.
299
+ *
300
+ * @param {string} id - Panel identifier to remove.
301
+ */
210
302
  removePanel (id) {
211
303
  this.eventBus.emit(events.APP_REMOVE_PANEL, id)
212
304
  }
213
305
 
306
+ /**
307
+ * Show a panel.
308
+ *
309
+ * @param {string} id - Panel identifier to show.
310
+ */
214
311
  showPanel (id) {
215
312
  this.eventBus.emit(events.APP_SHOW_PANEL, id)
216
313
  }
217
314
 
315
+ /**
316
+ * Hide a panel.
317
+ *
318
+ * @param {string} id - Panel identifier to hide.
319
+ */
218
320
  hidePanel (id) {
219
321
  this.eventBus.emit(events.APP_HIDE_PANEL, id)
220
322
  }
221
323
 
324
+ /**
325
+ * Add a custom control to the UI.
326
+ *
327
+ * @param {string} id - Unique control identifier.
328
+ * @param {ControlDefinition} config - Control configuration.
329
+ */
222
330
  addControl (id, config) {
223
331
  this.eventBus.emit(events.APP_ADD_CONTROL, { id, config })
224
332
  }
@@ -1,32 +1,41 @@
1
+ /**
2
+ * Default configuration options for InteractiveMap.
3
+ *
4
+ * These values are used when no corresponding option is provided by the consumer.
5
+ * See {@link InteractiveMapConfig} in types.js for full property documentation.
6
+ *
7
+ * @type {Partial<import('../types.js').InteractiveMapConfig>}
8
+ */
1
9
  const defaults = {
2
- mapViewParamKey: 'mv',
3
- behaviour: 'buttonFirst',
4
- backgroundColor: 'var(--background-color)',
5
- maxMobileWidth: 640,
6
- minDesktopWidth: 835,
7
- hybridWidth: null, // Defaults to maxMobileWidth if not set
8
- containerHeight: '600px',
9
- mapSize: 'small',
10
10
  appColorScheme: 'light',
11
11
  autoColorScheme: false,
12
- mapLabel: 'Interactive map',
13
- buttonText: 'Map view',
12
+ backgroundColor: 'var(--background-color)',
13
+ behaviour: 'buttonFirst',
14
14
  buttonClass: 'im-c-open-map-button',
15
+ buttonText: 'Map view',
16
+ containerHeight: '600px',
15
17
  deviceNotSupportedText: 'Your device is not supported. A map is available with a more up-to-date browser or device.',
18
+ enableFullscreen: false,
19
+ enableZoomControls: false,
16
20
  genericErrorText: 'There was a problem loading the map. Please try again later.',
21
+ hasExitButton: false,
22
+ hybridWidth: null, // Defaults to maxMobileWidth if not set
17
23
  keyboardHintText: '<span class="im-u-visually-hidden">Press </span><kbd>Alt</kbd> + <kbd>K</kbd> <span class="im-u-visually-hidden">to view </span>keyboard shortcuts',
18
- pageTitle: 'Map view',
19
- zoomDelta: 1,
20
- nudgeZoomDelta: 0.1,
21
- panDelta: 100,
22
- nudgePanDelta: 5,
24
+ mapLabel: 'Interactive map',
23
25
  mapProvider: null,
24
- reverseGeocode: null,
25
- markerShape: 'pin',
26
+ mapSize: 'small',
27
+ mapViewParamKey: 'mv',
28
+ maxMobileWidth: 640,
29
+ minDesktopWidth: 835,
26
30
  markerColor: '#ff0000',
27
- enableFullscreen: false,
28
- enableZoomControls: false,
29
- readMapText: true
31
+ markerShape: 'pin',
32
+ nudgePanDelta: 5,
33
+ nudgeZoomDelta: 0.1,
34
+ panDelta: 100,
35
+ pageTitle: 'Map view',
36
+ readMapText: false,
37
+ reverseGeocodeProvider: null,
38
+ zoomDelta: 1
30
39
  }
31
40
 
32
41
  export default defaults
@@ -1,39 +1,145 @@
1
+ /**
2
+ * Event constants for the Interactive Map event bus.
3
+ *
4
+ * Events are grouped into:
5
+ * - **App commands**: Internal use, but may be used by plugin authors.
6
+ * - **App responses**: Subscribe to these with `on()` to react to app state changes.
7
+ * - **Map commands**: Internal use, but may be used by plugin authors.
8
+ * - **Map responses**: Subscribe to these with `on()` to react to map state changes.
9
+ *
10
+ * @example
11
+ * // Subscribe to app ready event
12
+ * map.on(EVENTS.APP_READY, () => {
13
+ * console.log('Map is ready!')
14
+ * })
15
+ *
16
+ * // Subscribe to panel events
17
+ * map.on(EVENTS.APP_PANEL_OPENED, ({ panelId }) => {
18
+ * console.log('Panel opened:', panelId)
19
+ * })
20
+ */
1
21
  export const EVENTS = {
2
- // App commands
22
+ // ============================================
23
+ // App commands (internal / plugin authors)
24
+ // ============================================
25
+
26
+ /** @internal Add a marker. Payload: { id, coords, options } */
3
27
  APP_ADD_MARKER: 'app:addmarker',
28
+ /** @internal Remove a marker. Payload: id */
4
29
  APP_REMOVE_MARKER: 'app:removemarker',
30
+ /** @internal Set application mode. Payload: mode */
5
31
  APP_SET_MODE: 'app:setmode',
32
+ /** @internal Revert to previous mode. */
6
33
  APP_REVERT_MODE: 'app:revertmode',
34
+ /** @internal Add a button. Payload: { id, config } */
7
35
  APP_ADD_BUTTON: 'app:addbutton',
36
+ /** @internal Set a buttons state. Payload: { id, prop, value? } */
37
+ APP_TOGGLE_BUTTON_STATE: 'app:togglebuttonstate',
38
+ /** @internal Add a panel. Payload: { id, config } */
8
39
  APP_ADD_PANEL: 'app:addpanel',
40
+ /** @internal Remove a panel. Payload: id */
9
41
  APP_REMOVE_PANEL: 'app:removepanel',
42
+ /** @internal Show a panel. Payload: id */
10
43
  APP_SHOW_PANEL: 'app:showpanel',
44
+ /** @internal Hide a panel. Payload: id */
11
45
  APP_HIDE_PANEL: 'app:hidepanel',
46
+ /** @internal Add a control. Payload: { id, config } */
12
47
  APP_ADD_CONTROL: 'app:addcontrol',
13
48
 
14
- // App responses
49
+ // ============================================
50
+ // App responses (end-user / subscribe)
51
+ // ============================================
52
+
53
+ /**
54
+ * Emitted when the app is fully initialized and ready for interaction.
55
+ * Use this to perform actions that require the map to be available.
56
+ *
57
+ * @example
58
+ * map.on(EVENTS.APP_READY, () => {
59
+ * map.addMarker('home', [-0.1276, 51.5074])
60
+ * })
61
+ */
15
62
  APP_READY: 'app:ready',
63
+
64
+ /**
65
+ * Emitted when a panel is opened.
66
+ * Payload: { panelId: string }
67
+ *
68
+ * @example
69
+ * map.on(EVENTS.APP_PANEL_OPENED, ({ panelId }) => {
70
+ * console.log('Panel opened:', panelId)
71
+ * })
72
+ */
16
73
  APP_PANEL_OPENED: 'app:panelopened',
74
+
75
+ /**
76
+ * Emitted when a panel is closed.
77
+ * Payload: { panelId: string }
78
+ *
79
+ * @example
80
+ * map.on(EVENTS.APP_PANEL_CLOSED, ({ panelId }) => {
81
+ * console.log('Panel closed:', panelId)
82
+ * })
83
+ */
17
84
  APP_PANEL_CLOSED: 'app:panelclosed',
18
85
 
19
- // Map commands
86
+ // ============================================
87
+ // Map commands (internal / plugin authors)
88
+ // ============================================
89
+
90
+ /** @internal Set map style. Payload: styleId */
20
91
  MAP_SET_STYLE: 'map:setstyle',
92
+ /** @internal Set map size. Payload: { width, height } */
21
93
  MAP_SET_SIZE: 'map:setsize',
94
+ /** @internal Set pixel ratio. Payload: pixelRatio */
22
95
  MAP_SET_PIXEL_RATIO: 'map:setpixelratio',
23
96
 
24
- // Map responses
97
+ // ============================================
98
+ // Map responses (advanced / subscribe)
99
+ // ============================================
100
+
101
+ /** @internal Emitted when map styles are initialized. */
25
102
  MAP_INIT_MAP_STYLES: 'map:initmapstyles',
103
+
104
+ /** Emitted when the map style changes. Payload: { styleId: string } */
26
105
  MAP_STYLE_CHANGE: 'map:stylechange',
106
+
107
+ /** Emitted when the map style has fully loaded. */
27
108
  MAP_LOADED: 'map:loaded',
109
+
110
+ /** Emitted when the map is ready for interaction. Payload: { map } */
28
111
  MAP_READY: 'map:ready',
112
+
113
+ /** Emitted once after the map first becomes idle following initial load. */
29
114
  MAP_FIRST_IDLE: 'map:firstidle',
115
+
116
+ /** Emitted when map movement starts (pan, zoom, or rotation). */
30
117
  MAP_MOVE_START: 'map:movestart',
118
+
119
+ /** Emitted continuously during map movement. Payload: { center, zoom, bounds, resolution } */
31
120
  MAP_MOVE: 'map:move',
121
+
122
+ /** Emitted when map movement ends. Payload: { center, zoom, bounds, resolution } */
32
123
  MAP_MOVE_END: 'map:moveend',
124
+
125
+ /** Emitted when map state is updated. Payload: { center, zoom, bounds, resolution } */
33
126
  MAP_STATE_UPDATED: 'map:stateupdated',
127
+
128
+ /** Emitted when map data (tiles, features) changes. */
34
129
  MAP_DATA_CHANGE: 'map:datachange',
130
+
131
+ /** Emitted on each map render frame. Use sparingly as this fires frequently. */
35
132
  MAP_RENDER: 'map:render',
133
+
134
+ /**
135
+ * Emitted when the map is clicked.
136
+ * Payload: { coords: [number, number], point: { x, y }, features: any[] }
137
+ */
36
138
  MAP_CLICK: 'map:click',
139
+
140
+ /** Emitted when the user exits the map (e.g., via the close button). */
37
141
  MAP_EXIT: 'map:exit',
142
+
143
+ /** Emitted when the map is destroyed. Payload: { mapId: string } */
38
144
  MAP_DESTROY: 'map:destroy'
39
145
  }
package/src/index.js CHANGED
@@ -1,3 +1,6 @@
1
- import InteractiveMap from './InteractiveMap/InteractiveMap.js'
1
+ // Export the main class
2
+ export { default } from './InteractiveMap/InteractiveMap.js'
3
+ export { default as InteractiveMap } from './InteractiveMap/InteractiveMap.js'
2
4
 
3
- export default InteractiveMap
5
+ // Export events
6
+ export { EVENTS } from './config/events.js'
@@ -136,10 +136,26 @@
136
136
 
137
137
  // Apply clip-path only to ::before for the shadow
138
138
  &::before {
139
- $clip-top: if($has-bottom, 0, -20px);
140
- $clip-right: if($has-left, 0, -20px);
141
- $clip-bottom: if($has-top, 0, -20px);
142
- $clip-left: if($has-right, 0, -20px);
139
+ $clip-top: -20px;
140
+ $clip-right: -20px;
141
+ $clip-bottom: -20px;
142
+ $clip-left: -20px;
143
+
144
+ @if $has-bottom {
145
+ $clip-top: 0;
146
+ }
147
+
148
+ @if $has-left {
149
+ $clip-right: 0;
150
+ }
151
+
152
+ @if $has-top {
153
+ $clip-bottom: 0;
154
+ }
155
+
156
+ @if $has-right {
157
+ $clip-left: 0;
158
+ }
143
159
 
144
160
  clip-path: inset(#{$clip-top} #{$clip-right} #{$clip-bottom} #{$clip-left});
145
161
  }