@defra/interactive-map 0.0.39-alpha → 0.0.41-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 (387) hide show
  1. package/dist/css/index.css +1 -1
  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/control-definition.md +9 -1
  7. package/docs/api/slots.md +26 -5
  8. package/docs/api.md +4 -4
  9. package/docs/assets/images/slot-map.svg +61 -262
  10. package/docs/examples/draw-tools.mdx +3 -3
  11. package/docs/plugins/draw.md +80 -17
  12. package/docs/plugins/search.md +1 -1
  13. package/govuk-prototype-kit.config.json +2 -0
  14. package/jest.setup.js +5 -0
  15. package/package.json +9 -1
  16. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  17. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  18. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  19. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  20. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  21. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  22. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  23. package/plugins/datasets/dist/css/index.css +1 -1
  24. package/plugins/datasets/dist/esm/esriLayerAdapter.js +1 -1
  25. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  26. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  27. package/plugins/datasets/dist/umd/im-datasets-esri-adapter.js +1 -1
  28. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  29. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  30. package/plugins/datasets/dist/umd/index.js +1 -1
  31. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +2 -3
  32. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.test.js +175 -0
  33. package/plugins/datasets/src/adapters/esri/registry/esriDataset.js +1 -1
  34. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +55 -0
  35. package/plugins/datasets/src/adapters/loadLayerAdapter.js +1 -1
  36. package/plugins/datasets/src/adapters/loadLayerAdapter.test.js +61 -0
  37. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +1 -3
  38. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +17 -3
  39. package/plugins/datasets/src/api/setOpacity.test.js +9 -0
  40. package/plugins/datasets/src/components/LayersMenu/LayersMenu.jsx +10 -25
  41. package/plugins/datasets/src/components/LayersMenu/LayersMenu.test.jsx +0 -42
  42. package/plugins/datasets/src/datasets.scss +0 -1
  43. package/plugins/datasets/src/fetch/createDynamicSource.js +135 -129
  44. package/plugins/datasets/src/fetch/createDynamicSource.test.js +318 -0
  45. package/plugins/datasets/src/fetch/fetchGeoJSON.test.js +83 -0
  46. package/plugins/datasets/src/index.test.js +36 -0
  47. package/plugins/datasets/src/initialise/DatasetsInit.jsx +17 -7
  48. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +262 -0
  49. package/plugins/datasets/src/initialise/initialiseDatasets.js +16 -5
  50. package/plugins/datasets/src/initialise/initialiseDatasets.test.js +42 -0
  51. package/plugins/datasets/src/manifest.js +0 -38
  52. package/plugins/datasets/src/manifest.test.js +49 -0
  53. package/plugins/datasets/src/reducers/datasetsToMenu.test.js +54 -1
  54. package/plugins/datasets/src/reducers/pluginState.js +3 -16
  55. package/plugins/datasets/src/reducers/pluginState.test.js +23 -0
  56. package/plugins/datasets/src/registry/dataset.js +15 -4
  57. package/plugins/datasets/src/registry/dataset.test.js +61 -0
  58. package/plugins/datasets/src/registry/datasetRegistry.js +12 -9
  59. package/plugins/datasets/src/registry/datasetRegistry.test.js +17 -5
  60. package/plugins/datasets/src/registry/globalDataset.js +0 -3
  61. package/plugins/datasets/src/registry/isVisibleWhen.js +6 -3
  62. package/plugins/datasets/src/registry/isVisibleWhen.test.js +11 -1
  63. package/plugins/datasets/src/utils/bbox.test.js +125 -0
  64. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  65. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  66. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  67. package/plugins/draw/dist/esm/index.js +1 -1
  68. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +2 -1
  69. package/plugins/draw/dist/umd/im-draw-ml-adapter.js.LICENSE.txt +1 -0
  70. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  71. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  72. package/plugins/draw/dist/umd/index.js +1 -1
  73. package/plugins/draw/src/DrawInit.jsx +12 -4
  74. package/plugins/draw/src/DrawInit.test.jsx +51 -10
  75. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +92 -12
  76. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +246 -4
  77. package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +109 -14
  78. package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +174 -11
  79. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +12 -0
  80. package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.js +9 -1
  81. package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.test.js +24 -3
  82. package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.js +1 -1
  83. package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.test.js +1 -1
  84. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +194 -0
  85. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +457 -0
  86. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/__helpers__/harness.js +102 -0
  87. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/keyboardHandlers.js +82 -0
  88. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/keyboardHandlers.test.js +83 -0
  89. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointOperations.js +55 -0
  90. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointOperations.test.js +62 -0
  91. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +138 -0
  92. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +197 -0
  93. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/touchHandlers.js +92 -0
  94. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/touchHandlers.test.js +101 -0
  95. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +46 -0
  96. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +42 -0
  97. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +151 -0
  98. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.test.js +156 -0
  99. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.js +5 -28
  100. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.test.js +24 -39
  101. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +4 -5
  102. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.js +20 -23
  103. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.test.js +25 -5
  104. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +6 -36
  105. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +7 -49
  106. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.js +4 -54
  107. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.test.js +8 -33
  108. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +29 -72
  109. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.test.js +11 -4
  110. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +158 -0
  111. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +314 -0
  112. package/plugins/draw/src/adapters/maplibre/snap/prototypePatches.js +6 -1
  113. package/plugins/draw/src/adapters/maplibre/snap/prototypePatches.test.js +21 -0
  114. package/plugins/draw/src/adapters/maplibre/snap/snapInstance.js +6 -2
  115. package/plugins/draw/src/adapters/maplibre/snap/snapInstance.test.js +12 -0
  116. package/plugins/draw/src/adapters/maplibre/styles.js +38 -11
  117. package/plugins/draw/src/adapters/maplibre/styles.test.js +39 -0
  118. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +79 -0
  119. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.test.js +135 -0
  120. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +42 -0
  121. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +85 -0
  122. package/plugins/draw/src/adapters/maplibre/utils/keyboardShortcuts.js +34 -0
  123. package/plugins/draw/src/adapters/maplibre/utils/keyboardShortcuts.test.js +78 -0
  124. package/plugins/draw/src/adapters/maplibre/utils/snapHelpers.js +16 -3
  125. package/plugins/draw/src/adapters/maplibre/utils/snapHelpers.test.js +21 -3
  126. package/plugins/draw/src/adapters/maplibre/utils/snapMovement.js +59 -0
  127. package/plugins/draw/src/adapters/maplibre/utils/snapMovement.test.js +73 -0
  128. package/plugins/draw/src/adapters/maplibre/utils/touchDragMath.js +33 -0
  129. package/plugins/draw/src/adapters/maplibre/utils/touchDragMath.test.js +70 -0
  130. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +27 -2
  131. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +93 -0
  132. package/plugins/draw/src/adapters/openlayers/__helpers__/harness.js +9 -0
  133. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +19 -1
  134. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +34 -1
  135. package/plugins/draw/src/adapters/openlayers/core/styles.js +73 -1
  136. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +122 -3
  137. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +1 -0
  138. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +27 -1
  139. package/plugins/draw/src/adapters/openlayers/draw/drawInput.js +24 -4
  140. package/plugins/draw/src/adapters/openlayers/draw/drawInput.test.js +47 -3
  141. package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +1 -1
  142. package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +32 -1
  143. package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.js +9 -5
  144. package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.test.js +34 -1
  145. package/plugins/draw/src/adapters/openlayers/edit/modifyInteraction.js +5 -3
  146. package/plugins/draw/src/adapters/openlayers/edit/modifyInteraction.test.js +11 -0
  147. package/plugins/draw/src/adapters/openlayers/edit/nudge.js +12 -5
  148. package/plugins/draw/src/adapters/openlayers/edit/nudge.test.js +26 -3
  149. package/plugins/draw/src/adapters/openlayers/edit/touchHandler.js +18 -13
  150. package/plugins/draw/src/adapters/openlayers/edit/touchHandler.test.js +46 -1
  151. package/plugins/draw/src/adapters/openlayers/olDraw.js +11 -4
  152. package/plugins/draw/src/adapters/openlayers/olDraw.test.js +48 -6
  153. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +156 -0
  154. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +246 -0
  155. package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +267 -0
  156. package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +327 -0
  157. package/plugins/draw/src/adapters/openlayers/point/pointDragInteraction.js +71 -0
  158. package/plugins/draw/src/adapters/openlayers/point/pointOps.js +34 -0
  159. package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +32 -0
  160. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +82 -0
  161. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +107 -0
  162. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +83 -0
  163. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +214 -0
  164. package/plugins/draw/src/adapters/openlayers/snap/snapIndicator.js +3 -1
  165. package/plugins/draw/src/adapters/openlayers/snap/snapInteraction.js +6 -9
  166. package/plugins/draw/src/adapters/openlayers/snap/snapInteraction.test.js +15 -4
  167. package/plugins/draw/src/adapters/openlayers/utils/olCoords.js +1 -1
  168. package/plugins/draw/src/api/addFeature.js +16 -1
  169. package/plugins/draw/src/api/addFeature.test.js +62 -5
  170. package/plugins/draw/src/api/editFeature.js +7 -4
  171. package/plugins/draw/src/api/editFeature.test.js +16 -0
  172. package/plugins/draw/src/api/newPoint.js +42 -0
  173. package/plugins/draw/src/api/newPoint.test.js +117 -0
  174. package/plugins/draw/src/api/setStyle.js +43 -0
  175. package/plugins/draw/src/api/setStyle.test.js +75 -0
  176. package/plugins/draw/src/events.js +21 -14
  177. package/plugins/draw/src/events.test.js +15 -1
  178. package/plugins/draw/src/manifest.js +18 -6
  179. package/plugins/draw/src/manifest.test.js +32 -1
  180. package/plugins/draw/src/reducer.test.js +7 -0
  181. package/plugins/draw/src/utils/stripInternalProperties.js +19 -0
  182. package/plugins/draw/src/utils/stripInternalProperties.test.js +50 -0
  183. package/plugins/draw/src/utils/symbolKeys.js +5 -0
  184. package/plugins/draw/src/validation/liveDrawChecks.test.js +54 -0
  185. package/plugins/draw/src/validation/liveStroke.test.js +64 -1
  186. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  187. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  188. package/plugins/interact/dist/umd/index.js +1 -1
  189. package/plugins/interact/src/hooks/useCrossHairVisibility.js +12 -4
  190. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +88 -1
  191. package/plugins/interact/src/hooks/useHighlightSync.js +33 -12
  192. package/plugins/interact/src/hooks/useHighlightSync.test.js +96 -25
  193. package/plugins/interact/src/utils/featureQueries.js +18 -0
  194. package/plugins/interact/src/utils/featureQueries.test.js +15 -0
  195. package/plugins/interact/src/utils/spatial.js +9 -3
  196. package/plugins/interact/src/utils/spatial.test.js +12 -1
  197. package/plugins/map-key/dist/css/index.css +62 -0
  198. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -0
  199. package/plugins/map-key/dist/esm/index.js +1 -0
  200. package/plugins/map-key/dist/umd/im-map-key-plugin.js +2 -0
  201. package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +1 -0
  202. package/plugins/map-key/dist/umd/index.js +2 -0
  203. package/plugins/map-key/dist/umd/index.js.LICENSE.txt +1 -0
  204. package/plugins/map-key/package.json +28 -0
  205. package/plugins/map-key/src/components/Key/EmptyKey.jsx +7 -0
  206. package/plugins/{datasets → map-key}/src/components/Key/EmptyKey.test.jsx +2 -2
  207. package/plugins/map-key/src/components/Key/Key.jsx +41 -0
  208. package/plugins/{datasets → map-key}/src/components/Key/Key.module.scss +15 -14
  209. package/plugins/map-key/src/components/Key/Key.test.jsx +73 -0
  210. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +16 -0
  211. package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +53 -0
  212. package/plugins/map-key/src/components/Key/KeyItem.jsx +29 -0
  213. package/plugins/map-key/src/components/Key/KeyItem.test.jsx +67 -0
  214. package/plugins/map-key/src/components/Key/KeySvg.jsx +42 -0
  215. package/plugins/{datasets → map-key}/src/components/Key/KeySvg.test.jsx +14 -12
  216. package/plugins/map-key/src/components/Key/KeySvgLine.jsx +28 -0
  217. package/plugins/{datasets → map-key}/src/components/Key/KeySvgLine.test.jsx +1 -1
  218. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +23 -0
  219. package/plugins/{datasets → map-key}/src/components/Key/KeySvgPattern.test.jsx +2 -2
  220. package/plugins/map-key/src/components/Key/KeySvgRect.jsx +33 -0
  221. package/plugins/{datasets → map-key}/src/components/Key/KeySvgRect.test.jsx +1 -1
  222. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +27 -0
  223. package/plugins/{datasets → map-key}/src/components/Key/KeySvgSymbol.test.jsx +5 -6
  224. package/plugins/map-key/src/components/Key/MapKey.jsx +50 -0
  225. package/plugins/map-key/src/components/Key/MapKey.test.jsx +130 -0
  226. package/plugins/{datasets → map-key}/src/components/Key/svgProperties.js +2 -2
  227. package/plugins/{datasets → map-key}/src/components/Key/svgProperties.test.js +2 -2
  228. package/plugins/map-key/src/index.js +13 -0
  229. package/plugins/map-key/src/index.test.js +31 -0
  230. package/plugins/map-key/src/initialise/MapKeyInit.jsx +15 -0
  231. package/plugins/map-key/src/initialise/MapKeyInit.test.jsx +39 -0
  232. package/plugins/map-key/src/manifest.js +30 -0
  233. package/plugins/map-key/src/manifest.test.js +63 -0
  234. package/plugins/map-key/src/mapKey.scss +4 -0
  235. package/plugins/map-key/src/registry/getDatasetRegistry.js +6 -0
  236. package/plugins/map-key/src/registry/getDatasetRegistry.test.js +23 -0
  237. package/plugins/map-key/src/registry/index.js +3 -0
  238. package/plugins/map-key/src/registry/index.test.js +15 -0
  239. package/plugins/menu/dist/css/index.css +80 -0
  240. package/plugins/menu/dist/esm/im-menu-plugin.js +1 -0
  241. package/plugins/menu/dist/esm/index.js +1 -0
  242. package/plugins/menu/dist/umd/im-menu-plugin.js +1 -0
  243. package/plugins/menu/dist/umd/index.js +2 -0
  244. package/plugins/menu/dist/umd/index.js.LICENSE.txt +1 -0
  245. package/plugins/menu/package.json +28 -0
  246. package/plugins/menu/src/components/Menu/CheckboxGroupWrapper.jsx +21 -0
  247. package/plugins/menu/src/components/Menu/GroupLegend.jsx +17 -0
  248. package/plugins/menu/src/components/Menu/GroupLegend.test.jsx +68 -0
  249. package/plugins/menu/src/components/Menu/Menu.jsx +19 -0
  250. package/plugins/menu/src/components/Menu/Menu.module.scss +90 -0
  251. package/plugins/menu/src/components/Menu/Menu.test.jsx +161 -0
  252. package/plugins/menu/src/components/Menu/MenuCheckbox.jsx +35 -0
  253. package/plugins/menu/src/components/Menu/MenuCheckbox.test.jsx +93 -0
  254. package/plugins/menu/src/components/Menu/MenuGroup.jsx +11 -0
  255. package/plugins/{datasets/src/components/LayersMenu/LayersMenuRadio.jsx → menu/src/components/Menu/MenuRadio.jsx} +6 -4
  256. package/plugins/{datasets/src/components/LayersMenu/LayersMenuRadio.test.jsx → menu/src/components/Menu/MenuRadio.test.jsx} +18 -18
  257. package/plugins/menu/src/components/Menu/RadioGroupWrapper.jsx +32 -0
  258. package/plugins/{datasets/src/components/LayersMenu/LayersRadioGroupWrapper.test.jsx → menu/src/components/Menu/RadioGroupWrapper.test.jsx} +21 -21
  259. package/plugins/menu/src/components/Menu/useIdPrefix.jsx +4 -0
  260. package/plugins/menu/src/index.js +13 -0
  261. package/plugins/menu/src/index.test.js +31 -0
  262. package/plugins/menu/src/initialise/MenuInit.jsx +24 -0
  263. package/plugins/menu/src/initialise/MenuInit.test.jsx +50 -0
  264. package/plugins/menu/src/initialise/createMenu.js +10 -0
  265. package/plugins/menu/src/initialise/createMenu.test.js +37 -0
  266. package/plugins/menu/src/manifest.js +35 -0
  267. package/plugins/menu/src/manifest.test.js +63 -0
  268. package/plugins/menu/src/menu.scss +4 -0
  269. package/plugins/menu/src/reducers/menuStateReducer.test.js +38 -0
  270. package/plugins/menu/src/reducers/pluginState.js +35 -0
  271. package/plugins/menu/src/reducers/pluginState.test.js +57 -0
  272. package/plugins/menu/src/registry/getDatasetRegistry.js +9 -0
  273. package/plugins/menu/src/registry/getDatasetRegistry.test.js +23 -0
  274. package/plugins/menu/src/registry/index.js +3 -0
  275. package/plugins/menu/src/registry/index.test.js +15 -0
  276. package/plugins/menu/src/registry/isVisibleWhen.js +43 -0
  277. package/plugins/menu/src/registry/isVisibleWhen.test.js +48 -0
  278. package/plugins/search/dist/css/index.css +1 -1
  279. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  280. package/plugins/search/dist/esm/index.js +1 -1
  281. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  282. package/plugins/search/dist/umd/index.js +1 -1
  283. package/plugins/search/src/Search.jsx +7 -5
  284. package/plugins/search/src/components/Form/Form.module.scss +9 -20
  285. package/plugins/search/src/index.js +0 -1
  286. package/plugins/search/src/index.test.js +2 -4
  287. package/plugins/search/src/manifest.js +1 -1
  288. package/plugins/search/src/search.scss +17 -16
  289. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  290. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  291. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  292. package/providers/beta/openlayers/src/openlayersProvider.js +4 -1
  293. package/providers/beta/openlayers/src/openlayersProvider.test.js +18 -0
  294. package/providers/beta/openlayers/src/utils/highlightFeatures.js +52 -5
  295. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +176 -0
  296. package/providers/beta/openlayers/src/utils/symbolImages.js +40 -0
  297. package/providers/beta/openlayers/src/utils/symbolImages.test.js +58 -0
  298. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  299. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  300. package/providers/maplibre/dist/umd/index.js +1 -1
  301. package/providers/maplibre/src/utils/drawLayerBuckets.js +14 -0
  302. package/providers/maplibre/src/utils/drawLayerBuckets.test.js +18 -0
  303. package/providers/maplibre/src/utils/highlightFeatures.js +80 -55
  304. package/providers/maplibre/src/utils/highlightFeatures.test.js +156 -17
  305. package/providers/maplibre/src/utils/hoverCursor.js +30 -14
  306. package/providers/maplibre/src/utils/hoverCursor.test.js +35 -0
  307. package/providers/maplibre/src/utils/patternImages.js +1 -1
  308. package/providers/maplibre/src/utils/symbolImages.js +41 -3
  309. package/providers/maplibre/src/utils/symbolImages.test.js +40 -6
  310. package/rollup.esm.mjs +11 -1
  311. package/sonar-project.properties +7 -1
  312. package/src/App/components/Actions/Actions.test.jsx +47 -0
  313. package/src/App/components/Attributions/Attributions.module.scss +10 -0
  314. package/src/App/components/Hints/Hints.jsx +7 -2
  315. package/src/App/components/Hints/Hints.test.jsx +13 -0
  316. package/src/App/components/KeyboardHelp/KeyboardHelp.jsx +2 -3
  317. package/src/App/components/KeyboardHelp/KeyboardHelp.test.jsx +3 -6
  318. package/src/App/components/{MoveControl/MoveControl.jsx → MoveControls/MoveControls.jsx} +10 -10
  319. package/src/App/components/{MoveControl/MoveControl.module.scss → MoveControls/MoveControls.module.scss} +60 -29
  320. package/src/App/components/{MoveControl/MoveControl.test.jsx → MoveControls/MoveControls.test.jsx} +48 -48
  321. package/src/App/components/Panel/Panel.jsx +18 -3
  322. package/src/App/components/Panel/Panel.module.scss +18 -8
  323. package/src/App/components/Panel/Panel.test.jsx +34 -0
  324. package/src/App/components/Tooltip/Tooltip.test.jsx +12 -14
  325. package/src/App/components/Viewport/Viewport.jsx +9 -1
  326. package/src/App/components/Viewport/Viewport.test.jsx +11 -0
  327. package/src/App/hooks/useFeatureItems.js +16 -7
  328. package/src/App/hooks/useFeatureItems.test.js +57 -0
  329. package/src/App/hooks/useLayoutMeasurements.js +95 -84
  330. package/src/App/hooks/useLayoutMeasurements.test.js +61 -1
  331. package/src/App/initialiseApp.js +11 -8
  332. package/src/App/initialiseApp.test.js +15 -3
  333. package/src/App/layout/Layout.jsx +12 -11
  334. package/src/App/layout/Layout.test.jsx +2 -0
  335. package/src/App/layout/layout.module.scss +31 -17
  336. package/src/App/registry/keyboardShortcutRegistry.js +25 -13
  337. package/src/App/registry/keyboardShortcutRegistry.test.js +49 -32
  338. package/src/App/registry/pluginRegistry.js +2 -3
  339. package/src/App/registry/pluginRegistry.test.js +16 -3
  340. package/src/App/renderer/HtmlElementHost.jsx +18 -5
  341. package/src/App/renderer/HtmlElementHost.test.jsx +54 -0
  342. package/src/App/renderer/mapButtons.js +28 -12
  343. package/src/App/renderer/mapButtons.test.js +17 -4
  344. package/src/App/renderer/mapControls.js +3 -1
  345. package/src/App/renderer/mapControls.test.js +16 -0
  346. package/src/App/renderer/mapPanels.js +44 -9
  347. package/src/App/renderer/mapPanels.test.js +51 -2
  348. package/src/App/renderer/orderItems.js +28 -0
  349. package/src/App/renderer/orderItems.test.js +50 -0
  350. package/src/App/renderer/slotAggregator.js +2 -18
  351. package/src/App/renderer/slotHelpers.js +3 -1
  352. package/src/App/renderer/slotHelpers.test.js +5 -0
  353. package/src/App/renderer/slots.js +3 -0
  354. package/src/App/store/AppProvider.jsx +4 -2
  355. package/src/App/store/appDispatchMiddleware.js +1 -1
  356. package/src/App/store/appDispatchMiddleware.test.js +8 -0
  357. package/src/InteractiveMap/InteractiveMap.js +8 -2
  358. package/src/InteractiveMap/InteractiveMap.test.js +20 -3
  359. package/src/config/appConfig.js +17 -15
  360. package/src/config/appConfig.test.js +22 -22
  361. package/src/config/defaults.js +3 -1
  362. package/src/config/events.js +2 -0
  363. package/src/config/mergeConfig.js +7 -0
  364. package/src/config/mergeConfig.test.js +20 -0
  365. package/src/scss/main.scss +1 -1
  366. package/src/scss/settings/_colors.scss +1 -0
  367. package/src/scss/settings/_dimensions.scss +2 -3
  368. package/src/scss/settings/_transition.scss +1 -1
  369. package/src/services/eventBus.js +44 -0
  370. package/src/services/eventBus.test.js +83 -0
  371. package/src/services/symbolRegistry.js +1 -1
  372. package/src/test-utils.js +5 -0
  373. package/src/types.js +25 -7
  374. package/webpack.umd.mjs +2 -0
  375. package/plugins/datasets/src/components/Key/EmptyKey.jsx +0 -7
  376. package/plugins/datasets/src/components/Key/Key.jsx +0 -50
  377. package/plugins/datasets/src/components/Key/KeyGroupItem.jsx +0 -18
  378. package/plugins/datasets/src/components/Key/KeyItem.jsx +0 -23
  379. package/plugins/datasets/src/components/Key/KeySvg.jsx +0 -22
  380. package/plugins/datasets/src/components/Key/KeySvgLine.jsx +0 -19
  381. package/plugins/datasets/src/components/Key/KeySvgPattern.jsx +0 -13
  382. package/plugins/datasets/src/components/Key/KeySvgRect.jsx +0 -22
  383. package/plugins/datasets/src/components/Key/KeySvgSymbol.jsx +0 -16
  384. package/plugins/datasets/src/components/LayersMenu/LayersRadioGroupWrapper.jsx +0 -41
  385. /package/plugins/{datasets → menu}/src/reducers/menuStateReducer.js +0 -0
  386. /package/{providers/maplibre/src → src}/utils/rasteriseToImageData.js +0 -0
  387. /package/{providers/maplibre/src → src}/utils/rasteriseToImageData.test.js +0 -0
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,S as o,C as i,M as a,K as s,s as c,a as l,b as u,d,e as p,r as h,l as f,p as g,f as y,g as m,m as v,h as x,j as _,k as b,n as E,o as S,q as w,t as I,v as O,u as P,L as M,H as C,A as T}from"./im-draw-plugin.js";const L={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},A={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},k={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},V={POLYGON:"polygon",LINE:"line_string",POINT:"point"},F={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},N={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},D={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},j={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},R={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},U={ACTIVE:"true",INACTIVE:"false"},B=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var G=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:U,classes:L,cursors:k,events:D,geojsonTypes:F,interactions:B,meta:R,modes:N,sources:A,types:V,updateActions:j});function H(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function Y(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function X(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===U.ACTIVE&&e.featureTarget.properties.meta===R.FEATURE))}function J(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===U.INACTIVE&&e.featureTarget.properties.meta===R.FEATURE))}function $(e){return void 0===e.featureTarget}function K(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===R.FEATURE)}function q(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===R.VERTEX)}function z(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function Z(e){return"Escape"===e.key||27===e.keyCode}function W(e){return"Enter"===e.key||13===e.keyCode}function Q(e){return"Backspace"===e.key||8===e.keyCode}function ee(e){return"Delete"===e.key||46===e.keyCode}function te(e){return"1"===e.key||49===e.keyCode}function re(e){return"2"===e.key||50===e.keyCode}function ne(e){return"3"===e.key||51===e.keyCode}function oe(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var ie=Object.freeze({__proto__:null,isActiveFeature:X,isBackspaceKey:Q,isDeleteKey:ee,isDigit1Key:te,isDigit2Key:re,isDigit3Key:ne,isDigitKey:oe,isEnterKey:W,isEscapeKey:Z,isFeature:K,isInactiveFeature:J,isOfMetaType:H,isShiftDown:z,isShiftMousedown:Y,isTrue:function(){return!0},isVertex:q,noTarget:$});function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function se(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var ce,le,ue={},de={};function pe(){return ce||(ce=1,de.RADIUS=6378137,de.FLATTENING=1/298.257223563,de.POLAR_RADIUS=6356752.3142),de}var he=function(){if(le)return ue;le=1;var e=pe();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(r(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(r(e[n]))}return t}function r(t){var r,o,i,a,s,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,a=u-1,s=0):c===u-1?(i=u-1,a=0,s=1):(i=c,a=c+1,s=c+2),r=t[i],o=t[a],l+=(n(t[s][0])-n(r[0]))*Math.sin(n(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function n(e){return e*Math.PI/180}return ue.geometry=function e(r){var n,o=0;switch(r.type){case"Polygon":return t(r.coordinates);case"MultiPolygon":for(n=0;n<r.coordinates.length;n++)o+=t(r.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<r.geometries.length;n++)o+=e(r.geometries[n]);return o}},ue.ring=r,ue}(),fe=ae(he);const ge={Point:0,LineString:1,MultiLineString:1,Polygon:2};function ye(e,t){const r=ge[e.geometry.type]-ge[t.geometry.type];return 0===r&&e.geometry.type===F.POLYGON?e.area-t.area:r}function me(e){return e.map(e=>(e.geometry.type===F.POLYGON&&(e.area=fe.geometry({type:F.FEATURE,property:{},geometry:e.geometry})),e)).sort(ye).map(e=>(delete e.area,e))}function ve(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function xe(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}xe.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},xe.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},xe.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},xe.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((e,t)=>e.v-t.v).map(e=>e.k)},xe.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const _e=[R.FEATURE,R.MIDPOINT,R.VERTEX];var be={click:function(e,t,r){return Ee(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Ee(e,t,r,r.options.touchBuffer)}};function Ee(e,t,r,n){if(null===r.map)return[];const o=e?ve(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==_e.indexOf(e.properties.meta)),s=new xe,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),me(c)}function Se(e,t){const r=be.click(e,null,t),n={mouse:k.NONE};return r[0]&&(n.mouse=r[0].properties.active===U.ACTIVE?k.MOVE:k.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=k.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function we(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function Ie(e,t,r={}){const n=null!=r.fineTolerance?r.fineTolerance:4,o=null!=r.grossTolerance?r.grossTolerance:12,i=null!=r.interval?r.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const a=we(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Oe(e,t,r={}){const n=null!=r.tolerance?r.tolerance:25,o=null!=r.interval?r.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return we(e.point,t.point)<n&&t.time-e.time<o}const Pe=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===r[e])throw new Error(`Invalid event type: ${e}`);r[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=r[e];let a=i.length;for(;a--;){const e=i[a];if(e.selector(o)){e.fn.call(n,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const Me=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Ce(){return Me()}const Te=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ce(),this.type=t.geometry.type};Te.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Te.prototype.incomingCoords=function(e){this.setCoordinates(e)},Te.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Te.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Te.prototype.setProperty=function(e,t){this.properties[e]=t},Te.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:F.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Te.prototype.internal=function(e){const t={id:this.id,meta:R.FEATURE,"meta:type":this.type,active:U.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:F.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Le=function(e,t){Te.call(this,e,t)};(Le.prototype=Object.create(Te.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Le.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},Le.prototype.getCoordinate=function(){return this.getCoordinates()};const Ae=function(e,t){Te.call(this,e,t)};(Ae.prototype=Object.create(Te.prototype)).isValid=function(){return this.coordinates.length>1},Ae.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},Ae.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Ae.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Ae.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const ke=function(e,t){Te.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(ke.prototype=Object.create(Te.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},ke.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},ke.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ke.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(e=>parseInt(e,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},ke.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},ke.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},ke.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},ke.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const Ve={MultiPoint:Le,MultiLineString:Ae,MultiPolygon:ke},Fe=(e,t,r,n,o)=>{const i=r.split("."),a=parseInt(i[0],10),s=i[1]?i.slice(1).join("."):null;return e[a][t](s,n,o)},Ne=function(e,t){if(Te.call(this,e,t),delete this.coordinates,this.model=Ve[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function De(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ne.prototype=Object.create(Te.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ce(),type:F.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ne.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ne.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ne.prototype.getCoordinate=function(e){return Fe(this.features,"getCoordinate",e)},Ne.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===F.POLYGON?e.getCoordinates():e.coordinates)))},Ne.prototype.updateCoordinate=function(e,t,r){Fe(this.features,"updateCoordinate",e,t,r),this.changed()},Ne.prototype.addCoordinate=function(e,t,r){Fe(this.features,"addCoordinate",e,t,r),this.changed()},Ne.prototype.removeCoordinate=function(e){Fe(this.features,"removeCoordinate",e),this.changed()},Ne.prototype.getFeatures=function(){return this.features},De.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},De.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},De.prototype.getSelected=function(){return this._ctx.store.getSelected()},De.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},De.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},De.prototype.getFeature=function(e){return this._ctx.store.get(e)},De.prototype.select=function(e){return this._ctx.store.select(e)},De.prototype.deselect=function(e){return this._ctx.store.deselect(e)},De.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},De.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},De.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},De.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},De.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},De.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},De.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},De.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},De.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},De.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return be[r](e,t,this._ctx)},De.prototype.newFeature=function(e){const t=e.geometry.type;return t===F.POINT?new Le(this._ctx,e):t===F.LINE_STRING?new Ae(this._ctx,e):t===F.POLYGON?new ke(this._ctx,e):new Ne(this._ctx,e)},De.prototype.isInstanceOf=function(e,t){if(e===F.POINT)return t instanceof Le;if(e===F.LINE_STRING)return t instanceof Ae;if(e===F.POLYGON)return t instanceof ke;if("MultiFeature"===e)return t instanceof Ne;throw new Error(`Unknown feature class: ${e}`)},De.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},De.prototype.onSetup=function(){},De.prototype.onDrag=function(){},De.prototype.onClick=function(){},De.prototype.onMouseMove=function(){},De.prototype.onMouseDown=function(){},De.prototype.onMouseUp=function(){},De.prototype.onMouseOut=function(){},De.prototype.onKeyUp=function(){},De.prototype.onKeyDown=function(){},De.prototype.onTouchStart=function(){},De.prototype.onTouchMove=function(){},De.prototype.onTouchEnd=function(){},De.prototype.onTap=function(){},De.prototype.onStop=function(){},De.prototype.onTrash=function(){},De.prototype.onCombineFeature=function(){},De.prototype.onUncombineFeature=function(){},De.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const je={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Re=Object.keys(je);function Ue(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new De(r));return{start(){o=i.onSetup(n),Re.forEach(t=>{const r=je[t];let n=()=>!1;var a;e[r]&&(n=()=>!0),this.on(t,n,(a=r,e=>i[a](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function Be(e){return[].concat(e).filter(e=>void 0!==e)}function Ge(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(A.HOT)))return s();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let r=[],n=[];e.isDirty?n=e.getAllIds():(r=e.getChangedIds().filter(t=>void 0!==e.get(t)),n=e.sources.hot.filter(t=>t.properties.id&&-1===r.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===r.indexOf(t)});const i=o!==e.sources.cold.length||n.length>0;function a(r,n){const o=e.get(r).internal(t);e.ctx.events.currentModeRender(o,r=>{r.properties.mode=t,e.sources[n].push(r)})}function s(){e.isDirty=!1,e.clearChangedIds()}r.forEach(e=>a(e,"hot")),n.forEach(e=>a(e,"cold")),i&&e.ctx.map.getSource(A.COLD).setData({type:F.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(A.HOT).setData({type:F.FEATURE_COLLECTION,features:e.sources.hot}),s()}function He(e){let t;this._features={},this._featureIds=new xe,this._selectedFeatureIds=new xe,this._selectedCoordinates=[],this._changedFeatureIds=new xe,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ge.call(this),this._emitSelectionChange&&(this.ctx.events.fire(D.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(D.RENDER,{})}))},this.isDirty=!1}function Ye(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}He.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},He.prototype.setDirty=function(){return this.isDirty=!0,this},He.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(D.CREATE,{features:[t.toGeoJSON()]})}return this},He.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(D.UPDATE,{action:t.action?t.action:j.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},He.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},He.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},He.prototype.getAllIds=function(){return this._featureIds.values()},He.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},He.prototype.delete=function(e,t={}){const r=[];return Be(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===r.indexOf(this._features[e])&&r.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),r.length&&this.ctx.events.fire(D.DELETE,{features:r}),Ye(this,t),this},He.prototype.get=function(e){return this._features[e]},He.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},He.prototype.select=function(e,t={}){return Be(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},He.prototype.deselect=function(e,t={}){return Be(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Ye(this,t),this},He.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},He.prototype.setSelected=function(e,t={}){return e=Be(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},He.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},He.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},He.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},He.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},He.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},He.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},He.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:j.CHANGE_PROPERTIES})},He.prototype.storeMapConfig=function(){B.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},He.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},He.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Xe=["mode","feature","mouse"];function Je(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,r)=>(t[r]=Ue(e.options.modes[r]),t),{});let r={},n={};const o={};let i=null,a=null;o.drag=function(t,r){r({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:k.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ie(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Oe(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=Se(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Se(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Se(t,e);t.featureTarget=n,Ie(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(e){a.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;n={time:(new Date).getTime(),point:t.point};const r=be.touch(t,null,e)[0];t.featureTarget=r,a.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const r=be.touch(t,null,e)[0];t.featureTarget=r,Oe(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=Q(e),r=ee(e),n=oe(e);return!(t||r||n)};function c(r,n,o={}){a.stop();const s=t[r];if(void 0===s)throw new Error(`${r} is not valid`);i=r;const c=s(e,n);a=Pe(c,e),o.silent||e.map.fire(D.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(L.CANVAS)&&((Q(t)||ee(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):te(t)&&e.options.controls.point?c(N.DRAW_POINT):re(t)&&e.options.controls.line_string?c(N.DRAW_LINE_STRING):ne(t)&&e.options.controls.polygon&&c(N.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,a=Pe(t[i](e),e)},changeMode:c,actionable:function(t){let r=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(r=!0),l[e]=t[e]}),r&&e.map.fire(D.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];Xe.forEach(e=>{o[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==o[e]&&r.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),r.length>0&&e.container.classList.add(...r),n=Object.assign(n,o)}function s(e,t={}){const n=document.createElement("button");return n.className=`${L.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),n.target===r)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),n}function c(){r&&(r.classList.remove(L.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(L.ACTIVE_BUTTON),r=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:a,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),a()},addButtons:function(){const r=e.options.controls,n=document.createElement("div");return n.className=`${L.CONTROL_GROUP} ${L.CONTROL_BASE}`,r?(r[V.POINT]&&(t[V.POINT]=s(V.POINT,{container:n,className:L.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(N.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[V.LINE]&&(t[V.LINE]=s(V.LINE,{container:n,className:L.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(N.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[V.POLYGON]&&(t[V.POLYGON]=s(V.POLYGON,{container:n,className:L.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(N.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:L.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:L.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:L.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach(e=>{const r=t[e];r.parentNode&&r.parentNode.removeChild(r),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new He(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(A.COLD,{data:{type:F.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(A.HOT,{data:{type:F.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(A.COLD)&&e.map.removeSource(A.COLD),e.map.getSource(A.HOT)&&e.map.removeSource(A.HOT)}};return e.setup=n,n}const $e="#3bb2d0",Ke="#fbb03b",qe="#fff";var ze=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Ke,$e],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],Ke,$e],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":qe}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],Ke,$e]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":qe}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":Ke}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Ke}}];function Ze(e,t){this.x=e,this.y=t}function We(e,t){const r=t.getBoundingClientRect();return new Ze(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function Qe(e,t,r,n){return{type:F.FEATURE,properties:{meta:R.VERTEX,parent:e,coord_path:r,active:n?U.ACTIVE:U.INACTIVE},geometry:{type:F.POINT,coordinates:t}}}function et(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return tt(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>tt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return nt(e);default:throw new Error("unknown GeoJSON type")}}function tt(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=rt(e.properties),null==e.geometry?t.geometry=null:t.geometry=nt(e.geometry),t}function rt(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=rt(n):t[r]=n}),t):t}function nt(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>nt(e)),t):(t.coordinates=ot(e.coordinates),t)}function ot(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>ot(e))}function it(e,t={}){return at(e,"mercator",t)}function at(e,n,o={}){var i=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&t(e[0])?e="mercator"===n?st(e):ct(e):(!0!==i&&(e=et(e)),r(e,function(e){var t="mercator"===n?st(e):ct(e);e[0]=t[0],e[1]=t[1]})),e}function st(e){var t,r=Math.PI/180,n=6378137,o=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*r,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*r))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function ct(e){var t=180/Math.PI,r=6378137;return[e[0]*t/r,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/r)))*t]}function lt(e,t,r){const n=t.geometry.coordinates,o=r.geometry.coordinates;if(n[1]>85||n[1]<-85||o[1]>85||o[1]<-85)return null;const i=it(n),a=it(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return at(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:F.FEATURE,properties:{meta:R.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:F.POINT,coordinates:u}}}function ut(e,t={},r=null){const{type:n,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let a=[];function s(e,r){let n="",o=null;e.forEach((e,s)=>{const l=null!=r?`${r}.${s}`:String(s),u=Qe(i,e,l,c(l));if(t.midpoints&&o){const e=lt(i,o,u);e&&a.push(e)}o=u;const d=JSON.stringify(e);n!==d&&a.push(u),0===s&&(n=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===F.POINT?a.push(Qe(i,o,r,c(r))):n===F.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===F.LINE_STRING?s(o,r):0===n.indexOf(F.MULTI_PREFIX)&&function(){const r=n.replace(F.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:F.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(ut(i,t,o))})}(),a}Ze.prototype={clone(){return new Ze(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,o=r*this.x+t*this.y;return this.x=n,this.y=o,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),o=t.x+r*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Ze},Ze.convert=function(e){if(e instanceof Ze)return e;if(Array.isArray(e))return new Ze(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Ze(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var dt={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:pt,LAT_MAX:ht,LAT_RENDERED_MIN:ft,LAT_RENDERED_MAX:gt,LNG_MIN:yt,LNG_MAX:mt}=G;function vt(e,t){let r=pt,n=ht,o=pt,i=ht,a=mt,s=yt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),d>s&&(s=d)});const c=t;return r+c.lat>gt&&(c.lat=gt-r),o+c.lat>ht&&(c.lat=ht-o),n+c.lat<ft&&(c.lat=ft-n),i+c.lat<pt&&(c.lat=pt-i),a+c.lng<=yt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=mt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function xt(e,t){const r=vt(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+r.lng,lat:e[1]+r.lat};return[t.lng,t.lat]},o=e=>e.map(e=>n(e)),i=e=>e.map(e=>o(e));let a;e.type===F.POINT?a=n(t):e.type===F.LINE_STRING||e.type===F.MULTI_POINT?a=t.map(n):e.type===F.POLYGON||e.type===F.MULTI_LINE_STRING?a=t.map(o):e.type===F.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const _t={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(D.UPDATE,{action:j.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let r=!1;if(e.length>1){r=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(r=!1)})}const n=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new xe).values()},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){dt.enable(this)},onMouseMove:function(e,t){return K(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};_t.onTap=_t.onClick=function(e,t){return $(t)?this.clickAnywhere(e,t):H(R.VERTEX)(t)?this.clickOnVertex(e,t):K(t)?this.clickOnFeature(e,t):void 0},_t.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),dt.enable(this),this.stopExtendedInteractions(e)},_t.clickOnVertex=function(e,t){this.changeMode(N.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:k.MOVE})},_t.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},_t.clickOnFeature=function(e,t){dt.disable(this),this.stopExtendedInteractions(e);const r=z(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==F.POINT)return this.changeMode(N.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:k.POINTER}),1===n.length&&dt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:k.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:k.MOVE})),this.doRender(o)},_t.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),X(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&Y(t)?this.startBoxSelect(e,t):void 0},_t.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=We(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},_t.onTouchStart=function(e,t){if(X(t))return this.startOnActiveFeature(e,t)},_t.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},_t.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:k.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(L.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=We(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),o=Math.max(e.boxSelectStartLocation.x,r.x),i=Math.min(e.boxSelectStartLocation.y,r.y),a=Math.max(e.boxSelectStartLocation.y,r.y),s=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=s,e.boxSelectElement.style.WebkitTransform=s,e.boxSelectElement.style.width=o-n+"px",e.boxSelectElement.style.height=a-i+"px"},_t.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},_t.onTouchEnd=_t.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,We(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),o=this.getUniqueIds(n).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:k.MOVE}))}this.stopExtendedInteractions(e)},_t.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?U.ACTIVE:U.INACTIVE,r(t),this.fireActionable(),t.properties.active===U.ACTIVE&&t.geometry.type!==F.POINT&&ut(t).forEach(r)},_t.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},_t.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),r.push(i.toGeoJSON())}if(r.length>1){const e=this.newFeature({type:F.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(D.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},_t.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],r=[];for(let n=0;n<e.length;n++){const o=e[n];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))}t.length>1&&this.fire(D.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const bt=H(R.VERTEX),Et=H(R.MIDPOINT),St={fireUpdate:function(){this.fire(D.UPDATE,{action:j.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);z(t)||-1!==n?z(t)&&-1===n&&e.selectedCoordPaths.push(r.coord_path):e.selectedCoordPaths=[r.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,r){xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=vt(n.map(e=>({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:e}})),r);for(let t=0;t<n.length;t++){const r=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],r[0]+o.lng,r[1]+o.lat)}},clickNoTarget:function(){this.changeMode(N.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(N.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===F.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),dt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){dt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=U.ACTIVE,r(t),ut(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=U.INACTIVE,r(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(N.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=X(t),n=bt(t),o=Et(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:k.MOVE}):this.updateUIClasses({mouse:k.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};St.onTouchStart=St.onMouseDown=function(e,t){return bt(t)?this.onVertex(e,t):X(t)?this.onFeature(e,t):Et(t)?this.onMidpoint(e,t):void 0},St.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},St.onClick=function(e,t){return $(t)?this.clickNoTarget(e,t):X(t)?this.clickActiveFeature(e,t):J(t)?this.clickInactive(e,t):void this.stopDragging(e)},St.onTap=function(e,t){return $(t)?this.clickNoTarget(e,t):X(t)?this.clickActiveFeature(e,t):J(t)?this.clickInactive(e,t):void 0},St.onTouchEnd=St.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const wt={};function It(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}wt.onSetup=function(){const e=this.newFeature({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:k.ADD}),this.activateUIButton(V.POINT),this.setActionableState({trash:!0}),{point:e}},wt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},wt.onTap=wt.onClick=function(e,t){this.updateUIClasses({mouse:k.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(D.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.point.id]})},wt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},wt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?U.ACTIVE:U.INACTIVE,!n)return r(t)},wt.onTrash=wt.stopDrawingAndRemove,wt.onKeyUp=function(e,t){if(Z(t)||W(t))return this.stopDrawingAndRemove(e,t)};const Ot={onSetup:function(){const e=this.newFeature({type:F.FEATURE,properties:{},geometry:{type:F.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),dt.disable(this),this.updateUIClasses({mouse:k.ADD}),this.activateUIButton(V.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:k.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),q(t)&&this.updateUIClasses({mouse:k.POINTER})}};Ot.onTap=Ot.onClick=function(e,t){return q(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ot.onKeyUp=function(e,t){Z(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)):W(t)&&this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ot.onStop=function(e){this.updateUIClasses({mouse:k.NONE}),dt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(D.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Ot.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?U.ACTIVE:U.INACTIVE,!n)return r(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=R.FEATURE,r(Qe(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(Qe(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:F.FEATURE,properties:t.properties,geometry:{coordinates:e,type:F.LINE_STRING}}),3===o)return}return r(t)}},Ot.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)};const Pt={onSetup:function(e){const t=(e=e||{}).featureId;let r,n,o="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const a=r.coordinates.length-1;if(r.coordinates[a][0]===i[0]&&r.coordinates[a][1]===i[1])n=a+1,r.addCoordinate(n,...r.coordinates[a]);else{if(r.coordinates[0][0]!==i[0]||r.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",n=0,r.addCoordinate(n,...r.coordinates[0])}}else r=this.newFeature({type:F.FEATURE,properties:{},geometry:{type:F.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),dt.disable(this),this.updateUIClasses({mouse:k.ADD}),this.activateUIButton(V.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&It(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:k.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),q(t)&&this.updateUIClasses({mouse:k.POINTER})}};Pt.onTap=Pt.onClick=function(e,t){if(q(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Pt.onKeyUp=function(e,t){W(t)?this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]}):Z(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT))},Pt.onStop=function(e){dt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(D.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Pt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},Pt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?U.ACTIVE:U.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=R.FEATURE,r(Qe(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),r(t))};var Mt={simple_select:_t,direct_select:St,draw_point:wt,draw_polygon:Ot,draw_line_string:Pt};const Ct={defaultMode:N.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:ze,modes:Mt,controls:{},userProperties:!1,suppressAPIEvents:!0},Tt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Lt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function At(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?A.HOT:A.COLD}))}var kt,Vt;var Ft,Nt,Dt=ae(Vt?kt:(Vt=1,kt=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}));var jt=function(){if(Nt)return Ft;Nt=1,Ft=function(t){if(!t||!t.type)return null;var r=e[t.type];if(!r)return null;if("geometry"===r)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===r)return{type:"FeatureCollection",features:[t]};if("featurecollection"===r)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Ft}(),Rt=ae(jt);function Ut(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Bt={Polygon:ke,LineString:Ae,Point:Le,MultiPolygon:Ne,MultiLineString:Ne,MultiPoint:Ne};var Gt=Object.freeze({__proto__:null,CommonSelectors:ie,ModeHandler:Pe,StringSet:xe,constrainFeatureMovement:vt,createMidPoint:lt,createSupplementaryPoints:ut,createVertex:Qe,doubleClickZoom:dt,euclideanDistance:we,featuresAt:be,getFeatureAtAndSetCursors:Se,isClick:Ie,isEventAtCoordinates:It,isTap:Oe,mapEventToBoundingBox:ve,moveFeatures:xt,sortFeatures:me,stringSetsAreEqual:Ut,theme:ze,toDenseArray:Be});const Ht=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Lt,e.controls):t.controls=Object.assign({},Tt,e.controls),t=Object.assign({},Ct,t),t.styles=At(t.styles,"cold").concat(At(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=N;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return be.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:F.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:F.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==F.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(r),a=new xe(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Rt(t))).features.map(t=>{if(t.id=t.id||Ce(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=Bt[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Dt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Dt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:F.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==N.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===N.DIRECT_SELECT?e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===N.SIMPLE_SELECT&&t.getMode()===N.SIMPLE_SELECT?(Ut(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===N.DIRECT_SELECT&&t.getMode()===N.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,o,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,o,i){return e.store.setFeatureProperty(n,o,i,{silent:r}),t},t}(r,t),r.api=t;const n=Je(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=V,t.options=e,t};function Yt(e){Ht(e,this)}Yt.modes=Mt,Yt.constants=G,Yt.lib=Gt;var Xt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}};function Jt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function $t(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Jt(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Jt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Kt(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function qt(e){var t;return!!(null!=e&&e.status&&null!=e&&e.snapStatus&&(null===(t=e.snapCoords)||void 0===t?void 0:t.length)>=2)}function zt(e){return qt(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Zt(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function Wt(e,t){var r,n,o;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(r=e.snappedFeatures)&&void 0!==r&&r.length&&(e.snappedFeatures.length=0),null!==(n=e.closeFeatures)&&void 0!==n&&n.length&&(e.closeFeatures.length=0),null!==(o=e.lines)&&void 0!==o&&o.length&&(e.lines.length=0));null!=t&&t.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function Qt(e){var t,r,n;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(t=e.snappedFeatures)&&void 0!==t&&t.length&&(e.snappedFeatures.length=0),null!==(r=e.closeFeatures)&&void 0!==r&&r.length&&(e.closeFeatures.length=0),null!==(n=e.lines)&&void 0!==n&&n.length&&(e.lines.length=0))}function er(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var tr=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},rr=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!0}),r+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,o)=>{t.push({start:r,length:e.length,path:[n,o],closed:!0}),r+=e.length})})}return t},nr=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},or=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},ir=(e,t)=>{var r=t.split(".").map(Number),n=rr(e);for(var o of n){if(o.path.every((e,t)=>e===r[t])&&r.length===o.path.length+1){var i=r[r.length-1];return o.start+i}}return r[r.length-1]},ar=(e,t)=>({x:e.x*t,y:e.y*t}),sr=e=>e instanceof window.SVGElement||e.ownerSVGElement,cr={move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},lr={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},ur={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,r){e&&setTimeout(()=>{var n=this.getFeature(r);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){var t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(cr[e.type],e.vertexIndex,e.featureId))},handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r),this.emitGeometryValidation(lr[r.type],r.vertexIndex,r.featureId)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=rr(i),c=nr(s,r);if(c){or(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,ar(this.map.project(l),e.scale))}}},undoInsertVertex(e,t){var{vertexIndex:r,featureId:n}=t,o=this.getFeature(n);if(o){var i=o.toGeoJSON(),a=rr(o),s=nr(a,r);if(s)or(i,s.segment.path).splice(s.localIdx,1),this._applyUndoAndSync(e,i,n),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},undoDeleteVertex(e,t){var{vertexIndex:r,position:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=rr(i),c=nr(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)or(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,ar(this.map.project(e.vertecies[r]),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertecies=this.getVerticies(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}},dr=o.touchTargetSize/2;var pr=e=>{var t,r,n=e.querySelector("[data-im-draw-touch-target]");return n||(e.insertAdjacentHTML("beforeend",(t=o.touchTargetSize,r=dr,"\n <svg width='".concat(t,"' height='").concat(t,"' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:").concat(r,"px 0 0 -").concat(r,"px;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 "))),n=e.querySelector("[data-im-draw-touch-target]")),n},hr=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},fr=(e,t)=>{t&&e&&(e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px"),e.style.display="block")},gr=e=>{e&&(e.style.display="none")},yr=e=>{if(!e)return!1;var t=e.parentNode;return t instanceof globalThis.SVGElement||null!=(null==t?void 0:t.ownerSVGElement)},mr=function(e){var t,r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=null!==(t=null==e?void 0:e.mapColorScheme)&&void 0!==t?t:"light",c=null!==(r=null==e?void 0:e.id)&&void 0!==r?r:null,l=e=>{var t;return function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return"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]}(null!==(t=a[e])&&void 0!==t?t:i[e],s,c)};return{editStroke:l("editStroke"),editFill:l("editFill"),editVertex:l("editVertex"),editMidpoint:l("editMidpoint"),editActive:l("editActive"),editHalo:l("editHalo"),invalidStroke:l("invalidStroke"),splitValid:l("splitValid"),splitInvalid:l("splitInvalid"),shapeStroke:l("shapeStroke"),strokeWidth:null!==(n=a.strokeWidth)&&void 0!==n?n:o.strokeWidth,shapeFill:l("shapeFill"),snapVertex:l("snapVertex"),snapEdge:l("snapEdge"),mapStyleId:c}};function vr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function xr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?vr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):vr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var _r=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=mr(t,r);hr(e,{editActive:n,editHalo:o,editVertex:i})}},br={addTouchVertexTarget(e){e.touchVertexTarget=pr(e.container),_r(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||sr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){Qt(Kt(this.map)),null!=e&&e.featureId&&(this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=void 0,e._touchMoved=!1)},onTap(e,t){var r,n,o=Kt(this.map);o&&Wt(o,this.map);var i=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,a=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if("vertex"===i){var s=this.getFeature(e.featureId),c=ir(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(xr(xr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){Qt(Kt(this.map));var r=this.getVerticies(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&sr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=t.touches[0].clientX,i=t.touches[0].clientY,a=window.getComputedStyle(e.touchVertexTarget);e.deltaTarget={x:o-Number.parseFloat(a.left),y:i-Number.parseFloat(a.top)};var s=this.map.project(n);e.deltaVertex={x:o/e.scale-s.x,y:i/e.scale-s.y}}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&sr(t.target.parentNode)){e._touchMoved=!0;var r=t.touches[0].clientX,n=t.touches[0].clientY,o={x:r/e.scale-e.deltaVertex.x,y:n/e.scale-e.deltaVertex.y},i=this.map.unproject(o);if(er(e)){var a=Kt(this.map);Zt(a,this.map,o),i=zt(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function Er(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var Sr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},wr={updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(t,r){var[n,o]=this.getVertexOrMidpoint(t,r);n<0||!o||this.changeMode(t,function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Er(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Er(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({selectedVertexIndex:n,selectedVertexType:o},"vertex"===o&&{coordPath:this.getCoordPath(t,n)}))},getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?s.nudgeAmount:s.stepAmount,[o,i]=t?Sr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getNewCoord(e,t){return this.getOffset(tr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},getOffsetByDelta(e,t,r,n){var o=this.map.project(e),i=n?s.stepAmount:s.nudgeAmount;return this.map.unproject({x:o.x+t*i,y:o.y+r*i})},resolveSnapTarget(e,t,r,o,i){var a=Kt(this.map);if(er(e)&&e._isSnapped&&a){var s=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:n.snapRadius}(a)+1,c=this.map.project(o);return e._isSnapped=!1,Wt(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return er(e)&&a&&(Zt(a,this.map,this.map.project(l)),qt(a))?(e._isSnapped=!0,zt(a)):(e._isSnapped=!1,l)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=tr(i))||void 0===o?void 0:o[e.selectedVertexIndex]);if(a){var s=[...a],c=e.selectedVertexIndex,l=this.resolveSnapTarget(e,t,r,a,()=>this.getOffsetByDelta(a,t,r,n));this.moveVertex(e,l),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:c,previousPosition:s})}}},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertecies.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=rr(o),s=r+1,c=null,l=0,u=0;for(var d of a){var p=d.closed?d.length:d.length-1;if(r<u+p){c=d,l=r-u+1,s=d.start+l;break}u+=p}c&&(or(i,c.path).splice(l,0,[n.lng,n.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),this.changeMode(e,{selectedVertexIndex:s,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,s)}))},moveVertex(e,t){if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).checkSnap&&!1!==e.enableSnap){var r,n=this.map._snapInstance;null!=n&&n.snapStatus&&(null===(r=n.snapCoords)||void 0===r?void 0:r.length)>=2&&(t={lng:n.snapCoords[0],lat:n.snapCoords[1]})}var o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=rr(o),s=nr(a,e.selectedVertexIndex);s&&(or(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertecies=this.getVerticies(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=rr(t),n=nr(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?a.Polygon:a.LineString;if(!(o.length<=i)){var s=[...e.vertecies[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:s}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}},Ir={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e,n[0]):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=rr(r),o=nr(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVerticies(e){return tr(this.getFeature(e))},getMidpoints(e){var t=this.getFeature(e),r=tr(t),n=rr(t);if(null==r||!r.length||!n.length)return[];var o=[];for(var i of n)for(var a=i.closed?i.length:i.length-1,s=0;s<a;s++){var c=i.start+s,l=i.start+(s+1)%i.length,[u,d]=r[c],[p,h]=r[l];o.push([(u+p)/2,(d+h)/2])}return o},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertecies)&&void 0!==r&&r.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertecies)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertecies.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=c(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=rr(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertecies.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertecies.length}},Or=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Pr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Mr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Cr=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Mr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},Tr={onKeydown(e,t){Cr(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Or.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?(e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey)(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){var t,r,n=Kt(this.map);n&&Wt(n,this.map),null!==(t=e.vertecies)&&void 0!==t&&t.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertecies)&&void 0!==r&&r.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){var r;if("midpoint"!==e.selectedVertexType){var n=this.getFeature(e.featureId),o=n&&(null===(r=tr(n))||void 0===r?void 0:r[e.selectedVertexIndex]);o&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...o],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,o)))}else this.insertVertex(e,t)},_keyboardMoveTarget(e,t,r){var[n,o]=Pr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},handleUndoShortcut(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))},onKeyup(e,t){Cr(e)||(e.interfaceType="keyboard",Or.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&null!=e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=null)),"Delete"===t.key&&this.deleteVertex(e))}},Lr="draw.vertexselection",Ar={onMouseDown(e,t){var r,n;Qt(Kt(this.map));var o=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,i=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if(["vertex","midpoint"].includes(o)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,St.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=ir(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertecies)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=ir(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(Lr,{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(Lr,{index:r,numVertecies:e.vertecies.length})}St.onClick.call(this,e,t)},onMouseUp(e,t){Qt(Kt(this.map));var r=e._isInsertingVertex&&null!=e._insertedVertexIndex,n=this._didVertexMove(e);(e.dragMoving||n||r)&&(this.syncVertices(e),r?this._recordInsertionUndo(e):n&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,St.onMouseUp.call(this,e,t)},_didVertexMove(e){var t;if(!e._moveStartPosition||null==e._moveStartIndex)return!1;var r=this.getFeature(e.featureId),n=r&&(null===(t=tr(r))||void 0===t?void 0:t[e._moveStartIndex]);return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){var t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(Lr,{index:t,numVertecies:e.vertecies.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=Kt(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),er(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),Zt(n,this.map,t.point);var o=zt(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else St.onDrag.call(this,e,t)}}};function kr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Vr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?kr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):kr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Fr="draw.nudgevertex",Nr=Vr(Vr(Vr(Vr(Vr(Vr(Vr(Vr({},Yt.modes.direct_select),ur),br),wr),Ir),Tr),Ar),{},{onSetup(e){var t,r,n,o=Yt.modes.direct_select.onSetup.call(this,e);(Object.assign(o,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:o.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1}),this.map._lastEditFeatureId!==o.featureId)&&(null===(n=this.map._undoStack)||void 0===n||n.clear(),this.map._lastEditFeatureId=o.featureId);var i=this.getFeature(o.featureId);o.featureType=null==i?void 0:i.type,o.vertecies=this.getVerticies(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o);var a=Kt(this.map);if(a&&Wt(a,this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var s=o.vertecies[o.selectedVertexIndex];s&&setTimeout(()=>{this.updateTouchVertexTarget(o,ar(this.map.project(s),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=t=>r=>t.call(this,e,r),r=this.handlers={keydown:t(this.onKeydown),keyup:t(this.onKeyup),pointerdown:t(this.onPointerevent),pointermove:t(this.onPointerevent),pointerup:t(this.onPointerevent),click:t(this.onButtonClick),touchstart:t(this.onTouchstart),touchmove:t(this.onTouchmove),touchend:t(this.onTouchend),selectionchange:t(this.onSelectionChange),scalechange:t(this.onScaleChange),update:t(this.onUpdate),move:t(this.onMove),interfacetypechange:t(this.onInterfaceTypeChange),nudgevertex:t(this.onNudgeVertex)};window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),this.map.on("draw.selectionchange",r.selectionchange),this.map.on("draw.scalechange",r.scalechange),this.map.on("draw.update",r.update),this.map.on("move",r.move),this.map.on("draw.interfacetypechange",r.interfacetypechange),this.map.on(Fr,r.nudgevertex)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertecies.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=tr(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire("draw.vertexselection",{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?ar(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?ar(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertecies.map(e=>JSON.stringify(e))).size!==e.vertecies.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,ar(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertecies[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,ar(this.map.project(r),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",Vr(Vr({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;e.container.removeEventListener("pointerdown",t.pointerdown),e.container.removeEventListener("pointermove",t.pointermove),e.container.removeEventListener("pointerup",t.pointerup),e.container.removeEventListener("touchstart",t.touchstart),e.container.removeEventListener("touchmove",t.touchmove),e.container.removeEventListener("touchend",t.touchend),this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.scalechange",t.scalechange),this.map.off("draw.update",t.update),this.map.off("move",t.move),this.map.off("draw.interfacetypechange",t.interfacetypechange),this.map.off(Fr,t.nudgevertex),this.map.dragPan.enable(),window.removeEventListener("click",t.click),window.removeEventListener("keydown",t.keydown,{capture:!0}),window.removeEventListener("keyup",t.keyup,{capture:!0}),this.hideTouchVertexIndicator(e)}});function Dr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function jr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Dr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Dr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Rr=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?jr(jr({},e),{},{featureId:null}):e,a=jr(jr({},t.onSetup.call(this,i)),e);a[r].properties=e.properties;var{container:s,vertexMarkerId:c,getInterfaceType:l}=a,u=l?l():a.interfaceType;a.interfaceType=u;var d=s.querySelector("#".concat(c));a.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(a):this._hideCrossHair(a);var p=(e,t)=>this[e]=t.bind(this,a),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(e=>{var[t,r]=e;return p(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),a},onStop(e){t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function Ur(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Br(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ur(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ur(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Gr=(e,t,r,n,o)=>{setTimeout(()=>{var i=t(n);i&&e.fire("draw.geometrychange",((e,t,r)=>{var n=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[n]}:{type:"LineString",coordinates:n},properties:{}},phase:r,vertexIndex:Math.max(0,n.length-1)}})(i,r,o))},0)},Hr=e=>{var{geometryType:t,getFeature:r,getCoords:n}=e;return{_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(e,o){var i=r(e);if(!i||!o)return!0;var a=l({placed:n(i).slice(0,-1),point:o,geometryType:t,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Gr(this.map,r,n,e,t)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onCreate(e,t){((e,t,r)=>{e.delete(t.id),t.id=r,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}},Yr=e=>{var{ParentMode:t,getFeature:r,getCoords:n,validateClick:o,finishOnInvalidClick:i}=e;return{onClick(e,a){var s;if(!this._isIgnorableClick(a)&&(!1!==this.map._drawGeometryValid||"vertex"!==(null===(s=a.featureTarget)||void 0===s||null===(s=s.properties)||void 0===s?void 0:s.meta))){var c=Kt(this.map);if(er(e)&&qt(c))a=function(e,t){var r=zt(t);return r?$t($t({},e),{},{lngLat:r}):e}(a,c);else if(!((e,t)=>{var a=n(r(e));return a.length>0&&(a[a.length-1]=[t.lngLat.lng,t.lngLat.lat]),i||o(r(e))})(e,a))return;if(this._canPlaceVertex(e,[a.lngLat.lng,a.lngLat.lat])){var l=n(r(e)).length;t.onClick.call(this,e,a),n(r(e)).length>l&&(this.pushDrawUndo(e),this.dispatchVertexChange(n(r(e))),this.emitDrawValidation(e))}}},doClick(e){if(!this.map._undoInProgress){var a=r(e),s=n(a);if(this.dispatchVertexChange(s),o(a)){var c=Kt(this.map),l=er(e)&&function(e,t){var r=zt(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(this._canPlaceVertex(e,[u.lng,u.lat])){l?(t.onClick.call(this,e,l),this._ctx.store.render()):this._simulateMouse("click",t.onClick,e);var d=n(r(e));this.pushDrawUndo(e),this.dispatchVertexChange(d),this.emitDrawValidation(e)}}else i&&!1!==this.map._drawGeometryValid&&(s.pop(),this.map.fire("draw.create",{features:[a.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[a.id]}))}}}};function Xr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Jr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var $r=e=>{var{geometryType:t,getFeature:r}=e;return{pushDrawUndo(e){var n=this.map._undoStack;n&&!this.map._undoInProgress&&n.push({type:"draw_vertex",geometryType:t,featureId:r(e).id})},onUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"draw_vertex"===(null==r?void 0:r.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))}},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}},Kr=e=>{var{ParentMode:t,geometryType:r,getCoords:n,getFeature:o}=e;return{undoVertex(e){var t=o(e),r=n(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_removeLastVertex(e,t,o){var i="Polygon"===r?t.coordinates[0]:o;i.splice(-2,1),i[i.length-1]=[...i[i.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(t))},_updateRubberBand(e,n){if(["touch","keyboard"].includes(e.interfaceType))this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render();else{var o=n["Polygon"===r?n.length-2:n.length-1],i={lng:o[0],lat:o[1]},a=this.map.project(i);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}this.dispatchVertexChange(n)}}},qr=e=>{var{ParentMode:t,featureProp:r,geometryType:n}=e;return{_reinitializeFeature(e,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(e,i);var a=this.map.getCenter(),s=[[a.lng,a.lat],[a.lng,a.lat]],c=this.newFeature({type:"Feature",properties:e.properties||{},geometry:{type:n,coordinates:[s]}});return c.id=i,this._ctx.store.add(c),e[r]=c,e.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render(),this.dispatchVertexChange(s),!0},_restartLineStringDraw(e,t){var r=this.map._undoStack;return r&&r.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}},zr=e=>{var{ParentMode:t,getFeature:r,INTERFACE_KEYS:n}=e;return{onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(e,n){var o=document.activeElement;if(!o||o===e.container||!e.container.contains(o))if("Escape"!==n.key)o!==e.container&&t.onKeyUp.call(this,e,n);else if("keyboard"===e.interfaceType){var i=this.map._undoStack;i&&i.clear(),this._reinitializeFeature(e,r(e))}}}};function Zr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Wr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Zr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Zr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Qr=e=>{var{ParentMode:t,getFeature:r,getCoords:n}=e;return{onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(e,r){if(er(e)){var n=Kt(this.map);Zt(n,this.map,r.point);var o=zt(n);o&&(r=Wr(Wr({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e){if(["touch","keyboard"].includes(e.interfaceType)){er(e)&&function(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);e.snapToClosestPoint({point:n,lngLat:r})}(Kt(this.map),this.map);var r=Kt(this.map),n=er(e)&&zt(r);if(n){var o=this.map.project([n.lng,n.lat]);t.onMouseMove.call(this,e,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}else this._simulateMouse("mousemove",t.onMouseMove,e)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(r(e)))}}},en=e=>{var{ParentMode:t,geometryType:r,getFeature:n,getPlacedCoords:o}=e;return{_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},toDisplayFeatures(e,i,a){t.toDisplayFeatures.call(this,e,i,a);var s=n(e);i.geometry.type===r&&i.properties.id===s.id&&o(i).forEach(e=>a({type:"Feature",properties:{meta:"draw-vertex",parent:s.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}};function tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function rn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?tn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var nn=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s,finishOnInvalidClick:c,getFeature:e=>e[r],INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return rn(rn(rn(rn(rn(rn(rn({},e),Rr(l)),(e=>Br(Br({},Hr(e)),Yr(e)))(l)),(e=>Jr(Jr(Jr({},$r(e)),Kr(e)),qr(e)))(l)),zr(l)),Qr(l)),en(l))},on=nn(Yt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>u(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),an=nn(Yt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>d(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),sn=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],cn=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":sn(e,"fill",t.shapeFill)}}),ln=(e,t)=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":sn(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),un=e=>({id:"stroke-preview-line",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),dn=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),pn=(e,t,r)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),hn=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),fn=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),gn=(e,t,r)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),yn=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),mn=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),vn=function(e){var t,r,n,i,a,s=mr(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:c,midpointRadius:l,vertexHaloRadius:u,midpointHaloRadius:d}=o;return[cn(e,s),(a=s.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":a}}),(i=s.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":i,"line-width":2,"line-opacity":1}}),(n=s.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":n,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),ln(e,s),(r=s.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":r,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(t=s.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t,"line-width":2,"line-opacity":1}}),un(s.editStroke),fn(s.editMidpoint,l),gn(s.editHalo,s.editActive,d),yn(s.editMidpoint,l),dn(s.editVertex,c),pn(s.editHalo,s.editActive,u),hn(s.editVertex,c),mn(s.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function xn(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function _n(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function bn(e,t,r){void 0===r&&(r={});var n=xn(e),o=xn(t),i=p(o[1]-n[1]),a=p(o[0]-n[0]),s=p(n[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function En(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Sn(e,t,r,n={}){const o=En(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return void 0!==o[2]?g([d,h,o[2]],n.properties):g([d,h],n.properties)}function wn(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return v(e,t);return x(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function In(e,t,r={}){if(!0===r.final)return function(e,t){let r=In(t,e);return r=(r+180)%360,r}(e,t);const n=En(e),o=En(t),i=p(n[0]),a=p(o[0]),s=p(n[1]),c=p(o[1]),l=Math.sin(a-i)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(a-i);return y(Math.atan2(l,u))}var On=In;function Pn(e,t,r,n){void 0===n&&(n={});var o=xn(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return g([d,h],n.properties)}function Mn(e){if(!e)throw new Error("geojson is required");var t=[];return _(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=_n(n);break;case"LineString":r=[_n(n)]}r.forEach(function(r){var n=function(e,t){var r=[];return e.reduce(function(e,n){var o,i,a,s,c,l,u=x([e,n],t);return u.bbox=(i=n,a=(o=e)[0],s=o[1],c=i[0],l=i[1],[a<c?a:c,s<l?s:l,a>c?a:c,s>l?s:l]),r.push(u),n}),r}(r,e.properties);n.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),b(t)}var Cn={exports:{}};function Tn(e,t,r,n,o){Ln(e,t,r||0,n||e.length-1,o||kn)}function Ln(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);Ln(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(An(e,r,t),o(e[n],u)>0&&An(e,r,n);d<p;){for(An(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?An(e,r,p):An(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function An(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function kn(e,t){return e<t?-1:e>t?1:0}function Vn(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Fn(e,t){Nn(e,0,e.children.length,t,e)}function Nn(e,t,r,n,o){o||(o=Jn(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<r;i++){const t=e.children[i];Dn(o,e.leaf?n(t):t)}return o}function Dn(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function jn(e,t){return e.minX-t.minX}function Rn(e,t){return e.minY-t.minY}function Un(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Bn(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Gn(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Hn(e,t){const r=Math.max(e.minX,t.minX),n=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-r)*Math.max(0,i-n)}function Yn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Xn(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Jn(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function $n(e,t,r,n,o){const i=[t,r];for(;i.length;){if((r=i.pop())-(t=i.pop())<=n)continue;const a=t+Math.ceil((r-t)/n/2)*n;Tn(e,a,t,r,o),i.push(t,a,a,r)}}var Kn,qn=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const r=[];if(!Xn(e,t))return r;const n=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const a=t.children[i],s=t.leaf?n(a):a;Xn(e,s)&&(t.leaf?r.push(a):Yn(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!Xn(e,t))return!1;const r=[];for(;t;){for(let n=0;n<t.children.length;n++){const o=t.children[n],i=t.leaf?this.toBBox(o):o;if(Xn(e,i)){if(t.leaf||Yn(e,i))return!0;r.push(o)}}t=r.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=Jn([]),this}remove(e,t){if(!e)return this;let r=this.data;const n=this.toBBox(e),o=[],i=[];let a,s,c;for(;r||o.length;){if(r||(r=o.pop(),s=o[o.length-1],a=i.pop(),c=!0),r.leaf){const n=Vn(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!Yn(r,n)?s?(a++,r=s.children[a],c=!1):r=null:(o.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const r=[];for(;e;)e.leaf?t.push(...e.children):r.push(...e.children),e=r.pop();return t}_build(e,t,r,n){const o=r-t+1;let i,a=this._maxEntries;if(o<=a)return i=Jn(e.slice(t,r+1)),Fn(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=Jn([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));$n(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);$n(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Fn(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=Un(a),c=Gn(e,a)-s;c<o?(o=c,n=s<n?s:n,r=a):c===o&&s<n&&(n=s,r=a)}t=r||t.children[0]}return t}_insert(e,t,r){const n=r?e:this.toBBox(e),o=[],i=this._chooseSubtree(n,this.data,t,o);for(i.children.push(e),Dn(i,n);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(n,o,t)}_split(e,t){const r=e[t],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const i=this._chooseSplitIndex(r,o,n),a=Jn(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Fn(r,this.toBBox),Fn(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=Jn([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Fn(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=Nn(e,0,a,this.toBBox),s=Nn(e,a,r,this.toBBox),c=Hn(t,s),l=Un(t)+Un(s);c<o?(o=c,n=a,i=l<i?l:i):c===o&&l<i&&(i=l,n=a)}return n||r-t}_chooseSplitAxis(e,t,r){const n=e.leaf?this.compareMinX:jn,o=e.leaf?this.compareMinY:Rn;this._allDistMargin(e,t,r,n)<this._allDistMargin(e,t,r,o)&&e.children.sort(n)}_allDistMargin(e,t,r,n){e.children.sort(n);const o=this.toBBox,i=Nn(e,0,t,o),a=Nn(e,r-t,r,o);let s=Bn(i)+Bn(a);for(let n=t;n<r-t;n++){const t=e.children[n];Dn(i,e.leaf?o(t):t),s+=Bn(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Dn(a,e.leaf?o(t):t),s+=Bn(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Dn(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Fn(e[r],this.toBBox)}}}),zn=se(qn),Zn={};function Wn(){if(Kn)return Zn;Kn=1,Object.defineProperty(Zn,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},r={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function n(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function o(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:e},t,r)}function i(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:e},t,r)}function a(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:e},t,r)}function s(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return n({type:"MultiLineString",coordinates:e},t,r)}function l(e,t,r={}){return n({type:"MultiPoint",coordinates:e},t,r)}function u(e,t,r={}){return n({type:"MultiPolygon",coordinates:e},t,r)}function d(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e/n}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Zn.areaFactors=r,Zn.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Zn.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Zn.convertArea=function(e,t="meters",n="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=r[t];if(!o)throw new Error("invalid original units");const i=r[n];if(!i)throw new Error("invalid final units");return e/o*i},Zn.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),r)},Zn.degreesToRadians=function(e){return e%360*Math.PI/180},Zn.earthRadius=e,Zn.factors=t,Zn.feature=n,Zn.featureCollection=s,Zn.geometry=function(e,t,r={}){switch(e){case"Point":return o(t).geometry;case"LineString":return a(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},Zn.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},Zn.isNumber=f,Zn.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Zn.lengthToDegrees=function(e,t){return h(p(e,t))},Zn.lengthToRadians=p,Zn.lineString=a,Zn.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},Zn.multiLineString=c,Zn.multiPoint=l,Zn.multiPolygon=u,Zn.point=o,Zn.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},Zn.polygon=i,Zn.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},Zn.radiansToDegrees=h,Zn.radiansToLength=d,Zn.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const r=Math.pow(10,t||0);return Math.round(e*r)/r},Zn.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach(e=>{if(!f(e))throw new Error("bbox must only contain numbers")})},Zn.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},Zn}var Qn,eo={};function to(){if(Qn)return eo;Qn=1,Object.defineProperty(eo,"__esModule",{value:!0});var e=Wn();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var x=0;x<c;x++){var _=0,b=0;if(null!==(s=d?u.geometries[x]:u)){l=s.coordinates;var E=s.type;switch(p=!n||"Polygon"!==E&&"MultiPolygon"!==E?0:1,E){case null:break;case"Point":if(!1===r(l,h,v,_,b))return!1;h++,_++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,_,b))return!1;h++,"MultiPoint"===E&&_++}"LineString"===E&&_++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,_,b))return!1;h++}"MultiLineString"===E&&_++,"Polygon"===E&&b++}"Polygon"===E&&_++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(b=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-p;a++){if(!1===r(l[o][i][a],h,v,_,b))return!1;h++}b++}_++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(r=0;r<g;r++){for(s=h?e.features[r].geometry:f?e.geometry:e,l=h?e.features[r].properties:f?e.properties:{},u=h?e.features[r].bbox:f?e.bbox:void 0,d=h?e.features[r].id:f?e.id:void 0,a=(c=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=c?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,r){o(t,function(t,n,o,i,a){var s,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==r(e.feature.call(void 0,t,o,{bbox:i,id:a}),n,0)&&void 0}switch(c){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:s,coordinates:t.coordinates[l]};if(!1===r(e.feature.call(void 0,u,o),n,l))return!1}})}function a(r,n){i(r,function(r,o,i){var a=0;if(r.geometry){var s=r.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var c,l=0,u=0,d=0;return!1!==t(r,function(t,s,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return eo.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},eo.coordEach=t,eo.coordReduce=function(e,r,n,o){var i=n;return t(e,function(e,t,o,a,s){i=0===t&&void 0===n?e:r(i,e,t,o,a,s)},o),i},eo.featureEach=n,eo.featureReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},eo.findPoint=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.coordIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return e.point.call(void 0,l,c,r);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,r);case"LineString":return s<0&&(s=l.length+s),e.point.call(void 0,l[s],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s),e.point.call(void 0,l[a][s],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),e.point.call(void 0,l[i][s],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s),e.point.call(void 0,l[i][a][s],c,r)}throw new Error("geojson is invalid")},eo.findSegment=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.segmentIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=l.length+s-1),e.lineString.call(void 0,[l[s],l[s+1]],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s-1),e.lineString.call(void 0,[l[a][s],l[a][s+1]],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s-1),e.lineString.call(void 0,[l[i][s],l[i][s+1]],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s-1),e.lineString.call(void 0,[l[i][a][s],l[i][a][s+1]],c,r)}throw new Error("geojson is invalid")},eo.flattenEach=i,eo.flattenReduce=function(e,t,r){var n=r;return i(e,function(e,o,i){n=0===o&&0===i&&void 0===r?e:t(n,e,o,i)}),n},eo.geomEach=o,eo.geomReduce=function(e,t,r){var n=r;return o(e,function(e,o,i,a,s){n=0===o&&void 0===r?e:t(n,e,o,i,a,s)}),n},eo.lineEach=s,eo.lineReduce=function(e,t,r){var n=r;return s(e,function(e,o,i,a){n=0===o&&void 0===r?e:t(n,e,o,i,a)}),n},eo.propEach=r,eo.propReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},eo.segmentEach=a,eo.segmentReduce=function(e,t,r){var n=r,o=!1;return a(e,function(e,i,a,s,c){n=!1===o&&void 0===r?e:t(n,e,i,a,s,c),o=!0}),n},eo}var ro,no,oo={};function io(){if(ro)return oo;ro=1,Object.defineProperty(oo,"__esModule",{value:!0});var e=to();function t(t,r={}){if(null!=t.bbox&&!0!==r.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}var r=t;return oo.bbox=t,oo.default=r,oo}var ao=function(){if(no)return Cn.exports;no=1;var e=zn,t=Wn(),r=to(),n=io().default,o=r.featureEach;r.coordEach,t.polygon;var i=t.featureCollection;function a(t){var r=new e(t);return r.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.insert.call(this,t)},r.load=function(t){var r=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}),e.prototype.load.call(this,r)},r.remove=function(t,r){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.remove.call(this,t,r)},r.clear=function(){return e.prototype.clear.call(this)},r.search=function(t){var r=e.prototype.search.call(this,this.toBBox(t));return i(r)},r.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},r.all=function(){var t=e.prototype.all.call(this);return i(t)},r.toJSON=function(){return e.prototype.toJSON.call(this)},r.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},r.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=n(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=n(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},r}return Cn.exports=a,Cn.exports.default=a,Cn.exports}(),so=ae(ao);function co(e,t){var r={},n=[];if("LineString"===e.type&&(e=E(e)),"LineString"===t.type&&(t=E(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=lo(e,t);return o&&n.push(o),b(n)}var i=so();return i.load(Mn(t)),S(Mn(e),function(e){S(i.search(e),function(t){var o=lo(e,t);if(o){var i=_n(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),b(n)}function lo(e,t){var r=_n(e),n=_n(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],d=n[1][1],p=(d-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var y=h/p,m=f/p;return y>=0&&y<=1&&m>=0&&m<=1?g([o+y*(a-o),i+y*(s-i)]):null}function uo(e,t,r){void 0===r&&(r={});var n=g([1/0,1/0],{dist:1/0}),o=0;return _(e,function(e){for(var i=_n(e),a=0;a<i.length-1;a++){var s=g(i[a]);s.properties.dist=bn(t,s,r);var c=g(i[a+1]);c.properties.dist=bn(t,c,r);var l=bn(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=On(s,c),p=Pn(t,u,d+90,r),h=Pn(t,u,d-90,r),f=co(x([p.geometry.coordinates,h.geometry.coordinates]),x([s.geometry.coordinates,c.geometry.coordinates])),y=null;f.features.length>0&&((y=f.features[0]).properties.dist=bn(t,y,r),y.properties.location=o+bn(s,y,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),y&&y.properties.dist<n.properties.dist&&((n=y).properties.index=a),o+=l}}),n}function po(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ho(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=po(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return g([d,h],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=po(e),o=po(t),i=p(o[1]-n[1]),a=p(o[0]-n[0]),s=p(n[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,On(e,t));return r}var fo=function(){return fo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},fo.apply(this,arguments)},go=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],r=0;r<e.features.length;r++){var n=e.features[r],o=n.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var a=this.features.unknow.snapPoints;i=fo(fo({},i),a)}var s=this.doSnap(n,i);t.push(s)}else if(void 0!==this.features.unknow){a=this.features.unknow.snapPoints,s=this.doSnap(n,a);t.push(s)}else t.push(n)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return bn(g(e),g(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],d=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=bn(g([r.lng,r.lat]),g([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var a=!1,s=this.getCloseFeatures(e,i);s?(this.snapStatus=!0,this.snapCoords=s.coords,a=function(e,t,r={}){const n=r.steps||64,o=r.properties?r.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<n;o++)i.push(Sn(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),m([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=b(0==a?[]:[a]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(b([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n=w(e),o=[];if(n.map(function(e){var n=bn(g(e),g([t.lng,t.lat]),{units:"meters"});n<r&&o.push({coords:e,dist:n,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(x(e))});break;case"Polygon":var o=wn(e.geometry);n.push(o);break;case"MultiPolygon":wn(e.geometry).coodinates.map(function(e){n.push(x(e))})}return n},e.prototype.searchInMidPoint=function(e,t,r){var n=this.getLines(e,t,r),o=[];n.map(function(e){o=o.concat(Mn(e).features)});var i=[];if(o.map(function(e){var n=ho(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=bn(n,g([t.lng,t.lat]),{units:"meters"});o<r&&i.push({coords:n.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,r){for(var n=this.getLines(e,t,r),o=[],i=0;i<n.length;i++){var a=uo(n[i],g([t.lng,t.lat]),{units:"meters"});void 0!==a.properties.dist&&a.properties.dist<r&&o.push({coords:a.geometry.coordinates,dist:a.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var r=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(r.length>0){for(var n,o=!1,i=0;i<r.length;i++){var a=r[i],s=this.options.rules,c=e.lngLat;if(o=!1,-1!==s.indexOf("vertex")&&null==n&&(n=this.searchInVertex(a,c,t))){o=!0;break}if(-1!==s.indexOf("midpoint")&&null==n&&(n=this.searchInMidPoint(a,c,t))){o=!0;break}if(-1!==s.indexOf("edge")&&null==n&&(n=this.searchInEdge(a,c,t))){o=!0;break}}return!!o&&n}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}(),yo="snap-helper-circle",mo="mapbox-gl-draw-hot";function vo(e){if(!go.prototype.__snapPatched){go.prototype.__snapPatched=!0;var t=go.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){var r,n;if(this.status){var o=t.setMapData.call(this,e);return(null==e||null===(r=e.features)||void 0===r?void 0:r.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(yo)&&this.map.setLayoutProperty(yo,"visibility","visible"),o}},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,r,n){var o=e.geometry;if(null==o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>m(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>x(e)):t.getLines.call(this,e,r,n)}catch(e){return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];var o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));var i=this.options.radius||n.snapRadius,a=e.point;e.point=[[a.x-i,a.y-i],[a.x+i,a.y+i]];var s=t.getCloseFeatures.call(this,e,r);return e.point=a,s}}(t,r),function(e,t,r){e.searchInVertex=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInVertex.apply(this,n);return i&&(i.color=r.vertex),i},e.searchInMidPoint=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInMidPoint.apply(this,n);return i&&(i.color=r.midpoint),i},e.searchInEdge=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInEdge.apply(this,n);return i&&(i.color=r.edge),i}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){var r;if(this.status&&(null===(r=this.map)||void 0===r||!r._isZooming))try{var n,o,i=t.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}}function xo(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function _o(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}var bo=new Set(["draw_polygon","draw_line","edit_vertex"]);function Eo(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(yo)&&e.removeLayer(yo),e.getSource(yo)&&e.removeSource(yo)}(e),_o(r);var o=new go({map:e,drawing:t,options:{layers:n.layers,radius:n.radius,rules:n.rules},status:n.status,onSnapped:n.onSnapped});return function(e,t,r){var n=t;Object.defineProperty(e,"status",{get:()=>n&&bo.has(r.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{n=e}}(o,n.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,n.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function So(e,t,r){e.on("style.load",()=>{xo(()=>e._removed?null:e.getSource(mo),n=>{_o(n),function(e){var t;e.getSource(yo)||e.addSource(yo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(yo)||e.addLayer({id:yo,type:"fill",source:yo,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Eo(e,t,n,r)})})}function wo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Io(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:a=[],radius:s=n.snapRadius,rules:c=["vertex","midpoint","edge"],status:l=!1,onSnapped:u=()=>{},colors:d={}}=o,p={layers:a,radius:s,rules:c,status:l,onSnapped:u};return vo(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?wo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):wo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:i.snapVertex,midpoint:i.snapMidpoint,edge:i.snapEdge},d)),So(t,r,p),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(yo)){e.setLayoutProperty(yo,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(yo,"visibility","visible")}})}(t),xo(()=>t._removed?null:t.getSource(mo),e=>Eo(t,r,e,p)),t._snapInstance}var Oo=e=>{var t=[];return{push(r){t.push(r),e(t.length)},pop(){var r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}};function Po(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Mo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Po(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Po(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Co=e=>{var t,{mapStyle:r,mapProvider:o,events:i,eventBus:a,snapLayers:s,pluginConfig:c={}}=e,{map:l}=o;Yt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Yt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Yt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var u=Mo(Mo({},Yt.modes),{},{disabled:Xt,edit_vertex:Nr,draw_polygon:on,draw_line:an}),d=o._mapboxDrawInstance;d?Object.assign(d.modes,u):(d=new Yt({modes:u,styles:vn(r,c),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),l.addControl(d),o._mapboxDrawInstance=d);var p=((e,t)=>{var r=e.getCanvas(),n=null,o=e=>{1===e.touches.length&&(n={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"===t.getMode()&&n){var o=e.changedTouches[0],i=o.clientX-n.x,a=o.clientY-n.y;Date.now()-n.time<300&&Math.abs(i)<10&&Math.abs(a)<10&&r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),n=null}else n=null};return r.addEventListener("touchstart",o,{passive:!0}),r.addEventListener("touchend",i,{passive:!0}),{remove(){r.removeEventListener("touchstart",o),r.removeEventListener("touchend",i)}}})(l,d);o.draw=d,l._drawCurrentMapStyle=r,l._drawPluginConfig=c,o.snapEnabled=!1;var h=o.undoStack;h||(h=Oo(e=>l.fire("draw.undochange",{length:e})),o.undoStack=h),l._undoStack=h;var f=mr(r,c);Io(l,d,{layers:s,radius:null!==(t=c.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:f.snapVertex,edge:f.snapEdge}});var g=e=>{l._drawCurrentMapStyle=e,l.once("idle",()=>{var t;!function(e,t){vn(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})}(l,e,c);var r=null===(t=l._drawEditContainer)||void 0===t?void 0:t.querySelector("[data-im-draw-touch-target]");_r(r,e,c)})};a.on(i.MAP_SET_STYLE,g);var y=e=>{l.fire("draw.scalechange",{scale:I[e]})};return a.on(i.MAP_SET_SIZE,y),{draw:d,remove(){p.remove(),a.off(i.MAP_SET_STYLE,g),a.off(i.MAP_SET_SIZE,y),d.changeMode("disabled"),o.draw=null}}},To="draw.create",Lo="draw.update",Ao="draw.modechange",ko="draw.editfinish",Vo="draw.cancel",Fo="draw.vertexselection",No="draw.vertexchange",Do="draw.undochange",jo="draw.undo",Ro="draw.geometrychange",Uo="draw.interfacetypechange",Bo="draw.placementblocked",Go="draw.nudgevertex",Ho="styledata";function Yo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Xo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Yo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Jo=e=>"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,16),$o=e=>"function"==typeof cancelAnimationFrame?cancelAnimationFrame(e):clearTimeout(e),Ko=e=>{var{onChange:t,validate:r=O}=e,n=!1,o=null,i=null,a=()=>{null!=o&&($o(o),o=null),i=null},s=(e,r)=>{e!==n&&(n=e,t(e,null!=r?r:null))},c=()=>{if(o=null,i){var{feature:e,context:t,onGeometryChange:n}=i,{valid:a,reason:c}=r(e,t,{onGeometryChange:n});s(!a,c)}};return{update(e){var{feature:t,context:n={},numVertices:l,onGeometryChange:u}=e,d=Xo(Xo({},n),{},{numVertices:l}),p=r(t,d);return p.valid?"function"!=typeof u?(a(),void s(!1,null)):(i={feature:t,context:d,onGeometryChange:u},void(null==o&&(o=Jo(c)))):(a(),void s(!0,p.reason))},set(e,t){a(),s(e,null!=t?t:null)},refresh(){t(n,null)},destroy(){a()}}};function qo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function zo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Zo=e=>{var{onStrokeChange:t,onPlaceChange:r}=e,n=e=>{var t=!1;return(r,n)=>{r!==t&&(t=r,e(r,null!=n?n:null))}},o=n(t),i=n(r),s=!1,c=null,l=null,u=null,d=()=>{null!=l&&($o(l),l=null),u=null},p=(e,t,r,n,o)=>{var i,a=(null!==(i=t.numVertices)&&void 0!==i?i:0)<n?{valid:!0}:P(e,zo(zo({},t),{},{phase:"preview"}),{rules:r});o(!a.valid||s,a.valid?c:a.reason)},h=()=>{var e,t;if(u){var{feature:r,context:n}=u,s=null!==(e=a[null==r||null===(t=r.geometry)||void 0===t?void 0:t.type])&&void 0!==e?e:0;p(r,n,M,s,o),p(r,n,C,0,i)}},f=()=>{if(l=null,u){var{feature:e,context:t,onGeometryChange:r}=u,n=P(e,zo(zo({},t),{},{phase:"preview"}),{rules:[],onGeometryChange:r});s=!n.valid,c=n.reason,h()}};return{update(e){var{feature:t,context:r={},numVertices:n,onGeometryChange:o}=e;u={feature:t,context:zo(zo({},r),{},{numVertices:n}),onGeometryChange:o},h(),"function"==typeof o&&null==l&&(l=Jo(f))},reset(){d(),s=!1,c=null,o(!1,null),i(!1,null)},destroy(){d()}}};function Wo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Qo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Wo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Wo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ei=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),ti=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),ri=(e,t)=>{var r,n,o,i,a,s,c;return"draw_polygon"===e?{feature:ei(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1}:"draw_line"===e?{feature:ti(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1}:"edit_vertex"===e?Array.isArray(null===(i=t[0])||void 0===i?void 0:i[0])?{feature:ei(t),numVertices:null!==(a=null===(s=t[0])||void 0===s?void 0:s.length)&&void 0!==a?a:0}:{feature:ti(t),numVertices:null!==(c=null==t?void 0:t.length)&&void 0!==c?c:0}:null};var ni=Object.freeze({__proto__:null,MaplibreDrawAdapter:class{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._bus=(n=new Map,{on(e,t){n.has(e)||n.set(e,new Set),n.get(e).add(t)},off(e,t){var r;null===(r=n.get(e))||void 0===r||r.delete(t)},emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var i=n.get(e);i&&Array.from(i).forEach(e=>e(...r))}}),this._editingFeatureId=null;var{draw:o,remove:i}=Co({mapStyle:t.mapStyle,mapProvider:e,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:null!==(r=t.pluginConfig)&&void 0!==r?r:{}});this._draw=o,this._cleanupDraw=i,this._liveStroke=Ko({onChange:(e,t)=>{this._applyStrokeInvalid(e),"edit_vertex"===this._draw.getMode()&&this._bus.emit(T.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=Zo({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(T.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>this._bus.emit(T.CREATE,e.features[0]),editfinish:e=>this._bus.emit(T.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(T.CANCEL),vertexselection:e=>this._bus.emit(T.VERTEX_SELECTION,Qo(Qo({},e),{},{numVertices:e.numVertecies})),vertexchange:e=>this._bus.emit(T.VERTEX_CHANGE,Qo(Qo({},e),{},{numVertices:e.numVertecies})),undochange:e=>this._bus.emit(T.UNDO_CHANGE,e.length),update:e=>this._bus.emit(T.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(T.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(T.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(T.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(To,this._mapHandlers.create),this._map.on(ko,this._mapHandlers.editfinish),this._map.on(Vo,this._mapHandlers.cancel),this._map.on(Fo,this._mapHandlers.vertexselection),this._map.on(No,this._mapHandlers.vertexchange),this._map.on(Do,this._mapHandlers.undochange),this._map.on(Lo,this._mapHandlers.update),this._map.on(Ro,this._mapHandlers.geometrychange),this._map.on(Bo,this._mapHandlers.placementblocked),this._map.on(Uo,this._mapHandlers.interfacetypechange),this._map.on(Ao,this._mapHandlers.modechange),this._map.on(Ho,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"===e&&(this._editingFeatureId=null!==(t=r.featureId)&&void 0!==t?t:null);"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=ri(t,e.coordinates);r&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:r.feature,numVertices:r.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update(Qo(Qo({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(Uo,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if("edit_vertex"===t&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(ko,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==t&&"draw_line"!==t||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();"draw_polygon"!==t&&"draw_line"!==t||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(jo)}nudgeSelectedVertex(e,t,r){this._map.fire(Go,{dx:e,dy:t,isLargeStep:r})}setGeometryValid(e){this._map._drawGeometryValid=e}set _geometryValidator(e){this._map._drawGeometryValidator=e}get _geometryValidator(){return this._map._drawGeometryValidator}setInvalid(e){this._liveStroke.set(e)}_applyStrokeInvalid(e){this._setLayerVisibility("stroke-active",!e),this._setLayerVisibility("stroke-active-invalid",e),this._setLayerVisibility("fill-active",!e)}_setLayerVisibility(e,t){["hot","cold"].forEach(r=>{var n="".concat(e,".").concat(r);this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}add(e){return this._draw.add(e)}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=Kt(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(Qt(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=Kt(this._map);null!=t&&t.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,r){this._draw.setFeatureProperty(e,t,r)}setDrawingPreviewProperty(e,t){var r,n=this._currentDrawEvent;null!=n&&n.properties&&(n.properties[e]=t),null==n||null===(r=n.ctx)||void 0===r||null===(r=r.store)||void 0===r||r.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","edit_vertex"]).has(e.mode)||Wt(Kt(this._map),this._map)}_handleStyleData(){var e;this._liveStroke.refresh();var t=this._map.getStyle().layers||[];!t.length||null!==(e=t[t.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||t.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>this._map.moveLayer(e.id))}remove(){this._map.off(To,this._mapHandlers.create),this._map.off(ko,this._mapHandlers.editfinish),this._map.off(Vo,this._mapHandlers.cancel),this._map.off(Fo,this._mapHandlers.vertexselection),this._map.off(No,this._mapHandlers.vertexchange),this._map.off(Do,this._mapHandlers.undochange),this._map.off(Lo,this._mapHandlers.update),this._map.off(Ro,this._mapHandlers.geometrychange),this._map.off(Bo,this._mapHandlers.placementblocked),this._map.off(Uo,this._mapHandlers.interfacetypechange),this._map.off(Ao,this._mapHandlers.modechange),this._map.off(Ho,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}},displayedShape:ri});export{ni as M,Zo as a,pr as b,Ko as c,hr as d,Oo as e,gr as h,yr as i,mr as r,fr as s};
1
+ import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,S as o,C as i,K as a,M as s,s as c,v as l,a as u,b as d,d as p,e as h,r as f,l as g,p as y,f as m,g as v,m as b,h as _,j as x,k as O,n as P,o as E,q as S,t as w,u as I,w as C,L as M,H as T,A as L}from"./im-draw-plugin.js";import k from"@babel/runtime/helpers/asyncToGenerator";const A={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},j={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},V={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},F={POLYGON:"polygon",LINE:"line_string",POINT:"point"},D={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},N={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},R={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},U={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},B={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},G={ACTIVE:"true",INACTIVE:"false"},H=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var Y=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:G,classes:A,cursors:V,events:R,geojsonTypes:D,interactions:H,meta:B,modes:N,sources:j,types:F,updateActions:U});function X(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function K(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function J(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===G.ACTIVE&&e.featureTarget.properties.meta===B.FEATURE))}function $(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===G.INACTIVE&&e.featureTarget.properties.meta===B.FEATURE))}function q(e){return void 0===e.featureTarget}function z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===B.FEATURE)}function Z(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===B.VERTEX)}function W(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function Q(e){return"Escape"===e.key||27===e.keyCode}function ee(e){return"Enter"===e.key||13===e.keyCode}function te(e){return"Backspace"===e.key||8===e.keyCode}function re(e){return"Delete"===e.key||46===e.keyCode}function ne(e){return"1"===e.key||49===e.keyCode}function oe(e){return"2"===e.key||50===e.keyCode}function ie(e){return"3"===e.key||51===e.keyCode}function ae(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var se=Object.freeze({__proto__:null,isActiveFeature:J,isBackspaceKey:te,isDeleteKey:re,isDigit1Key:ne,isDigit2Key:oe,isDigit3Key:ie,isDigitKey:ae,isEnterKey:ee,isEscapeKey:Q,isFeature:z,isInactiveFeature:$,isOfMetaType:X,isShiftDown:W,isShiftMousedown:K,isTrue:function(){return!0},isVertex:Z,noTarget:q});function ce(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function le(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var ue,de,pe={},he={};function fe(){return ue||(ue=1,he.RADIUS=6378137,he.FLATTENING=1/298.257223563,he.POLAR_RADIUS=6356752.3142),he}var ge=function(){if(de)return pe;de=1;var e=fe();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(r(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(r(e[n]))}return t}function r(t){var r,o,i,a,s,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,a=u-1,s=0):c===u-1?(i=u-1,a=0,s=1):(i=c,a=c+1,s=c+2),r=t[i],o=t[a],l+=(n(t[s][0])-n(r[0]))*Math.sin(n(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function n(e){return e*Math.PI/180}return pe.geometry=function e(r){var n,o=0;switch(r.type){case"Polygon":return t(r.coordinates);case"MultiPolygon":for(n=0;n<r.coordinates.length;n++)o+=t(r.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<r.geometries.length;n++)o+=e(r.geometries[n]);return o}},pe.ring=r,pe}(),ye=ce(ge);const me={Point:0,LineString:1,MultiLineString:1,Polygon:2};function ve(e,t){const r=me[e.geometry.type]-me[t.geometry.type];return 0===r&&e.geometry.type===D.POLYGON?e.area-t.area:r}function be(e){return e.map(e=>(e.geometry.type===D.POLYGON&&(e.area=ye.geometry({type:D.FEATURE,property:{},geometry:e.geometry})),e)).sort(ve).map(e=>(delete e.area,e))}function _e(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function xe(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}xe.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},xe.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},xe.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},xe.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((e,t)=>e.v-t.v).map(e=>e.k)},xe.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Oe=[B.FEATURE,B.MIDPOINT,B.VERTEX];var Pe={click:function(e,t,r){return Ee(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Ee(e,t,r,r.options.touchBuffer)}};function Ee(e,t,r,n){if(null===r.map)return[];const o=e?_e(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==Oe.indexOf(e.properties.meta)),s=new xe,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),be(c)}function Se(e,t){const r=Pe.click(e,null,t),n={mouse:V.NONE};return r[0]&&(n.mouse=r[0].properties.active===G.ACTIVE?V.MOVE:V.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=V.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function we(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function Ie(e,t,r={}){const n=null!=r.fineTolerance?r.fineTolerance:4,o=null!=r.grossTolerance?r.grossTolerance:12,i=null!=r.interval?r.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const a=we(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Ce(e,t,r={}){const n=null!=r.tolerance?r.tolerance:25,o=null!=r.interval?r.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return we(e.point,t.point)<n&&t.time-e.time<o}const Me=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===r[e])throw new Error(`Invalid event type: ${e}`);r[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=r[e];let a=i.length;for(;a--;){const e=i[a];if(e.selector(o)){e.fn.call(n,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const Te=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Le(){return Te()}const ke=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Le(),this.type=t.geometry.type};ke.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ke.prototype.incomingCoords=function(e){this.setCoordinates(e)},ke.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ke.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ke.prototype.setProperty=function(e,t){this.properties[e]=t},ke.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:D.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ke.prototype.internal=function(e){const t={id:this.id,meta:B.FEATURE,"meta:type":this.type,active:G.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:D.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ae=function(e,t){ke.call(this,e,t)};(Ae.prototype=Object.create(ke.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ae.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},Ae.prototype.getCoordinate=function(){return this.getCoordinates()};const je=function(e,t){ke.call(this,e,t)};(je.prototype=Object.create(ke.prototype)).isValid=function(){return this.coordinates.length>1},je.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},je.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},je.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},je.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ve=function(e,t){ke.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ve.prototype=Object.create(ke.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ve.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ve.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ve.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(e=>parseInt(e,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},Ve.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},Ve.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},Ve.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ve.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const Fe={MultiPoint:Ae,MultiLineString:je,MultiPolygon:Ve},De=(e,t,r,n,o)=>{const i=r.split("."),a=parseInt(i[0],10),s=i[1]?i.slice(1).join("."):null;return e[a][t](s,n,o)},Ne=function(e,t){if(ke.call(this,e,t),delete this.coordinates,this.model=Fe[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function Re(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ne.prototype=Object.create(ke.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Le(),type:D.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ne.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ne.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ne.prototype.getCoordinate=function(e){return De(this.features,"getCoordinate",e)},Ne.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===D.POLYGON?e.getCoordinates():e.coordinates)))},Ne.prototype.updateCoordinate=function(e,t,r){De(this.features,"updateCoordinate",e,t,r),this.changed()},Ne.prototype.addCoordinate=function(e,t,r){De(this.features,"addCoordinate",e,t,r),this.changed()},Ne.prototype.removeCoordinate=function(e){De(this.features,"removeCoordinate",e),this.changed()},Ne.prototype.getFeatures=function(){return this.features},Re.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Re.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Re.prototype.getSelected=function(){return this._ctx.store.getSelected()},Re.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Re.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Re.prototype.getFeature=function(e){return this._ctx.store.get(e)},Re.prototype.select=function(e){return this._ctx.store.select(e)},Re.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Re.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Re.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Re.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Re.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Re.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Re.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Re.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Re.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Re.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Re.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return Pe[r](e,t,this._ctx)},Re.prototype.newFeature=function(e){const t=e.geometry.type;return t===D.POINT?new Ae(this._ctx,e):t===D.LINE_STRING?new je(this._ctx,e):t===D.POLYGON?new Ve(this._ctx,e):new Ne(this._ctx,e)},Re.prototype.isInstanceOf=function(e,t){if(e===D.POINT)return t instanceof Ae;if(e===D.LINE_STRING)return t instanceof je;if(e===D.POLYGON)return t instanceof Ve;if("MultiFeature"===e)return t instanceof Ne;throw new Error(`Unknown feature class: ${e}`)},Re.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Re.prototype.onSetup=function(){},Re.prototype.onDrag=function(){},Re.prototype.onClick=function(){},Re.prototype.onMouseMove=function(){},Re.prototype.onMouseDown=function(){},Re.prototype.onMouseUp=function(){},Re.prototype.onMouseOut=function(){},Re.prototype.onKeyUp=function(){},Re.prototype.onKeyDown=function(){},Re.prototype.onTouchStart=function(){},Re.prototype.onTouchMove=function(){},Re.prototype.onTouchEnd=function(){},Re.prototype.onTap=function(){},Re.prototype.onStop=function(){},Re.prototype.onTrash=function(){},Re.prototype.onCombineFeature=function(){},Re.prototype.onUncombineFeature=function(){},Re.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Ue={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Be=Object.keys(Ue);function Ge(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Re(r));return{start(){o=i.onSetup(n),Be.forEach(t=>{const r=Ue[t];let n=()=>!1;var a;e[r]&&(n=()=>!0),this.on(t,n,(a=r,e=>i[a](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function He(e){return[].concat(e).filter(e=>void 0!==e)}function Ye(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(j.HOT)))return s();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let r=[],n=[];e.isDirty?n=e.getAllIds():(r=e.getChangedIds().filter(t=>void 0!==e.get(t)),n=e.sources.hot.filter(t=>t.properties.id&&-1===r.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===r.indexOf(t)});const i=o!==e.sources.cold.length||n.length>0;function a(r,n){const o=e.get(r).internal(t);e.ctx.events.currentModeRender(o,r=>{r.properties.mode=t,e.sources[n].push(r)})}function s(){e.isDirty=!1,e.clearChangedIds()}r.forEach(e=>a(e,"hot")),n.forEach(e=>a(e,"cold")),i&&e.ctx.map.getSource(j.COLD).setData({type:D.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(j.HOT).setData({type:D.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Xe(e){let t;this._features={},this._featureIds=new xe,this._selectedFeatureIds=new xe,this._selectedCoordinates=[],this._changedFeatureIds=new xe,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ye.call(this),this._emitSelectionChange&&(this.ctx.events.fire(R.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(R.RENDER,{})}))},this.isDirty=!1}function Ke(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}Xe.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Xe.prototype.setDirty=function(){return this.isDirty=!0,this},Xe.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(R.CREATE,{features:[t.toGeoJSON()]})}return this},Xe.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(R.UPDATE,{action:t.action?t.action:U.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Xe.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Xe.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Xe.prototype.getAllIds=function(){return this._featureIds.values()},Xe.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Xe.prototype.delete=function(e,t={}){const r=[];return He(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===r.indexOf(this._features[e])&&r.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),r.length&&this.ctx.events.fire(R.DELETE,{features:r}),Ke(this,t),this},Xe.prototype.get=function(e){return this._features[e]},Xe.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Xe.prototype.select=function(e,t={}){return He(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Xe.prototype.deselect=function(e,t={}){return He(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Ke(this,t),this},Xe.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Xe.prototype.setSelected=function(e,t={}){return e=He(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},Xe.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Xe.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Xe.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Xe.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Xe.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Xe.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Xe.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:U.CHANGE_PROPERTIES})},Xe.prototype.storeMapConfig=function(){H.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Xe.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Xe.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Je=["mode","feature","mouse"];function $e(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,r)=>(t[r]=Ge(e.options.modes[r]),t),{});let r={},n={};const o={};let i=null,a=null;o.drag=function(t,r){r({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:V.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ie(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Ce(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=Se(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Se(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Se(t,e);t.featureTarget=n,Ie(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(e){a.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;n={time:(new Date).getTime(),point:t.point};const r=Pe.touch(t,null,e)[0];t.featureTarget=r,a.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const r=Pe.touch(t,null,e)[0];t.featureTarget=r,Ce(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=te(e),r=re(e),n=ae(e);return!(t||r||n)};function c(r,n,o={}){a.stop();const s=t[r];if(void 0===s)throw new Error(`${r} is not valid`);i=r;const c=s(e,n);a=Me(c,e),o.silent||e.map.fire(R.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(A.CANVAS)&&((te(t)||re(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):ne(t)&&e.options.controls.point?c(N.DRAW_POINT):oe(t)&&e.options.controls.line_string?c(N.DRAW_LINE_STRING):ie(t)&&e.options.controls.polygon&&c(N.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,a=Me(t[i](e),e)},changeMode:c,actionable:function(t){let r=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(r=!0),l[e]=t[e]}),r&&e.map.fire(R.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];Je.forEach(e=>{o[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==o[e]&&r.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),r.length>0&&e.container.classList.add(...r),n=Object.assign(n,o)}function s(e,t={}){const n=document.createElement("button");return n.className=`${A.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),n.target===r)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),n}function c(){r&&(r.classList.remove(A.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(A.ACTIVE_BUTTON),r=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:a,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),a()},addButtons:function(){const r=e.options.controls,n=document.createElement("div");return n.className=`${A.CONTROL_GROUP} ${A.CONTROL_BASE}`,r?(r[F.POINT]&&(t[F.POINT]=s(F.POINT,{container:n,className:A.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(N.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[F.LINE]&&(t[F.LINE]=s(F.LINE,{container:n,className:A.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(N.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[F.POLYGON]&&(t[F.POLYGON]=s(F.POLYGON,{container:n,className:A.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(N.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:A.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:A.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:A.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach(e=>{const r=t[e];r.parentNode&&r.parentNode.removeChild(r),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new Xe(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(j.COLD,{data:{type:D.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(j.HOT,{data:{type:D.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(j.COLD)&&e.map.removeSource(j.COLD),e.map.getSource(j.HOT)&&e.map.removeSource(j.HOT)}};return e.setup=n,n}const qe="#3bb2d0",ze="#fbb03b",Ze="#fff";var We=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],ze,qe],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],ze,qe],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Ze}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],ze,qe]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Ze}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":ze}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":ze}}];function Qe(e,t){this.x=e,this.y=t}function et(e,t){const r=t.getBoundingClientRect();return new Qe(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function tt(e,t,r,n){return{type:D.FEATURE,properties:{meta:B.VERTEX,parent:e,coord_path:r,active:n?G.ACTIVE:G.INACTIVE},geometry:{type:D.POINT,coordinates:t}}}function rt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return nt(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>nt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return it(e);default:throw new Error("unknown GeoJSON type")}}function nt(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=ot(e.properties),null==e.geometry?t.geometry=null:t.geometry=it(e.geometry),t}function ot(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=ot(n):t[r]=n}),t):t}function it(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>it(e)),t):(t.coordinates=at(e.coordinates),t)}function at(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>at(e))}function st(e,t={}){return ct(e,"mercator",t)}function ct(e,n,o={}){var i=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&t(e[0])?e="mercator"===n?lt(e):ut(e):(!0!==i&&(e=rt(e)),r(e,function(e){var t="mercator"===n?lt(e):ut(e);e[0]=t[0],e[1]=t[1]})),e}function lt(e){var t,r=Math.PI/180,n=6378137,o=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*r,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*r))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function ut(e){var t=180/Math.PI,r=6378137;return[e[0]*t/r,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/r)))*t]}function dt(e,t,r){const n=t.geometry.coordinates,o=r.geometry.coordinates;if(n[1]>85||n[1]<-85||o[1]>85||o[1]<-85)return null;const i=st(n),a=st(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ct(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:D.FEATURE,properties:{meta:B.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:D.POINT,coordinates:u}}}function pt(e,t={},r=null){const{type:n,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let a=[];function s(e,r){let n="",o=null;e.forEach((e,s)=>{const l=null!=r?`${r}.${s}`:String(s),u=tt(i,e,l,c(l));if(t.midpoints&&o){const e=dt(i,o,u);e&&a.push(e)}o=u;const d=JSON.stringify(e);n!==d&&a.push(u),0===s&&(n=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===D.POINT?a.push(tt(i,o,r,c(r))):n===D.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===D.LINE_STRING?s(o,r):0===n.indexOf(D.MULTI_PREFIX)&&function(){const r=n.replace(D.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:D.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(pt(i,t,o))})}(),a}Qe.prototype={clone(){return new Qe(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,o=r*this.x+t*this.y;return this.x=n,this.y=o,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),o=t.x+r*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Qe},Qe.convert=function(e){if(e instanceof Qe)return e;if(Array.isArray(e))return new Qe(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Qe(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var ht={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:ft,LAT_MAX:gt,LAT_RENDERED_MIN:yt,LAT_RENDERED_MAX:mt,LNG_MIN:vt,LNG_MAX:bt}=Y;function _t(e,t){let r=ft,n=gt,o=ft,i=gt,a=bt,s=vt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),d>s&&(s=d)});const c=t;return r+c.lat>mt&&(c.lat=mt-r),o+c.lat>gt&&(c.lat=gt-o),n+c.lat<yt&&(c.lat=yt-n),i+c.lat<ft&&(c.lat=ft-i),a+c.lng<=vt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=bt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function xt(e,t){const r=_t(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+r.lng,lat:e[1]+r.lat};return[t.lng,t.lat]},o=e=>e.map(e=>n(e)),i=e=>e.map(e=>o(e));let a;e.type===D.POINT?a=n(t):e.type===D.LINE_STRING||e.type===D.MULTI_POINT?a=t.map(n):e.type===D.POLYGON||e.type===D.MULTI_LINE_STRING?a=t.map(o):e.type===D.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Ot={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(R.UPDATE,{action:U.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let r=!1;if(e.length>1){r=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(r=!1)})}const n=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new xe).values()},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){ht.enable(this)},onMouseMove:function(e,t){return z(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Ot.onTap=Ot.onClick=function(e,t){return q(t)?this.clickAnywhere(e,t):X(B.VERTEX)(t)?this.clickOnVertex(e,t):z(t)?this.clickOnFeature(e,t):void 0},Ot.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),ht.enable(this),this.stopExtendedInteractions(e)},Ot.clickOnVertex=function(e,t){this.changeMode(N.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:V.MOVE})},Ot.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Ot.clickOnFeature=function(e,t){ht.disable(this),this.stopExtendedInteractions(e);const r=W(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==D.POINT)return this.changeMode(N.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:V.POINTER}),1===n.length&&ht.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:V.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:V.MOVE})),this.doRender(o)},Ot.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),J(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&K(t)?this.startBoxSelect(e,t):void 0},Ot.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=et(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Ot.onTouchStart=function(e,t){if(J(t))return this.startOnActiveFeature(e,t)},Ot.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Ot.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:V.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(A.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=et(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),o=Math.max(e.boxSelectStartLocation.x,r.x),i=Math.min(e.boxSelectStartLocation.y,r.y),a=Math.max(e.boxSelectStartLocation.y,r.y),s=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=s,e.boxSelectElement.style.WebkitTransform=s,e.boxSelectElement.style.width=o-n+"px",e.boxSelectElement.style.height=a-i+"px"},Ot.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Ot.onTouchEnd=Ot.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,et(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),o=this.getUniqueIds(n).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:V.MOVE}))}this.stopExtendedInteractions(e)},Ot.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?G.ACTIVE:G.INACTIVE,r(t),this.fireActionable(),t.properties.active===G.ACTIVE&&t.geometry.type!==D.POINT&&pt(t).forEach(r)},Ot.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Ot.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),r.push(i.toGeoJSON())}if(r.length>1){const e=this.newFeature({type:D.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(R.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Ot.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],r=[];for(let n=0;n<e.length;n++){const o=e[n];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))}t.length>1&&this.fire(R.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const Pt=X(B.VERTEX),Et=X(B.MIDPOINT),St={fireUpdate:function(){this.fire(R.UPDATE,{action:U.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);W(t)||-1!==n?W(t)&&-1===n&&e.selectedCoordPaths.push(r.coord_path):e.selectedCoordPaths=[r.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,r){xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=_t(n.map(e=>({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:e}})),r);for(let t=0;t<n.length;t++){const r=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],r[0]+o.lng,r[1]+o.lat)}},clickNoTarget:function(){this.changeMode(N.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(N.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===D.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),ht.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){ht.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=G.ACTIVE,r(t),pt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=G.INACTIVE,r(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(N.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=J(t),n=Pt(t),o=Et(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:V.MOVE}):this.updateUIClasses({mouse:V.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};St.onTouchStart=St.onMouseDown=function(e,t){return Pt(t)?this.onVertex(e,t):J(t)?this.onFeature(e,t):Et(t)?this.onMidpoint(e,t):void 0},St.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},St.onClick=function(e,t){return q(t)?this.clickNoTarget(e,t):J(t)?this.clickActiveFeature(e,t):$(t)?this.clickInactive(e,t):void this.stopDragging(e)},St.onTap=function(e,t){return q(t)?this.clickNoTarget(e,t):J(t)?this.clickActiveFeature(e,t):$(t)?this.clickInactive(e,t):void 0},St.onTouchEnd=St.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const wt={};function It(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}wt.onSetup=function(){const e=this.newFeature({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:V.ADD}),this.activateUIButton(F.POINT),this.setActionableState({trash:!0}),{point:e}},wt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},wt.onTap=wt.onClick=function(e,t){this.updateUIClasses({mouse:V.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(R.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.point.id]})},wt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},wt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?G.ACTIVE:G.INACTIVE,!n)return r(t)},wt.onTrash=wt.stopDrawingAndRemove,wt.onKeyUp=function(e,t){if(Q(t)||ee(t))return this.stopDrawingAndRemove(e,t)};const Ct={onSetup:function(){const e=this.newFeature({type:D.FEATURE,properties:{},geometry:{type:D.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),ht.disable(this),this.updateUIClasses({mouse:V.ADD}),this.activateUIButton(F.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:V.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),Z(t)&&this.updateUIClasses({mouse:V.POINTER})}};Ct.onTap=Ct.onClick=function(e,t){return Z(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ct.onKeyUp=function(e,t){Q(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)):ee(t)&&this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ct.onStop=function(e){this.updateUIClasses({mouse:V.NONE}),ht.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(R.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Ct.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?G.ACTIVE:G.INACTIVE,!n)return r(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=B.FEATURE,r(tt(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(tt(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:D.FEATURE,properties:t.properties,geometry:{coordinates:e,type:D.LINE_STRING}}),3===o)return}return r(t)}},Ct.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)};const Mt={onSetup:function(e){const t=(e=e||{}).featureId;let r,n,o="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const a=r.coordinates.length-1;if(r.coordinates[a][0]===i[0]&&r.coordinates[a][1]===i[1])n=a+1,r.addCoordinate(n,...r.coordinates[a]);else{if(r.coordinates[0][0]!==i[0]||r.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",n=0,r.addCoordinate(n,...r.coordinates[0])}}else r=this.newFeature({type:D.FEATURE,properties:{},geometry:{type:D.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),ht.disable(this),this.updateUIClasses({mouse:V.ADD}),this.activateUIButton(F.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&It(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:V.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),Z(t)&&this.updateUIClasses({mouse:V.POINTER})}};Mt.onTap=Mt.onClick=function(e,t){if(Z(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Mt.onKeyUp=function(e,t){ee(t)?this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]}):Q(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT))},Mt.onStop=function(e){ht.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(R.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Mt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},Mt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?G.ACTIVE:G.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=B.FEATURE,r(tt(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),r(t))};var Tt={simple_select:Ot,direct_select:St,draw_point:wt,draw_polygon:Ct,draw_line_string:Mt};const Lt={defaultMode:N.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:We,modes:Tt,controls:{},userProperties:!1,suppressAPIEvents:!0},kt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},At={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function jt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?j.HOT:j.COLD}))}var Vt,Ft;var Dt,Nt,Rt=ce(Ft?Vt:(Ft=1,Vt=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}));var Ut=function(){if(Nt)return Dt;Nt=1,Dt=function(t){if(!t||!t.type)return null;var r=e[t.type];if(!r)return null;if("geometry"===r)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===r)return{type:"FeatureCollection",features:[t]};if("featurecollection"===r)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Dt}(),Bt=ce(Ut);function Gt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Ht={Polygon:Ve,LineString:je,Point:Ae,MultiPolygon:Ne,MultiLineString:Ne,MultiPoint:Ne};var Yt=Object.freeze({__proto__:null,CommonSelectors:se,ModeHandler:Me,StringSet:xe,constrainFeatureMovement:_t,createMidPoint:dt,createSupplementaryPoints:pt,createVertex:tt,doubleClickZoom:ht,euclideanDistance:we,featuresAt:Pe,getFeatureAtAndSetCursors:Se,isClick:Ie,isEventAtCoordinates:It,isTap:Ce,mapEventToBoundingBox:_e,moveFeatures:xt,sortFeatures:be,stringSetsAreEqual:Gt,theme:We,toDenseArray:He});const Xt=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},At,e.controls):t.controls=Object.assign({},kt,e.controls),t=Object.assign({},Lt,t),t.styles=jt(t.styles,"cold").concat(jt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=N;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Pe.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:D.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:D.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==D.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(r),a=new xe(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Bt(t))).features.map(t=>{if(t.id=t.id||Le(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=Ht[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Rt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Rt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:D.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==N.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===N.DIRECT_SELECT?e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===N.SIMPLE_SELECT&&t.getMode()===N.SIMPLE_SELECT?(Gt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===N.DIRECT_SELECT&&t.getMode()===N.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,o,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,o,i){return e.store.setFeatureProperty(n,o,i,{silent:r}),t},t}(r,t),r.api=t;const n=$e(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=F,t.options=e,t};function Kt(e){Xt(e,this)}Kt.modes=Tt,Kt.constants=Y,Kt.lib=Yt;var Jt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},$t="draw.create",qt="draw.update",zt="draw.modechange",Zt="draw.editfinish",Wt="draw.cancel",Qt="draw.vertexselection",er="draw.vertexchange",tr="draw.undochange",rr="draw.undo",nr="draw.geometrychange",or="draw.interfacetypechange",ir="draw.placementblocked",ar="draw.nudgevertex",sr="styledata",cr=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},lr=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!0}),r+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,o)=>{t.push({start:r,length:e.length,path:[n,o],closed:!0}),r+=e.length})})}return t},ur=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},dr=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},pr=(e,t)=>{var r=t.split(".").map(Number),n=lr(e);for(var o of n){if(o.path.every((e,t)=>e===r[t])&&r.length===o.path.length+1){var i=r[r.length-1];return o.start+i}}return r[r.length-1]},hr=(e,t)=>({x:e.x*t,y:e.y*t}),fr=e=>e instanceof window.SVGElement||e.ownerSVGElement;function gr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function yr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?gr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function mr(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function vr(e){var t;return!!(null!=e&&e.status&&null!=e&&e.snapStatus&&(null===(t=e.snapCoords)||void 0===t?void 0:t.length)>=2)}function br(e){return vr(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function _r(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function xr(e,t){e&&(e._autoSnapSuspended=t)}function Or(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Pr(e,t){var r,n,o;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(r=e.snappedFeatures)&&void 0!==r&&r.length&&(e.snappedFeatures.length=0),null!==(n=e.closeFeatures)&&void 0!==n&&n.length&&(e.closeFeatures.length=0),null!==(o=e.lines)&&void 0!==o&&o.length&&(e.lines.length=0));null!=t&&t.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function Er(e){var t,r,n;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(t=e.snappedFeatures)&&void 0!==t&&t.length&&(e.snappedFeatures.length=0),null!==(r=e.closeFeatures)&&void 0!==r&&r.length&&(e.closeFeatures.length=0),null!==(n=e.lines)&&void 0!==n&&n.length&&(e.lines.length=0))}function Sr(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var wr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r=>n=>r.call(e,t,n),o={keydown:n(e.onKeydown),keyup:n(e.onKeyup),pointerdown:n(e.onPointerevent),pointermove:n(e.onPointerevent),pointerup:n(e.onPointerevent),click:n(e.onButtonClick),touchstart:n(e.onTouchstart),touchmove:n(e.onTouchmove),touchend:n(e.onTouchend),scalechange:n(e.onScaleChange),move:n(e.onMove),interfacetypechange:n(e.onInterfaceTypeChange)};for(var[i,a]of Object.entries(r))o[i]=n(a);return o},Ir=(e,t,r)=>{window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),t.on("draw.scalechange",r.scalechange),t.on("move",r.move),t.on(or,r.interfacetypechange),t.on(ar,r.nudge)},Cr=(e,t,r)=>{e.container.removeEventListener("pointerdown",r.pointerdown),e.container.removeEventListener("pointermove",r.pointermove),e.container.removeEventListener("pointerup",r.pointerup),e.container.removeEventListener("touchstart",r.touchstart),e.container.removeEventListener("touchmove",r.touchmove),e.container.removeEventListener("touchend",r.touchend),t.off("draw.scalechange",r.scalechange),t.off("move",r.move),t.off(or,r.interfacetypechange),t.off(ar,r.nudge),t.dragPan.enable(),window.removeEventListener("click",r.click),window.removeEventListener("keydown",r.keydown,{capture:!0}),window.removeEventListener("keyup",r.keyup,{capture:!0})},Mr=e=>{var t=mr(e);t&&Pr(t,e)},Tr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,r){e&&setTimeout(()=>{var n=this.getFeature(r);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){var t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}};function Lr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function kr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Lr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ar={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},jr=kr(kr({},Tr),{},{UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Ar,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r),this.emitGeometryValidation(Ar[r.type],r.vertexIndex,r.featureId)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=lr(i),c=ur(s,r);if(c){dr(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,hr(this.map.project(l),e.scale))}}},undoInsertVertex(e,t){var{vertexIndex:r,featureId:n}=t,o=this.getFeature(n);if(o){var i=o.toGeoJSON(),a=lr(o),s=ur(a,r);if(s)dr(i,s.segment.path).splice(s.localIdx,1),this._applyUndoAndSync(e,i,n),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},undoDeleteVertex(e,t){var{vertexIndex:r,position:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=lr(i),c=ur(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)dr(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,hr(this.map.project(e.vertecies[r]),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertecies=this.getVerticies(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}}),Vr=o.touchTargetSize/2;var Fr=e=>{var t,r,n=e.querySelector("[data-im-draw-touch-target]");return n||(e.insertAdjacentHTML("beforeend",(t=o.touchTargetSize,r=Vr,"\n <svg width='".concat(t,"' height='").concat(t,"' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:").concat(r,"px 0 0 -").concat(r,"px;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 "))),n=e.querySelector("[data-im-draw-touch-target]")),n},Dr=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},Nr=(e,t)=>{t&&e&&(e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px"),e.style.display="block")},Rr=e=>{e&&(e.style.display="none")},Ur=e=>{if(!e)return!1;var t=e.parentNode;return t instanceof globalThis.SVGElement||null!=(null==t?void 0:t.ownerSVGElement)},Br=function(e){var t,r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=null!==(t=null==e?void 0:e.mapColorScheme)&&void 0!==t?t:"light",c=null!==(r=null==e?void 0:e.id)&&void 0!==r?r:null,l=e=>{var t;return function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return"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]}(null!==(t=a[e])&&void 0!==t?t:i[e],s,c)};return{editStroke:l("editStroke"),editFill:l("editFill"),editVertex:l("editVertex"),editMidpoint:l("editMidpoint"),editActive:l("editActive"),editHalo:l("editHalo"),invalidStroke:l("invalidStroke"),splitValid:l("splitValid"),splitInvalid:l("splitInvalid"),shapeStroke:l("shapeStroke"),strokeWidth:null!==(n=a.strokeWidth)&&void 0!==n?n:o.strokeWidth,shapeFill:l("shapeFill"),snapVertex:l("snapVertex"),snapEdge:l("snapEdge"),mapStyleId:c}},Gr=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Hr=(e,t,r,n,o)=>{var i=window.getComputedStyle(t),a={x:r.x-Number.parseFloat(i.left),y:r.y-Number.parseFloat(i.top)},s=e.project(n);return{deltaTarget:a,deltaVertex:{x:r.x/o-s.x,y:r.y/o-s.y}}},Yr=(e,t,r)=>{var n={x:r.x/t.scale-t.deltaVertex.x,y:r.y/t.scale-t.deltaVertex.y},o=e.unproject(n);if(Sr(t)){var i=mr(e);_r(i,e,n),o=br(i)||o}return o};function Xr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Kr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Jr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=Br(t,r);Dr(e,{editActive:n,editHalo:o,editVertex:i})}},$r={addTouchVertexTarget(e){e.touchVertexTarget=Fr(e.container),Jr(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||fr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(Er(mr(this.map)),null!=e&&e.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,hr(this.map.project(t),e.scale))}},onTap(e,t){var r,n,o=mr(this.map);o&&Pr(o,this.map);var i=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,a=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if("vertex"===i){var s=this.getFeature(e.featureId),c=pr(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(Kr(Kr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){Er(mr(this.map));var r=this.getVerticies(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&fr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=Gr(t);Object.assign(e,Hr(this.map,e.touchVertexTarget,o,n,e.scale))}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&fr(t.target.parentNode)){e._touchMoved=!0;var r=Gr(t);this.moveVertex(e,Yr(this.map,e,r)),this.updateTouchVertexTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}},qr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),zr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Zr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Wr=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Zr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},Qr=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,en={handleUndoShortcut(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},tn={getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?a.nudgeAmount:a.stepAmount,[o,i]=t?zr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getOffsetByDelta(e,t,r,n){var o=this.map.project(e),i=n?a.stepAmount:a.nudgeAmount;return this.map.unproject({x:o.x+t*i,y:o.y+r*i})},resolveSnapTarget(e,t,r,o,i){var a=mr(this.map);if(Sr(e)&&e._isSnapped&&a){var s=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:n.snapRadius}(a)+1,c=this.map.project(o);return e._isSnapped=!1,Pr(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return Sr(e)&&a&&(_r(a,this.map,this.map.project(l)),vr(a))?(e._isSnapped=!0,br(a)):(e._isSnapped=!1,l)}};function rn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function nn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?rn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var on=nn(nn({},tn),{},{updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(e,t){var[r,n]=this.getVertexOrMidpoint(e,t);r<0||!n||this.changeMode(e,nn({selectedVertexIndex:r,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,r)}))},getNewCoord(e,t){return this.getOffset(cr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=cr(i))||void 0===o?void 0:o[e.selectedVertexIndex]);if(a){var s=[...a],c=e.selectedVertexIndex,l=this.resolveSnapTarget(e,t,r,a,()=>this.getOffsetByDelta(a,t,r,n));this.moveVertex(e,l),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:c,previousPosition:s})}}},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertecies.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=lr(o),s=r+1,c=null,l=0,u=0;for(var d of a){var p=d.closed?d.length:d.length-1;if(r<u+p){c=d,l=r-u+1,s=d.start+l;break}u+=p}c&&(dr(i,c.path).splice(l,0,[n.lng,n.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),this.changeMode(e,{selectedVertexIndex:s,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,s)}))},moveVertex(e,t){if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).checkSnap&&!1!==e.enableSnap){var r,n=this.map._snapInstance;null!=n&&n.snapStatus&&(null===(r=n.snapCoords)||void 0===r?void 0:r.length)>=2&&(t={lng:n.snapCoords[0],lat:n.snapCoords[1]})}var o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=lr(o),s=ur(a,e.selectedVertexIndex);s&&(dr(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertecies=this.getVerticies(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=lr(t),n=ur(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?s.Polygon:s.LineString;if(!(o.length<=i)){var a=[...e.vertecies[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}}),an={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e,n[0]):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=lr(r),o=ur(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVerticies(e){return cr(this.getFeature(e))},getMidpoints(e){var t=this.getFeature(e),r=cr(t),n=lr(t);if(null==r||!r.length||!n.length)return[];var o=[];for(var i of n)for(var a=i.closed?i.length:i.length-1,s=0;s<a;s++){var c=i.start+s,l=i.start+(s+1)%i.length,[u,d]=r[c],[p,h]=r[l];o.push([(u+p)/2,(d+h)/2])}return o},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertecies)&&void 0!==r&&r.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertecies)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertecies.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=c(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=lr(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertecies.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertecies.length}};function sn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function cn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?sn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):sn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ln=cn(cn({},en),{},{onKeydown(e,t){Wr(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?qr.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?Qr(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){var t,r,n=mr(this.map);n&&Pr(n,this.map),null!==(t=e.vertecies)&&void 0!==t&&t.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertecies)&&void 0!==r&&r.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){var r;if("midpoint"!==e.selectedVertexType){var n=this.getFeature(e.featureId),o=n&&(null===(r=cr(n))||void 0===r?void 0:r[e.selectedVertexIndex]);o&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...o],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,o)))}else this.insertVertex(e,t)},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Wr(e)||(e.interfaceType="keyboard",qr.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&null!=e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=null)),"Delete"===t.key&&this.deleteVertex(e))}}),un={onMouseDown(e,t){var r,n;Er(mr(this.map));var o=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,i=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if(["vertex","midpoint"].includes(o)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,St.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=pr(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertecies)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=pr(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(Qt,{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(Qt,{index:r,numVertecies:e.vertecies.length})}St.onClick.call(this,e,t)},onMouseUp(e,t){Er(mr(this.map));var r=e._isInsertingVertex&&null!=e._insertedVertexIndex,n=this._didVertexMove(e);(e.dragMoving||n||r)&&(this.syncVertices(e),r?this._recordInsertionUndo(e):n&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,St.onMouseUp.call(this,e,t)},_didVertexMove(e){var t;if(!e._moveStartPosition||null==e._moveStartIndex)return!1;var r=this.getFeature(e.featureId),n=r&&(null===(t=cr(r))||void 0===t?void 0:t[e._moveStartIndex]);return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){var t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(Qt,{index:t,numVertecies:e.vertecies.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=mr(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),Sr(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),_r(n,this.map,t.point);var o=br(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else St.onDrag.call(this,e,t)}}};function dn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function pn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?dn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):dn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var hn=pn(pn(pn(pn(pn(pn(pn(pn({},Kt.modes.direct_select),jr),$r),on),an),ln),un),{},{onSetup(e){var t,r,n,o=Kt.modes.direct_select.onSetup.call(this,e);(Object.assign(o,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:o.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1}),this.map._lastEditFeatureId!==o.featureId)&&(null===(n=this.map._undoStack)||void 0===n||n.clear(),this.map._lastEditFeatureId=o.featureId);var i=this.getFeature(o.featureId);if(o.featureType=null==i?void 0:i.type,o.vertecies=this.getVerticies(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o),Mr(this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var a=o.vertecies[o.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(o,hr(this.map.project(a),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=this.handlers=wr(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate});Ir(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertecies.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=cr(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire(Qt,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?hr(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?hr(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertecies.map(e=>JSON.stringify(e))).size!==e.vertecies.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,hr(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertecies[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,hr(this.map.project(r),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",pn(pn({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),Cr(e,this.map,t),this.hideTouchVertexIndicator(e)}});function fn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function gn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?fn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):fn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var yn={move_point:"commit-move"},mn=gn(gn({},Tr),{},{UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:yn,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_point"===r.type&&this.undoMovePoint(e,r),this.emitGeometryValidation(yn[r.type],r.vertexIndex,r.featureId)}},undoMovePoint(e,t){var{previousPosition:r,featureId:n}=t,o=this.getFeature(n);o&&(o.updateCoordinate("",r[0],r[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,hr(this.map.project(r),e.scale)))}}),vn={addTouchPointTarget(e){e.touchPointTarget=Fr(e.container),Jr(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){Er(mr(this.map)),e._touchMoved&&e._moveStartPosition&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._touchMoved=!1,e.feature&&this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){Er(mr(this.map));var r=this.getPointCoord(e);if(r&&fr(t.target.parentNode)){e._moveStartPosition=[...r],e._touchMoved=!1;var n=Gr(t);Object.assign(e,Hr(this.map,e.touchPointTarget,n,r,e.scale))}},onTouchmove(e,t){if(fr(t.target.parentNode)){e._touchMoved=!0;var r=Gr(t);this.movePoint(e,Yr(this.map,e,r)),this.updateTouchPointTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}};function bn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _n(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?bn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):bn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var xn=_n(_n({},tn),{},{getPointCoord(e){var t;return null===(t=this.getFeature(e.featureId))||void 0===t?void 0:t.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,r,n){var o=this.getPointCoord(e);if(o){var i=[...o],a=this.resolveSnapTarget(e,t,r,o,()=>this.getOffsetByDelta(o,t,r,n));this.movePoint(e,a),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}}});function On(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Pn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?On(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):On(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var En=Pn(Pn({},en),{},{onKeydown(e,t){Wr(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?qr.has(t.key)?this.handleArrowKey(e,t):Qr(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){var r=this.getPointCoord(e);r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r]),this.movePoint(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Wr(e)||(e.interfaceType="keyboard",qr.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}}),Sn="edit_point",wn={onFeature(e,t){e.dragMoving||(e._moveStartPosition=[...e.feature.coordinates],e._grabOffset=[e.feature.coordinates[0]-t.lngLat.lng,e.feature.coordinates[1]-t.lngLat.lat],xr(mr(this.map),!0)),St.onFeature.call(this,e,t)},onClick(e,t){if(!J(t)&&((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=l(r,{mode:Sn,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:Sn,vertexIndex:0}),n})(this.map,[t.lngLat.lng,t.lngLat.lat])){var r=[...e.feature.coordinates],n=mr(this.map),o=t.lngLat;Sr(e)&&n&&(_r(n,this.map,t.point),o=br(n)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:r})}},onMouseUp(e,t){var r=mr(this.map);Er(r),xr(r,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,St.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;var t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var r=mr(this.map);if(r&&(r.snapStatus=!1,r.snapCoords=null),Sr(e)&&null!=r&&r.status){if(e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};_r(r,this.map,this.map.project([n.lng,n.lat]));var o=br(r)||n;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else St.onDrag.call(this,e,t)}},onTrash(){}};function In(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Cn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?In(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):In(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Mn=Cn(Cn(Cn(Cn(Cn(Cn(Cn({},Kt.modes.direct_select),mn),vn),xn),En),wn),{},{onSetup(e){var t,r,n=e.featureId,o=this.getFeature(n);if(!o)throw new Error("You must provide a featureId to enter edit_point mode");var i,a={featureId:n,feature:o,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};(this.setSelectedCoordinates([]),this.setSelected(n),ht.disable(this),this.setActionableState({trash:!1}),Object.assign(a,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:null!==(t=e.scale)&&void 0!==t?t:1}),this.map._lastEditFeatureId!==a.featureId)&&(null===(i=this.map._undoStack)||void 0===i||i.clear(),this.map._lastEditFeatureId=a.featureId);return this.setupEventListeners(a),this.map._drawEditContainer=e.container,this.addTouchPointTarget(a),null===(r=a.container)||void 0===r||r.focus({preventScroll:!0}),Mr(this.map),"touch"===a.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(a,hr(this.map.project(a.feature.coordinates),a.scale))},0),this.map.fire(Qt,{index:0,numVertecies:1}),a},setupEventListeners(e){var t=this.handlers=wr(this,e,{nudge:this.onNudgePoint});Ir(e,this.map,t)},toDisplayFeatures(e,t,r){t.properties.active=e.featureId===t.properties.id?"true":"false",r(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Cr(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}});function Tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ln(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Tn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var kn=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?Ln(Ln({},e),{},{featureId:null}):e,a=Ln(Ln({},t.onSetup.call(this,i)),e);a[r].properties=e.properties;var{container:s,vertexMarkerId:c,getInterfaceType:l}=a,u=l?l():a.interfaceType;a.interfaceType=u;var d=s.querySelector("#".concat(c));a.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(a):this._hideCrossHair(a);var p=(e,t)=>this[e]=t.bind(this,a),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(e=>{var[t,r]=e;return p(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),a},onStop(e){t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),["touch","keyboard"].includes(e.interfaceType)||this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function An(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function jn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?An(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):An(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vn=(e,t,r,n,o)=>{setTimeout(()=>{var i=t(n);i&&e.fire("draw.geometrychange",((e,t,r)=>{var n=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[n]}:{type:"LineString",coordinates:n},properties:{}},phase:r,vertexIndex:Math.max(0,n.length-1)}})(i,r,o))},0)},Fn=e=>{var{geometryType:t,getFeature:r,getCoords:n}=e;return{_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(e,o){var i=r(e);if(!i||!o)return!0;var a=u({placed:n(i).slice(0,-1),point:o,geometryType:t,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Vn(this.map,r,n,e,t)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onCreate(e,t){((e,t,r)=>{e.delete(t.id),t.id=r,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}},Dn=e=>{var{ParentMode:t,getFeature:r,getCoords:n,validateClick:o,finishOnInvalidClick:i}=e;return{onClick(e,a){var s;if(!this._isIgnorableClick(a)&&(!1!==this.map._drawGeometryValid||"vertex"!==(null===(s=a.featureTarget)||void 0===s||null===(s=s.properties)||void 0===s?void 0:s.meta))){var c=mr(this.map);if(Sr(e)&&vr(c))a=function(e,t){var r=br(t);return r?yr(yr({},e),{},{lngLat:r}):e}(a,c);else if(!((e,t)=>{var a=n(r(e));return a.length>0&&(a[a.length-1]=[t.lngLat.lng,t.lngLat.lat]),i||o(r(e))})(e,a))return;if(this._canPlaceVertex(e,[a.lngLat.lng,a.lngLat.lat])){var l=n(r(e)).length;t.onClick.call(this,e,a),n(r(e)).length>l&&(this.pushDrawUndo(e),this.dispatchVertexChange(n(r(e))),this.emitDrawValidation(e))}}},doClick(e){if(!this.map._undoInProgress){var a=r(e),s=n(a);if(this.dispatchVertexChange(s),o(a)){var c=mr(this.map),l=Sr(e)&&function(e,t){var r=br(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(this._canPlaceVertex(e,[u.lng,u.lat])){l?(t.onClick.call(this,e,l),this._ctx.store.render()):this._simulateMouse("click",t.onClick,e);var d=n(r(e));this.pushDrawUndo(e),this.dispatchVertexChange(d),this.emitDrawValidation(e)}}else i&&!1!==this.map._drawGeometryValid&&(s.pop(),this.map.fire("draw.create",{features:[a.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[a.id]}))}}}};function Nn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Rn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Nn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Nn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Un=e=>{var{geometryType:t,getFeature:r}=e;return{pushDrawUndo(e){var n=this.map._undoStack;n&&!this.map._undoInProgress&&n.push({type:"draw_vertex",geometryType:t,featureId:r(e).id})},onUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"draw_vertex"===(null==r?void 0:r.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))}},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}},Bn=e=>{var{ParentMode:t,geometryType:r,getCoords:n,getFeature:o}=e;return{undoVertex(e){var t=o(e),r=n(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_removeLastVertex(e,t,o){var i="Polygon"===r?t.coordinates[0]:o;i.splice(-2,1),i[i.length-1]=[...i[i.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(t))},_updateRubberBand(e,n){if(["touch","keyboard"].includes(e.interfaceType))this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render();else{var o=n["Polygon"===r?n.length-2:n.length-1],i={lng:o[0],lat:o[1]},a=this.map.project(i);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}this.dispatchVertexChange(n)}}},Gn=e=>{var{ParentMode:t,featureProp:r,geometryType:n}=e;return{_reinitializeFeature(e,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(e,i);var a=this.map.getCenter(),s=[[a.lng,a.lat],[a.lng,a.lat]],c=this.newFeature({type:"Feature",properties:e.properties||{},geometry:{type:n,coordinates:[s]}});return c.id=i,this._ctx.store.add(c),e[r]=c,e.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render(),this.dispatchVertexChange(s),!0},_restartLineStringDraw(e,t){var r=this.map._undoStack;return r&&r.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}},Hn=e=>{var{ParentMode:t,getFeature:r,INTERFACE_KEYS:n}=e;return{onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(e,n){var o=document.activeElement;if(!o||o===e.container||!e.container.contains(o))if("Escape"!==n.key)o!==e.container&&t.onKeyUp.call(this,e,n);else if("keyboard"===e.interfaceType){var i=this.map._undoStack;i&&i.clear(),this._reinitializeFeature(e,r(e))}}}};function Yn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Xn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Yn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Kn=e=>{var{ParentMode:t,getFeature:r,getCoords:n}=e;return{onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(e,r){if(Sr(e)){var n=mr(this.map);_r(n,this.map,r.point);var o=br(n);o&&(r=Xn(Xn({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e){if(["touch","keyboard"].includes(e.interfaceType)){Sr(e)&&Or(mr(this.map),this.map);var r=mr(this.map),n=Sr(e)&&br(r);if(n){var o=this.map.project([n.lng,n.lat]);t.onMouseMove.call(this,e,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}else this._simulateMouse("mousemove",t.onMouseMove,e)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(r(e)))}}},Jn=e=>{var{ParentMode:t,geometryType:r,getFeature:n,getPlacedCoords:o}=e;return{_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},toDisplayFeatures(e,i,a){t.toDisplayFeatures.call(this,e,i,a);var s=n(e);i.geometry.type===r&&i.properties.id===s.id&&o(i).forEach(e=>a({type:"Feature",properties:{meta:"draw-vertex",parent:s.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}};function $n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function qn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?$n(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):$n(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zn=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s,finishOnInvalidClick:c,getFeature:e=>e[r],INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return qn(qn(qn(qn(qn(qn(qn({},e),kn(l)),(e=>jn(jn({},Fn(e)),Dn(e)))(l)),(e=>Rn(Rn(Rn({},Un(e)),Bn(e)),Gn(e)))(l)),Hn(l)),Kn(l)),Jn(l))},Zn=zn(Kt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>d(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Wn=zn(Kt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>p(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)});function Qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function eo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Qn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Qn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var to="draw_point",ro=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),no=Kt.modes.draw_point,oo=kn({ParentMode:no,featureProp:"point",excludeFeatureIdFromSetup:!1}),io={onKeyUp(){},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},onCreate(e,t){var r,n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),null===(r=e.resolvePointSymbol)||void 0===r||r.call(e,e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e){["touch","keyboard"].includes(e.interfaceType)&&Sr(e)&&Or(mr(this.map),this.map)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onTouchStart(e){this._setInterface(e,"touch"),this.onMove(e)},onTouchEnd(e){this._setInterface(e,"touch"),this.onMove(e)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onMouseMove(e,t){Sr(e)&&_r(mr(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),ro.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&ro.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(!(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())){var r=mr(this.map),n=Sr(e)&&vr(r)?br(r):null;this._commit(e,n||t.lngLat)}},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){var t=mr(this.map);Sr(e)&&Or(t,this.map);var r=Sr(e)&&vr(t)?br(t):null;this._commit(e,r||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=l(r,{mode:to,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:to,vertexIndex:0}),n})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},ao=eo(eo(eo({},no),oo),io),so=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],co=["get","user_sortKey"],lo=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":co},paint:{"fill-color":so(e,"fill",t.shapeFill)}}),uo=(e,t)=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round","line-sort-key":co},paint:{"line-color":so(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),po=e=>({id:"stroke-preview-line",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),ho=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),fo=(e,t,r)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),go=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),yo=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),mo=(e,t,r)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),vo=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),bo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),_o=function(e){var t,r,n,i,a,s=Br(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:c,midpointRadius:l,vertexHaloRadius:u,midpointHaloRadius:d}=o;return[lo(e,s),(a=s.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":a}}),(i=s.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":i,"line-width":2,"line-opacity":1}}),(n=s.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":n,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),uo(e,s),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":co},paint:{}},(r=s.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":r,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(t=s.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t,"line-width":2,"line-opacity":1}}),po(s.editStroke),yo(s.editMidpoint,l),mo(s.editHalo,s.editActive,d),vo(s.editMidpoint,l),ho(s.editVertex,c),fo(s.editHalo,s.editActive,u),go(s.editVertex,c),bo(s.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function xo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Oo(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Po(e,t,r){void 0===r&&(r={});var n=xo(e),o=xo(t),i=h(o[1]-n[1]),a=h(o[0]-n[0]),s=h(n[1]),c=h(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return f(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Eo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function So(e,t,r,n={}){const o=Eo(e),i=h(o[0]),a=h(o[1]),s=h(r),c=g(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=m(u),p=m(l);return void 0!==o[2]?y([d,p,o[2]],n.properties):y([d,p],n.properties)}function wo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return b(e,t);return _(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Io(e,t,r={}){if(!0===r.final)return function(e,t){let r=Io(t,e);return r=(r+180)%360,r}(e,t);const n=Eo(e),o=Eo(t),i=h(n[0]),a=h(o[0]),s=h(n[1]),c=h(o[1]),l=Math.sin(a-i)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(a-i);return m(Math.atan2(l,u))}var Co=Io;function Mo(e,t,r,n){void 0===n&&(n={});var o=xo(e),i=h(o[0]),a=h(o[1]),s=h(r),c=g(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=m(u),p=m(l);return y([d,p],n.properties)}function To(e){if(!e)throw new Error("geojson is required");var t=[];return x(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=Oo(n);break;case"LineString":r=[Oo(n)]}r.forEach(function(r){var n=function(e,t){var r=[];return e.reduce(function(e,n){var o,i,a,s,c,l,u=_([e,n],t);return u.bbox=(i=n,a=(o=e)[0],s=o[1],c=i[0],l=i[1],[a<c?a:c,s<l?s:l,a>c?a:c,s>l?s:l]),r.push(u),n}),r}(r,e.properties);n.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),O(t)}var Lo={exports:{}};function ko(e,t,r,n,o){Ao(e,t,r||0,n||e.length-1,o||Vo)}function Ao(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);Ao(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(jo(e,r,t),o(e[n],u)>0&&jo(e,r,n);d<p;){for(jo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?jo(e,r,p):jo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function jo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Vo(e,t){return e<t?-1:e>t?1:0}function Fo(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Do(e,t){No(e,0,e.children.length,t,e)}function No(e,t,r,n,o){o||(o=$o(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<r;i++){const t=e.children[i];Ro(o,e.leaf?n(t):t)}return o}function Ro(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Uo(e,t){return e.minX-t.minX}function Bo(e,t){return e.minY-t.minY}function Go(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ho(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Yo(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Xo(e,t){const r=Math.max(e.minX,t.minX),n=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-r)*Math.max(0,i-n)}function Ko(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Jo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function $o(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function qo(e,t,r,n,o){const i=[t,r];for(;i.length;){if((r=i.pop())-(t=i.pop())<=n)continue;const a=t+Math.ceil((r-t)/n/2)*n;ko(e,a,t,r,o),i.push(t,a,a,r)}}var zo,Zo=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const r=[];if(!Jo(e,t))return r;const n=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const a=t.children[i],s=t.leaf?n(a):a;Jo(e,s)&&(t.leaf?r.push(a):Ko(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!Jo(e,t))return!1;const r=[];for(;t;){for(let n=0;n<t.children.length;n++){const o=t.children[n],i=t.leaf?this.toBBox(o):o;if(Jo(e,i)){if(t.leaf||Ko(e,i))return!0;r.push(o)}}t=r.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=$o([]),this}remove(e,t){if(!e)return this;let r=this.data;const n=this.toBBox(e),o=[],i=[];let a,s,c;for(;r||o.length;){if(r||(r=o.pop(),s=o[o.length-1],a=i.pop(),c=!0),r.leaf){const n=Fo(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!Ko(r,n)?s?(a++,r=s.children[a],c=!1):r=null:(o.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const r=[];for(;e;)e.leaf?t.push(...e.children):r.push(...e.children),e=r.pop();return t}_build(e,t,r,n){const o=r-t+1;let i,a=this._maxEntries;if(o<=a)return i=$o(e.slice(t,r+1)),Do(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=$o([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));qo(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);qo(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Do(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=Go(a),c=Yo(e,a)-s;c<o?(o=c,n=s<n?s:n,r=a):c===o&&s<n&&(n=s,r=a)}t=r||t.children[0]}return t}_insert(e,t,r){const n=r?e:this.toBBox(e),o=[],i=this._chooseSubtree(n,this.data,t,o);for(i.children.push(e),Ro(i,n);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(n,o,t)}_split(e,t){const r=e[t],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const i=this._chooseSplitIndex(r,o,n),a=$o(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Do(r,this.toBBox),Do(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=$o([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Do(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=No(e,0,a,this.toBBox),s=No(e,a,r,this.toBBox),c=Xo(t,s),l=Go(t)+Go(s);c<o?(o=c,n=a,i=l<i?l:i):c===o&&l<i&&(i=l,n=a)}return n||r-t}_chooseSplitAxis(e,t,r){const n=e.leaf?this.compareMinX:Uo,o=e.leaf?this.compareMinY:Bo;this._allDistMargin(e,t,r,n)<this._allDistMargin(e,t,r,o)&&e.children.sort(n)}_allDistMargin(e,t,r,n){e.children.sort(n);const o=this.toBBox,i=No(e,0,t,o),a=No(e,r-t,r,o);let s=Ho(i)+Ho(a);for(let n=t;n<r-t;n++){const t=e.children[n];Ro(i,e.leaf?o(t):t),s+=Ho(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Ro(a,e.leaf?o(t):t),s+=Ho(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Ro(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Do(e[r],this.toBBox)}}}),Wo=le(Zo),Qo={};function ei(){if(zo)return Qo;zo=1,Object.defineProperty(Qo,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},r={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function n(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function o(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:e},t,r)}function i(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:e},t,r)}function a(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:e},t,r)}function s(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return n({type:"MultiLineString",coordinates:e},t,r)}function l(e,t,r={}){return n({type:"MultiPoint",coordinates:e},t,r)}function u(e,t,r={}){return n({type:"MultiPolygon",coordinates:e},t,r)}function d(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e/n}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Qo.areaFactors=r,Qo.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Qo.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Qo.convertArea=function(e,t="meters",n="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=r[t];if(!o)throw new Error("invalid original units");const i=r[n];if(!i)throw new Error("invalid final units");return e/o*i},Qo.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),r)},Qo.degreesToRadians=function(e){return e%360*Math.PI/180},Qo.earthRadius=e,Qo.factors=t,Qo.feature=n,Qo.featureCollection=s,Qo.geometry=function(e,t,r={}){switch(e){case"Point":return o(t).geometry;case"LineString":return a(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},Qo.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},Qo.isNumber=f,Qo.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Qo.lengthToDegrees=function(e,t){return h(p(e,t))},Qo.lengthToRadians=p,Qo.lineString=a,Qo.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},Qo.multiLineString=c,Qo.multiPoint=l,Qo.multiPolygon=u,Qo.point=o,Qo.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},Qo.polygon=i,Qo.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},Qo.radiansToDegrees=h,Qo.radiansToLength=d,Qo.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const r=Math.pow(10,t||0);return Math.round(e*r)/r},Qo.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach(e=>{if(!f(e))throw new Error("bbox must only contain numbers")})},Qo.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},Qo}var ti,ri={};function ni(){if(ti)return ri;ti=1,Object.defineProperty(ri,"__esModule",{value:!0});var e=ei();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var b=0;b<c;b++){var _=0,x=0;if(null!==(s=d?u.geometries[b]:u)){l=s.coordinates;var O=s.type;switch(p=!n||"Polygon"!==O&&"MultiPolygon"!==O?0:1,O){case null:break;case"Point":if(!1===r(l,h,v,_,x))return!1;h++,_++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,_,x))return!1;h++,"MultiPoint"===O&&_++}"LineString"===O&&_++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,_,x))return!1;h++}"MultiLineString"===O&&_++,"Polygon"===O&&x++}"Polygon"===O&&_++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(x=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-p;a++){if(!1===r(l[o][i][a],h,v,_,x))return!1;h++}x++}_++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(r=0;r<g;r++){for(s=h?e.features[r].geometry:f?e.geometry:e,l=h?e.features[r].properties:f?e.properties:{},u=h?e.features[r].bbox:f?e.bbox:void 0,d=h?e.features[r].id:f?e.id:void 0,a=(c=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=c?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,r){o(t,function(t,n,o,i,a){var s,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==r(e.feature.call(void 0,t,o,{bbox:i,id:a}),n,0)&&void 0}switch(c){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:s,coordinates:t.coordinates[l]};if(!1===r(e.feature.call(void 0,u,o),n,l))return!1}})}function a(r,n){i(r,function(r,o,i){var a=0;if(r.geometry){var s=r.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var c,l=0,u=0,d=0;return!1!==t(r,function(t,s,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return ri.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},ri.coordEach=t,ri.coordReduce=function(e,r,n,o){var i=n;return t(e,function(e,t,o,a,s){i=0===t&&void 0===n?e:r(i,e,t,o,a,s)},o),i},ri.featureEach=n,ri.featureReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},ri.findPoint=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.coordIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return e.point.call(void 0,l,c,r);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,r);case"LineString":return s<0&&(s=l.length+s),e.point.call(void 0,l[s],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s),e.point.call(void 0,l[a][s],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),e.point.call(void 0,l[i][s],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s),e.point.call(void 0,l[i][a][s],c,r)}throw new Error("geojson is invalid")},ri.findSegment=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.segmentIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=l.length+s-1),e.lineString.call(void 0,[l[s],l[s+1]],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s-1),e.lineString.call(void 0,[l[a][s],l[a][s+1]],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s-1),e.lineString.call(void 0,[l[i][s],l[i][s+1]],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s-1),e.lineString.call(void 0,[l[i][a][s],l[i][a][s+1]],c,r)}throw new Error("geojson is invalid")},ri.flattenEach=i,ri.flattenReduce=function(e,t,r){var n=r;return i(e,function(e,o,i){n=0===o&&0===i&&void 0===r?e:t(n,e,o,i)}),n},ri.geomEach=o,ri.geomReduce=function(e,t,r){var n=r;return o(e,function(e,o,i,a,s){n=0===o&&void 0===r?e:t(n,e,o,i,a,s)}),n},ri.lineEach=s,ri.lineReduce=function(e,t,r){var n=r;return s(e,function(e,o,i,a){n=0===o&&void 0===r?e:t(n,e,o,i,a)}),n},ri.propEach=r,ri.propReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},ri.segmentEach=a,ri.segmentReduce=function(e,t,r){var n=r,o=!1;return a(e,function(e,i,a,s,c){n=!1===o&&void 0===r?e:t(n,e,i,a,s,c),o=!0}),n},ri}var oi,ii,ai={};function si(){if(oi)return ai;oi=1,Object.defineProperty(ai,"__esModule",{value:!0});var e=ni();function t(t,r={}){if(null!=t.bbox&&!0!==r.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}var r=t;return ai.bbox=t,ai.default=r,ai}var ci=function(){if(ii)return Lo.exports;ii=1;var e=Wo,t=ei(),r=ni(),n=si().default,o=r.featureEach;r.coordEach,t.polygon;var i=t.featureCollection;function a(t){var r=new e(t);return r.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.insert.call(this,t)},r.load=function(t){var r=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}),e.prototype.load.call(this,r)},r.remove=function(t,r){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.remove.call(this,t,r)},r.clear=function(){return e.prototype.clear.call(this)},r.search=function(t){var r=e.prototype.search.call(this,this.toBBox(t));return i(r)},r.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},r.all=function(){var t=e.prototype.all.call(this);return i(t)},r.toJSON=function(){return e.prototype.toJSON.call(this)},r.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},r.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=n(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=n(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},r}return Lo.exports=a,Lo.exports.default=a,Lo.exports}(),li=ce(ci);function ui(e,t){var r={},n=[];if("LineString"===e.type&&(e=P(e)),"LineString"===t.type&&(t=P(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=di(e,t);return o&&n.push(o),O(n)}var i=li();return i.load(To(t)),E(To(e),function(e){E(i.search(e),function(t){var o=di(e,t);if(o){var i=Oo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),O(n)}function di(e,t){var r=Oo(e),n=Oo(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],d=n[1][1],p=(d-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var g=h/p,m=f/p;return g>=0&&g<=1&&m>=0&&m<=1?y([o+g*(a-o),i+g*(s-i)]):null}function pi(e,t,r){void 0===r&&(r={});var n=y([1/0,1/0],{dist:1/0}),o=0;return x(e,function(e){for(var i=Oo(e),a=0;a<i.length-1;a++){var s=y(i[a]);s.properties.dist=Po(t,s,r);var c=y(i[a+1]);c.properties.dist=Po(t,c,r);var l=Po(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=Co(s,c),p=Mo(t,u,d+90,r),h=Mo(t,u,d-90,r),f=ui(_([p.geometry.coordinates,h.geometry.coordinates]),_([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Po(t,g,r),g.properties.location=o+Po(s,g,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),g&&g.properties.dist<n.properties.dist&&((n=g).properties.index=a),o+=l}}),n}function hi(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function fi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=hi(e),i=h(o[0]),a=h(o[1]),s=h(r),c=g(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=m(u),p=m(l);return y([d,p],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=hi(e),o=hi(t),i=h(o[1]-n[1]),a=h(o[0]-n[0]),s=h(n[1]),c=h(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return f(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,Co(e,t));return r}var gi=function(){return gi=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},gi.apply(this,arguments)},yi=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],r=0;r<e.features.length;r++){var n=e.features[r],o=n.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var a=this.features.unknow.snapPoints;i=gi(gi({},i),a)}var s=this.doSnap(n,i);t.push(s)}else if(void 0!==this.features.unknow){a=this.features.unknow.snapPoints,s=this.doSnap(n,a);t.push(s)}else t.push(n)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Po(y(e),y(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],d=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=Po(y([r.lng,r.lat]),y([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var a=!1,s=this.getCloseFeatures(e,i);s?(this.snapStatus=!0,this.snapCoords=s.coords,a=function(e,t,r={}){const n=r.steps||64,o=r.properties?r.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<n;o++)i.push(So(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),v([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=O(0==a?[]:[a]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(O([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n=S(e),o=[];if(n.map(function(e){var n=Po(y(e),y([t.lng,t.lat]),{units:"meters"});n<r&&o.push({coords:e,dist:n,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(_(e))});break;case"Polygon":var o=wo(e.geometry);n.push(o);break;case"MultiPolygon":wo(e.geometry).coodinates.map(function(e){n.push(_(e))})}return n},e.prototype.searchInMidPoint=function(e,t,r){var n=this.getLines(e,t,r),o=[];n.map(function(e){o=o.concat(To(e).features)});var i=[];if(o.map(function(e){var n=fi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Po(n,y([t.lng,t.lat]),{units:"meters"});o<r&&i.push({coords:n.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,r){for(var n=this.getLines(e,t,r),o=[],i=0;i<n.length;i++){var a=pi(n[i],y([t.lng,t.lat]),{units:"meters"});void 0!==a.properties.dist&&a.properties.dist<r&&o.push({coords:a.geometry.coordinates,dist:a.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var r=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(r.length>0){for(var n,o=!1,i=0;i<r.length;i++){var a=r[i],s=this.options.rules,c=e.lngLat;if(o=!1,-1!==s.indexOf("vertex")&&null==n&&(n=this.searchInVertex(a,c,t))){o=!0;break}if(-1!==s.indexOf("midpoint")&&null==n&&(n=this.searchInMidPoint(a,c,t))){o=!0;break}if(-1!==s.indexOf("edge")&&null==n&&(n=this.searchInEdge(a,c,t))){o=!0;break}}return!!o&&n}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}(),mi="snap-helper-circle",vi="mapbox-gl-draw-hot";function bi(e){if(!yi.prototype.__snapPatched){yi.prototype.__snapPatched=!0;var t=yi.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){var r,n;if(this.status){var o=t.setMapData.call(this,e);return(null==e||null===(r=e.features)||void 0===r?void 0:r.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(mi)&&this.map.setLayoutProperty(mi,"visibility","visible"),o}},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,r,n){var o=e.geometry;if(null==o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>v(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>_(e)):t.getLines.call(this,e,r,n)}catch(e){return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];var o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));var i=this.options.radius||n.snapRadius,a=e.point;e.point=[[a.x-i,a.y-i],[a.x+i,a.y+i]];var s=t.getCloseFeatures.call(this,e,r);return e.point=a,s}}(t,r),function(e,t,r){e.searchInVertex=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInVertex.apply(this,n);return i&&(i.color=r.vertex),i},e.searchInMidPoint=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInMidPoint.apply(this,n);return i&&(i.color=r.midpoint),i},e.searchInEdge=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInEdge.apply(this,n);return i&&(i.color=r.edge),i}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){var r;if(this.status&&(null===(r=this.map)||void 0===r||!r._isZooming)&&(!this._autoSnapSuspended||e._explicit))try{var n,o,i=t.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}}function _i(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function xi(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}var Oi=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Pi(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(mi)&&e.removeLayer(mi),e.getSource(mi)&&e.removeSource(mi)}(e),xi(r);var o=new yi({map:e,drawing:t,options:{layers:n.layers,radius:n.radius,rules:n.rules},status:n.status,onSnapped:n.onSnapped});return function(e,t,r){var n=t;Object.defineProperty(e,"status",{get:()=>n&&Oi.has(r.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{n=e}}(o,n.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,n.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function Ei(e,t,r){e.on("style.load",()=>{_i(()=>e._removed?null:e.getSource(vi),n=>{xi(n),function(e){var t;e.getSource(mi)||e.addSource(mi,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(mi)||e.addLayer({id:mi,type:"fill",source:mi,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Pi(e,t,n,r)})})}function Si(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function wi(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:a=[],radius:s=n.snapRadius,rules:c=["vertex","midpoint","edge"],status:l=!1,onSnapped:u=()=>{},colors:d={}}=o,p={layers:a,radius:s,rules:c,status:l,onSnapped:u};return bi(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Si(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Si(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:i.snapVertex,midpoint:i.snapMidpoint,edge:i.snapEdge},d)),Ei(t,r,p),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(mi)){e.setLayoutProperty(mi,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(mi,"visibility","visible")}})}(t),_i(()=>t._removed?null:t.getSource(vi),e=>Pi(t,r,e,p)),t._snapInstance}var Ii=e=>{var t=[];return{push(r){t.push(r),e(t.length)},pop(){var r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}},Ci=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];var r=Object.values(e)[0];return null!=r?r:null}return null},Mi={symbol:"pin",backgroundColor:"#ca3535",foregroundColor:"#ffffff"},Ti={dot:"M8 3c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.241 5-5-2.24-5-5-5z",cross:"M6 3H10V6H13V10H10V13H6V10H3V6H6Z",diamond:"M8 2L14 8L8 14L2 8Z",triangle:"M8 2L14 14H2Z",square:"M3 3H13V13H3Z"},Li={id:"pin",viewBox:"0 0 44 44",anchor:[.5,.9],graphic:Ti.dot,svg:'<path d="M22 40.999c-3.621 0-8.306-5.864-10.258-8.3C9.02 29.302 6 23.66 6 19.002a16.01 16.01 0 0 1 16-16 16.01 16.01 0 0 1 16 16c0 4.658-3.02 10.3-5.742 13.697-1.952 2.437-6.637 8.3-10.258 8.3z" fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>\n <path d="M22 7.001a12.01 12.01 0 0 1 12 12c0 7.623-10.377 17.998-12 17.998S10 26.624 10 19.001a12.01 12.01 0 0 1 12-12z" fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>\n <g transform="translate(22, 19) scale(0.8) translate(-8, -8)"><path d="{{graphic}}" fill="{{foregroundColor}}"/></g>'},ki={id:"circle",viewBox:"0 0 44 44",anchor:[.5,.5],graphic:Ti.dot,svg:'<circle cx="22" cy="22" r="16" fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>\n <circle cx="22" cy="22" r="12" fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>\n <g transform="translate(22, 22) scale(0.8) translate(-8, -8)"><path d="{{graphic}}" fill="{{foregroundColor}}"/></g>'},Ai={id:"square",viewBox:"0 0 44 44",anchor:[.5,.5],graphic:Ti.dot,svg:'<path d="M13 6h18c3.863 0 7 3.137 7 7v18c0 3.863-3.137 7-7 7H13c-3.863 0-7-3.137-7-7V13c0-3.863 3.137-7 7-7" fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>\n <path d="M13 34a3 3 0 0 1-3-3V13a3 3 0 0 1 3-3h18a3 3 0 0 1 3 3v18a3 3 0 0 1-3 3H13z" fill-rule="nonzero" fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>\n <g transform="translate(22, 22) scale(0.8) translate(-8, -8)"><path d="{{graphic}}" fill="{{foregroundColor}}"/></g>'},ji=new Set(["symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),Vi=e=>{if(!(e=>!(!e.symbol&&!e.symbolSvgContent))(e))return{};var t={};return ji.forEach(r=>{if(null!=e[r]){var n=r.charAt(6).toLowerCase()+r.slice(7);t[n]=e[r]}}),t},Fi=(e,t)=>{var r;return e.symbolViewBox?e.symbolViewBox:null!==(r=null==t?void 0:t.viewBox)&&void 0!==r?r:"0 0 38 38"},Di=(e,t)=>{var r;return e.symbolAnchor?e.symbolAnchor:null!==(r=null==t?void 0:t.anchor)&&void 0!==r?r:[.5,.5]},Ni={light:{haloColor:"#ffffff",selectedColor:"#0b0c0c",activeColor:"#ffdd00",foregroundColor:"#0b0c0c"},dark:{haloColor:"#0b0c0c",selectedColor:"#ffffff",activeColor:"#ffdd00",foregroundColor:"#ffffff"}};function Ri(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ui(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ri(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ri(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Bi=new Map,Gi=new Map,Hi={},Yi=e=>{var t=0;for(var r of e)t=Math.trunc((t<<5)-t+r.codePointAt(0));return Math.abs(t).toString(36)},Xi=new Set(["id","svg","viewBox","anchor","symbol","symbolSvgContent"]);function Ki(e,t,r){var n,o,i,a,s=null==r?void 0:r.id,c=Object.fromEntries(Object.entries(e||{}).filter(e=>{var[t]=e;return!Xi.has(t)})),l=Object.fromEntries(Object.entries(Hi).filter(e=>{var[t]=e;return!Xi.has(t)})),u=Object.fromEntries(Object.entries(t).filter(e=>{var[,t]=e;return null!=t})),d=Ui(Ui(Ui(Ui({},Mi),l),c),u),p=null!==(n=Ni[null==r?void 0:r.mapColorScheme])&&void 0!==n?n:Ni.light;return d.haloColor=null!==(o=null==r?void 0:r.haloColor)&&void 0!==o?o:p.haloColor,d.selectedColor=null!==(i=null==r?void 0:r.selectedColor)&&void 0!==i?i:p.selectedColor,d.activeColor=null!==(a=null==r?void 0:r.activeColor)&&void 0!==a?a:p.activeColor,"string"==typeof d.graphic&&Ti[d.graphic]&&(d.graphic=Ti[d.graphic]),Object.fromEntries(Object.entries(d).map(e=>{var[t,r]=e;return[t,Ci(r,s)||""]}))}function Ji(e,t){return Object.entries(t).reduce((e,t)=>{var[r,n]=t;return e.replaceAll("{{".concat(r,"}}"),n)},e)}var $i={setDefaults(e){Hi=e||{}},getDefaults:()=>Ui(Ui({},Mi),Hi),register(e){Bi.set(e.id,e)},get:e=>Bi.get(e),list:()=>[...Bi.values()],clear(){Bi.clear()},initialise(){this.register(Li),this.register(ki),this.register(Ai)},resolve(e,t,r){var n=Ki(e,t||{},r);return e?(n.selectedColor="none",n.activeColor="none",Ji(e.svg,n)):""},resolveActive(e,t,r){var n=Ki(e,t||{},r);return e?Ji(e.svg,n):""},resolveSelected(e,t,r){var n=Ki(e,t||{},r);return e?(n.activeColor="none",Ji(e.svg,n)):""},getSymbolImageId(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2,o=this.getSymbolDef(e);if(!o)return null;var i=Vi(e),a=r?this.resolveActive(o,i,t):this.resolve(o,i,t);return"symbol-".concat(r?"act-":"").concat(Yi(a),"-").concat(n,"x")},getSymbolDef(e){return e.symbolSvgContent?{svg:e.symbolSvgContent}:e.symbol?this.get(e.symbol):void 0},rasteriseSymbolImage(e,t,r,n){var o=this;return k(function*(){var i=o.getSymbolDef(e);if(!i)return null;var a,s,c=Vi(e);"active"===r?(a=o.resolveActive(i,c,t),s="act-"):"selected"===r?(a=o.resolveSelected(i,c,t),s="sel-"):(a=o.resolve(i,c,t),s="");var l="symbol-".concat(s).concat(Yi(a),"-").concat(n,"x"),u=Gi.get(l);if(!u){var d=Fi(e,i),[,,p,h]=d.split(" ").map(Number),f='<svg xmlns="http://www.w3.org/2000/svg" width="'.concat(p*n,'" height="').concat(h*n,'" viewBox="').concat(d,'">').concat(a,"</svg>");u=yield((e,t,r)=>new Promise((n,o)=>{var i="data:image/svg+xml;charset=utf-8,".concat(encodeURIComponent(e)),a=new Image(t,r);a.onload=()=>{var e=document.createElement("canvas");e.width=t,e.height=r;var o=e.getContext("2d");o.drawImage(a,0,0,t,r),n(o.getImageData(0,0,t,r))},a.onerror=()=>{o(new Error("Failed to rasterise SVG: ".concat(e.slice(0,80))))},a.src=i}))(f,p*n,h*n),Gi.set(l,u)}return{imageId:l,imageData:u}})()}};$i.initialise();var qi=.25,zi=.75,Zi=e=>{var[t,r]=e,n=(e=>e<=qi?"left":e>=zi?"right":"")(t),o=(e=>e<=qi?"top":e>=zi?"bottom":"")(r);return o+(n&&o?"-":"")+n||"center"},Wi=e=>e<=qi?0:e>=zi?1:.5,Qi=e=>Math.round(100*e)/100;function ea(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ta(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ea(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ea(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ra=e=>!!(null!=e&&e.symbol||null!=e&&e.symbolSvgContent),na=(e,t,r)=>{var n;if(null!==(n=e._symbolIconOffsetMap)&&void 0!==n||(e._symbolIconOffsetMap={}),!e._symbolIconOffsetMap[t]){e._symbolIconOffsetMap[t]=r;var o=(e=>{var t=["match",["get","user_symbolImageId"]];for(var[r,n]of Object.entries(e))t.push(r,["literal",n]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);["hot","cold"].forEach(t=>{var r="".concat("point-symbol",".").concat(t);e.getLayer(r)&&e.setLayoutProperty(r,"icon-offset",o)})}},oa=function(){var e=k(function*(e){var t,r,n,o,{draw:i,mapProvider:a,map:s,featureId:c,properties:l,pixelRatioOverride:u}=e;if(!ra(l))return null;var d=s._drawCurrentMapStyle,p=null!=u?u:(e=>{var t;return(null===(t=e.getPixelRatio)||void 0===t?void 0:t.call(e))||1})(s);yield a.addSymbolsToMap([l],d,$i);var h=i.get(c);if(!h)return null;var f=$i.getSymbolImageId(l,d,!1,p);if(!f)return null;var g=null!==(t=null===(r=s._activeSymbolImageMap)||void 0===r?void 0:r[f])&&void 0!==t?t:null,y=null!==(n=null===(o=s._selectedSymbolImageMap)||void 0===o?void 0:o[f])&&void 0!==n?n:null,m=$i.getSymbolDef(l),v=Di(l,m),b=Zi(v),_=((e,t)=>{var[r,n]=e,[,,o,i]=t.split(" ").map(Number);return[Qi((Wi(r)-r)*o),Qi((Wi(n)-n)*i)]})(v,Fi(l,m));return na(s,f,_),ta(ta({},h),{},{properties:ta(ta({},l),{},{symbolImageId:f,symbolIconAnchor:b,symbolActiveImageId:g,symbolSelectedImageId:y})})});return function(t){return e.apply(this,arguments)}}(),ia=function(){var e=k(function*(e){try{var t=yield oa(e);if(!t)return;e.draw.add(t)}catch(t){console.error("[draw] failed to resolve point symbol",e.featureId,t)}});return function(t){return e.apply(this,arguments)}}(),aa=function(){var e=k(function*(e){var{draw:t,mapProvider:r,map:n,pixelRatioOverride:o}=e,i=t.getAll().features.filter(e=>"Point"===e.geometry.type&&ra(e.properties)),a=yield Promise.allSettled(i.map(e=>oa({draw:t,mapProvider:r,map:n,featureId:e.id,properties:e.properties,pixelRatioOverride:o})));a.filter(e=>"rejected"===e.status).forEach(e=>{console.error("[draw] failed to resolve point symbol",e.reason)});var s=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);s.length&&t.add({type:"FeatureCollection",features:s})});return function(t){return e.apply(this,arguments)}}();function sa(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ca(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?sa(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):sa(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var la="mapbox-gl-draw-cold",ua="mapbox-gl-draw-hot",da=e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:i}=e,a=t._drawCurrentMapStyle;t.once("idle",()=>{var e,s=((e,t)=>{if(e.getSource(la))return!1;var r={type:"FeatureCollection",features:[]};return e.addSource(la,{data:r,type:"geojson"}),e.addSource(ua,{data:r,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(t,r);!function(e,t){_o(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})}(t,a,o);var c=null===(e=t._drawEditContainer)||void 0===e?void 0:e.querySelector("[data-im-draw-touch-target]");Jr(c,a,o),aa({draw:r,mapProvider:n,map:t}).then(()=>{s&&r.set(r.getAll()),t.triggerRepaint(),i()})})},pa=e=>{var t,{mapStyle:r,mapProvider:o,events:i,eventBus:a,snapLayers:s,pluginConfig:c={}}=e,{map:l}=o;Kt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Kt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Kt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var u=ca(ca({},Kt.modes),{},{disabled:Jt,edit_vertex:hn,edit_point:Mn,draw_polygon:Zn,draw_line:Wn,draw_point:ao}),d=o._mapboxDrawInstance;d?Object.assign(d.modes,u):(d=new Kt({modes:u,styles:_o(r,c),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),l.addControl(d),o._mapboxDrawInstance=d);var p=((e,t)=>{var r=e.getCanvas(),n=null,o=e=>{1===e.touches.length&&(n={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"===t.getMode()&&n){var o=e.changedTouches[0],i=o.clientX-n.x,a=o.clientY-n.y;Date.now()-n.time<300&&Math.abs(i)<10&&Math.abs(a)<10&&r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),n=null}else n=null};return r.addEventListener("touchstart",o,{passive:!0}),r.addEventListener("touchend",i,{passive:!0}),{remove(){r.removeEventListener("touchstart",o),r.removeEventListener("touchend",i)}}})(l,d);o.draw=d,l._drawCurrentMapStyle=r,l._drawPluginConfig=c,o.snapEnabled=!1;var h=o.undoStack;h||(h=Ii(e=>l.fire("draw.undochange",{length:e})),o.undoStack=h),l._undoStack=h;var f=Br(r,c);wi(l,d,{layers:s,radius:null!==(t=c.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:f.snapVertex,edge:f.snapEdge}});var g=()=>a.emit(i.MAP_DATA_CHANGE),{handleSetMapStyle:y,handleStyleChanged:m}=(e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,eventBus:i,events:a,notifyPointSymbolsRefreshed:s}=e,c=e=>{t._drawCurrentMapStyle=e};i.on(a.MAP_SET_STYLE,c);var l=!1,u=()=>{l||(l=!0,da({map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:()=>{l=!1,s()}}))};return i.on(a.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:l,draw:d,mapProvider:o,pluginConfig:c,eventBus:a,events:i,notifyPointSymbolsRefreshed:g}),v=e=>{l.fire("draw.scalechange",{scale:w[e]})};a.on(i.MAP_SET_SIZE,v);var b=e=>{aa({draw:d,mapProvider:o,map:l,pixelRatioOverride:e}).then(()=>{l.triggerRepaint(),g()})};return a.on(i.MAP_SET_PIXEL_RATIO,b),{draw:d,remove(){p.remove(),a.off(i.MAP_SET_STYLE,y),a.off(i.MAP_STYLE_CHANGE,m),a.off(i.MAP_SET_SIZE,v),a.off(i.MAP_SET_PIXEL_RATIO,b),d.changeMode("disabled"),o.draw=null}}};function ha(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function fa(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ha(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ha(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ga=e=>"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,16),ya=e=>"function"==typeof cancelAnimationFrame?cancelAnimationFrame(e):clearTimeout(e),ma=e=>{var{onChange:t,validate:r=I}=e,n=!1,o=null,i=null,a=()=>{null!=o&&(ya(o),o=null),i=null},s=(e,r)=>{e!==n&&(n=e,t(e,null!=r?r:null))},c=()=>{if(o=null,i){var{feature:e,context:t,onGeometryChange:n}=i,{valid:a,reason:c}=r(e,t,{onGeometryChange:n});s(!a,c)}};return{update(e){var{feature:t,context:n={},numVertices:l,onGeometryChange:u}=e,d=fa(fa({},n),{},{numVertices:l}),p=r(t,d);return p.valid?"function"!=typeof u?(a(),void s(!1,null)):(i={feature:t,context:d,onGeometryChange:u},void(null==o&&(o=ga(c)))):(a(),void s(!0,p.reason))},set(e,t){a(),s(e,null!=t?t:null)},refresh(){t(n,null)},destroy(){a()}}};function va(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ba(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?va(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):va(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var _a=e=>{var{onStrokeChange:t,onPlaceChange:r}=e,n=e=>{var t=!1;return(r,n)=>{r!==t&&(t=r,e(r,null!=n?n:null))}},o=n(t),i=n(r),a=!1,c=null,l=null,u=null,d=()=>{null!=l&&(ya(l),l=null),u=null},p=(e,t,r,n,o)=>{var i,s=(null!==(i=t.numVertices)&&void 0!==i?i:0)<n?{valid:!0}:C(e,ba(ba({},t),{},{phase:"preview"}),{rules:r});o(!s.valid||a,s.valid?c:s.reason)},h=()=>{var e,t;if(u){var{feature:r,context:n}=u,a=null!==(e=s[null==r||null===(t=r.geometry)||void 0===t?void 0:t.type])&&void 0!==e?e:0;p(r,n,M,a,o),p(r,n,T,0,i)}},f=()=>{if(l=null,u){var{feature:e,context:t,onGeometryChange:r}=u,n=C(e,ba(ba({},t),{},{phase:"preview"}),{rules:[],onGeometryChange:r});a=!n.valid,c=n.reason,h()}};return{update(e){var{feature:t,context:r={},numVertices:n,onGeometryChange:o}=e;u={feature:t,context:ba(ba({},r),{},{numVertices:n}),onGeometryChange:o},h(),"function"==typeof o&&null==l&&(l=ga(f))},reset(){d(),a=!1,c=null,o(!1,null),i(!1,null)},destroy(){d()}}};function xa(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Oa(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?xa(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):xa(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Pa=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),Ea=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),Sa=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),wa=(e,t)=>{var r,n,o;if("draw_polygon"===e)return{feature:Pa(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1};if("draw_line"===e)return{feature:Ea(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1};if("edit_vertex"===e){var i,a=t[0];return Array.isArray(null==a?void 0:a[0])?{feature:Pa(t),numVertices:a.length}:{feature:Ea(t),numVertices:null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0}}return"edit_point"===e?{feature:Sa(t),numVertices:1}:null};var Ia=Object.freeze({__proto__:null,MaplibreDrawAdapter:class{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._bus=(n=new Map,{on(e,t){n.has(e)||n.set(e,new Set),n.get(e).add(t)},off(e,t){var r;null===(r=n.get(e))||void 0===r||r.delete(t)},emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var i=n.get(e);i&&Array.from(i).forEach(e=>e(...r))}}),this._editingFeatureId=null,this._sortKeyCounter=0;var{draw:o,remove:i}=pa({mapStyle:t.mapStyle,mapProvider:e,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:null!==(r=t.pluginConfig)&&void 0!==r?r:{}});this._draw=o,this._cleanupDraw=i,this._liveStroke=ma({onChange:(e,t)=>{this._applyStrokeInvalid(e);var r=this._draw.getMode();"edit_vertex"!==r&&"edit_point"!==r||this._bus.emit(L.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=_a({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(L.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{var t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(L.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(L.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(L.CANCEL),vertexselection:e=>this._bus.emit(L.VERTEX_SELECTION,Oa(Oa({},e),{},{numVertices:e.numVertecies})),vertexchange:e=>this._bus.emit(L.VERTEX_CHANGE,Oa(Oa({},e),{},{numVertices:e.numVertecies})),undochange:e=>this._bus.emit(L.UNDO_CHANGE,e.length),update:e=>this._bus.emit(L.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(L.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(L.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(L.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on($t,this._mapHandlers.create),this._map.on(Zt,this._mapHandlers.editfinish),this._map.on(Wt,this._mapHandlers.cancel),this._map.on(Qt,this._mapHandlers.vertexselection),this._map.on(er,this._mapHandlers.vertexchange),this._map.on(tr,this._mapHandlers.undochange),this._map.on(qt,this._mapHandlers.update),this._map.on(nr,this._mapHandlers.geometrychange),this._map.on(ir,this._mapHandlers.placementblocked),this._map.on(or,this._mapHandlers.interfacetypechange),this._map.on(zt,this._mapHandlers.modechange),this._map.on(sr,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=null!==(t=r.featureId)&&void 0!==t?t:null);"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(r=Oa(Oa({},r),{},{resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)})),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){return ia({draw:this._draw,mapProvider:this._mapProvider,map:this._map,featureId:e,properties:t})}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=wa(t,e.coordinates);r&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:r.feature,numVertices:r.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update(Oa(Oa({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(or,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if(("edit_vertex"===t||"edit_point"===t)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(Zt,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==t&&"draw_line"!==t||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();"draw_polygon"!==t&&"draw_line"!==t||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(rr)}nudgeSelectedVertex(e,t,r){this._map.fire(ar,{dx:e,dy:t,isLargeStep:r})}setGeometryValid(e){this._map._drawGeometryValid=e}set _geometryValidator(e){this._map._drawGeometryValidator=e}get _geometryValidator(){return this._map._drawGeometryValidator}setInvalid(e){this._liveStroke.set(e)}_applyStrokeInvalid(e){this._setLayerVisibility("stroke-active",!e),this._setLayerVisibility("stroke-active-invalid",e),this._setLayerVisibility("fill-active",!e)}_setLayerVisibility(e,t){["hot","cold"].forEach(r=>{var n="".concat(e,".").concat(r);this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){var t,r,n=null==(null===(t=e.properties)||void 0===t?void 0:t.sortKey)?Oa(Oa({},e.properties),{},{sortKey:this._nextSortKey()}):e.properties,o=Oa(Oa({},e),{},{properties:n}),i=this._draw.add(o);return"Point"===(null===(r=o.geometry)||void 0===r?void 0:r.type)&&ra(n)&&this._resolvePointSymbol(i[0],n),i}setStyle(e,t){var r=this._draw.get(e);r&&this.add(Oa(Oa({},r),{},{properties:Oa(Oa({},r.properties),t)}))}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=mr(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(Er(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=mr(this._map);null!=t&&t.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,r){this._draw.setFeatureProperty(e,t,r)}setDrawingPreviewProperty(e,t){var r,n=this._currentDrawEvent;null!=n&&n.properties&&(n.properties[e]=t),null==n||null===(r=n.ctx)||void 0===r||null===(r=r.store)||void 0===r||r.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]).has(e.mode)||Pr(mr(this._map),this._map)}_handleStyleData(){var e,t=this._map.getStyle();if(t){this._liveStroke.refresh();var r=t.layers||[];!r.length||null!==(e=r[r.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||r.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>this._map.moveLayer(e.id))}}remove(){this._map.off($t,this._mapHandlers.create),this._map.off(Zt,this._mapHandlers.editfinish),this._map.off(Wt,this._mapHandlers.cancel),this._map.off(Qt,this._mapHandlers.vertexselection),this._map.off(er,this._mapHandlers.vertexchange),this._map.off(tr,this._mapHandlers.undochange),this._map.off(qt,this._mapHandlers.update),this._map.off(nr,this._mapHandlers.geometrychange),this._map.off(ir,this._mapHandlers.placementblocked),this._map.off(or,this._mapHandlers.interfacetypechange),this._map.off(zt,this._mapHandlers.modechange),this._map.off(sr,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}},displayedShape:wa});export{Ia as M,_a as a,Fr as b,ma as c,Dr as d,Nr as e,Ii as f,Di as g,Rr as h,Ur as i,Br as r,$i as s};