@defra/interactive-map 0.0.55-alpha → 0.0.57-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 (502) hide show
  1. package/assets/templates/style-switcher.njk +2 -2
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/button-definition.md +11 -0
  7. package/docs/api/context.md +4 -0
  8. package/docs/api.md +20 -2
  9. package/docs/architecture/interactive-map.likec4 +4 -4
  10. package/docs/plugins/datasets.md +11 -0
  11. package/docs/plugins/draw.md +197 -35
  12. package/docs/plugins/interact.md +24 -1
  13. package/docs/plugins/search.md +2 -2
  14. package/docusaurus.config.cjs +25 -3
  15. package/govuk-prototype-kit.config.json +6 -7
  16. package/package.json +20 -23
  17. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  18. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  19. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  20. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  21. package/plugins/datasets/dist/esm/index.js +1 -1
  22. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  23. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  24. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  25. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  26. package/plugins/datasets/dist/umd/index.js +1 -1
  27. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +18 -16
  28. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.test.js +2 -2
  29. package/plugins/datasets/src/adapters/esri/registry/esriDataset.js +2 -3
  30. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  31. package/plugins/datasets/src/adapters/loadLayerAdapter.js +2 -20
  32. package/plugins/datasets/src/adapters/loadLayerAdapter.test.js +9 -9
  33. package/plugins/datasets/src/adapters/mapboxStyleLayerAdapter.js +7 -7
  34. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +19 -19
  35. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +1 -1
  36. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
  37. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +2 -2
  38. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +1 -1
  39. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +21 -21
  40. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +5 -5
  41. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +2 -3
  42. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +2 -2
  43. package/plugins/datasets/src/api/getOpacity.js +1 -2
  44. package/plugins/datasets/src/api/getOpacity.test.js +9 -12
  45. package/plugins/datasets/src/api/getStyle.js +1 -2
  46. package/plugins/datasets/src/api/getStyle.test.js +5 -8
  47. package/plugins/datasets/src/api/removeDataset.js +2 -4
  48. package/plugins/datasets/src/api/removeDataset.test.js +5 -10
  49. package/plugins/datasets/src/api/setData.js +2 -4
  50. package/plugins/datasets/src/api/setData.test.js +6 -14
  51. package/plugins/datasets/src/api/setFeatureVisibility.js +1 -2
  52. package/plugins/datasets/src/api/setFeatureVisibility.test.js +8 -11
  53. package/plugins/datasets/src/components/LayersMenu/LayersMenu.jsx +1 -0
  54. package/plugins/datasets/src/components/LayersMenu/LayersMenuCheckbox.jsx +1 -3
  55. package/plugins/datasets/src/components/LayersMenu/LayersMenuCheckbox.test.jsx +13 -18
  56. package/plugins/datasets/src/index.js +2 -2
  57. package/plugins/datasets/src/index.test.js +8 -1
  58. package/plugins/datasets/src/initialise/DatasetsInit.jsx +37 -26
  59. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +120 -89
  60. package/plugins/datasets/src/initialise/initialiseDatasets.js +2 -3
  61. package/plugins/datasets/src/initialise/initialiseDatasets.test.js +23 -10
  62. package/plugins/datasets/src/manifest.js +53 -44
  63. package/plugins/datasets/src/manifest.test.js +36 -4
  64. package/plugins/datasets/src/reducers/pluginState.js +5 -5
  65. package/plugins/datasets/src/reducers/pluginState.test.js +21 -20
  66. package/plugins/datasets/src/registry/__mocks__/datasetRegistry.js +7 -6
  67. package/plugins/datasets/src/registry/createDataset.js +2 -2
  68. package/plugins/datasets/src/registry/dataset.js +9 -10
  69. package/plugins/datasets/src/registry/dataset.test.js +63 -64
  70. package/plugins/datasets/src/registry/datasetRegistry.js +39 -10
  71. package/plugins/datasets/src/registry/datasetRegistry.test.js +83 -1
  72. package/plugins/datasets/src/registry/globalDataset.js +9 -17
  73. package/plugins/datasets/src/registry/isVisibleWhen.js +9 -17
  74. package/plugins/datasets/src/registry/isVisibleWhen.test.js +27 -20
  75. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +26 -27
  76. package/plugins/datasets/src/utils/hasLayersMenu.js +13 -0
  77. package/plugins/datasets/src/utils/hasLayersMenu.test.js +25 -0
  78. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  79. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  80. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  81. package/plugins/draw/dist/esm/index.js +1 -1
  82. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  83. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  84. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  85. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  86. package/plugins/draw/dist/umd/index.js +1 -1
  87. package/plugins/draw/src/DrawInit.jsx +53 -29
  88. package/plugins/draw/src/DrawInit.test.jsx +105 -2
  89. package/plugins/draw/src/adapterEvents.js +78 -44
  90. package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
  91. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
  92. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
  93. package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
  94. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
  95. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
  96. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
  97. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
  98. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
  99. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
  100. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
  101. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
  102. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
  103. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
  104. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
  105. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
  106. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
  107. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
  108. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
  109. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
  110. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
  111. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
  112. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
  113. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
  114. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
  115. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +1 -1
  116. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
  117. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
  118. package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
  119. package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
  120. package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
  121. package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
  122. package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
  123. package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
  124. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
  125. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
  126. package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
  127. package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
  128. package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
  129. package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
  130. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
  131. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
  132. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +1 -1
  133. package/plugins/draw/src/api/createNewShape.js +4 -4
  134. package/plugins/draw/src/api/createNewShape.test.js +1 -1
  135. package/plugins/draw/src/api/editFeature.js +8 -11
  136. package/plugins/draw/src/api/editFeature.test.js +33 -22
  137. package/plugins/draw/src/api/newLine.test.js +3 -3
  138. package/plugins/draw/src/api/newPoint.js +4 -5
  139. package/plugins/draw/src/api/newPoint.test.js +3 -3
  140. package/plugins/draw/src/api/newPolygon.test.js +3 -3
  141. package/plugins/draw/src/api/recheckGeometry.js +32 -0
  142. package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
  143. package/plugins/draw/src/api/setGeometry.js +33 -0
  144. package/plugins/draw/src/api/setGeometry.test.js +48 -0
  145. package/plugins/draw/src/api/split.js +23 -22
  146. package/plugins/draw/src/api/split.test.js +33 -18
  147. package/plugins/draw/src/events.js +265 -77
  148. package/plugins/draw/src/events.test.js +708 -34
  149. package/plugins/draw/src/hooks/useSpatialList.js +10 -11
  150. package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
  151. package/plugins/draw/src/manifest.js +33 -17
  152. package/plugins/draw/src/manifest.test.js +104 -10
  153. package/plugins/draw/src/reducer.js +31 -9
  154. package/plugins/draw/src/reducer.test.js +35 -3
  155. package/plugins/draw/src/utils/drawModes.js +27 -0
  156. package/plugins/draw/src/utils/drawModes.test.js +27 -0
  157. package/plugins/draw/src/utils/needsDrawTarget.js +18 -0
  158. package/plugins/draw/src/utils/needsDrawTarget.test.js +32 -0
  159. package/plugins/draw/src/utils/touchTarget.js +34 -26
  160. package/plugins/draw/src/utils/touchTarget.test.js +32 -20
  161. package/plugins/draw/src/validation/commitChecks.js +185 -0
  162. package/plugins/draw/src/validation/commitChecks.test.js +205 -0
  163. package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
  164. package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
  165. package/plugins/draw/src/validation/liveStroke.js +6 -6
  166. package/plugins/draw/src/validation/liveStroke.test.js +27 -27
  167. package/plugins/draw/src/validation/rules.js +16 -14
  168. package/plugins/draw/src/validation/rules.test.js +5 -5
  169. package/plugins/draw/src/validation/validateGeometry.js +58 -31
  170. package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
  171. package/plugins/draw-es/dist/esm/index.js +1 -0
  172. package/plugins/{beta/draw-es → draw-es}/src/DrawInit.jsx +1 -1
  173. package/plugins/{beta/draw-es → draw-es}/src/events.test.js +1 -1
  174. package/plugins/{beta/draw-es → draw-es}/src/graphic.js +1 -1
  175. package/plugins/frame/dist/esm/index.js +1 -0
  176. package/plugins/{beta/frame → frame}/dist/umd/im-frame-plugin.js +1 -1
  177. package/plugins/{beta/frame → frame}/dist/umd/index.js +1 -1
  178. package/plugins/{beta/frame → frame}/package.json +2 -2
  179. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  180. package/plugins/interact/dist/esm/index.js +1 -1
  181. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  182. package/plugins/interact/dist/umd/index.js +1 -1
  183. package/plugins/interact/src/InteractInit.jsx +3 -3
  184. package/plugins/interact/src/api/enable.test.js +13 -0
  185. package/plugins/interact/src/defaults.js +1 -0
  186. package/plugins/interact/src/hooks/useCrossHairVisibility.js +27 -17
  187. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +72 -7
  188. package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
  189. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
  190. package/plugins/interact/src/hooks/useSpatialList.js +16 -17
  191. package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
  192. package/plugins/interact/src/manifest.js +4 -4
  193. package/plugins/interact/src/manifest.test.js +29 -0
  194. package/plugins/interact/src/reducer.js +7 -2
  195. package/plugins/interact/src/reducer.test.js +12 -2
  196. package/plugins/interact/src/utils/needsTarget.js +20 -0
  197. package/plugins/interact/src/utils/needsTarget.test.js +36 -0
  198. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  199. package/plugins/map-key/dist/esm/index.js +1 -1
  200. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  201. package/plugins/map-key/dist/umd/index.js +1 -1
  202. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +4 -0
  203. package/plugins/map-key/src/components/Key/MapKey.jsx +15 -15
  204. package/plugins/map-key/src/components/Key/MapKey.test.jsx +29 -15
  205. package/plugins/map-key/src/initialise/MapKeyInit.jsx +5 -8
  206. package/plugins/map-key/src/initialise/MapKeyInit.test.jsx +9 -7
  207. package/plugins/map-key/src/manifest.test.js +0 -1
  208. package/plugins/map-key/src/reducers/mergeKeyGroupItems.js +14 -33
  209. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +34 -50
  210. package/plugins/map-key/src/reducers/pluginState.js +6 -1
  211. package/plugins/map-key/src/reducers/pluginState.test.js +13 -4
  212. package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -0
  213. package/plugins/map-styles/dist/esm/index.js +1 -0
  214. package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -0
  215. package/plugins/{beta/map-styles → map-styles}/dist/umd/index.js +1 -1
  216. package/plugins/{beta/map-styles → map-styles}/src/MapStyles.jsx +3 -3
  217. package/plugins/{beta/map-styles → map-styles}/src/MapStylesInit.jsx +1 -1
  218. package/plugins/menu/dist/esm/index.js +1 -1
  219. package/plugins/scale-bar/dist/esm/index.js +1 -0
  220. package/plugins/{beta/scale-bar → scale-bar}/dist/umd/im-scale-bar-plugin.js +1 -1
  221. package/plugins/{beta/scale-bar → scale-bar}/dist/umd/index.js +1 -1
  222. package/plugins/{beta/scale-bar → scale-bar}/package.json +2 -2
  223. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  224. package/plugins/search/dist/esm/index.js +1 -1
  225. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  226. package/plugins/search/dist/umd/index.js +1 -1
  227. package/plugins/search/src/components/Suggestions/Suggestions.jsx +3 -1
  228. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +11 -0
  229. package/plugins/search/src/utils/markedToElements.jsx +25 -0
  230. package/plugins/search/src/utils/markedToElements.test.jsx +49 -0
  231. package/plugins/search/src/utils/parseOsNamesResults.js +6 -4
  232. package/plugins/search/src/utils/parseOsNamesResults.test.js +18 -0
  233. package/plugins/use-location/dist/esm/index.js +1 -0
  234. package/plugins/{beta/use-location → use-location}/dist/umd/im-use-location-plugin.js +1 -1
  235. package/plugins/{beta/use-location → use-location}/dist/umd/index.js +1 -1
  236. package/providers/esri/dist/esm/index.js +1 -0
  237. package/providers/{beta/esri → esri}/src/esriProvider.js +1 -1
  238. package/providers/{beta/esri → esri}/src/mapEvents.js +2 -2
  239. package/providers/maplibre/dist/esm/index.js +1 -1
  240. package/providers/maplibre/dist/umd/index.js +1 -1
  241. package/providers/maplibre/src/index.js +11 -2
  242. package/providers/maplibre/src/index.test.js +23 -1
  243. package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
  244. package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
  245. package/providers/maplibre/src/utils/workerUrl.js +12 -0
  246. package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
  247. package/providers/open-names/dist/esm/index.js +1 -0
  248. package/providers/{beta/open-names → open-names}/dist/umd/im-reverse-geocode.js +1 -1
  249. package/providers/{beta/open-names → open-names}/dist/umd/index.js +1 -1
  250. package/providers/openlayers/dist/esm/index.js +1 -0
  251. package/providers/openlayers/dist/umd/im-openlayers-provider.js +2 -0
  252. package/providers/{beta/openlayers → openlayers}/dist/umd/index.js +1 -1
  253. package/providers/{beta/openlayers → openlayers}/src/index.js +4 -4
  254. package/providers/{beta/openlayers → openlayers}/src/mapEvents.js +2 -2
  255. package/providers/{beta/openlayers → openlayers}/src/mapEvents.test.js +2 -2
  256. package/providers/{beta/openlayers → openlayers}/src/openlayersProvider.js +3 -3
  257. package/providers/{beta/openlayers → openlayers}/src/utils/highlightFeatures.js +1 -1
  258. package/providers/{beta/openlayers → openlayers}/src/utils/patternImages.js +1 -1
  259. package/providers/{beta/openlayers → openlayers}/src/utils/symbolImages.js +1 -1
  260. package/rollup.esm.mjs +43 -47
  261. package/sonar-project.properties +1 -1
  262. package/src/App/App.jsx +4 -1
  263. package/src/App/App.test.jsx +6 -0
  264. package/src/App/components/MapButton/MapButton.jsx +6 -0
  265. package/src/App/components/MapButton/MapButton.test.jsx +10 -0
  266. package/src/App/components/Markers/Markers.jsx +3 -5
  267. package/src/App/components/Markers/Markers.test.jsx +9 -11
  268. package/src/App/components/Panel/Panel.jsx +2 -9
  269. package/src/App/hooks/useInterfaceAPI.js +16 -4
  270. package/src/App/hooks/useInterfaceAPI.test.js +66 -1
  271. package/src/App/renderer/PluginInits.jsx +8 -7
  272. package/src/App/renderer/PluginInits.test.jsx +20 -5
  273. package/src/App/renderer/SlotItemsProvider.jsx +33 -0
  274. package/src/App/renderer/SlotItemsProvider.test.jsx +59 -0
  275. package/src/App/renderer/SlotRenderer.jsx +3 -14
  276. package/src/App/renderer/SlotRenderer.test.jsx +11 -44
  277. package/src/App/renderer/mapButtons.js +24 -12
  278. package/src/App/renderer/mapButtons.test.js +32 -1
  279. package/src/App/renderer/mapControls.js +6 -8
  280. package/src/App/renderer/mapControls.test.js +10 -0
  281. package/src/App/renderer/mapPanels.js +16 -19
  282. package/src/App/renderer/mapPanels.test.js +37 -9
  283. package/src/App/renderer/pluginWrapper.js +10 -8
  284. package/src/App/renderer/pluginWrapper.test.js +23 -9
  285. package/src/App/renderer/slotAggregator.js +18 -5
  286. package/src/App/renderer/slotAggregator.test.js +68 -25
  287. package/src/App/renderer/slotHelpers.js +13 -0
  288. package/src/App/renderer/slotHelpers.test.js +16 -1
  289. package/src/App/store/AppProvider.jsx +19 -1
  290. package/src/App/store/AppProvider.test.jsx +41 -0
  291. package/src/App/store/MapProvider.jsx +3 -0
  292. package/src/App/store/MapProvider.test.jsx +24 -0
  293. package/src/App/store/appActionsMap.js +10 -1
  294. package/src/App/store/appActionsMap.test.js +21 -0
  295. package/src/App/store/appDispatchMiddleware.js +29 -17
  296. package/src/App/store/appDispatchMiddleware.test.js +31 -0
  297. package/src/InteractiveMap/parseDataProperties.js +4 -4
  298. package/src/InteractiveMap/parseDataProperties.test.js +62 -6
  299. package/src/config/events.js +4 -2
  300. package/src/config/mapSizeScales.js +3 -0
  301. package/src/scss/tools/_govuk-content.scss +4 -3
  302. package/src/types.js +4 -0
  303. package/src/utils/focusAfterPanelClose.js +9 -0
  304. package/src/utils/focusAfterPanelClose.test.js +40 -0
  305. package/webpack.dev.mjs +9 -3
  306. package/webpack.prod.mjs +11 -4
  307. package/webpack.umd.mjs +6 -7
  308. package/plugins/beta/draw-es/dist/esm/index.js +0 -1
  309. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +0 -1
  310. package/plugins/beta/draw-ml/dist/esm/index.js +0 -1
  311. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +0 -1
  312. package/plugins/beta/draw-ml/dist/umd/index.js +0 -2
  313. package/plugins/beta/draw-ml/src/DrawInit.jsx +0 -85
  314. package/plugins/beta/draw-ml/src/api/addFeature.js +0 -27
  315. package/plugins/beta/draw-ml/src/api/deleteFeature.js +0 -13
  316. package/plugins/beta/draw-ml/src/api/editFeature.js +0 -75
  317. package/plugins/beta/draw-ml/src/api/merge.js +0 -9
  318. package/plugins/beta/draw-ml/src/api/newLine.js +0 -68
  319. package/plugins/beta/draw-ml/src/api/newPolygon.js +0 -68
  320. package/plugins/beta/draw-ml/src/api/split.js +0 -81
  321. package/plugins/beta/draw-ml/src/defaults.js +0 -17
  322. package/plugins/beta/draw-ml/src/draw.scss +0 -26
  323. package/plugins/beta/draw-ml/src/events.js +0 -185
  324. package/plugins/beta/draw-ml/src/index.js +0 -13
  325. package/plugins/beta/draw-ml/src/manifest.js +0 -110
  326. package/plugins/beta/draw-ml/src/mapboxDraw.js +0 -143
  327. package/plugins/beta/draw-ml/src/mapboxSnap.js +0 -321
  328. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +0 -552
  329. package/plugins/beta/draw-ml/src/modes/disabledMode.js +0 -23
  330. package/plugins/beta/draw-ml/src/modes/drawLineMode.js +0 -18
  331. package/plugins/beta/draw-ml/src/modes/drawPolygonMode.js +0 -16
  332. package/plugins/beta/draw-ml/src/modes/editVertex/geometryHelpers.js +0 -135
  333. package/plugins/beta/draw-ml/src/modes/editVertex/helpers.js +0 -2
  334. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +0 -142
  335. package/plugins/beta/draw-ml/src/modes/editVertex/undoHandlers.js +0 -133
  336. package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +0 -142
  337. package/plugins/beta/draw-ml/src/modes/editVertex/vertexQueries.js +0 -121
  338. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +0 -495
  339. package/plugins/beta/draw-ml/src/reducer.js +0 -90
  340. package/plugins/beta/draw-ml/src/styles.js +0 -190
  341. package/plugins/beta/draw-ml/src/undoStack.js +0 -50
  342. package/plugins/beta/draw-ml/src/utils/debounce.js +0 -16
  343. package/plugins/beta/draw-ml/src/utils/flattenStyleProperties.js +0 -49
  344. package/plugins/beta/draw-ml/src/utils/snapHelpers.js +0 -200
  345. package/plugins/beta/draw-ml/src/utils/spatial.js +0 -258
  346. package/plugins/beta/draw-ol/dist/css/index.css +0 -1
  347. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +0 -1
  348. package/plugins/beta/draw-ol/dist/esm/EditMode.js +0 -1
  349. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +0 -1
  350. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +0 -1
  351. package/plugins/beta/draw-ol/dist/esm/index.js +0 -1
  352. package/plugins/beta/draw-ol/src/DrawInit.jsx +0 -65
  353. package/plugins/beta/draw-ol/src/api/addFeature.js +0 -29
  354. package/plugins/beta/draw-ol/src/api/deleteFeature.js +0 -11
  355. package/plugins/beta/draw-ol/src/api/editFeature.js +0 -50
  356. package/plugins/beta/draw-ol/src/api/newLine.js +0 -44
  357. package/plugins/beta/draw-ol/src/api/newPolygon.js +0 -44
  358. package/plugins/beta/draw-ol/src/core/OLDrawManager.js +0 -153
  359. package/plugins/beta/draw-ol/src/core/featureStore.js +0 -65
  360. package/plugins/beta/draw-ol/src/core/styles.js +0 -98
  361. package/plugins/beta/draw-ol/src/core/undoStack.js +0 -31
  362. package/plugins/beta/draw-ol/src/defaults.js +0 -16
  363. package/plugins/beta/draw-ol/src/draw/DrawMode.js +0 -121
  364. package/plugins/beta/draw-ol/src/draw/drawInput.js +0 -243
  365. package/plugins/beta/draw-ol/src/draw.scss +0 -17
  366. package/plugins/beta/draw-ol/src/edit/EditMode.js +0 -424
  367. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +0 -229
  368. package/plugins/beta/draw-ol/src/edit/midpointLayer.js +0 -57
  369. package/plugins/beta/draw-ol/src/edit/touchHandler.js +0 -171
  370. package/plugins/beta/draw-ol/src/edit/undoOps.js +0 -95
  371. package/plugins/beta/draw-ol/src/edit/vertexHitTest.js +0 -72
  372. package/plugins/beta/draw-ol/src/edit/vertexLayer.js +0 -49
  373. package/plugins/beta/draw-ol/src/edit/vertexOps.js +0 -99
  374. package/plugins/beta/draw-ol/src/events.js +0 -114
  375. package/plugins/beta/draw-ol/src/index.js +0 -12
  376. package/plugins/beta/draw-ol/src/manifest.js +0 -125
  377. package/plugins/beta/draw-ol/src/olDraw.js +0 -38
  378. package/plugins/beta/draw-ol/src/reducer.js +0 -41
  379. package/plugins/beta/draw-ol/src/snap/snapEngine.js +0 -153
  380. package/plugins/beta/draw-ol/src/snap/snapGeometry.js +0 -177
  381. package/plugins/beta/draw-ol/src/snap/snapIndicator.js +0 -81
  382. package/plugins/beta/draw-ol/src/snap/snapInteraction.js +0 -57
  383. package/plugins/beta/draw-ol/src/snap/snapManager.js +0 -99
  384. package/plugins/beta/draw-ol/src/utils/flattenStyleProperties.js +0 -47
  385. package/plugins/beta/draw-ol/src/utils/geometryHelpers.js +0 -103
  386. package/plugins/beta/draw-ol/src/utils/olCoords.js +0 -35
  387. package/plugins/beta/draw-ol/src/utils/resolveColors.js +0 -39
  388. package/plugins/beta/draw-ol/src/utils/spatial.js +0 -24
  389. package/plugins/beta/draw-ol/src/utils/touchTarget.js +0 -61
  390. package/plugins/beta/frame/dist/esm/index.js +0 -1
  391. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +0 -1
  392. package/plugins/beta/map-styles/dist/esm/index.js +0 -1
  393. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +0 -1
  394. package/plugins/beta/scale-bar/dist/esm/index.js +0 -1
  395. package/plugins/beta/use-location/dist/esm/index.js +0 -1
  396. package/plugins/map-key/src/registry/getDatasetRegistry.js +0 -6
  397. package/plugins/map-key/src/registry/getDatasetRegistry.test.js +0 -23
  398. package/plugins/map-key/src/registry/index.js +0 -1
  399. package/plugins/map-key/src/registry/index.test.js +0 -7
  400. package/providers/beta/esri/dist/esm/index.js +0 -1
  401. package/providers/beta/open-names/dist/esm/index.js +0 -1
  402. package/providers/beta/openlayers/dist/esm/index.js +0 -1
  403. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +0 -2
  404. package/providers/beta/openlayers/dist/umd/index.js.LICENSE.txt +0 -1
  405. /package/plugins/{beta/draw-es → draw-es}/dist/esm/im-draw-es-plugin.js +0 -0
  406. /package/plugins/{beta/draw-es → draw-es}/src/api/addFeature.js +0 -0
  407. /package/plugins/{beta/draw-es → draw-es}/src/api/deleteFeature.js +0 -0
  408. /package/plugins/{beta/draw-es → draw-es}/src/api/editFeature.js +0 -0
  409. /package/plugins/{beta/draw-es → draw-es}/src/api/newPolygon.js +0 -0
  410. /package/plugins/{beta/draw-es → draw-es}/src/api/removeSafeZone.js +0 -0
  411. /package/plugins/{beta/draw-es → draw-es}/src/events.js +0 -0
  412. /package/plugins/{beta/draw-es → draw-es}/src/index.js +0 -0
  413. /package/plugins/{beta/draw-es → draw-es}/src/manifest.js +0 -0
  414. /package/plugins/{beta/draw-es → draw-es}/src/reducer.js +0 -0
  415. /package/plugins/{beta/draw-es → draw-es}/src/sketchViewModel.js +0 -0
  416. /package/plugins/{beta/frame → frame}/dist/css/index.css +0 -0
  417. /package/plugins/{beta/frame → frame}/dist/esm/im-frame-plugin.js +0 -0
  418. /package/plugins/{beta/draw-ml → frame}/dist/umd/index.js.LICENSE.txt +0 -0
  419. /package/plugins/{beta/frame → frame}/src/Frame.jsx +0 -0
  420. /package/plugins/{beta/frame → frame}/src/FrameInit.jsx +0 -0
  421. /package/plugins/{beta/frame → frame}/src/api/addFrame.js +0 -0
  422. /package/plugins/{beta/frame → frame}/src/api/editFeature.js +0 -0
  423. /package/plugins/{beta/frame → frame}/src/config.js +0 -0
  424. /package/plugins/{beta/frame → frame}/src/frame.scss +0 -0
  425. /package/plugins/{beta/frame → frame}/src/index.js +0 -0
  426. /package/plugins/{beta/frame → frame}/src/manifest.js +0 -0
  427. /package/plugins/{beta/frame → frame}/src/reducer.js +0 -0
  428. /package/plugins/{beta/frame → frame}/src/utils.js +0 -0
  429. /package/plugins/{beta/map-styles → map-styles}/dist/css/index.css +0 -0
  430. /package/plugins/{beta/frame → map-styles}/dist/umd/index.js.LICENSE.txt +0 -0
  431. /package/plugins/{beta/map-styles → map-styles}/src/config.js +0 -0
  432. /package/plugins/{beta/map-styles → map-styles}/src/index.js +0 -0
  433. /package/plugins/{beta/map-styles → map-styles}/src/manifest.js +0 -0
  434. /package/plugins/{beta/map-styles → map-styles}/src/mapStyles.scss +0 -0
  435. /package/plugins/{beta/scale-bar → scale-bar}/dist/css/index.css +0 -0
  436. /package/plugins/{beta/scale-bar → scale-bar}/dist/esm/im-scale-bar-plugin.js +0 -0
  437. /package/plugins/{beta/map-styles → scale-bar}/dist/umd/index.js.LICENSE.txt +0 -0
  438. /package/plugins/{beta/scale-bar → scale-bar}/src/ScaleBar.jsx +0 -0
  439. /package/plugins/{beta/scale-bar → scale-bar}/src/ScaleBar.test.jsx +0 -0
  440. /package/plugins/{beta/scale-bar → scale-bar}/src/index.js +0 -0
  441. /package/plugins/{beta/scale-bar → scale-bar}/src/index.test.js +0 -0
  442. /package/plugins/{beta/scale-bar → scale-bar}/src/manifest.js +0 -0
  443. /package/plugins/{beta/scale-bar → scale-bar}/src/scaleBar.scss +0 -0
  444. /package/plugins/{beta/scale-bar → scale-bar}/src/utils.js +0 -0
  445. /package/plugins/{beta/scale-bar → scale-bar}/src/utils.test.js +0 -0
  446. /package/plugins/{beta/use-location → use-location}/dist/esm/im-use-location-plugin.js +0 -0
  447. /package/plugins/{beta/scale-bar → use-location}/dist/umd/index.js.LICENSE.txt +0 -0
  448. /package/plugins/{beta/use-location → use-location}/src/UseLocation.jsx +0 -0
  449. /package/plugins/{beta/use-location → use-location}/src/UseLocationInit.jsx +0 -0
  450. /package/plugins/{beta/use-location → use-location}/src/defaults.js +0 -0
  451. /package/plugins/{beta/use-location → use-location}/src/events.js +0 -0
  452. /package/plugins/{beta/use-location → use-location}/src/index.js +0 -0
  453. /package/plugins/{beta/use-location → use-location}/src/manifest.js +0 -0
  454. /package/plugins/{beta/use-location → use-location}/src/reducer.js +0 -0
  455. /package/providers/{beta/esri → esri}/dist/css/index.css +0 -0
  456. /package/providers/{beta/esri → esri}/dist/esm/im-esri-provider.js +0 -0
  457. /package/providers/{beta/esri → esri}/src/appEvents.js +0 -0
  458. /package/providers/{beta/esri → esri}/src/defaults.js +0 -0
  459. /package/providers/{beta/esri → esri}/src/esriProvider.scss +0 -0
  460. /package/providers/{beta/esri → esri}/src/index.js +0 -0
  461. /package/providers/{beta/esri → esri}/src/utils/coords.js +0 -0
  462. /package/providers/{beta/esri → esri}/src/utils/coords.test.js +0 -0
  463. /package/providers/{beta/esri → esri}/src/utils/detectWebGL.js +0 -0
  464. /package/providers/{beta/esri → esri}/src/utils/esriFixes.js +0 -0
  465. /package/providers/{beta/esri → esri}/src/utils/query.js +0 -0
  466. /package/providers/{beta/esri → esri}/src/utils/spatial.js +0 -0
  467. /package/providers/{beta/esri → esri}/src/utils/spatial.test.js +0 -0
  468. /package/providers/{beta/open-names → open-names}/dist/esm/im-reverse-geocode.js +0 -0
  469. /package/providers/{beta/open-names → open-names}/dist/umd/im-reverse-geocode.js.LICENSE.txt +0 -0
  470. /package/{plugins/beta/use-location → providers/open-names}/dist/umd/index.js.LICENSE.txt +0 -0
  471. /package/providers/{beta/open-names → open-names}/src/index.js +0 -0
  472. /package/providers/{beta/open-names → open-names}/src/reverseGeocode.js +0 -0
  473. /package/providers/{beta/open-names → open-names}/src/utils/mapToLocationModel.js +0 -0
  474. /package/providers/{beta/open-names → open-names}/src/utils/mapToLocationModel.test.js +0 -0
  475. /package/providers/{beta/openlayers → openlayers}/dist/esm/im-openlayers-provider.js +0 -0
  476. /package/providers/{beta/openlayers → openlayers}/dist/umd/im-openlayers-provider.js.LICENSE.txt +0 -0
  477. /package/providers/{beta/open-names → openlayers}/dist/umd/index.js.LICENSE.txt +0 -0
  478. /package/providers/{beta/openlayers → openlayers}/src/appEvents.js +0 -0
  479. /package/providers/{beta/openlayers → openlayers}/src/appEvents.test.js +0 -0
  480. /package/providers/{beta/openlayers → openlayers}/src/defaults.js +0 -0
  481. /package/providers/{beta/openlayers → openlayers}/src/index.test.js +0 -0
  482. /package/providers/{beta/openlayers → openlayers}/src/openlayersProvider.test.js +0 -0
  483. /package/providers/{beta/openlayers → openlayers}/src/utils/bngProjection.js +0 -0
  484. /package/providers/{beta/openlayers → openlayers}/src/utils/filterEvaluator.js +0 -0
  485. /package/providers/{beta/openlayers → openlayers}/src/utils/filterEvaluator.test.js +0 -0
  486. /package/providers/{beta/openlayers → openlayers}/src/utils/highlightFeatures.test.js +0 -0
  487. /package/providers/{beta/openlayers → openlayers}/src/utils/hoverCursor.js +0 -0
  488. /package/providers/{beta/openlayers → openlayers}/src/utils/hoverCursor.test.js +0 -0
  489. /package/providers/{beta/openlayers → openlayers}/src/utils/openLayersFixes.js +0 -0
  490. /package/providers/{beta/openlayers → openlayers}/src/utils/openLayersFixes.test.js +0 -0
  491. /package/providers/{beta/openlayers → openlayers}/src/utils/patternImages.test.js +0 -0
  492. /package/providers/{beta/openlayers → openlayers}/src/utils/queryFeatures.js +0 -0
  493. /package/providers/{beta/openlayers → openlayers}/src/utils/queryFeatures.test.js +0 -0
  494. /package/providers/{beta/openlayers → openlayers}/src/utils/spatial.js +0 -0
  495. /package/providers/{beta/openlayers → openlayers}/src/utils/spatial.test.js +0 -0
  496. /package/providers/{beta/openlayers → openlayers}/src/utils/symbolImages.test.js +0 -0
  497. /package/providers/{beta/openlayers → openlayers}/src/utils/tileLayers.js +0 -0
  498. /package/providers/{beta/openlayers → openlayers}/src/utils/tileLayers.test.js +0 -0
  499. /package/providers/{beta/openlayers → openlayers}/src/utils/vtTileFragments.js +0 -0
  500. /package/providers/{beta/openlayers → openlayers}/src/utils/vtTileFragments.test.js +0 -0
  501. /package/providers/{beta/openlayers → openlayers}/src/utils/zoom.js +0 -0
  502. /package/providers/{beta/openlayers → openlayers}/src/utils/zoom.test.js +0 -0
@@ -1 +1 @@
1
- import{i as e,c as t,T as n,K as r,M as o,v as i,a as s,b as a,d as c,S as l,e as u,r as d,l as p,p as h,f,g,m,h as y,j as v,k as _,n as x,o as E,q as I,C as S,s as M,t as b,u as T,A as P}from"./im-draw-plugin.js";import{c as C,r as w,a as L,s as O,b as A,d as k,e as F,f as V}from"./liveDrawChecks.js";import"preact/compat";import"preact/jsx-runtime";const N={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"},D={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},R={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},U={POLYGON:"polygon",LINE:"line_string",POINT:"point"},B={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"},j={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},G={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"},H={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},Y={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},X={ACTIVE:"true",INACTIVE:"false"},$=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var K=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:X,classes:N,cursors:R,events:G,geojsonTypes:B,interactions:$,meta:Y,modes:j,sources:D,types:U,updateActions:H});function J(e){return function(t){const n=t.featureTarget;return!!n&&(!!n.properties&&n.properties.meta===e)}}function q(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function Z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===X.ACTIVE&&e.featureTarget.properties.meta===Y.FEATURE))}function z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===X.INACTIVE&&e.featureTarget.properties.meta===Y.FEATURE))}function W(e){return void 0===e.featureTarget}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===Y.FEATURE)}function ee(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===Y.VERTEX)}function te(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function ne(e){return"Escape"===e.key||27===e.keyCode}function re(e){return"Enter"===e.key||13===e.keyCode}function oe(e){return"Backspace"===e.key||8===e.keyCode}function ie(e){return"Delete"===e.key||46===e.keyCode}function se(e){return"1"===e.key||49===e.keyCode}function ae(e){return"2"===e.key||50===e.keyCode}function ce(e){return"3"===e.key||51===e.keyCode}function le(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var ue=Object.freeze({__proto__:null,isActiveFeature:Z,isBackspaceKey:oe,isDeleteKey:ie,isDigit1Key:se,isDigit2Key:ae,isDigit3Key:ce,isDigitKey:le,isEnterKey:re,isEscapeKey:ne,isFeature:Q,isInactiveFeature:z,isOfMetaType:J,isShiftDown:te,isShiftMousedown:q,isTrue:function(){return!0},isVertex:ee,noTarget:W});function de(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function pe(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){var n=!1;try{n=this instanceof e}catch{}return n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var he,fe,ge={},me={};function ye(){return he||(he=1,me.RADIUS=6378137,me.FLATTENING=1/298.257223563,me.POLAR_RADIUS=6356752.3142),me}var ve=function(){if(fe)return ge;fe=1;var e=ye();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(n(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(n(e[r]))}return t}function n(t){var n,o,i,s,a,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,s=u-1,a=0):c===u-1?(i=u-1,s=0,a=1):(i=c,s=c+1,a=c+2),n=t[i],o=t[s],l+=(r(t[a][0])-r(n[0]))*Math.sin(r(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function r(e){return e*Math.PI/180}return ge.geometry=function e(n){var r,o=0;switch(n.type){case"Polygon":return t(n.coordinates);case"MultiPolygon":for(r=0;r<n.coordinates.length;r++)o+=t(n.coordinates[r]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(r=0;r<n.geometries.length;r++)o+=e(n.geometries[r]);return o}},ge.ring=n,ge}(),_e=de(ve);const xe={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Ee(e,t){const n=xe[e.geometry.type]-xe[t.geometry.type];return 0===n&&e.geometry.type===B.POLYGON?e.area-t.area:n}function Ie(e){return e.map(e=>(e.geometry.type===B.POLYGON&&(e.area=_e.geometry({type:B.FEATURE,property:{},geometry:e.geometry})),e)).sort(Ee).map(e=>(delete e.area,e))}function Se(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Me(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,n=e.length;t<n;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}Me.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Me.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Me.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Me.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)},Me.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const be=[Y.FEATURE,Y.MIDPOINT,Y.VERTEX];var Te={click:function(e,t,n){return Pe(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return Pe(e,t,n,n.options.touchBuffer)}};function Pe(e,t,n,r){if(null===n.map)return[];const o=e?Se(e,r):t,i={};n.options.styles&&(i.layers=n.options.styles.map(e=>e.id).filter(e=>null!=n.map.getLayer(e)));const s=n.map.queryRenderedFeatures(o,i).filter(e=>-1!==be.indexOf(e.properties.meta)),a=new Me,c=[];return s.forEach(e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),Ie(c)}function Ce(e,t){const n=Te.click(e,null,t),r={mouse:R.NONE};return n[0]&&(r.mouse=n[0].properties.active===X.ACTIVE?R.MOVE:R.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=R.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function we(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Le(e,t,n={}){const r=null!=n.fineTolerance?n.fineTolerance:4,o=null!=n.grossTolerance?n.grossTolerance:12,i=null!=n.interval?n.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const s=we(e.point,t.point);return s<r||s<o&&t.time-e.time<i}function Oe(e,t,n={}){const r=null!=n.tolerance?n.tolerance:25,o=null!=n.interval?n.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return we(e.point,t.point)<r&&t.time-e.time<o}const Ae=function(e,t){const n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on(e,t,r){if(void 0===n[e])throw new Error(`Invalid event type: ${e}`);n[e].push({selector:t,fn:r})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=n[e];let s=i.length;for(;s--;){const e=i[s];if(e.selector(o)){e.fn.call(r,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(r),{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 ke=((e,t=21)=>(n=t)=>{let r="",o=0|n;for(;o--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Fe(){return ke()}const Ve=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Fe(),this.type=t.geometry.type};Ve.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Ve.prototype.incomingCoords=function(e){this.setCoordinates(e)},Ve.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ve.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Ve.prototype.setProperty=function(e,t){this.properties[e]=t},Ve.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:B.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Ve.prototype.internal=function(e){const t={id:this.id,meta:Y.FEATURE,"meta:type":this.type,active:X.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:B.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ne=function(e,t){Ve.call(this,e,t)};(Ne.prototype=Object.create(Ve.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ne.prototype.updateCoordinate=function(e,t,n){this.coordinates=3===arguments.length?[t,n]:[e,t],this.changed()},Ne.prototype.getCoordinate=function(){return this.getCoordinates()};const De=function(e,t){Ve.call(this,e,t)};(De.prototype=Object.create(Ve.prototype)).isValid=function(){return this.coordinates.length>1},De.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},De.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},De.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},De.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const Re=function(e,t){Ve.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Re.prototype=Object.create(Ve.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Re.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Re.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Re.prototype.addCoordinate=function(e,t,n){this.changed();const r=e.split(".").map(e=>parseInt(e,10));this.coordinates[r[0]].splice(r[1],0,[t,n])},Re.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},Re.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},Re.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Re.prototype.updateCoordinate=function(e,t,n){this.changed();const r=e.split("."),o=parseInt(r[0],10),i=parseInt(r[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,n]};const Ue={MultiPoint:Ne,MultiLineString:De,MultiPolygon:Re},Be=(e,t,n,r,o)=>{const i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,r,o)},je=function(e,t){if(Ve.call(this,e,t),delete this.coordinates,this.model=Ue[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 Ge(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(je.prototype=Object.create(Ve.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Fe(),type:B.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},je.prototype.isValid=function(){return this.features.every(e=>e.isValid())},je.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},je.prototype.getCoordinate=function(e){return Be(this.features,"getCoordinate",e)},je.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===B.POLYGON?e.getCoordinates():e.coordinates)))},je.prototype.updateCoordinate=function(e,t,n){Be(this.features,"updateCoordinate",e,t,n),this.changed()},je.prototype.addCoordinate=function(e,t,n){Be(this.features,"addCoordinate",e,t,n),this.changed()},je.prototype.removeCoordinate=function(e){Be(this.features,"removeCoordinate",e),this.changed()},je.prototype.getFeatures=function(){return this.features},Ge.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Ge.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),{})},Ge.prototype.getSelected=function(){return this._ctx.store.getSelected()},Ge.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Ge.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Ge.prototype.getFeature=function(e){return this._ctx.store.get(e)},Ge.prototype.select=function(e){return this._ctx.store.select(e)},Ge.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Ge.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Ge.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Ge.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Ge.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Ge.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Ge.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},Ge.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Ge.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Ge.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Ge.prototype.featuresAt=function(e,t,n="click"){if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return Te[n](e,t,this._ctx)},Ge.prototype.newFeature=function(e){const t=e.geometry.type;return t===B.POINT?new Ne(this._ctx,e):t===B.LINE_STRING?new De(this._ctx,e):t===B.POLYGON?new Re(this._ctx,e):new je(this._ctx,e)},Ge.prototype.isInstanceOf=function(e,t){if(e===B.POINT)return t instanceof Ne;if(e===B.LINE_STRING)return t instanceof De;if(e===B.POLYGON)return t instanceof Re;if("MultiFeature"===e)return t instanceof je;throw new Error(`Unknown feature class: ${e}`)},Ge.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Ge.prototype.onSetup=function(){},Ge.prototype.onDrag=function(){},Ge.prototype.onClick=function(){},Ge.prototype.onMouseMove=function(){},Ge.prototype.onMouseDown=function(){},Ge.prototype.onMouseUp=function(){},Ge.prototype.onMouseOut=function(){},Ge.prototype.onKeyUp=function(){},Ge.prototype.onKeyDown=function(){},Ge.prototype.onTouchStart=function(){},Ge.prototype.onTouchMove=function(){},Ge.prototype.onTouchEnd=function(){},Ge.prototype.onTap=function(){},Ge.prototype.onStop=function(){},Ge.prototype.onTrash=function(){},Ge.prototype.onCombineFeature=function(){},Ge.prototype.onUncombineFeature=function(){},Ge.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const He={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Ye=Object.keys(He);function Xe(e){const t=Object.keys(e);return function(n,r={}){let o={};const i=t.reduce((t,n)=>(t[n]=e[n],t),new Ge(n));return{start(){o=i.onSetup(r),Ye.forEach(t=>{const n=He[t];let r=()=>!1;var s;e[n]&&(r=()=>!0),this.on(t,r,(s=n,e=>i[s](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 $e(e){return[].concat(e).filter(e=>void 0!==e)}function Ke(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(D.HOT)))return a();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let n=[],r=[];e.isDirty?r=e.getAllIds():(n=e.getChangedIds().filter(t=>void 0!==e.get(t)),r=e.sources.hot.filter(t=>t.properties.id&&-1===n.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===n.indexOf(t)});const i=o!==e.sources.cold.length||r.length>0;function s(n,r){const o=e.get(n).internal(t);e.ctx.events.currentModeRender(o,n=>{n.properties.mode=t,e.sources[r].push(n)})}function a(){e.isDirty=!1,e.clearChangedIds()}n.forEach(e=>s(e,"hot")),r.forEach(e=>s(e,"cold")),i&&e.ctx.map.getSource(D.COLD).setData({type:B.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(D.HOT).setData({type:B.FEATURE_COLLECTION,features:e.sources.hot}),a()}function Je(e){let t;this._features={},this._featureIds=new Me,this._selectedFeatureIds=new Me,this._selectedCoordinates=[],this._changedFeatureIds=new Me,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ke.call(this),this._emitSelectionChange&&(this.ctx.events.fire(G.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(G.RENDER,{})}))},this.isDirty=!1}function qe(e,t={}){const n=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===n.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=n}Je.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Je.prototype.setDirty=function(){return this.isDirty=!0,this},Je.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(G.CREATE,{features:[t.toGeoJSON()]})}return this},Je.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(G.UPDATE,{action:t.action?t.action:H.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Je.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Je.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Je.prototype.getAllIds=function(){return this._featureIds.values()},Je.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Je.prototype.delete=function(e,t={}){const n=[];return $e(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===n.indexOf(this._features[e])&&n.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),n.length&&this.ctx.events.fire(G.DELETE,{features:n}),qe(this,t),this},Je.prototype.get=function(e){return this._features[e]},Je.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Je.prototype.select=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Je.prototype.deselect=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),qe(this,t),this},Je.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Je.prototype.setSelected=function(e,t={}){return e=$e(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},Je.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Je.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Je.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Je.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Je.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Je.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Je.prototype.setFeatureProperty=function(e,t,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:H.CHANGE_PROPERTIES})},Je.prototype.storeMapConfig=function(){$.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Je.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Je.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Ze=["mode","feature","mouse"];function ze(e){let t=null,n=null;const r={onRemove(){return e.map.off("load",r.connect),clearInterval(n),r.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",r.connect),clearInterval(n),r.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,n)=>(t[n]=Xe(e.options.modes[n]),t),{});let n={},r={};const o={};let i=null,s=null;o.drag=function(t,n){n({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:R.DRAG}),s.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Le(n,e))},o.touchdrag=function(e){o.drag(e,e=>!Oe(r,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const n=Ce(t,e);t.featureTarget=n,s.mousemove(t)},o.mousedown=function(t){n={time:(new Date).getTime(),point:t.point};const r=Ce(t,e);t.featureTarget=r,s.mousedown(t)},o.mouseup=function(t){const r=Ce(t,e);t.featureTarget=r,Le(n,{point:t.point,time:(new Date).getTime()})?s.click(t):s.mouseup(t)},o.mouseout=function(e){s.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;r={time:(new Date).getTime(),point:t.point};const n=Te.touch(t,null,e)[0];t.featureTarget=n,s.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return s.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const n=Te.touch(t,null,e)[0];t.featureTarget=n,Oe(r,{time:(new Date).getTime(),point:t.point})?s.tap(t):s.touchend(t)};const a=e=>{const t=oe(e),n=ie(e),r=le(e);return!(t||n||r)};function c(n,r,o={}){s.stop();const a=t[n];if(void 0===a)throw new Error(`${n} is not valid`);i=n;const c=a(e,r);s=Ae(c,e),o.silent||e.map.fire(G.MODE_CHANGE,{mode:n}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(N.CANVAS)&&((oe(t)||ie(t))&&e.options.controls.trash?(t.preventDefault(),s.trash()):a(t)?s.keydown(t):se(t)&&e.options.controls.point?c(j.DRAW_POINT):ae(t)&&e.options.controls.line_string?c(j.DRAW_LINE_STRING):ce(t)&&e.options.controls.polygon&&c(j.DRAW_POLYGON))},o.keyup=function(e){a(e)&&s.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:n,options:r,store:o}=e;r.styles.some(e=>n.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,s=Ae(t[i](e),e)},changeMode:c,actionable:function(t){let n=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(n=!0),l[e]=t[e]}),n&&e.map.fire(G.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>s.render(e,t),fire(t,n){e.map&&e.map.fire(t,n)},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){s.trash(e)},combineFeatures(){s.combineFeatures()},uncombineFeatures(){s.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let n=null,r={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function s(){if(!e.container)return;const t=[],n=[];Ze.forEach(e=>{o[e]!==r[e]&&(t.push(`${e}-${r[e]}`),null!==o[e]&&n.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),n.length>0&&e.container.classList.add(...n),r=Object.assign(r,o)}function a(e,t={}){const r=document.createElement("button");return r.className=`${N.CONTROL_BUTTON} ${t.className}`,r.setAttribute("title",t.title),t.container.appendChild(r),r.addEventListener("click",r=>{if(r.preventDefault(),r.stopPropagation(),r.target===n)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),r}function c(){n&&(n.classList.remove(N.ACTIVE_BUTTON),n=null)}function l(e){c();const r=t[e];r&&r&&"trash"!==e&&(r.classList.add(N.ACTIVE_BUTTON),n=r)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:s,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),s()},addButtons:function(){const n=e.options.controls,r=document.createElement("div");return r.className=`${N.CONTROL_GROUP} ${N.CONTROL_BASE}`,n?(n[U.POINT]&&(t[U.POINT]=a(U.POINT,{container:r,className:N.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(j.DRAW_POINT),onDeactivate:()=>e.events.trash()})),n[U.LINE]&&(t[U.LINE]=a(U.LINE,{container:r,className:N.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(j.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),n[U.POLYGON]&&(t[U.POLYGON]=a(U.POLYGON,{container:r,className:N.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(j.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),n.trash&&(t.trash=a("trash",{container:r,className:N.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),n.combine_features&&(t.combine_features=a("combineFeatures",{container:r,className:N.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),n.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:r,className:N.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),r):r},removeButtons:function(){Object.keys(t).forEach(e=>{const n=t[e];n.parentNode&&n.parentNode.removeChild(n),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new Je(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()?r.connect():(o.on("load",r.connect),n=setInterval(()=>{o.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(D.COLD,{data:{type:B.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(D.HOT,{data:{type:B.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(D.COLD)&&e.map.removeSource(D.COLD),e.map.getSource(D.HOT)&&e.map.removeSource(D.HOT)}};return e.setup=r,r}const We="#3bb2d0",Qe="#fbb03b",et="#fff";var tt=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Qe,We],"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"],Qe,We],"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":et}},{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"],Qe,We]}},{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":et}},{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":Qe}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Qe}}];function nt(e,t){this.x=e,this.y=t}function rt(e,t){const n=t.getBoundingClientRect();return new nt(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function ot(e,t,n,r){return{type:B.FEATURE,properties:{meta:Y.VERTEX,parent:e,coord_path:n,active:r?X.ACTIVE:X.INACTIVE},geometry:{type:B.POINT,coordinates:t}}}function it(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return st(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(e=>st(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ct(e);default:throw new Error("unknown GeoJSON type")}}function st(e){const t={type:"Feature"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=at(e.properties),null==e.geometry?t.geometry=null:t.geometry=ct(e.geometry),t}function at(e){const t={};return e?(Object.keys(e).forEach(n=>{const r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(e=>e):t[n]=at(r):t[n]=r}),t):t}function ct(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ct(e)),t):(t.coordinates=lt(e.coordinates),t)}function lt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>lt(e))}function ut(e,t={}){return dt(e,"mercator",t)}function dt(n,r,o={}){var i=(o=o||{}).mutate;if(!n)throw new Error("geojson is required");return Array.isArray(n)&&e(n[0])?n="mercator"===r?pt(n):ht(n):(!0!==i&&(n=it(n)),t(n,function(e){var t="mercator"===r?pt(e):ht(e);e[0]=t[0],e[1]=t[1]})),n}function pt(e){var t,n=Math.PI/180,r=6378137,o=20037508.342789244,i=[r*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*n,r*Math.log(Math.tan(.25*Math.PI+.5*e[1]*n))];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 ht(e){var t=180/Math.PI,n=6378137;return[e[0]*t/n,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/n)))*t]}function ft(e,t,n){const r=t.geometry.coordinates,o=n.geometry.coordinates;if(r[1]>85||r[1]<-85||o[1]>85||o[1]<-85)return null;const i=ut(r),s=ut(o),a=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return dt(e,"wgs84",t)}([c(i[0],s[0]),c(i[1],s[1])]),u=[a(l[0]),a(l[1])];return{type:B.FEATURE,properties:{meta:Y.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:n.properties.coord_path},geometry:{type:B.POINT,coordinates:u}}}function gt(e,t={},n=null){const{type:r,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let s=[];function a(e,n){let r="",o=null;e.forEach((e,a)=>{const l=null!=n?`${n}.${a}`:String(a),u=ot(i,e,l,c(l));if(t.midpoints&&o){const e=ft(i,o,u);e&&s.push(e)}o=u;const d=JSON.stringify(e);r!==d&&s.push(u),0===a&&(r=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return r===B.POINT?s.push(ot(i,o,n,c(n))):r===B.POLYGON?o.forEach((e,t)=>{a(e,null!==n?`${n}.${t}`:String(t))}):r===B.LINE_STRING?a(o,n):0===r.indexOf(B.MULTI_PREFIX)&&function(){const n=r.replace(B.MULTI_PREFIX,"");o.forEach((r,o)=>{const i={type:B.FEATURE,properties:e.properties,geometry:{type:n,coordinates:r}};s=s.concat(gt(i,t,o))})}(),s}nt.prototype={clone(){return new nt(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,n=e.y-this.y;return t*t+n*n},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,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,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),n=Math.sin(e),r=t*this.x-n*this.y,o=n*this.x+t*this.y;return this.x=r,this.y=o,this},_rotateAround(e,t){const n=Math.cos(e),r=Math.sin(e),o=t.x+n*(this.x-t.x)-r*(this.y-t.y),i=t.y+r*(this.x-t.x)+n*(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:nt},nt.convert=function(e){if(e instanceof nt)return e;if(Array.isArray(e))return new nt(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new nt(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var mt={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:yt,LAT_MAX:vt,LAT_RENDERED_MIN:_t,LAT_RENDERED_MAX:xt,LNG_MIN:Et,LNG_MAX:It}=K;function St(e,t){let n=yt,r=vt,o=yt,i=vt,s=It,a=Et;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],n=[e.geometry.coordinates].flat(t),r=n.map(e=>e[0]),o=n.map(e=>e[1]),i=e=>Math.min.apply(null,e),s=e=>Math.max.apply(null,e);return[i(r),i(o),s(r),s(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>n&&(n=c),l<r&&(r=l),l>o&&(o=l),c<i&&(i=c),u<s&&(s=u),d>a&&(a=d)});const c=t;return n+c.lat>xt&&(c.lat=xt-n),o+c.lat>vt&&(c.lat=vt-o),r+c.lat<_t&&(c.lat=_t-r),i+c.lat<yt&&(c.lat=yt-i),s+c.lng<=Et&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=It&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Mt(e,t){const n=St(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),r=e=>{const t={lng:e[0]+n.lng,lat:e[1]+n.lat};return[t.lng,t.lat]},o=e=>e.map(e=>r(e)),i=e=>e.map(e=>o(e));let s;e.type===B.POINT?s=r(t):e.type===B.LINE_STRING||e.type===B.MULTI_POINT?s=t.map(r):e.type===B.POLYGON||e.type===B.MULTI_LINE_STRING?s=t.map(o):e.type===B.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)})}const bt={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(G.UPDATE,{action:H.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let n=!1;if(e.length>1){n=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(n=!1)})}const r=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:n,uncombineFeatures:r,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 Me).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(){mt.enable(this)},onMouseMove:function(e,t){return Q(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};bt.onTap=bt.onClick=function(e,t){return W(t)?this.clickAnywhere(e,t):J(Y.VERTEX)(t)?this.clickOnVertex(e,t):Q(t)?this.clickOnFeature(e,t):void 0},bt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),mt.enable(this),this.stopExtendedInteractions(e)},bt.clickOnVertex=function(e,t){this.changeMode(j.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:R.MOVE})},bt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},bt.clickOnFeature=function(e,t){mt.disable(this),this.stopExtendedInteractions(e);const n=te(t),r=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!n&&i&&this.getFeature(o).type!==B.POINT)return this.changeMode(j.DIRECT_SELECT,{featureId:o});i&&n?(this.deselect(o),this.updateUIClasses({mouse:R.POINTER}),1===r.length&&mt.enable(this)):!i&&n?(this.select(o),this.updateUIClasses({mouse:R.MOVE})):i||n||(r.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:R.MOVE})),this.doRender(o)},bt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),Z(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&q(t)?this.startBoxSelect(e,t):void 0},bt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=rt(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},bt.onTouchStart=function(e,t){if(Z(t))return this.startOnActiveFeature(e,t)},bt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},bt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:R.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(N.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=rt(t.originalEvent,this.map.getContainer()),r=Math.min(e.boxSelectStartLocation.x,n.x),o=Math.max(e.boxSelectStartLocation.x,n.x),i=Math.min(e.boxSelectStartLocation.y,n.y),s=Math.max(e.boxSelectStartLocation.y,n.y),a=`translate(${r}px, ${i}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=o-r+"px",e.boxSelectElement.style.height=s-i+"px"},bt.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};Mt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},bt.onTouchEnd=bt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,rt(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),o=this.getUniqueIds(r).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:R.MOVE}))}this.stopExtendedInteractions(e)},bt.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?X.ACTIVE:X.INACTIVE,n(t),this.fireActionable(),t.properties.active===X.ACTIVE&&t.geometry.type!==B.POINT&&gt(t).forEach(n)},bt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},bt.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],n=[],r=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==r)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),n.push(i.toGeoJSON())}if(n.length>1){const e=this.newFeature({type:B.FEATURE,properties:n[0].properties,geometry:{type:`Multi${r}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(G.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},bt.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],n=[];for(let r=0;r<e.length;r++){const o=e[r];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}),n.push(o.toGeoJSON()))}t.length>1&&this.fire(G.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const Tt=J(Y.VERTEX),Pt=J(Y.MIDPOINT),Ct={fireUpdate:function(){this.fire(G.UPDATE,{action:H.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 n=t.featureTarget.properties,r=e.selectedCoordPaths.indexOf(n.coord_path);te(t)||-1!==r?te(t)&&-1===r&&e.selectedCoordPaths.push(n.coord_path):e.selectedCoordPaths=[n.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.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,n){Mt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,n){const r=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=St(r.map(e=>({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:e}})),n);for(let t=0;t<r.length;t++){const n=r[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],n[0]+o.lng,n[1]+o.lat)}},clickNoTarget:function(){this.changeMode(j.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(j.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===B.POINT)throw new TypeError("direct_select mode doesn't handle point features");const r={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,r.selectedCoordPaths)),this.setSelected(t),mt.disable(this),this.setActionableState({trash:!0}),r},onStop:function(){mt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=X.ACTIVE,n(t),gt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=X.INACTIVE,n(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(j.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=Z(t),r=Tt(t),o=Pt(t),i=0===e.selectedCoordPaths.length;n&&i||r&&!i?this.updateUIClasses({mouse:R.MOVE}):this.updateUIClasses({mouse:R.NONE});return(r||n||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ct.onTouchStart=Ct.onMouseDown=function(e,t){return Tt(t)?this.onVertex(e,t):Z(t)?this.onFeature(e,t):Pt(t)?this.onMidpoint(e,t):void 0},Ct.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat},Ct.onClick=function(e,t){return W(t)?this.clickNoTarget(e,t):Z(t)?this.clickActiveFeature(e,t):z(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ct.onTap=function(e,t){return W(t)?this.clickNoTarget(e,t):Z(t)?this.clickActiveFeature(e,t):z(t)?this.clickInactive(e,t):void 0},Ct.onTouchEnd=Ct.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const wt={};function Lt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}wt.onSetup=function(){const e=this.newFeature({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:R.ADD}),this.activateUIButton(U.POINT),this.setActionableState({trash:!0}),{point:e}},wt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)},wt.onTap=wt.onClick=function(e,t){this.updateUIClasses({mouse:R.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(G.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(j.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,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?X.ACTIVE:X.INACTIVE,!r)return n(t)},wt.onTrash=wt.stopDrawingAndRemove,wt.onKeyUp=function(e,t){if(ne(t)||re(t))return this.stopDrawingAndRemove(e,t)};const Ot={onSetup:function(){const e=this.newFeature({type:B.FEATURE,properties:{},geometry:{type:B.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),mt.disable(this),this.updateUIClasses({mouse:R.ADD}),this.activateUIButton(U.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Lt(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:R.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(j.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),ee(t)&&this.updateUIClasses({mouse:R.POINTER})}};Ot.onTap=Ot.onClick=function(e,t){return ee(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ot.onKeyUp=function(e,t){ne(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)):re(t)&&this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ot.onStop=function(e){this.updateUIClasses({mouse:R.NONE}),mt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(G.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT,{},{silent:!0})))},Ot.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?X.ACTIVE:X.INACTIVE,!r)return n(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=Y.FEATURE,n(ot(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const r=t.geometry.coordinates[0].length-3;n(ot(e.polygon.id,t.geometry.coordinates[0][r],`0.${r}`,!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(n({type:B.FEATURE,properties:t.properties,geometry:{coordinates:e,type:B.LINE_STRING}}),3===o)return}return n(t)}},Ot.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)};const At={onSetup:function(e){const t=(e=e||{}).featureId;let n,r,o="forward";if(t){if(n=this.getFeature(t),!n)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 s=n.coordinates.length-1;if(n.coordinates[s][0]===i[0]&&n.coordinates[s][1]===i[1])r=s+1,n.addCoordinate(r,...n.coordinates[s]);else{if(n.coordinates[0][0]!==i[0]||n.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",r=0,n.addCoordinate(r,...n.coordinates[0])}}else n=this.newFeature({type:B.FEATURE,properties:{},geometry:{type:B.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),mt.disable(this),this.updateUIClasses({mouse:R.ADD}),this.activateUIButton(U.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Lt(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&Lt(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:R.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(j.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),ee(t)&&this.updateUIClasses({mouse:R.POINTER})}};At.onTap=At.onClick=function(e,t){if(ee(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},At.onKeyUp=function(e,t){re(t)?this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.line.id]}):ne(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT))},At.onStop=function(e){mt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(G.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT,{},{silent:!0})))},At.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)},At.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?X.ACTIVE:X.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=Y.FEATURE,n(ot(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)),n(t))};var kt={simple_select:bt,direct_select:Ct,draw_point:wt,draw_polygon:Ot,draw_line_string:At};const Ft={defaultMode:j.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:tt,modes:kt,controls:{},userProperties:!1,suppressAPIEvents:!0},Vt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Nt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Dt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?D.HOT:D.COLD}))}var Rt,Ut;var Bt,jt,Gt=de(Ut?Rt:(Ut=1,Rt=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,o,i;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(o=r;0!==o--;)if(!e(t[o],n[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(o=r;0!==o--;)if(!Object.prototype.hasOwnProperty.call(n,i[o]))return!1;for(o=r;0!==o--;){var s=i[o];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n}));var Ht=function(){if(jt)return Bt;jt=1,Bt=function(t){if(!t||!t.type)return null;var n=e[t.type];if(!n)return null;if("geometry"===n)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===n)return{type:"FeatureCollection",features:[t]};if("featurecollection"===n)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Bt}(),Yt=de(Ht);function Xt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const $t={Polygon:Re,LineString:De,Point:Ne,MultiPolygon:je,MultiLineString:je,MultiPoint:je};var Kt=Object.freeze({__proto__:null,CommonSelectors:ue,ModeHandler:Ae,StringSet:Me,constrainFeatureMovement:St,createMidPoint:ft,createSupplementaryPoints:gt,createVertex:ot,doubleClickZoom:mt,euclideanDistance:we,featuresAt:Te,getFeatureAtAndSetCursors:Ce,isClick:Le,isEventAtCoordinates:Lt,isTap:Oe,mapEventToBoundingBox:Se,moveFeatures:Mt,sortFeatures:Ie,stringSetsAreEqual:Xt,theme:tt,toDenseArray:$e});const Jt=function(e,t){const n={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Nt,e.controls):t.controls=Object.assign({},Vt,e.controls),t=Object.assign({},Ft,t),t.styles=Dt(t.styles,"cold").concat(Dt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=j;const n=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Te.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:B.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:B.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:e.coordinates}}))}},t.set=function(n){if(void 0===n.type||n.type!==B.FEATURE_COLLECTION||!Array.isArray(n.features))throw new Error("Invalid FeatureCollection");const r=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(n),s=new Me(i);return o=o.filter(e=>!s.has(e)),o.length&&t.delete(o),r(),i},t.add=function(t){const r=JSON.parse(JSON.stringify(Yt(t))).features.map(t=>{if(t.id=t.id||Fe(),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 r=$t[t.geometry.type];if(void 0===r)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new r(e,t);e.store.add(o,{silent:n})}else{const r=e.store.get(t.id),o=r.properties;r.properties=t.properties,Gt(o,t.properties)||e.store.featureChanged(r.id,{silent:n}),Gt(r.getCoordinates(),t.geometry.coordinates)||r.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),r},t.get=function(t){const n=e.store.get(t);if(n)return n.toGeoJSON()},t.getAll=function(){return{type:B.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()!==j.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(j.SIMPLE_SELECT,void 0,{silent:n}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===j.DIRECT_SELECT?e.events.changeMode(j.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,o={}){return r===j.SIMPLE_SELECT&&t.getMode()===j.SIMPLE_SELECT?(Xt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:n}),e.store.render()),t):(r===j.DIRECT_SELECT&&t.getMode()===j.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,o,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,o,i){return e.store.setFeatureProperty(r,o,i,{silent:n}),t},t}(n,t),n.api=t;const r=ze(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=U,t.options=e,t};function qt(e){Jt(e,this)}qt.modes=kt,qt.constants=K,qt.lib=Kt;const Zt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,n){t.properties.active="false",n(t)}},zt="draw.create",Wt="draw.update",Qt="draw.modechange",en="draw.editfinish",tn="draw.cancel",nn="draw.vertexselection",rn="draw.vertexchange",on="draw.undochange",sn="draw.undo",an="draw.geometrychange",cn="draw.interfacetypechange",ln="draw.placementblocked",un="draw.nudgevertex",dn="draw.selectvertex",pn="draw.insertvertexatmidpoint",hn="styledata",fn=e=>{if(!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[]}},gn=e=>{const t=fn(e),n=mn(e);if(!t.length||!n.length)return[];const r=[];for(const e of n){const n=e.closed?e.length:e.length-1;for(let o=0;o<n;o++){const n=e.start+o,i=e.start+(o+1)%e.length,[s,a]=t[n],[c,l]=t[i];r.push([(s+c)/2,(a+l)/2])}}return r},mn=e=>{if(!e?.coordinates)return[];const t=[];let n=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!0}),n+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!1}),n+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,r)=>{e.forEach((e,o)=>{t.push({start:n,length:e.length,path:[r,o],closed:!0}),n+=e.length})})}return t},yn=(e,t)=>{for(const n of e)if(t>=n.start&&t<n.start+n.length)return{segment:n,localIdx:t-n.start};return null},vn=(e,t)=>{let n=e.geometry.coordinates;for(const e of t)n=n[e];return n},_n=(e,t)=>{const n=t.split(".").map(Number),r=mn(e);for(const e of r){if(e.path.every((e,t)=>e===n[t])&&n.length===e.path.length+1){const t=n[n.length-1];return e.start+t}}return n[n.length-1]},xn=(e,t)=>({x:e.x*t,y:e.y*t}),En=e=>e instanceof window.SVGElement||e.ownerSVGElement;function In(e){return e?._snapInstance??null}function Sn(e){return!!(e?.status&&e?.snapStatus&&e.snapCoords?.length>=2)}function Mn(e){return Sn(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function bn(e,t,n){if(!e||!t||!e.status)return!1;const r=t.unproject(n);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Tn(e,t){e&&(e._autoSnapSuspended=t)}function Pn(e,t){if(!e||!t||!e.status)return!1;const n=t.getCenter(),r=t.project(n);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function Cn(e,t){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0)),t?.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function wn(e){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0))}function Ln(e){return"function"==typeof e?.getSnapEnabled&&!0===e.getSnapEnabled()}const On=(e,t,n={})=>{const r=n=>r=>n.call(e,t,r),o={keydown:r(e.onKeydown),keyup:r(e.onKeyup),pointerdown:r(e.onPointerevent),pointermove:r(e.onPointerevent),pointerup:r(e.onPointerevent),click:r(e.onButtonClick),touchstart:r(e.onTouchstart),touchmove:r(e.onTouchmove),touchend:r(e.onTouchend),scalechange:r(e.onScaleChange),move:r(e.onMove),interfacetypechange:r(e.onInterfaceTypeChange)};for(const[e,t]of Object.entries(n))o[e]=r(t);return o},An=(e,t,n)=>{window.addEventListener("keydown",n.keydown,{capture:!0}),window.addEventListener("keyup",n.keyup,{capture:!0}),window.addEventListener("click",n.click),e.container.addEventListener("pointerdown",n.pointerdown),e.container.addEventListener("pointermove",n.pointermove),e.container.addEventListener("pointerup",n.pointerup),e.container.addEventListener("touchstart",n.touchstart,{passive:!1}),e.container.addEventListener("touchmove",n.touchmove,{passive:!1}),e.container.addEventListener("touchend",n.touchend,{passive:!1}),t.on("draw.scalechange",n.scalechange),t.on("move",n.move),t.on(cn,n.interfacetypechange),t.on(un,n.nudge)},kn=(e,t,n)=>{e.container.removeEventListener("pointerdown",n.pointerdown),e.container.removeEventListener("pointermove",n.pointermove),e.container.removeEventListener("pointerup",n.pointerup),e.container.removeEventListener("touchstart",n.touchstart),e.container.removeEventListener("touchmove",n.touchmove),e.container.removeEventListener("touchend",n.touchend),t.off("draw.scalechange",n.scalechange),t.off("move",n.move),t.off(cn,n.interfacetypechange),t.off(un,n.nudge),t.dragPan.enable(),window.removeEventListener("click",n.click),window.removeEventListener("keydown",n.keydown,{capture:!0}),window.removeEventListener("keyup",n.keyup,{capture:!0})},Fn=e=>{const t=In(e);t&&Cn(t,e)},Vn={fireGeometryChange(e){const t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,n){e&&setTimeout(()=>{const r=this.getFeature(n);r&&this.map.fire("draw.geometrychange",{feature:r.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){const t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}},Nn={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},Dn={...Vn,UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Nn,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_vertex"===n.type?this.undoMoveVertex(e,n):"insert_vertex"===n.type?this.undoInsertVertex(e,n):"delete_vertex"===n.type&&this.undoDeleteVertex(e,n),this.emitGeometryValidation(Nn[n.type],n.vertexIndex,n.featureId)},undoMoveVertex(e,t){const{vertexIndex:n,previousPosition:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=mn(i),c=yn(a,n);if(!c)return;vn(s,c.segment.path)[c.localIdx]=r,this._applyUndoAndSync(e,s,o);const l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,xn(this.map.project(l),e.scale))},undoInsertVertex(e,t){const{vertexIndex:n,featureId:r}=t,o=this.getFeature(r);if(!o)return;const i=o.toGeoJSON(),s=mn(o),a=yn(s,n);if(!a)return;vn(i,a.segment.path).splice(a.localIdx,1),this._applyUndoAndSync(e,i,r),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})},undoDeleteVertex(e,t){const{vertexIndex:n,position:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=mn(i);let c=yn(a,n);if(!c)for(const e of a)if(n===e.start+e.length){c={segment:e,localIdx:e.length};break}if(!c)return;vn(s,c.segment.path).splice(c.localIdx,0,r),this._applyUndoAndSync(e,s,o),this.updateTouchVertexTarget(e,xn(this.map.project(e.vertices[n]),e.scale)),this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,n)})},_applyUndoAndSync(e,t,n){this._ctx.api.add(t),e.vertices=this.getVertices(n),e.midpoints=this.getMidpoints(n),this._ctx.store.render(),this.fireGeometryChange(e)}},Rn=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Un=(e,t,n,r,o)=>{const i=window.getComputedStyle(t),s={x:n.x-Number.parseFloat(i.left),y:n.y-Number.parseFloat(i.top)},a=e.project(r);return{deltaTarget:s,deltaVertex:{x:n.x/o-a.x,y:n.y/o-a.y}}},Bn=(e,t,n)=>{const r={x:n.x/t.scale-t.deltaVertex.x,y:n.y/t.scale-t.deltaVertex.y};let o=e.unproject(r);if(Ln(t)){const t=In(e);bn(t,e,r),o=Mn(t)||o}return o},jn=(e,t,n={})=>{if(!e)return;const{editActive:r,editHalo:o,editVertex:i}=w(t,n);L(e,{editActive:r,editHalo:o,editVertex:i})},Gn={addTouchVertexTarget(e){e.touchVertexTarget=C(e.container),jn(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:`${t.y}px`,left:`${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||En(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(wn(In(this.map)),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;const t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xn(this.map.project(t),e.scale))}},onTap(e,t){const n=In(this.map);n&&Cn(n,this.map);const r=t.featureTarget?.properties.meta,o=t.featureTarget?.properties.coord_path;if("vertex"===r){const t=this.getFeature(e.featureId),n=_n(t,o);this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:o})}else"midpoint"===r?this.insertVertex({...e,selectedVertexIndex:this.getVertexIndexFromMidpoint(e,o),selectedVertexType:"midpoint"}):this.clickNoTarget(e)},onTouchstart(e,t){wn(In(this.map));const n=this.getVertices(e.featureId),r=n?.[e.selectedVertexIndex];if(!r||!En(t.target.parentNode))return;e._moveStartPosition=[...r],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;const o=Rn(t);Object.assign(e,Un(this.map,e.touchVertexTarget,o,r,e.scale))},onTouchmove(e,t){if(e.selectedVertexIndex<0||!En(t.target.parentNode))return;e._touchMoved=!0;const n=Rn(t);this.moveVertex(e,Bn(this.map,e,n)),this.updateTouchVertexTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},Hn=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Yn={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Xn=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),$n=e=>{const t=document.activeElement;return!(!t||t===document.body)&&(!e.container?.contains(t)&&(Xn.has(t.tagName)||t.isContentEditable||t.hasAttribute("tabindex")))},Kn=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,Jn={handleUndoShortcut(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},qn={getOffset(e,t){const n=this.map.project(e),o=t?.shiftKey?r.nudgeAmount:r.stepAmount,[i,s]=t?Yn[t.key].map(e=>e*o):[0,0];return this.map.unproject({x:n.x+i,y:n.y+s})},getOffsetByDelta(e,t,n,o){const i=this.map.project(e),s=o?r.stepAmount:r.nudgeAmount;return this.map.unproject({x:i.x+t*s,y:i.y+n*s})},resolveSnapTarget(e,t,r,o,i){const s=In(this.map);if(Ln(e)&&e._isSnapped&&s){const i=function(e){return e?.options?.radius??n.snapRadius}(s)+1,a=this.map.project(o);return e._isSnapped=!1,Cn(s,this.map),this.map.unproject({x:a.x+t*i,y:a.y+r*i})}const a=i();return Ln(e)&&s&&(bn(s,this.map,this.map.project(a)),Sn(s))?(e._isSnapped=!0,Mn(s)):(e._isSnapped=!1,a)}},Zn={...qn,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){const[n,r]=this.getVertexOrMidpoint(e,t);n<0||!r||this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:r,..."vertex"===r&&{coordPath:this.getCoordPath(e,n)}})},getNewCoord(e,t){return this.getOffset(fn(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,n,r){if("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)return;const o=this.getFeature(e.featureId),i=o&&fn(o)?.[e.selectedVertexIndex];if(!i)return;const s=[...i],a=e.selectedVertexIndex,c=this.resolveSnapTarget(e,t,n,i,()=>this.getOffsetByDelta(i,t,n,r));this.moveVertex(e,c),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:a,previousPosition:s})},insertVertex(e,t){const n=e.selectedVertexIndex-e.vertices.length,r=this.getOffset(e.midpoints[n],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),s=mn(o);let a=n+1,c=null,l=0,u=0;for(const e of s){const t=e.closed?e.length:e.length-1;if(n<u+t){c=e,l=n-u+1,a=e.start+l;break}u+=t}if(!c)return;vn(i,c.path).splice(l,0,[r.lng,r.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:a}),this.changeMode(e,{selectedVertexIndex:a,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,a)})},moveVertex(e,t,n={}){if(n.checkSnap&&!1!==e.enableSnap){const e=this.map._snapInstance;e?.snapStatus&&e.snapCoords?.length>=2&&(t={lng:e.snapCoords[0],lat:e.snapCoords[1]})}const r=this.getFeature(e.featureId),o=r.toGeoJSON(),i=mn(r),s=yn(i,e.selectedVertexIndex);if(!s)return;vn(o,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(o),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature)},deleteVertex(e){const t=this.getFeature(e.featureId);if(!t)return;const n=mn(t),r=yn(n,e.selectedVertexIndex);if(!r)return;const{segment:i}=r,s=i.closed?o.Polygon:o.LineString;if(i.length<=s)return;const a=[...e.vertices[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...r.segment.path,r.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})}},zn={findVertexIndex(e,t,n){const r=[];return e.forEach((e,n)=>{e[0]===t[0]&&e[1]===t[1]&&r.push(n)}),0===r.length?-1:1===r.length?r[0]:n>=0?r.reduce((e,t)=>Math.abs(t-n)<Math.abs(e-n)?t:e,r[0]):r[0]},getCoordPath(e,t){const n=this.getFeature(e.featureId);if(!n)return"0";const r=mn(n),o=yn(r,t);if(!o)return"0";const{segment:i,localIdx:s}=o;return[...i.path,s].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return fn(this.getFeature(e))},getMidpoints(e){return gn(this.getFeature(e))},getVertexOrMidpoint(e,t){if(e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),!e.vertices?.length)return[-1,null];const n=e=>e?Object.values(this.map.project(e)):null,r=[...e.vertices.map(n),...e.midpoints.map(n)].filter(Boolean);if(!r.length)return[-1,null];const o=r[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),i=O(o,r,t);return[i,i<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){const n=this.getFeature(e.featureId),r=mn(n),o=t.split(".").map(Number);let i=0;for(const t of r){if(t.path.every((e,t)=>e===o[t])&&o.length===t.path.length+1){const n=o[o.length-1],r=n>0?n-1:t.length-2;return e.vertices.length+i+r}i+=t.closed?t.length:t.length-1}return e.vertices.length}},Wn={...Jn,onKeydown(e,t){$n(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Hn.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?Kn(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){const t=In(this.map);t&&Cn(t,this.map),e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),e.vertices?.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){if("midpoint"===e.selectedVertexType)return void this.insertVertex(e,t);const n=this.getFeature(e.featureId),r=n&&fn(n)?.[e.selectedVertexIndex];r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,n){const[r,o]=Yn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){$n(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&A(t),Hn.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))}},Qn={onMouseDown(e,t){wn(In(this.map));const n=t.featureTarget?.properties.meta,r=t.featureTarget?.properties.coord_path;if(["vertex","midpoint"].includes(n)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,Ct.onMouseDown.call(this,e,t),"vertex"===n&&r)){const t=this.getFeature(e.featureId),n=_n(t,r);e.selectedVertexIndex=n,e.selectedVertexType="vertex",e.coordPath=r;const o=e.vertices?.[n];o&&(e._moveStartPosition=[...o],e._moveStartIndex=n)}if("midpoint"===n){const t=this.getFeature(e.featureId),n=_n(t,r);e._insertedVertexIndex=n,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,r),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(nn,{index:e.selectedVertexIndex,numVertices:e.vertices.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){const t=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(nn,{index:t,numVertices:e.vertices.length})}Ct.onClick.call(this,e,t)},onMouseUp(e,t){wn(In(this.map));const n=e._isInsertingVertex&&null!=e._insertedVertexIndex,r=this._didVertexMove(e);(e.dragMoving||r||n)&&(this.syncVertices(e),n?this._recordInsertionUndo(e):r&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,Ct.onMouseUp.call(this,e,t)},_didVertexMove(e){if(!e._moveStartPosition||null==e._moveStartIndex)return!1;const t=this.getFeature(e.featureId),n=t&&fn(t)?.[e._moveStartIndex];return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){const 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(nn,{index:t,numVertices:e.vertices.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=In(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!Ln(e)||!n?.status)return void Ct.onDrag.call(this,e,t);if(!e.selectedCoordPaths?.length||!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation(),bn(n,this.map,t.point);const r=Mn(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],r.lng,r.lat),e.dragMoveLocation=t.lngLat}},er={...qt.modes.direct_select,...Dn,...Gn,...Zn,...zn,...Wn,...Qn,onSetup(e){const t=qt.modes.direct_select.onSetup.call(this,e);Object.assign(t,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:t.featureId,selectedVertexIndex:e.selectedVertexIndex??-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:e.scale??1}),this.map._lastEditFeatureId!==t.featureId&&(this.map._undoStack?.clear(),this.map._lastEditFeatureId=t.featureId);const n=this.getFeature(t.featureId);if(t.featureType=n?.type,t.vertices=this.getVertices(t.featureId),t.midpoints=this.getMidpoints(t.featureId),this.setupEventListeners(t),this.applyVertexSelection(t,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(t),Fn(this.map),"touch"===t.interfaceType&&t.selectedVertexIndex>=0&&"vertex"===t.selectedVertexType){const e=t.vertices[t.selectedVertexIndex];e&&setTimeout(()=>{this.updateTouchVertexTarget(t,xn(this.map.project(e),t.scale))},0)}return t._ignorePointermoveDeselect=!0,setTimeout(()=>{t._ignorePointermoveDeselect=!1},100),t},setupEventListeners(e){const t=this.handlers=On(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint});An(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(dn,t.selectvertex),this.map.on(pn,t.insertvertexatmidpoint)},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.vertices.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){this.syncVertices(e);const n=t.points[t.points.length-1]?.geometry.coordinates;if("keyboard"!==e.interfaceType&&n&&!e.coordPath){const r=t.features[0]?.geometry,o=fn(r);e.selectedVertexIndex=this.findVertexIndex(o,n,e.selectedVertexIndex)}e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null,this.map.fire(nn,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});const r=n||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,r?xn(this.map.project(r),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;const n=e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,n?xn(this.map.project(n),e.scale):null)},onUpdate(e){new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,e.selectedVertexType??=null)},onMove(e){const t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xn(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);const n=e.vertices[e.selectedVertexIndex];n&&this.updateTouchVertexTarget(e,xn(this.map.project(n),e.scale))},onSelectVertex(e,t){e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));const n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,{selectedVertexIndex:t.index,selectedVertexType:n,..."vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}})},onInsertVertexAtMidpoint(e,t){e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex({...e,selectedVertexIndex:t.index,selectedVertexType:"midpoint"})},onButtonClick(e,t){t.target.closest(`#${e.deleteVertexButtonId}`)&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest(`#${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",{...e,...t})},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;const t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(dn,t.selectvertex),this.map.off(pn,t.insertvertexatmidpoint),kn(e,this.map,t),this.hideTouchVertexIndicator(e)}},tr={move_point:"commit-move"},nr={...Vn,UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:tr,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_point"===n.type&&this.undoMovePoint(e,n),this.emitGeometryValidation(tr[n.type],n.vertexIndex,n.featureId)},undoMovePoint(e,t){const{previousPosition:n,featureId:r}=t,o=this.getFeature(r);o&&(o.updateCoordinate("",n[0],n[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,xn(this.map.project(n),e.scale)))}},rr={addTouchPointTarget(e){e.touchPointTarget=C(e.container),jn(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:`${t.y}px`,left:`${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){wn(In(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,xn(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){wn(In(this.map));const n=this.getPointCoord(e);if(!n||!En(t.target.parentNode))return;e._moveStartPosition=[...n],e._touchMoved=!1;const r=Rn(t);Object.assign(e,Un(this.map,e.touchPointTarget,r,n,e.scale))},onTouchmove(e,t){if(!En(t.target.parentNode))return;e._touchMoved=!0;const n=Rn(t);this.movePoint(e,Bn(this.map,e,n)),this.updateTouchPointTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},or={...qn,getPointCoord(e){return this.getFeature(e.featureId)?.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,n,r){const o=this.getPointCoord(e);if(!o)return;const i=[...o],s=this.resolveSnapTarget(e,t,n,o,()=>this.getOffsetByDelta(o,t,n,r));this.movePoint(e,s),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}},ir={...Jn,onKeydown(e,t){$n(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Hn.has(t.key)?this.handleArrowKey(e,t):Kn(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){const n=this.getPointCoord(e);n&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...n]),this.movePoint(e,this._keyboardMoveTarget(e,t,n)))},_keyboardMoveTarget(e,t,n){const[r,o]=Yn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){$n(e)||(e.interfaceType="keyboard",A(t),Hn.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}},sr="edit_point",ar={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],Tn(In(this.map),!0)),Ct.onFeature.call(this,e,t)},onClick(e,t){if(Z(t))return;if(!((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:r,reason:o}=i(n,{mode:sr,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return r||e.fire("draw.placementblocked",{feature:n,reason:o??null,phase:"place",mode:sr,vertexIndex:0}),r})(this.map,[t.lngLat.lng,t.lngLat.lat]))return;const n=[...e.feature.coordinates],r=In(this.map);let o=t.lngLat;Ln(e)&&r&&(bn(r,this.map,t.point),o=Mn(r)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:n})},onMouseUp(e,t){const n=In(this.map);wn(n),Tn(n,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Ct.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;const t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=In(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!Ln(e)||!n?.status)return void Ct.onDrag.call(this,e,t);if(!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};bn(n,this.map,this.map.project([r.lng,r.lat]));const o=Mn(n)||r;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat},onTrash(){}},cr={...qt.modes.direct_select,...nr,...rr,...or,...ir,...ar,onSetup(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter edit_point mode");const r={featureId:t,feature:n,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};return this.setSelectedCoordinates([]),this.setSelected(t),mt.disable(this),this.setActionableState({trash:!1}),Object.assign(r,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:e.scale??1}),this.map._lastEditFeatureId!==r.featureId&&(this.map._undoStack?.clear(),this.map._lastEditFeatureId=r.featureId),this.setupEventListeners(r),this.map._drawEditContainer=e.container,this.addTouchPointTarget(r),r.container?.focus({preventScroll:!0}),Fn(this.map),"touch"===r.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(r,xn(this.map.project(r.feature.coordinates),r.scale))},0),this.map.fire(nn,{index:0,numVertices:1}),r},setupEventListeners(e){const t=this.handlers=On(this,e,{nudge:this.onNudgePoint});An(e,this.map,t)},toDisplayFeatures(e,t,n){t.properties.active=e.featureId===t.properties.id?"true":"false",n(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,kn(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}},lr=({ParentMode:e,featureProp:t,excludeFeatureIdFromSetup:n})=>({onSetup(r){const{map:o}=this,i=n?{...r,featureId:null}:r,s={...e.onSetup.call(this,i),...r};s[t].properties=r.properties;const{container:a,vertexMarkerId:c,getInterfaceType:l}=s,u=l?l():s.interfaceType;s.interfaceType=u;const d=a.querySelector(`#${c}`);s.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(s):this._hideCrossHair(s),s.crossHair&&(s.crossHair.activate=()=>this._placeAtCrossHair?.(s));const p=(e,t)=>this[e]=t.bind(this,s),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,t])=>p(e,t)),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"keyup",A,{capture:!0}],[window,"click",this.vertexButtonClickHandler],[a,"blur",this.blurHandler],[a,"pointermove",this.pointermoveHandler],[a,"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,t,n,r])=>e.addEventListener?e.addEventListener(t,n,r):e.on(t,n)),s},onStop(t){e.onStop.call(this,t),this._listeners.forEach(([e,t,n,r])=>e.removeEventListener?e.removeEventListener(t,n,r):e.off(t,n)),t.crossHair?.activate&&(t.crossHair.activate=null),["touch","keyboard"].includes(t.interfaceType)||this._hideCrossHair(t),this.map.fire("draw.interfacetypechange",{interfaceType:t.interfaceType})}}),ur=(e,t,n,r,o)=>{setTimeout(()=>{const i=t(r);i&&e.fire("draw.geometrychange",((e,t,n)=>{const r=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[r]}:{type:"LineString",coordinates:r},properties:{}},phase:n,vertexIndex:Math.max(0,r.length-1)}})(i,n,o))},0)},dr=({geometryType:e,getFeature:t,getCoords:n})=>({_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(r,o){const i=t(r);if(!i||!o)return!0;const a=s({placed:n(i).slice(0,-1),point:o,geometryType:e,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e,r="commit-add"){ur(this.map,t,n,e,r)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this.doClick(e)},onCreate(e,t){((e,t,n)=>{e.delete(t.id),t.id=n,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}),pr=({ParentMode:e,getFeature:t,getCoords:n,validateClick:r,finishOnInvalidClick:o})=>({onClick(i,s){if(this._isIgnorableClick(s))return;if(!1===this.map._drawGeometryValid&&"vertex"===s.featureTarget?.properties?.meta)return;const a=In(this.map);if(Ln(i)&&Sn(a))s=function(e,t){const n=Mn(t);return n?{...e,lngLat:n}:e}(s,a);else if(!((e,i)=>{const s=n(t(e));return s.length>0&&(s[s.length-1]=[i.lngLat.lng,i.lngLat.lat]),o||r(t(e))})(i,s))return;if(!this._canPlaceVertex(i,[s.lngLat.lng,s.lngLat.lat]))return;const c=n(t(i)).length;e.onClick.call(this,i,s),n(t(i)).length>c&&(this.pushDrawUndo(i),this.dispatchVertexChange(n(t(i))),this.emitDrawValidation(i))},doClick(i){if(this.map._undoInProgress)return;const s=t(i),a=n(s);if(this.dispatchVertexChange(a),!r(s))return void(o&&!1!==this.map._drawGeometryValid&&(a.pop(),this.map.fire("draw.create",{features:[s.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[s.id]})));const c=In(this.map),l=Ln(i)&&function(e,t){const n=Mn(t);if(!n)return null;const r=e.project([n.lng,n.lat]);return{lngLat:n,point:r,originalEvent:new MouseEvent("click",{clientX:r.x,clientY:r.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(!this._canPlaceVertex(i,[u.lng,u.lat]))return;l?(e.onClick.call(this,i,l),this._ctx.store.render()):this._simulateMouse("click",e.onClick,i);const d=n(t(i));this.pushDrawUndo(i),this.dispatchVertexChange(d),this.emitDrawValidation(i)},_placeAtCrossHair(e){this.doClick(e)}}),hr=e=>({...dr(e),...pr(e)}),fr=({geometryType:e,getFeature:t})=>({pushDrawUndo(n){const r=this.map._undoStack;r&&!this.map._undoInProgress&&r.push({type:"draw_vertex",geometryType:e,featureId:t(n).id})},onUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"draw_vertex"===n?.type&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))},_handleUndoKeydown(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}),gr=({ParentMode:e,geometryType:t,getCoords:n,getFeature:r,RUBBER_BAND_OFFSET:o})=>({undoVertex(e){const t=r(e),o=n(t);return!(o.length<2)&&(2===o.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,o),!0))},_removeLastVertex(e,r,i){const s="Polygon"===t?r.coordinates[0]:i;s.splice(-o,1),s[s.length-1]=[...s[s.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(r))},_updateRubberBand(n,r){if(["touch","keyboard"].includes(n.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,n),this._ctx.store.render();else{const o=r["Polygon"===t?r.length-2:r.length-1],i={lng:o[0],lat:o[1]},s=this.map.project(i);e.onMouseMove.call(this,n,{lngLat:i,point:s,originalEvent:new MouseEvent("mousemove",{clientX:s.x,clientY:s.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",n.polygon||n.line)}this.dispatchVertexChange(r)}}),mr=({ParentMode:e,featureProp:t,geometryType:n})=>({_reinitializeFeature(r,o){const i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(r,i);const s=this.map.getCenter(),a=[[s.lng,s.lat],[s.lng,s.lat]],c=this.newFeature({type:"Feature",properties:r.properties||{},geometry:{type:n,coordinates:[a]}});return c.id=i,this._ctx.store.add(c),r[t]=c,r.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,r),this._ctx.store.render(),this.dispatchVertexChange(a),!0},_restartLineStringDraw(e,t){const n=this.map._undoStack;return n&&n.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}}),yr=e=>({...fr(e),...gr(e),...mr(e)}),vr=({ParentMode:e,getFeature:t,INTERFACE_KEYS:n})=>({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(n,r){const o=document.activeElement;if(!o||o===n.container||!n.container.contains(o))if("Escape"!==r.key)o!==n.container&&e.onKeyUp.call(this,n,r);else if("keyboard"===n.interfaceType){const e=this.map._undoStack;e&&e.clear(),this._reinitializeFeature(n,t(n))}}}),_r=({ParentMode:e,getFeature:t,getCoords:n})=>({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(t,n){if(Ln(t)){const e=In(this.map);bn(e,this.map,n.point);const t=Mn(e);t&&(n={...n,lngLat:t})}e.onMouseMove.call(this,t,n),this.map.fire("draw.geometrychange",t.polygon||t.line)},onMove(t,n){const r="move"===n?.type&&!n.originalEvent;if(["touch","keyboard"].includes(t.interfaceType)||r){Ln(t)&&Pn(In(this.map),this.map);const n=In(this.map),r=Ln(t)&&Mn(n);if(r){const n=this.map.project([r.lng,r.lat]);e.onMouseMove.call(this,t,{lngLat:r,point:n,originalEvent:new MouseEvent("mousemove",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",t.polygon||t.line)}else this._simulateMouse("mousemove",e.onMouseMove,t)}},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(t(e)))}}),xr=({ParentMode:e,geometryType:t,getFeature:n,getPlacedCoords:r})=>({_simulateMouse(e,t,n){const{map:r}=this,o=r.getCenter(),i=r.project(o);t.call(this,n,{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",n.polygon||n.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,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},toDisplayFeatures(o,i,s){e.toDisplayFeatures.call(this,o,i,s);const a=n(o);i.geometry.type===t&&i.properties.id===a.id&&r(i).forEach(e=>s({type:"Feature",properties:{meta:"draw-vertex",parent:a.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}),Er=(e,t)=>{const{featureProp:n,geometryType:r,getCoords:o,validateClick:i,getPlacedCoords:s,excludeFeatureIdFromSetup:a=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:n,geometryType:r,getCoords:o,validateClick:i,getPlacedCoords:s,excludeFeatureIdFromSetup:a,finishOnInvalidClick:c,getFeature:e=>e[n],RUBBER_BAND_OFFSET:2,INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return{...e,...lr(l),...hr(l),...yr(l),...vr(l),..._r(l),...xr(l)}},Ir=Er(qt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>a(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Sr=Er(qt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>c(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),Mr="draw_point",br=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),Tr=qt.modes.draw_point,Pr=lr({ParentMode:Tr,featureProp:"point",excludeFeatureIdFromSetup:!1}),Cr={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,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},onCreate(e,t){const n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),e.resolvePointSymbol?.(e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){const n="move"===t?.type&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||n)&&Ln(e)&&Pn(In(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){Ln(e)&&bn(In(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),br.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&br.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())return;const n=In(this.map),r=Ln(e)&&Sn(n)?Mn(n):null;this._commit(e,r||t.lngLat)},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){const t=In(this.map);Ln(e)&&Pn(t,this.map);const n=Ln(e)&&Sn(t)?Mn(t):null;this._commit(e,n||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:r,reason:o}=i(n,{mode:Mr,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return r||e.fire("draw.placementblocked",{feature:n,reason:o??null,phase:"place",mode:Mr,vertexIndex:0}),r})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},wr={...Tr,...Pr,...Cr},Lr=(e,t,n)=>["coalesce",["get",`user_${t}${e.id.charAt(0).toUpperCase()+e.id.slice(1)}`],["get",`user_${t}`],n],Or=["coalesce",["get","user_sortKey"],0],Ar=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":Or},paint:{"fill-color":Lr(e,"fill",t.shapeFill)}}),kr=(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":Or},paint:{"line-color":Lr(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),Fr=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}}),Vr=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),Nr=(e,t,n)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":n,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Dr=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Rr=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),Ur=(e,t,n)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":n,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Br=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),jr=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Gr=(e,t={})=>{const n=w(e,t),{vertexRadius:r,midpointRadius:o,vertexHaloRadius:i,midpointHaloRadius:s}=l;return[Ar(e,n),(p=n.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":p}}),(d=n.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":d,"line-width":2,"line-opacity":1}}),(u=n.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":u,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),kr(e,n),{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":Or},paint:{}},(c=n.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":c,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(a=n.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":a,"line-width":2,"line-opacity":1}}),Fr(n.editStroke),Rr(n.editMidpoint,o),Ur(n.editHalo,n.editActive,s),Br(n.editMidpoint,o),Vr(n.editVertex,r),Nr(n.editHalo,n.editActive,i),Dr(n.editVertex,r),jr(n.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}}];var a,c,u,d,p};function Hr(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 Yr(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 Xr(e,t,n){void 0===n&&(n={});var r=Hr(e),o=Hr(t),i=u(o[1]-r[1]),s=u(o[0]-r[0]),a=u(r[1]),c=u(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return d(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}function $r(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 Kr(e,t,n,r={}){const o=$r(e),i=u(o[0]),s=u(o[1]),a=u(n),c=p(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),d=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),g=f(d),m=f(l);return void 0!==o[2]?h([g,m,o[2]],r.properties):h([g,m],r.properties)}function Jr(e,t){var n;return void 0===t&&(t={}),function(e,t){if(e.length>1)return m(e,t);return y(e[0],t)}(("Feature"===(n=e).type?n.geometry:n).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function qr(e,t,n={}){if(!0===n.final)return function(e,t){let n=qr(t,e);return n=(n+180)%360,n}(e,t);const r=$r(e),o=$r(t),i=u(r[0]),s=u(o[0]),a=u(r[1]),c=u(o[1]),l=Math.sin(s-i)*Math.cos(c),d=Math.cos(a)*Math.sin(c)-Math.sin(a)*Math.cos(c)*Math.cos(s-i);return f(Math.atan2(l,d))}var Zr=qr;function zr(e,t,n,r){void 0===r&&(r={});var o=Hr(e),i=u(o[0]),s=u(o[1]),a=u(n),c=p(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),d=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),g=f(d),m=f(l);return h([g,m],r.properties)}function Wr(e){if(!e)throw new Error("geojson is required");var t=[];return v(e,function(e){!function(e,t){var n=[],r=e.geometry;if(null!==r){switch(r.type){case"Polygon":n=Yr(r);break;case"LineString":n=[Yr(r)]}n.forEach(function(n){var r=function(e,t){var n=[];return e.reduce(function(e,r){var o,i,s,a,c,l,u=y([e,r],t);return u.bbox=(i=r,s=(o=e)[0],a=o[1],c=i[0],l=i[1],[s<c?s:c,a<l?a:l,s>c?s:c,a>l?a:l]),n.push(u),r}),n}(n,e.properties);r.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),_(t)}var Qr={exports:{}};function eo(e,t,n,r,o){to(e,t,n||0,r||e.length-1,o||ro)}function to(e,t,n,r,o){for(;r>n;){if(r-n>600){var i=r-n+1,s=t-n+1,a=Math.log(i),c=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*c*(i-c)/i)*(s-i/2<0?-1:1);to(e,t,Math.max(n,Math.floor(t-s*c/i+l)),Math.min(r,Math.floor(t+(i-s)*c/i+l)),o)}var u=e[t],d=n,p=r;for(no(e,n,t),o(e[r],u)>0&&no(e,n,r);d<p;){for(no(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[n],u)?no(e,n,p):no(e,++p,r),p<=t&&(n=p+1),t<=p&&(r=p-1)}}function no(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function ro(e,t){return e<t?-1:e>t?1:0}function oo(e,t,n){if(!n)return t.indexOf(e);for(let r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function io(e,t){so(e,0,e.children.length,t,e)}function so(e,t,n,r,o){o||(o=yo(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<n;i++){const t=e.children[i];ao(o,e.leaf?r(t):t)}return o}function ao(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 co(e,t){return e.minX-t.minX}function lo(e,t){return e.minY-t.minY}function uo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function po(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ho(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 fo(e,t){const n=Math.max(e.minX,t.minX),r=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-n)*Math.max(0,i-r)}function go(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function mo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function yo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function vo(e,t,n,r,o){const i=[t,n];for(;i.length;){if((n=i.pop())-(t=i.pop())<=r)continue;const s=t+Math.ceil((n-t)/r/2)*r;eo(e,s,t,n,o),i.push(t,s,s,n)}}var _o,xo=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 n=[];if(!mo(e,t))return n;const r=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const s=t.children[i],a=t.leaf?r(s):s;mo(e,a)&&(t.leaf?n.push(s):go(e,a)?this._all(s,n):o.push(s))}t=o.pop()}return n}collides(e){let t=this.data;if(!mo(e,t))return!1;const n=[];for(;t;){for(let r=0;r<t.children.length;r++){const o=t.children[r],i=t.leaf?this.toBBox(o):o;if(mo(e,i)){if(t.leaf||go(e,i))return!0;n.push(o)}}t=n.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=yo([]),this}remove(e,t){if(!e)return this;let n=this.data;const r=this.toBBox(e),o=[],i=[];let s,a,c;for(;n||o.length;){if(n||(n=o.pop(),a=o[o.length-1],s=i.pop(),c=!0),n.leaf){const r=oo(e,n.children,t);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}c||n.leaf||!go(n,r)?a?(s++,n=a.children[s],c=!1):n=null:(o.push(n),i.push(s),s=0,a=n,n=n.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 n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){const o=n-t+1;let i,s=this._maxEntries;if(o<=s)return i=yo(e.slice(t,n+1)),io(i,this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,r-1))),i=yo([]),i.leaf=!1,i.height=r;const a=Math.ceil(o/s),c=a*Math.ceil(Math.sqrt(s));vo(e,t,n,c,this.compareMinX);for(let o=t;o<=n;o+=c){const t=Math.min(o+c-1,n);vo(e,o,t,a,this.compareMinY);for(let n=o;n<=t;n+=a){const o=Math.min(n+a-1,t);i.children.push(this._build(e,n,o,r-1))}}return io(i,this.toBBox),i}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const s=t.children[i],a=uo(s),c=ho(e,s)-a;c<o?(o=c,r=a<r?a:r,n=s):c===o&&a<r&&(r=a,n=s)}t=n||t.children[0]}return t}_insert(e,t,n){const r=n?e:this.toBBox(e),o=[],i=this._chooseSubtree(r,this.data,t,o);for(i.children.push(e),ao(i,r);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(r,o,t)}_split(e,t){const n=e[t],r=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,r);const i=this._chooseSplitIndex(n,o,r),s=yo(n.children.splice(i,n.children.length-i));s.height=n.height,s.leaf=n.leaf,io(n,this.toBBox),io(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this.data=yo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,io(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,o=1/0,i=1/0;for(let s=t;s<=n-t;s++){const t=so(e,0,s,this.toBBox),a=so(e,s,n,this.toBBox),c=fo(t,a),l=uo(t)+uo(a);c<o?(o=c,r=s,i=l<i?l:i):c===o&&l<i&&(i=l,r=s)}return r||n-t}_chooseSplitAxis(e,t,n){const r=e.leaf?this.compareMinX:co,o=e.leaf?this.compareMinY:lo;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,o)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);const o=this.toBBox,i=so(e,0,t,o),s=so(e,n-t,n,o);let a=po(i)+po(s);for(let r=t;r<n-t;r++){const t=e.children[r];ao(i,e.leaf?o(t):t),a+=po(i)}for(let r=n-t-1;r>=t;r--){const t=e.children[r];ao(s,e.leaf?o(t):t),a+=po(s)}return a}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)ao(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)0===e[n].children.length?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():io(e[n],this.toBBox)}}}),Eo=pe(xo),Io={};function So(){if(_o)return Io;_o=1,Object.defineProperty(Io,"__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},n={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 r(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function o(e,t,n={}){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 r({type:"Point",coordinates:e},t,n)}function i(e,t,n={}){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 r({type:"Polygon",coordinates:e},t,n)}function s(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return r({type:"LineString",coordinates:e},t,n)}function a(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function c(e,t,n={}){return r({type:"MultiLineString",coordinates:e},t,n)}function l(e,t,n={}){return r({type:"MultiPoint",coordinates:e},t,n)}function u(e,t,n={}){return r({type:"MultiPolygon",coordinates:e},t,n)}function d(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e*r}function p(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e/r}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Io.areaFactors=n,Io.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Io.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Io.convertArea=function(e,t="meters",r="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=n[t];if(!o)throw new Error("invalid original units");const i=n[r];if(!i)throw new Error("invalid final units");return e/o*i},Io.convertLength=function(e,t="kilometers",n="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),n)},Io.degreesToRadians=function(e){return e%360*Math.PI/180},Io.earthRadius=e,Io.factors=t,Io.feature=r,Io.featureCollection=a,Io.geometry=function(e,t,n={}){switch(e){case"Point":return o(t).geometry;case"LineString":return s(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")}},Io.geometryCollection=function(e,t,n={}){return r({type:"GeometryCollection",geometries:e},t,n)},Io.isNumber=f,Io.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Io.lengthToDegrees=function(e,t){return h(p(e,t))},Io.lengthToRadians=p,Io.lineString=s,Io.lineStrings=function(e,t,n={}){return a(e.map(e=>s(e,t)),n)},Io.multiLineString=c,Io.multiPoint=l,Io.multiPolygon=u,Io.point=o,Io.points=function(e,t,n={}){return a(e.map(e=>o(e,t)),n)},Io.polygon=i,Io.polygons=function(e,t,n={}){return a(e.map(e=>i(e,t)),n)},Io.radiansToDegrees=h,Io.radiansToLength=d,Io.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const n=Math.pow(10,t||0);return Math.round(e*n)/n},Io.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")})},Io.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")},Io}var Mo,bo={};function To(){if(Mo)return bo;Mo=1,Object.defineProperty(bo,"__esModule",{value:!0});var e=So();function t(e,n,r){if(null!==e)for(var o,i,s,a,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,m="Feature"===f,y=g?e.features.length:1,v=0;v<y;v++){c=(d=!!(u=g?e.features[v].geometry:m?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var _=0;_<c;_++){var x=0,E=0;if(null!==(a=d?u.geometries[_]:u)){l=a.coordinates;var I=a.type;switch(p=!r||"Polygon"!==I&&"MultiPolygon"!==I?0:1,I){case null:break;case"Point":if(!1===n(l,h,v,x,E))return!1;h++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===n(l[o],h,v,x,E))return!1;h++,"MultiPoint"===I&&x++}"LineString"===I&&x++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===n(l[o][i],h,v,x,E))return!1;h++}"MultiLineString"===I&&x++,"Polygon"===I&&E++}"Polygon"===I&&x++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(E=0,i=0;i<l[o].length;i++){for(s=0;s<l[o][i].length-p;s++){if(!1===n(l[o][i][s],h,v,x,E))return!1;h++}E++}x++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===t(a.geometries[o],n,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function n(e,t){var n;switch(e.type){case"FeatureCollection":for(n=0;n<e.features.length&&!1!==t(e.features[n].properties,n);n++);break;case"Feature":t(e.properties,0)}}function r(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function o(e,t){var n,r,o,i,s,a,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(n=0;n<g;n++){for(a=h?e.features[n].geometry:f?e.geometry:e,l=h?e.features[n].properties:f?e.properties:{},u=h?e.features[n].bbox:f?e.bbox:void 0,d=h?e.features[n].id:f?e.id:void 0,s=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,o=0;o<s;o++)if(null!==(i=c?a.geometries[o]:a))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(r=0;r<i.geometries.length;r++)if(!1===t(i.geometries[r],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,n){o(t,function(t,r,o,i,s){var a,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==n(e.feature.call(void 0,t,o,{bbox:i,id:s}),r,0)&&void 0}switch(c){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:a,coordinates:t.coordinates[l]};if(!1===n(e.feature.call(void 0,u,o),r,l))return!1}})}function s(n,r){i(n,function(n,o,i){var s=0;if(n.geometry){var a=n.geometry.type;if("Point"!==a&&"MultiPoint"!==a){var c,l=0,u=0,d=0;return!1!==t(n,function(t,a,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(s=0);var g=e.lineString.call(void 0,[c,t],n.properties);if(!1===r(g,o,i,f,s))return!1;s++,c=t})&&void 0}}})}function a(t,n){if(!t)throw new Error("geojson is required");i(t,function(t,r,o){if(null!==t.geometry){var i=t.geometry.type,s=t.geometry.coordinates;switch(i){case"LineString":if(!1===n(t,r,o,0,0))return!1;break;case"Polygon":for(var a=0;a<s.length;a++)if(!1===n(e.lineString.call(void 0,s[a],t.properties),r,o,a))return!1}}})}return bo.coordAll=function(e){var n=[];return t(e,function(e){n.push(e)}),n},bo.coordEach=t,bo.coordReduce=function(e,n,r,o){var i=r;return t(e,function(e,t,o,s,a){i=0===t&&void 0===r?e:n(i,e,t,o,s,a)},o),i},bo.featureEach=r,bo.featureReduce=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},bo.findPoint=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.coordIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":return e.point.call(void 0,l,c,n);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,n);case"LineString":return a<0&&(a=l.length+a),e.point.call(void 0,l[a],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a),e.point.call(void 0,l[s][a],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),e.point.call(void 0,l[i][a],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a),e.point.call(void 0,l[i][s][a],c,n)}throw new Error("geojson is invalid")},bo.findSegment=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.segmentIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":case"MultiPoint":return null;case"LineString":return a<0&&(a=l.length+a-1),e.lineString.call(void 0,[l[a],l[a+1]],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a-1),e.lineString.call(void 0,[l[s][a],l[s][a+1]],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a-1),e.lineString.call(void 0,[l[i][a],l[i][a+1]],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a-1),e.lineString.call(void 0,[l[i][s][a],l[i][s][a+1]],c,n)}throw new Error("geojson is invalid")},bo.flattenEach=i,bo.flattenReduce=function(e,t,n){var r=n;return i(e,function(e,o,i){r=0===o&&0===i&&void 0===n?e:t(r,e,o,i)}),r},bo.geomEach=o,bo.geomReduce=function(e,t,n){var r=n;return o(e,function(e,o,i,s,a){r=0===o&&void 0===n?e:t(r,e,o,i,s,a)}),r},bo.lineEach=a,bo.lineReduce=function(e,t,n){var r=n;return a(e,function(e,o,i,s){r=0===o&&void 0===n?e:t(r,e,o,i,s)}),r},bo.propEach=n,bo.propReduce=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},bo.segmentEach=s,bo.segmentReduce=function(e,t,n){var r=n,o=!1;return s(e,function(e,i,s,a,c){r=!1===o&&void 0===n?e:t(r,e,i,s,a,c),o=!0}),r},bo}var Po,Co,wo={};function Lo(){if(Po)return wo;Po=1,Object.defineProperty(wo,"__esModule",{value:!0});var e=To();function t(t,n={}){if(null!=t.bbox&&!0!==n.recompute)return t.bbox;const r=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r}var n=t;return wo.bbox=t,wo.default=n,wo}var Oo=function(){if(Co)return Qr.exports;Co=1;var e=Eo,t=So(),n=To(),r=Lo().default,o=n.featureEach;n.coordEach,t.polygon;var i=t.featureCollection;function s(t){var n=new e(t);return n.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.insert.call(this,t)},n.load=function(t){var n=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}),e.prototype.load.call(this,n)},n.remove=function(t,n){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.remove.call(this,t,n)},n.clear=function(){return e.prototype.clear.call(this)},n.search=function(t){var n=e.prototype.search.call(this,this.toBBox(t));return i(n)},n.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},n.all=function(){var t=e.prototype.all.call(this);return i(t)},n.toJSON=function(){return e.prototype.toJSON.call(this)},n.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},n.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=r(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=r(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},n}return Qr.exports=s,Qr.exports.default=s,Qr.exports}(),Ao=de(Oo);function ko(e,t){var n={},r=[];if("LineString"===e.type&&(e=x(e)),"LineString"===t.type&&(t=x(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=Fo(e,t);return o&&r.push(o),_(r)}var i=Ao();return i.load(Wr(t)),E(Wr(e),function(e){E(i.search(e),function(t){var o=Fo(e,t);if(o){var i=Yr(o).join(",");n[i]||(n[i]=!0,r.push(o))}})}),_(r)}function Fo(e,t){var n=Yr(e),r=Yr(t);if(2!==n.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==r.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=n[0][0],i=n[0][1],s=n[1][0],a=n[1][1],c=r[0][0],l=r[0][1],u=r[1][0],d=r[1][1],p=(d-l)*(s-o)-(u-c)*(a-i),f=(u-c)*(i-l)-(d-l)*(o-c),g=(s-o)*(i-l)-(a-i)*(o-c);if(0===p)return null;var m=f/p,y=g/p;return m>=0&&m<=1&&y>=0&&y<=1?h([o+m*(s-o),i+m*(a-i)]):null}function Vo(e,t,n){void 0===n&&(n={});var r=h([1/0,1/0],{dist:1/0}),o=0;return v(e,function(e){for(var i=Yr(e),s=0;s<i.length-1;s++){var a=h(i[s]);a.properties.dist=Xr(t,a,n);var c=h(i[s+1]);c.properties.dist=Xr(t,c,n);var l=Xr(a,c,n),u=Math.max(a.properties.dist,c.properties.dist),d=Zr(a,c),p=zr(t,u,d+90,n),f=zr(t,u,d-90,n),g=ko(y([p.geometry.coordinates,f.geometry.coordinates]),y([a.geometry.coordinates,c.geometry.coordinates])),m=null;g.features.length>0&&((m=g.features[0]).properties.dist=Xr(t,m,n),m.properties.location=o+Xr(a,m,n)),a.properties.dist<r.properties.dist&&((r=a).properties.index=s,r.properties.location=o),c.properties.dist<r.properties.dist&&((r=c).properties.index=s+1,r.properties.location=o+l),m&&m.properties.dist<r.properties.dist&&((r=m).properties.index=s),o+=l}}),r}function No(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 Do(e,t){var n=function(e,t,n,r){void 0===r&&(r={});var o=No(e),i=u(o[0]),s=u(o[1]),a=u(n),c=p(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),d=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),g=f(d),m=f(l);return h([g,m],r.properties)}(e,function(e,t,n){void 0===n&&(n={});var r=No(e),o=No(t),i=u(o[1]-r[1]),s=u(o[0]-r[0]),a=u(r[1]),c=u(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return d(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}(e,t)/2,Zr(e,t));return n}var Ro=function(){return Ro=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ro.apply(this,arguments)},Uo=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=[],n=0;n<e.features.length;n++){var r=e.features[n],o=r.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var s=this.features.unknow.snapPoints;i=Ro(Ro({},i),s)}var a=this.doSnap(r,i);t.push(a)}else if(void 0!==this.features.unknow){s=this.features.unknow.snapPoints,a=this.doSnap(r,s);t.push(a)}else t.push(r)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Xr(h(e),h(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var n=e.geometry.coordinates;for(var r in t)this.isPointSnapped(n,t[r])&&(e.geometry.coordinates=t[r]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],s=0;s<o.length;s++){for(var a=o[s],c=[],l=0;l<a.length;l++){var u=a[l],d=!1;for(var r in t)if(this.isPointSnapped(u,t[r])){d=!0,c.push(t[r]);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 r in t)if(this.isPointSnapped(h,t[r])){d=!0,c.push(t[r]);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,n=this.map.unproject(t),r=[t.x+this.options.radius,t.y],o=this.map.unproject(r),i=Xr(h([n.lng,n.lat]),h([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var s=!1,a=this.getCloseFeatures(e,i);a?(this.snapStatus=!0,this.snapCoords=a.coords,s=function(e,t,n={}){const r=n.steps||64,o=n.properties?n.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<r;o++)i.push(Kr(e,t,-360*o/r,n).geometry.coordinates);return i.push(i[0]),g([i],o)}(a.coords,i,{steps:64,units:"meters",properties:{color:a.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=_(0==s?[]:[s]);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(_([])))}),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 n=e.map.getSource("mapbox-gl-draw-hot");if(n){var r=n._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];r.features.length>0&&(r.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]],n=t[0].toFixed(6),r=t[1].toFixed(6),o={};if(o["".concat(n,"_").concat(r)]=t,e){var i=e._data;if(i.features.length>0){var s=i.features.find(function(e){return"feature"==e.properties.meta});if(s){var a=s.properties.id;this.features[a]?this.features[a].snapPoints["".concat(n,"_").concat(r)]=t:this.features[a]={id:a,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(n,"_").concat(r)]=t:this.features.unknow={id:a,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,n){var r=I(e),o=[];if(r.map(function(e){var r=Xr(h(e),h([t.lng,t.lat]),{units:"meters"});r<n&&o.push({coords:e,dist:r,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,n){var r=[];switch(e.geometry.type){case"LineString":r.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){r.push(y(e))});break;case"Polygon":var o=Jr(e.geometry);r.push(o);break;case"MultiPolygon":Jr(e.geometry).coodinates.map(function(e){r.push(y(e))})}return r},e.prototype.searchInMidPoint=function(e,t,n){var r=this.getLines(e,t,n),o=[];r.map(function(e){o=o.concat(Wr(e).features)});var i=[];if(o.map(function(e){var r=Do(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Xr(r,h([t.lng,t.lat]),{units:"meters"});o<n&&i.push({coords:r.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,n){for(var r=this.getLines(e,t,n),o=[],i=0;i<r.length;i++){var s=Vo(r[i],h([t.lng,t.lat]),{units:"meters"});void 0!==s.properties.dist&&s.properties.dist<n&&o.push({coords:s.geometry.coordinates,dist:s.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 n=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(n.length>0){for(var r,o=!1,i=0;i<n.length;i++){var s=n[i],a=this.options.rules,c=e.lngLat;if(o=!1,-1!==a.indexOf("vertex")&&null==r&&(r=this.searchInVertex(s,c,t))){o=!0;break}if(-1!==a.indexOf("midpoint")&&null==r&&(r=this.searchInMidPoint(s,c,t))){o=!0;break}if(-1!==a.indexOf("edge")&&null==r&&(r=this.searchInEdge(s,c,t))){o=!0;break}}return!!o&&r}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}();const Bo="snap-helper-circle",jo="mapbox-gl-draw-hot";function Go(e){if(Uo.prototype.__snapPatched)return;Uo.prototype.__snapPatched=!0;const t=Uo.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){if(!this.status)return;const n=t.setMapData.call(this,e);return e?.features?.length>0&&this.map?.getLayer(Bo)&&this.map.setLayoutProperty(Bo,"visibility","visible"),n},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,n,r){const o=e.geometry;if(!o?.coordinates)return[];const 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=>g(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>y(e)):t.getLines.call(this,e,n,r)}catch{return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];const o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));const i=this.options.radius||n.snapRadius,s=e.point;e.point=[[s.x-i,s.y-i],[s.x+i,s.y+i]];const a=t.getCloseFeatures.call(this,e,r);return e.point=s,a}}(t,r),function(e,t,n){e.searchInVertex=function(...e){const r=t.searchInVertex.apply(this,e);return r&&(r.color=n.vertex),r},e.searchInMidPoint=function(...e){const r=t.searchInMidPoint.apply(this,e);return r&&(r.color=n.midpoint),r},e.searchInEdge=function(...e){const r=t.searchInEdge.apply(this,e);return r&&(r.color=n.edge),r}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){if(this.status&&!this.map?._isZooming&&(!this._autoSnapSuspended||e._explicit))try{const n=t.snapToClosestPoint.call(this,e);return this.closeFeatures?.length>100&&(this.closeFeatures.length=0),this.lines?.length>100&&(this.lines.length=0),n}catch{return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}function Ho(e,t){!function n(){const r=e();null!==r&&(r?t(r):requestAnimationFrame(n))}()}function Yo(e){if(!e||e._data&&Array.isArray(e._data?.features))return;let t={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>t,set:e=>{t=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}const Xo=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function $o(e,t,n,r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(Bo)&&e.removeLayer(Bo),e.getSource(Bo)&&e.removeSource(Bo)}(e),Yo(n);const o=new Uo({map:e,drawing:t,options:{layers:r.layers,radius:r.radius,rules:r.rules},status:r.status,onSnapped:r.onSnapped});return function(e,t,n){let r=t;Object.defineProperty(e,"status",{get:()=>r&&Xo.has(n.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{r=e}}(o,r.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,r.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function Ko(e,t,n){e.on("style.load",()=>{Ho(()=>e._removed?null:e.getSource(jo),r=>{Yo(r),function(e){e.getSource(Bo)||e.addSource(Bo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Bo)||e.addLayer({id:Bo,type:"fill",source:Bo,paint:{"fill-color":["get","color"]},layout:{visibility:e._snapInstance?.status?"visible":"none"}})}(e),e._snapInstance||$o(e,t,r,n)})})}function Jo(e,t,r={}){if(e._snapInitialized)return e._snapInstance;e._snapInitialized=!0;const{layers:o=[],radius:i=n.snapRadius,rules:s=["vertex","midpoint","edge"],status:a=!1,onSnapped:c=()=>{},colors:l={}}=r,u={layers:o,radius:i,rules:s,status:a,onSnapped:c};return Go({vertex:S.snapVertex,midpoint:S.snapMidpoint,edge:S.snapEdge,...l}),Ko(e,t,u),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(Bo)){e.setLayoutProperty(Bo,"visibility","none");const t=e._snapInstance;t?.status&&e.setLayoutProperty(Bo,"visibility","visible")}})}(e),Ho(()=>e._removed?null:e.getSource(jo),n=>$o(e,t,n,u)),e._snapInstance}const qo="point-symbol",Zo=new Set([`${qo}.hot`,`${qo}.cold`]),zo=(e,t)=>{const n=(e=>{const t=["match",["get","user_symbolImageId"]];for(const[n,r]of Object.entries(e))t.push(n,["literal",r]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);t.options?.styles?.forEach(e=>{Zo.has(e.id)&&(e.layout={...e.layout,"icon-offset":n})}),Zo.forEach(t=>{e.getLayer(t)&&e.setLayoutProperty(t,"icon-offset",n)})},Wo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:o,properties:i,pixelRatioOverride:s})=>{if(!M(i))return null;const a=n._drawCurrentMapStyle,c=s??(e=>e.getPixelRatio?.()||1)(n);await t.addSymbolsToMap([i],a,r,c);const l=e.get(o);if(!l)return null;const u=r.getSymbolImageId(i,a,"normal",c);if(!u)return null;const d=t.getActiveSymbolImageId(u),p=t.getSelectedSymbolImageId(u),h=t.getSymbolIconLayout(r.getSymbolDef(i));return((e,t,n,r)=>{e._symbolIconOffsetMap??={},e._symbolIconOffsetMap[n]||(e._symbolIconOffsetMap[n]=r,zo(e,t))})(n,e,u,h["icon-offset"]),{...l,properties:{...i,symbolImageId:u,symbolIconAnchor:h["icon-anchor"],symbolActiveImageId:d,symbolSelectedImageId:p}}},Qo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,pixelRatioOverride:o})=>{n._pointSymbolRefreshId=(n._pointSymbolRefreshId??0)+1;const i=n._pointSymbolRefreshId,s=e.getAll().features.filter(e=>"Point"===e.geometry.type&&M(e.properties)),a=await Promise.allSettled(s.map(i=>Wo({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:i.id,properties:i.properties,pixelRatioOverride:o})));if(a.filter(e=>"rejected"===e.status).forEach(e=>{b.error("[draw] failed to resolve point symbol",e.reason)}),n._pointSymbolRefreshId!==i)return;const c=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);c.length&&e.add({type:"FeatureCollection",features:c}),((e,t)=>{const n=e._symbolIconOffsetMap;if(!n)return;const r=new Set(t.getAll().features.map(e=>e.properties?.symbolImageId)),o=Object.keys(n).filter(e=>!r.has(e));o.length&&(o.forEach(e=>delete n[e]),zo(e,t))})(n,e)},ei="mapbox-gl-draw-cold",ti="mapbox-gl-draw-hot",ni=({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,onDone:i})=>{const s=e._drawCurrentMapStyle;e.once("idle",()=>{const a=((e,t)=>{if(e.getSource(ei))return!1;const n={type:"FeatureCollection",features:[]};return e.addSource(ei,{data:n,type:"geojson"}),e.addSource(ti,{data:n,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(e,t);((e,t,n={})=>{Gr(t,n).forEach(t=>{Object.entries(t.paint).forEach(([n,r])=>{e.getLayer(`${t.id}.cold`)&&e.setPaintProperty(`${t.id}.cold`,n,r),e.getLayer(`${t.id}.hot`)&&e.setPaintProperty(`${t.id}.hot`,n,r)})})})(e,s,o);const c=e._drawEditContainer?.querySelector("[data-im-draw-touch-target]");jn(c,s,o),Qo({draw:t,mapProvider:n,map:e,symbolRegistry:r}).then(()=>{a&&t.set(t.getAll()),e.triggerRepaint(),i()}).catch(e=>b.error("[draw] failed to refresh point symbols after a style change",e))})},ri=({mapStyle:e,mapProvider:t,symbolRegistry:r,events:o,eventBus:i,snapLayers:s,pluginConfig:a={}})=>{const{map:c}=t;qt.constants.classes.CONTROL_BASE="maplibregl-ctrl",qt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",qt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";const l={...qt.modes,disabled:Zt,edit_vertex:er,edit_point:cr,draw_polygon:Ir,draw_line:Sr,draw_point:wr};let u=t._mapboxDrawInstance;u?Object.assign(u.modes,l):(u=new qt({modes:l,styles:Gr(e,a),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),c.addControl(u),t._mapboxDrawInstance=u);const d=((e,t)=>{const n=e.getCanvas();let r=null;const o=e=>{1===e.touches.length&&(r={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"!==t.getMode()||!r)return void(r=null);const o=e.changedTouches[0],i=o.clientX-r.x,s=o.clientY-r.y;Date.now()-r.time<300&&Math.abs(i)<10&&Math.abs(s)<10&&n.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),r=null};return n.addEventListener("touchstart",o,{passive:!0}),n.addEventListener("touchend",i,{passive:!0}),{remove(){n.removeEventListener("touchstart",o),n.removeEventListener("touchend",i)}}})(c,u);t.draw=u,c._drawCurrentMapStyle=e,c._drawPluginConfig=a,t.snapEnabled=!1;let p=t.undoStack;p||(p=k(e=>c.fire("draw.undochange",{length:e})),t.undoStack=p),c._undoStack=p;const h=w(e,a);Jo(c,u,{layers:s,radius:a.snapRadius??n.snapRadius,rules:["vertex","edge"],colors:{vertex:h.snapVertex,edge:h.snapEdge}});const f=()=>i.emit(o.MAP_DATA_CHANGE),{handleSetMapStyle:g,handleStyleChanged:m}=(({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,eventBus:i,events:s,notifyPointSymbolsRefreshed:a})=>{const c=t=>{e._drawCurrentMapStyle=t};i.on(s.MAP_SET_STYLE,c);let l=!1;const u=()=>{l||(l=!0,ni({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,onDone:()=>{l=!1,a()}}))};return i.on(s.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:c,draw:u,mapProvider:t,symbolRegistry:r,pluginConfig:a,eventBus:i,events:o,notifyPointSymbolsRefreshed:f}),y=e=>{c.fire("draw.scalechange",{scale:T[e]})};i.on(o.MAP_SET_SIZE,y);const v=e=>{Qo({draw:u,mapProvider:t,map:c,symbolRegistry:r,pixelRatioOverride:e}).then(()=>{c.triggerRepaint(),f()}).catch(e=>b.error("[draw] failed to refresh point symbols",e))};return i.on(o.MAP_SET_PIXEL_RATIO,v),{draw:u,remove(){d.remove(),i.off(o.MAP_SET_STYLE,g),i.off(o.MAP_STYLE_CHANGE,m),i.off(o.MAP_SET_SIZE,y),i.off(o.MAP_SET_PIXEL_RATIO,v),u.changeMode("disabled"),t.draw=null}}},oi=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),ii=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),si=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),ai=(e,t)=>{if("draw_polygon"===e)return{feature:oi(t),numVertices:(t[0]?.length??1)-1};if("draw_line"===e)return{feature:ii(t),numVertices:(t?.length??1)-1};if("edit_vertex"===e){const e=t[0];return Array.isArray(e?.[0])?{feature:oi(t),numVertices:e.length}:{feature:ii(t),numVertices:t?.length??0}}return"edit_point"===e?{feature:si(t),numVertices:1}:null};class ci{constructor(e,t){this._mapProvider=e,this._map=e.map,this._symbolRegistry=t.symbolRegistry,this._bus=(()=>{const e=new Map;return{on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)},emit(t,...n){const r=e.get(t);r&&Array.from(r).forEach(e=>e(...n))}}})(),this._editingFeatureId=null,this._sortKeyCounter=0;const{draw:n,remove:r}=ri({mapStyle:t.mapStyle,mapProvider:e,symbolRegistry:t.symbolRegistry,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:t.pluginConfig??{}});this._draw=n,this._cleanupDraw=r,this._liveStroke=F({onChange:(e,t)=>{this._applyStrokeInvalid(e);const n=this._draw.getMode();"edit_vertex"!==n&&"edit_point"!==n||this._bus.emit(P.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=V({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(P.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{const t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(P.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(P.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(P.CANCEL),vertexselection:e=>this._bus.emit(P.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(P.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(P.UNDO_CHANGE,e.length),update:e=>this._bus.emit(P.UPDATE,e.features[0]),geometrychange:e=>{e?.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(P.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(P.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(P.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(zt,this._mapHandlers.create),this._map.on(en,this._mapHandlers.editfinish),this._map.on(tn,this._mapHandlers.cancel),this._map.on(nn,this._mapHandlers.vertexselection),this._map.on(rn,this._mapHandlers.vertexchange),this._map.on(on,this._mapHandlers.undochange),this._map.on(Wt,this._mapHandlers.update),this._map.on(an,this._mapHandlers.geometrychange),this._map.on(ln,this._mapHandlers.placementblocked),this._map.on(cn,this._mapHandlers.interfacetypechange),this._map.on(Qt,this._mapHandlers.modechange),this._map.on(hn,this._mapHandlers.styledata)}changeMode(e,t={}){"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=t.featureId??null),"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(t={...t,resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)}),this._draw.changeMode(e,t),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){(async e=>{const t=await Wo(e);t&&e.draw.add(t)})({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>b.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(!e?.coordinates)return;const t=this._draw.getMode(),n=ai(t,e.coordinates);n&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:n.feature,numVertices:n.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update({...n,context:{mode:t},onGeometryChange:this._geometryValidator}))}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(cn,{interfaceType:e})}done(){this._mapProvider.undoStack?.clear();const e=this._draw.getMode();if(("edit_vertex"===e||"edit_point"===e)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(en,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==e&&"draw_line"!==e||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){this._mapProvider.undoStack?.clear();const e=this._draw.getMode();"draw_polygon"!==e&&"draw_line"!==e||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(sn)}nudgeSelectedVertex(e,t,n){this._map.fire(un,{dx:e,dy:t,isLargeStep:n})}getVertexItems(){const e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;const t=this._draw.get(this._editingFeatureId);if(!t)return e;const n=(e=>"Polygon"===e.type?{...e,coordinates:e.coordinates.map(e=>e.slice(0,-1))}:"MultiPolygon"===e.type?{...e,coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}:e)(t.geometry);return{vertices:fn(n),midpoints:gn(n)}}selectVertex(e){this._map.fire(dn,{index:e})}insertVertexAtMidpoint(e){this._map.fire(pn,{index:e})}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(n=>{const r=`${e}.${n}`;this._map.getLayer(r)&&this._map.setLayoutProperty(r,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){const t=null==e.properties?.sortKey?{...e.properties,sortKey:this._nextSortKey()}:e.properties,n={...e,properties:t},r=this._draw.add(n);return"Point"===n.geometry?.type&&M(t)&&this._resolvePointSymbol(r[0],t),r}setStyle(e,t){const n=this._draw.get(e);n&&this.add({...n,properties:{...n.properties,...t}})}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;const t=In(this._map);t?.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(wn(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){const t=In(this._map);t?.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,n){this._draw.setFeatureProperty(e,t,n)}setDrawingPreviewProperty(e,t){const n=this._currentDrawEvent;n?.properties&&(n.properties[e]=t),n?.ctx?.store?.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)||Cn(In(this._map),this._map)}_handleStyleData(){const e=this._map.getStyle();if(!e)return;this._liveStroke.refresh();const t=e.layers||[];t.length&&!t[t.length-1].source?.startsWith("mapbox-gl-draw")&&t.filter(e=>e.source?.startsWith("mapbox-gl-draw")).forEach(e=>this._map.moveLayer(e.id))}remove(){this._map.off(zt,this._mapHandlers.create),this._map.off(en,this._mapHandlers.editfinish),this._map.off(tn,this._mapHandlers.cancel),this._map.off(nn,this._mapHandlers.vertexselection),this._map.off(rn,this._mapHandlers.vertexchange),this._map.off(on,this._mapHandlers.undochange),this._map.off(Wt,this._mapHandlers.update),this._map.off(an,this._mapHandlers.geometrychange),this._map.off(ln,this._mapHandlers.placementblocked),this._map.off(cn,this._mapHandlers.interfacetypechange),this._map.off(Qt,this._mapHandlers.modechange),this._map.off(hn,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{ci as MaplibreDrawAdapter,ai as displayedShape};
1
+ import{i as e,c as t,T as n,C as r,K as o,M as i,v as s,t as a,a as c,b as l,d as u,S as d,e as p,r as h,l as f,p as g,f as m,g as y,m as v,h as _,j as x,k as I,n as E,o as S,q as M,s as b,u as P,w as T,A as C}from"./im-draw-plugin.js";import{c as w,r as L,a as O,s as A,b as k,h as F,d as V,e as N,f as D}from"./liveDrawChecks.js";import"preact/compat";const R={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"},U={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},B={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},j={POLYGON:"polygon",LINE:"line_string",POINT:"point"},G={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"},H={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},Y={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"},X={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},$={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},K={ACTIVE:"true",INACTIVE:"false"},J=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var q=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:K,classes:R,cursors:B,events:Y,geojsonTypes:G,interactions:J,meta:$,modes:H,sources:U,types:j,updateActions:X});function Z(e){return function(t){const n=t.featureTarget;return!!n&&(!!n.properties&&n.properties.meta===e)}}function z(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function W(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===K.ACTIVE&&e.featureTarget.properties.meta===$.FEATURE))}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===K.INACTIVE&&e.featureTarget.properties.meta===$.FEATURE))}function ee(e){return void 0===e.featureTarget}function te(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===$.FEATURE)}function ne(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===$.VERTEX)}function re(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function oe(e){return"Escape"===e.key||27===e.keyCode}function ie(e){return"Enter"===e.key||13===e.keyCode}function se(e){return"Backspace"===e.key||8===e.keyCode}function ae(e){return"Delete"===e.key||46===e.keyCode}function ce(e){return"1"===e.key||49===e.keyCode}function le(e){return"2"===e.key||50===e.keyCode}function ue(e){return"3"===e.key||51===e.keyCode}function de(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var pe=Object.freeze({__proto__:null,isActiveFeature:W,isBackspaceKey:se,isDeleteKey:ae,isDigit1Key:ce,isDigit2Key:le,isDigit3Key:ue,isDigitKey:de,isEnterKey:ie,isEscapeKey:oe,isFeature:te,isInactiveFeature:Q,isOfMetaType:Z,isShiftDown:re,isShiftMousedown:z,isTrue:function(){return!0},isVertex:ne,noTarget:ee});function he(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function fe(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){var n=!1;try{n=this instanceof e}catch{}return n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var ge,me,ye={},ve={};function _e(){return ge||(ge=1,ve.RADIUS=6378137,ve.FLATTENING=1/298.257223563,ve.POLAR_RADIUS=6356752.3142),ve}var xe=function(){if(me)return ye;me=1;var e=_e();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(n(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(n(e[r]))}return t}function n(t){var n,o,i,s,a,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,s=u-1,a=0):c===u-1?(i=u-1,s=0,a=1):(i=c,s=c+1,a=c+2),n=t[i],o=t[s],l+=(r(t[a][0])-r(n[0]))*Math.sin(r(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function r(e){return e*Math.PI/180}return ye.geometry=function e(n){var r,o=0;switch(n.type){case"Polygon":return t(n.coordinates);case"MultiPolygon":for(r=0;r<n.coordinates.length;r++)o+=t(n.coordinates[r]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(r=0;r<n.geometries.length;r++)o+=e(n.geometries[r]);return o}},ye.ring=n,ye}(),Ie=he(xe);const Ee={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Se(e,t){const n=Ee[e.geometry.type]-Ee[t.geometry.type];return 0===n&&e.geometry.type===G.POLYGON?e.area-t.area:n}function Me(e){return e.map(e=>(e.geometry.type===G.POLYGON&&(e.area=Ie.geometry({type:G.FEATURE,property:{},geometry:e.geometry})),e)).sort(Se).map(e=>(delete e.area,e))}function be(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Pe(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,n=e.length;t<n;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}Pe.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Pe.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Pe.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Pe.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)},Pe.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Te=[$.FEATURE,$.MIDPOINT,$.VERTEX];var Ce={click:function(e,t,n){return we(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return we(e,t,n,n.options.touchBuffer)}};function we(e,t,n,r){if(null===n.map)return[];const o=e?be(e,r):t,i={};n.options.styles&&(i.layers=n.options.styles.map(e=>e.id).filter(e=>null!=n.map.getLayer(e)));const s=n.map.queryRenderedFeatures(o,i).filter(e=>-1!==Te.indexOf(e.properties.meta)),a=new Pe,c=[];return s.forEach(e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),Me(c)}function Le(e,t){const n=Ce.click(e,null,t),r={mouse:B.NONE};return n[0]&&(r.mouse=n[0].properties.active===K.ACTIVE?B.MOVE:B.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=B.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function Oe(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Ae(e,t,n={}){const r=null!=n.fineTolerance?n.fineTolerance:4,o=null!=n.grossTolerance?n.grossTolerance:12,i=null!=n.interval?n.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const s=Oe(e.point,t.point);return s<r||s<o&&t.time-e.time<i}function ke(e,t,n={}){const r=null!=n.tolerance?n.tolerance:25,o=null!=n.interval?n.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return Oe(e.point,t.point)<r&&t.time-e.time<o}const Fe=function(e,t){const n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on(e,t,r){if(void 0===n[e])throw new Error(`Invalid event type: ${e}`);n[e].push({selector:t,fn:r})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=n[e];let s=i.length;for(;s--;){const e=i[s];if(e.selector(o)){e.fn.call(r,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(r),{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 Ve=((e,t=21)=>(n=t)=>{let r="",o=0|n;for(;o--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Ne(){return Ve()}const De=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ne(),this.type=t.geometry.type};De.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},De.prototype.incomingCoords=function(e){this.setCoordinates(e)},De.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},De.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},De.prototype.setProperty=function(e,t){this.properties[e]=t},De.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:G.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},De.prototype.internal=function(e){const t={id:this.id,meta:$.FEATURE,"meta:type":this.type,active:K.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:G.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Re=function(e,t){De.call(this,e,t)};(Re.prototype=Object.create(De.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Re.prototype.updateCoordinate=function(e,t,n){this.coordinates=3===arguments.length?[t,n]:[e,t],this.changed()},Re.prototype.getCoordinate=function(){return this.getCoordinates()};const Ue=function(e,t){De.call(this,e,t)};(Ue.prototype=Object.create(De.prototype)).isValid=function(){return this.coordinates.length>1},Ue.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},Ue.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Ue.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Ue.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const Be=function(e,t){De.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Be.prototype=Object.create(De.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Be.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Be.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Be.prototype.addCoordinate=function(e,t,n){this.changed();const r=e.split(".").map(e=>parseInt(e,10));this.coordinates[r[0]].splice(r[1],0,[t,n])},Be.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},Be.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},Be.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Be.prototype.updateCoordinate=function(e,t,n){this.changed();const r=e.split("."),o=parseInt(r[0],10),i=parseInt(r[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,n]};const je={MultiPoint:Re,MultiLineString:Ue,MultiPolygon:Be},Ge=(e,t,n,r,o)=>{const i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,r,o)},He=function(e,t){if(De.call(this,e,t),delete this.coordinates,this.model=je[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 Ye(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(He.prototype=Object.create(De.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ne(),type:G.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},He.prototype.isValid=function(){return this.features.every(e=>e.isValid())},He.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},He.prototype.getCoordinate=function(e){return Ge(this.features,"getCoordinate",e)},He.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===G.POLYGON?e.getCoordinates():e.coordinates)))},He.prototype.updateCoordinate=function(e,t,n){Ge(this.features,"updateCoordinate",e,t,n),this.changed()},He.prototype.addCoordinate=function(e,t,n){Ge(this.features,"addCoordinate",e,t,n),this.changed()},He.prototype.removeCoordinate=function(e){Ge(this.features,"removeCoordinate",e),this.changed()},He.prototype.getFeatures=function(){return this.features},Ye.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Ye.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),{})},Ye.prototype.getSelected=function(){return this._ctx.store.getSelected()},Ye.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Ye.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Ye.prototype.getFeature=function(e){return this._ctx.store.get(e)},Ye.prototype.select=function(e){return this._ctx.store.select(e)},Ye.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Ye.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Ye.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Ye.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Ye.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Ye.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Ye.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},Ye.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Ye.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Ye.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Ye.prototype.featuresAt=function(e,t,n="click"){if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return Ce[n](e,t,this._ctx)},Ye.prototype.newFeature=function(e){const t=e.geometry.type;return t===G.POINT?new Re(this._ctx,e):t===G.LINE_STRING?new Ue(this._ctx,e):t===G.POLYGON?new Be(this._ctx,e):new He(this._ctx,e)},Ye.prototype.isInstanceOf=function(e,t){if(e===G.POINT)return t instanceof Re;if(e===G.LINE_STRING)return t instanceof Ue;if(e===G.POLYGON)return t instanceof Be;if("MultiFeature"===e)return t instanceof He;throw new Error(`Unknown feature class: ${e}`)},Ye.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Ye.prototype.onSetup=function(){},Ye.prototype.onDrag=function(){},Ye.prototype.onClick=function(){},Ye.prototype.onMouseMove=function(){},Ye.prototype.onMouseDown=function(){},Ye.prototype.onMouseUp=function(){},Ye.prototype.onMouseOut=function(){},Ye.prototype.onKeyUp=function(){},Ye.prototype.onKeyDown=function(){},Ye.prototype.onTouchStart=function(){},Ye.prototype.onTouchMove=function(){},Ye.prototype.onTouchEnd=function(){},Ye.prototype.onTap=function(){},Ye.prototype.onStop=function(){},Ye.prototype.onTrash=function(){},Ye.prototype.onCombineFeature=function(){},Ye.prototype.onUncombineFeature=function(){},Ye.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Xe={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},$e=Object.keys(Xe);function Ke(e){const t=Object.keys(e);return function(n,r={}){let o={};const i=t.reduce((t,n)=>(t[n]=e[n],t),new Ye(n));return{start(){o=i.onSetup(r),$e.forEach(t=>{const n=Xe[t];let r=()=>!1;var s;e[n]&&(r=()=>!0),this.on(t,r,(s=n,e=>i[s](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 Je(e){return[].concat(e).filter(e=>void 0!==e)}function qe(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(U.HOT)))return a();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let n=[],r=[];e.isDirty?r=e.getAllIds():(n=e.getChangedIds().filter(t=>void 0!==e.get(t)),r=e.sources.hot.filter(t=>t.properties.id&&-1===n.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===n.indexOf(t)});const i=o!==e.sources.cold.length||r.length>0;function s(n,r){const o=e.get(n).internal(t);e.ctx.events.currentModeRender(o,n=>{n.properties.mode=t,e.sources[r].push(n)})}function a(){e.isDirty=!1,e.clearChangedIds()}n.forEach(e=>s(e,"hot")),r.forEach(e=>s(e,"cold")),i&&e.ctx.map.getSource(U.COLD).setData({type:G.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(U.HOT).setData({type:G.FEATURE_COLLECTION,features:e.sources.hot}),a()}function Ze(e){let t;this._features={},this._featureIds=new Pe,this._selectedFeatureIds=new Pe,this._selectedCoordinates=[],this._changedFeatureIds=new Pe,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,qe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(Y.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(Y.RENDER,{})}))},this.isDirty=!1}function ze(e,t={}){const n=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===n.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=n}Ze.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ze.prototype.setDirty=function(){return this.isDirty=!0,this},Ze.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(Y.CREATE,{features:[t.toGeoJSON()]})}return this},Ze.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(Y.UPDATE,{action:t.action?t.action:X.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ze.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ze.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ze.prototype.getAllIds=function(){return this._featureIds.values()},Ze.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ze.prototype.delete=function(e,t={}){const n=[];return Je(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===n.indexOf(this._features[e])&&n.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),n.length&&this.ctx.events.fire(Y.DELETE,{features:n}),ze(this,t),this},Ze.prototype.get=function(e){return this._features[e]},Ze.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Ze.prototype.select=function(e,t={}){return Je(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Ze.prototype.deselect=function(e,t={}){return Je(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),ze(this,t),this},Ze.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ze.prototype.setSelected=function(e,t={}){return e=Je(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},Ze.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ze.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ze.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ze.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Ze.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Ze.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ze.prototype.setFeatureProperty=function(e,t,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:X.CHANGE_PROPERTIES})},Ze.prototype.storeMapConfig=function(){J.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Ze.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Ze.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const We=["mode","feature","mouse"];function Qe(e){let t=null,n=null;const r={onRemove(){return e.map.off("load",r.connect),clearInterval(n),r.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",r.connect),clearInterval(n),r.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,n)=>(t[n]=Ke(e.options.modes[n]),t),{});let n={},r={};const o={};let i=null,s=null;o.drag=function(t,n){n({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:B.DRAG}),s.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ae(n,e))},o.touchdrag=function(e){o.drag(e,e=>!ke(r,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const n=Le(t,e);t.featureTarget=n,s.mousemove(t)},o.mousedown=function(t){n={time:(new Date).getTime(),point:t.point};const r=Le(t,e);t.featureTarget=r,s.mousedown(t)},o.mouseup=function(t){const r=Le(t,e);t.featureTarget=r,Ae(n,{point:t.point,time:(new Date).getTime()})?s.click(t):s.mouseup(t)},o.mouseout=function(e){s.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;r={time:(new Date).getTime(),point:t.point};const n=Ce.touch(t,null,e)[0];t.featureTarget=n,s.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return s.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const n=Ce.touch(t,null,e)[0];t.featureTarget=n,ke(r,{time:(new Date).getTime(),point:t.point})?s.tap(t):s.touchend(t)};const a=e=>{const t=se(e),n=ae(e),r=de(e);return!(t||n||r)};function c(n,r,o={}){s.stop();const a=t[n];if(void 0===a)throw new Error(`${n} is not valid`);i=n;const c=a(e,r);s=Fe(c,e),o.silent||e.map.fire(Y.MODE_CHANGE,{mode:n}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(R.CANVAS)&&((se(t)||ae(t))&&e.options.controls.trash?(t.preventDefault(),s.trash()):a(t)?s.keydown(t):ce(t)&&e.options.controls.point?c(H.DRAW_POINT):le(t)&&e.options.controls.line_string?c(H.DRAW_LINE_STRING):ue(t)&&e.options.controls.polygon&&c(H.DRAW_POLYGON))},o.keyup=function(e){a(e)&&s.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:n,options:r,store:o}=e;r.styles.some(e=>n.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,s=Fe(t[i](e),e)},changeMode:c,actionable:function(t){let n=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(n=!0),l[e]=t[e]}),n&&e.map.fire(Y.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>s.render(e,t),fire(t,n){e.map&&e.map.fire(t,n)},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){s.trash(e)},combineFeatures(){s.combineFeatures()},uncombineFeatures(){s.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let n=null,r={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function s(){if(!e.container)return;const t=[],n=[];We.forEach(e=>{o[e]!==r[e]&&(t.push(`${e}-${r[e]}`),null!==o[e]&&n.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),n.length>0&&e.container.classList.add(...n),r=Object.assign(r,o)}function a(e,t={}){const r=document.createElement("button");return r.className=`${R.CONTROL_BUTTON} ${t.className}`,r.setAttribute("title",t.title),t.container.appendChild(r),r.addEventListener("click",r=>{if(r.preventDefault(),r.stopPropagation(),r.target===n)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),r}function c(){n&&(n.classList.remove(R.ACTIVE_BUTTON),n=null)}function l(e){c();const r=t[e];r&&r&&"trash"!==e&&(r.classList.add(R.ACTIVE_BUTTON),n=r)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:s,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),s()},addButtons:function(){const n=e.options.controls,r=document.createElement("div");return r.className=`${R.CONTROL_GROUP} ${R.CONTROL_BASE}`,n?(n[j.POINT]&&(t[j.POINT]=a(j.POINT,{container:r,className:R.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(H.DRAW_POINT),onDeactivate:()=>e.events.trash()})),n[j.LINE]&&(t[j.LINE]=a(j.LINE,{container:r,className:R.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(H.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),n[j.POLYGON]&&(t[j.POLYGON]=a(j.POLYGON,{container:r,className:R.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(H.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),n.trash&&(t.trash=a("trash",{container:r,className:R.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),n.combine_features&&(t.combine_features=a("combineFeatures",{container:r,className:R.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),n.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:r,className:R.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),r):r},removeButtons:function(){Object.keys(t).forEach(e=>{const n=t[e];n.parentNode&&n.parentNode.removeChild(n),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new Ze(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()?r.connect():(o.on("load",r.connect),n=setInterval(()=>{o.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(U.COLD,{data:{type:G.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(U.HOT,{data:{type:G.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(U.COLD)&&e.map.removeSource(U.COLD),e.map.getSource(U.HOT)&&e.map.removeSource(U.HOT)}};return e.setup=r,r}const et="#3bb2d0",tt="#fbb03b",nt="#fff";var rt=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],tt,et],"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"],tt,et],"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":nt}},{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"],tt,et]}},{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":nt}},{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":tt}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":tt}}];function ot(e,t){this.x=e,this.y=t}function it(e,t){const n=t.getBoundingClientRect();return new ot(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function st(e,t,n,r){return{type:G.FEATURE,properties:{meta:$.VERTEX,parent:e,coord_path:n,active:r?K.ACTIVE:K.INACTIVE},geometry:{type:G.POINT,coordinates:t}}}function at(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return ct(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(e=>ct(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ut(e);default:throw new Error("unknown GeoJSON type")}}function ct(e){const t={type:"Feature"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=lt(e.properties),null==e.geometry?t.geometry=null:t.geometry=ut(e.geometry),t}function lt(e){const t={};return e?(Object.keys(e).forEach(n=>{const r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(e=>e):t[n]=lt(r):t[n]=r}),t):t}function ut(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ut(e)),t):(t.coordinates=dt(e.coordinates),t)}function dt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>dt(e))}function pt(e,t={}){return ht(e,"mercator",t)}function ht(n,r,o={}){var i=(o=o||{}).mutate;if(!n)throw new Error("geojson is required");return Array.isArray(n)&&e(n[0])?n="mercator"===r?ft(n):gt(n):(!0!==i&&(n=at(n)),t(n,function(e){var t="mercator"===r?ft(e):gt(e);e[0]=t[0],e[1]=t[1]})),n}function ft(e){var t,n=Math.PI/180,r=6378137,o=20037508.342789244,i=[r*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*n,r*Math.log(Math.tan(.25*Math.PI+.5*e[1]*n))];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 gt(e){var t=180/Math.PI,n=6378137;return[e[0]*t/n,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/n)))*t]}function mt(e,t,n){const r=t.geometry.coordinates,o=n.geometry.coordinates;if(r[1]>85||r[1]<-85||o[1]>85||o[1]<-85)return null;const i=pt(r),s=pt(o),a=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ht(e,"wgs84",t)}([c(i[0],s[0]),c(i[1],s[1])]),u=[a(l[0]),a(l[1])];return{type:G.FEATURE,properties:{meta:$.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:n.properties.coord_path},geometry:{type:G.POINT,coordinates:u}}}function yt(e,t={},n=null){const{type:r,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let s=[];function a(e,n){let r="",o=null;e.forEach((e,a)=>{const l=null!=n?`${n}.${a}`:String(a),u=st(i,e,l,c(l));if(t.midpoints&&o){const e=mt(i,o,u);e&&s.push(e)}o=u;const d=JSON.stringify(e);r!==d&&s.push(u),0===a&&(r=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return r===G.POINT?s.push(st(i,o,n,c(n))):r===G.POLYGON?o.forEach((e,t)=>{a(e,null!==n?`${n}.${t}`:String(t))}):r===G.LINE_STRING?a(o,n):0===r.indexOf(G.MULTI_PREFIX)&&function(){const n=r.replace(G.MULTI_PREFIX,"");o.forEach((r,o)=>{const i={type:G.FEATURE,properties:e.properties,geometry:{type:n,coordinates:r}};s=s.concat(yt(i,t,o))})}(),s}ot.prototype={clone(){return new ot(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,n=e.y-this.y;return t*t+n*n},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,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,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),n=Math.sin(e),r=t*this.x-n*this.y,o=n*this.x+t*this.y;return this.x=r,this.y=o,this},_rotateAround(e,t){const n=Math.cos(e),r=Math.sin(e),o=t.x+n*(this.x-t.x)-r*(this.y-t.y),i=t.y+r*(this.x-t.x)+n*(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:ot},ot.convert=function(e){if(e instanceof ot)return e;if(Array.isArray(e))return new ot(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new ot(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var vt={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:_t,LAT_MAX:xt,LAT_RENDERED_MIN:It,LAT_RENDERED_MAX:Et,LNG_MIN:St,LNG_MAX:Mt}=q;function bt(e,t){let n=_t,r=xt,o=_t,i=xt,s=Mt,a=St;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],n=[e.geometry.coordinates].flat(t),r=n.map(e=>e[0]),o=n.map(e=>e[1]),i=e=>Math.min.apply(null,e),s=e=>Math.max.apply(null,e);return[i(r),i(o),s(r),s(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>n&&(n=c),l<r&&(r=l),l>o&&(o=l),c<i&&(i=c),u<s&&(s=u),d>a&&(a=d)});const c=t;return n+c.lat>Et&&(c.lat=Et-n),o+c.lat>xt&&(c.lat=xt-o),r+c.lat<It&&(c.lat=It-r),i+c.lat<_t&&(c.lat=_t-i),s+c.lng<=St&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=Mt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Pt(e,t){const n=bt(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),r=e=>{const t={lng:e[0]+n.lng,lat:e[1]+n.lat};return[t.lng,t.lat]},o=e=>e.map(e=>r(e)),i=e=>e.map(e=>o(e));let s;e.type===G.POINT?s=r(t):e.type===G.LINE_STRING||e.type===G.MULTI_POINT?s=t.map(r):e.type===G.POLYGON||e.type===G.MULTI_LINE_STRING?s=t.map(o):e.type===G.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)})}const Tt={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(Y.UPDATE,{action:X.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let n=!1;if(e.length>1){n=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(n=!1)})}const r=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:n,uncombineFeatures:r,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 Pe).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(){vt.enable(this)},onMouseMove:function(e,t){return te(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Tt.onTap=Tt.onClick=function(e,t){return ee(t)?this.clickAnywhere(e,t):Z($.VERTEX)(t)?this.clickOnVertex(e,t):te(t)?this.clickOnFeature(e,t):void 0},Tt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),vt.enable(this),this.stopExtendedInteractions(e)},Tt.clickOnVertex=function(e,t){this.changeMode(H.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:B.MOVE})},Tt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Tt.clickOnFeature=function(e,t){vt.disable(this),this.stopExtendedInteractions(e);const n=re(t),r=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!n&&i&&this.getFeature(o).type!==G.POINT)return this.changeMode(H.DIRECT_SELECT,{featureId:o});i&&n?(this.deselect(o),this.updateUIClasses({mouse:B.POINTER}),1===r.length&&vt.enable(this)):!i&&n?(this.select(o),this.updateUIClasses({mouse:B.MOVE})):i||n||(r.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:B.MOVE})),this.doRender(o)},Tt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),W(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&z(t)?this.startBoxSelect(e,t):void 0},Tt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=it(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Tt.onTouchStart=function(e,t){if(W(t))return this.startOnActiveFeature(e,t)},Tt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Tt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:B.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(R.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=it(t.originalEvent,this.map.getContainer()),r=Math.min(e.boxSelectStartLocation.x,n.x),o=Math.max(e.boxSelectStartLocation.x,n.x),i=Math.min(e.boxSelectStartLocation.y,n.y),s=Math.max(e.boxSelectStartLocation.y,n.y),a=`translate(${r}px, ${i}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=o-r+"px",e.boxSelectElement.style.height=s-i+"px"},Tt.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};Pt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Tt.onTouchEnd=Tt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,it(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),o=this.getUniqueIds(r).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:B.MOVE}))}this.stopExtendedInteractions(e)},Tt.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?K.ACTIVE:K.INACTIVE,n(t),this.fireActionable(),t.properties.active===K.ACTIVE&&t.geometry.type!==G.POINT&&yt(t).forEach(n)},Tt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Tt.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],n=[],r=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==r)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),n.push(i.toGeoJSON())}if(n.length>1){const e=this.newFeature({type:G.FEATURE,properties:n[0].properties,geometry:{type:`Multi${r}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(Y.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},Tt.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],n=[];for(let r=0;r<e.length;r++){const o=e[r];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}),n.push(o.toGeoJSON()))}t.length>1&&this.fire(Y.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const Ct=Z($.VERTEX),wt=Z($.MIDPOINT),Lt={fireUpdate:function(){this.fire(Y.UPDATE,{action:X.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 n=t.featureTarget.properties,r=e.selectedCoordPaths.indexOf(n.coord_path);re(t)||-1!==r?re(t)&&-1===r&&e.selectedCoordPaths.push(n.coord_path):e.selectedCoordPaths=[n.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.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,n){Pt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,n){const r=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=bt(r.map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:e}})),n);for(let t=0;t<r.length;t++){const n=r[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],n[0]+o.lng,n[1]+o.lat)}},clickNoTarget:function(){this.changeMode(H.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(H.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===G.POINT)throw new TypeError("direct_select mode doesn't handle point features");const r={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,r.selectedCoordPaths)),this.setSelected(t),vt.disable(this),this.setActionableState({trash:!0}),r},onStop:function(){vt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=K.ACTIVE,n(t),yt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=K.INACTIVE,n(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(H.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=W(t),r=Ct(t),o=wt(t),i=0===e.selectedCoordPaths.length;n&&i||r&&!i?this.updateUIClasses({mouse:B.MOVE}):this.updateUIClasses({mouse:B.NONE});return(r||n||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Lt.onTouchStart=Lt.onMouseDown=function(e,t){return Ct(t)?this.onVertex(e,t):W(t)?this.onFeature(e,t):wt(t)?this.onMidpoint(e,t):void 0},Lt.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat},Lt.onClick=function(e,t){return ee(t)?this.clickNoTarget(e,t):W(t)?this.clickActiveFeature(e,t):Q(t)?this.clickInactive(e,t):void this.stopDragging(e)},Lt.onTap=function(e,t){return ee(t)?this.clickNoTarget(e,t):W(t)?this.clickActiveFeature(e,t):Q(t)?this.clickInactive(e,t):void 0},Lt.onTouchEnd=Lt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Ot={};function At(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Ot.onSetup=function(){const e=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:B.ADD}),this.activateUIButton(j.POINT),this.setActionableState({trash:!0}),{point:e}},Ot.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)},Ot.onTap=Ot.onClick=function(e,t){this.updateUIClasses({mouse:B.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(Y.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.point.id]})},Ot.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Ot.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?K.ACTIVE:K.INACTIVE,!r)return n(t)},Ot.onTrash=Ot.stopDrawingAndRemove,Ot.onKeyUp=function(e,t){if(oe(t)||ie(t))return this.stopDrawingAndRemove(e,t)};const kt={onSetup:function(){const e=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),vt.disable(this),this.updateUIClasses({mouse:B.ADD}),this.activateUIButton(j.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&At(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:B.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(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),ne(t)&&this.updateUIClasses({mouse:B.POINTER})}};kt.onTap=kt.onClick=function(e,t){return ne(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},kt.onKeyUp=function(e,t){oe(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)):ie(t)&&this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},kt.onStop=function(e){this.updateUIClasses({mouse:B.NONE}),vt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(Y.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT,{},{silent:!0})))},kt.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?K.ACTIVE:K.INACTIVE,!r)return n(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=$.FEATURE,n(st(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const r=t.geometry.coordinates[0].length-3;n(st(e.polygon.id,t.geometry.coordinates[0][r],`0.${r}`,!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(n({type:G.FEATURE,properties:t.properties,geometry:{coordinates:e,type:G.LINE_STRING}}),3===o)return}return n(t)}},kt.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)};const Ft={onSetup:function(e){const t=(e=e||{}).featureId;let n,r,o="forward";if(t){if(n=this.getFeature(t),!n)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 s=n.coordinates.length-1;if(n.coordinates[s][0]===i[0]&&n.coordinates[s][1]===i[1])r=s+1,n.addCoordinate(r,...n.coordinates[s]);else{if(n.coordinates[0][0]!==i[0]||n.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",r=0,n.addCoordinate(r,...n.coordinates[0])}}else n=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),vt.disable(this),this.updateUIClasses({mouse:B.ADD}),this.activateUIButton(j.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&At(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&At(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:B.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(H.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),ne(t)&&this.updateUIClasses({mouse:B.POINTER})}};Ft.onTap=Ft.onClick=function(e,t){if(ne(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Ft.onKeyUp=function(e,t){ie(t)?this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]}):oe(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT))},Ft.onStop=function(e){vt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(Y.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT,{},{silent:!0})))},Ft.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)},Ft.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?K.ACTIVE:K.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=$.FEATURE,n(st(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)),n(t))};var Vt={simple_select:Tt,direct_select:Lt,draw_point:Ot,draw_polygon:kt,draw_line_string:Ft};const Nt={defaultMode:H.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:rt,modes:Vt,controls:{},userProperties:!1,suppressAPIEvents:!0},Dt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Rt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Ut(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?U.HOT:U.COLD}))}var Bt,jt;var Gt,Ht,Yt=he(jt?Bt:(jt=1,Bt=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,o,i;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(o=r;0!==o--;)if(!e(t[o],n[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(o=r;0!==o--;)if(!Object.prototype.hasOwnProperty.call(n,i[o]))return!1;for(o=r;0!==o--;){var s=i[o];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n}));var Xt=function(){if(Ht)return Gt;Ht=1,Gt=function(t){if(!t||!t.type)return null;var n=e[t.type];if(!n)return null;if("geometry"===n)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===n)return{type:"FeatureCollection",features:[t]};if("featurecollection"===n)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Gt}(),$t=he(Xt);function Kt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Jt={Polygon:Be,LineString:Ue,Point:Re,MultiPolygon:He,MultiLineString:He,MultiPoint:He};var qt=Object.freeze({__proto__:null,CommonSelectors:pe,ModeHandler:Fe,StringSet:Pe,constrainFeatureMovement:bt,createMidPoint:mt,createSupplementaryPoints:yt,createVertex:st,doubleClickZoom:vt,euclideanDistance:Oe,featuresAt:Ce,getFeatureAtAndSetCursors:Le,isClick:Ae,isEventAtCoordinates:At,isTap:ke,mapEventToBoundingBox:be,moveFeatures:Pt,sortFeatures:Me,stringSetsAreEqual:Kt,theme:rt,toDenseArray:Je});const Zt=function(e,t){const n={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Rt,e.controls):t.controls=Object.assign({},Dt,e.controls),t=Object.assign({},Nt,t),t.styles=Ut(t.styles,"cold").concat(Ut(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=H;const n=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Ce.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:G.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:G.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:e.coordinates}}))}},t.set=function(n){if(void 0===n.type||n.type!==G.FEATURE_COLLECTION||!Array.isArray(n.features))throw new Error("Invalid FeatureCollection");const r=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(n),s=new Pe(i);return o=o.filter(e=>!s.has(e)),o.length&&t.delete(o),r(),i},t.add=function(t){const r=JSON.parse(JSON.stringify($t(t))).features.map(t=>{if(t.id=t.id||Ne(),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 r=Jt[t.geometry.type];if(void 0===r)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new r(e,t);e.store.add(o,{silent:n})}else{const r=e.store.get(t.id),o=r.properties;r.properties=t.properties,Yt(o,t.properties)||e.store.featureChanged(r.id,{silent:n}),Yt(r.getCoordinates(),t.geometry.coordinates)||r.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),r},t.get=function(t){const n=e.store.get(t);if(n)return n.toGeoJSON()},t.getAll=function(){return{type:G.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()!==H.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(H.SIMPLE_SELECT,void 0,{silent:n}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===H.DIRECT_SELECT?e.events.changeMode(H.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,o={}){return r===H.SIMPLE_SELECT&&t.getMode()===H.SIMPLE_SELECT?(Kt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:n}),e.store.render()),t):(r===H.DIRECT_SELECT&&t.getMode()===H.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,o,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,o,i){return e.store.setFeatureProperty(r,o,i,{silent:n}),t},t}(n,t),n.api=t;const r=Qe(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=j,t.options=e,t};function zt(e){Zt(e,this)}zt.modes=Vt,zt.constants=q,zt.lib=qt;const Wt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,n){t.properties.active="false",n(t)}},Qt="draw.create",en="draw.update",tn="draw.modechange",nn="draw.editfinish",rn="draw.cancel",on="draw.vertexselection",sn="draw.vertexchange",an="draw.undochange",cn="draw.undo",ln="draw.geometrychange",un="draw.interfacetypechange",dn="draw.placementblocked",pn="draw.nudgevertex",hn="draw.selectvertex",fn="draw.insertvertexatmidpoint",gn="draw.setgeometry",mn="styledata",yn=e=>{if(!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[]}},vn=e=>{const t=yn(e),n=_n(e);if(!t.length||!n.length)return[];const r=[];for(const e of n){const n=e.closed?e.length:e.length-1;for(let o=0;o<n;o++){const n=e.start+o,i=e.start+(o+1)%e.length,[s,a]=t[n],[c,l]=t[i];r.push([(s+c)/2,(a+l)/2])}}return r},_n=e=>{if(!e?.coordinates)return[];const t=[];let n=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!0}),n+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!1}),n+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,r)=>{e.forEach((e,o)=>{t.push({start:n,length:e.length,path:[r,o],closed:!0}),n+=e.length})})}return t},xn=(e,t)=>{for(const n of e)if(t>=n.start&&t<n.start+n.length)return{segment:n,localIdx:t-n.start};return null},In=(e,t)=>{let n=e.geometry.coordinates;for(const e of t)n=n[e];return n},En=(e,t)=>{const n=t.split(".").map(Number),r=_n(e);for(const e of r){if(e.path.every((e,t)=>e===n[t])&&n.length===e.path.length+1){const t=n[n.length-1];return e.start+t}}return n[n.length-1]},Sn=(e,t)=>({x:e.x*t,y:e.y*t}),Mn=e=>e instanceof window.SVGElement||e.ownerSVGElement;function bn(e){return e?._snapInstance??null}function Pn(e){return!!(e?.status&&e?.snapStatus&&e.snapCoords?.length>=2)}function Tn(e){return Pn(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Cn(e,t,n){if(!e||!t||!e.status)return!1;const r=t.unproject(n);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function wn(e,t){e&&(e._autoSnapSuspended=t)}function Ln(e,t){if(!e||!t||!e.status)return!1;const n=t.getCenter(),r=t.project(n);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function On(e,t){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0)),t?.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function An(e){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0))}function kn(e){return"function"==typeof e?.getSnapEnabled&&!0===e.getSnapEnabled()}const Fn=(e,t,n={})=>{const r=n=>r=>n.call(e,t,r),o={keydown:r(e.onKeydown),keyup:r(e.onKeyup),pointerdown:r(e.onPointerevent),pointermove:r(e.onPointerevent),pointerup:r(e.onPointerevent),click:r(e.onButtonClick),touchstart:r(e.onTouchstart),touchmove:r(e.onTouchmove),touchend:r(e.onTouchend),scalechange:r(e.onScaleChange),move:r(e.onMove),interfacetypechange:r(e.onInterfaceTypeChange)};for(const[e,t]of Object.entries(n))o[e]=r(t);return o},Vn=(e,t,n)=>{window.addEventListener("keydown",n.keydown,{capture:!0}),window.addEventListener("keyup",n.keyup,{capture:!0}),window.addEventListener("click",n.click),e.container.addEventListener("pointerdown",n.pointerdown),e.container.addEventListener("pointermove",n.pointermove),e.container.addEventListener("pointerup",n.pointerup),e.container.addEventListener("touchstart",n.touchstart,{passive:!1}),e.container.addEventListener("touchmove",n.touchmove,{passive:!1}),e.container.addEventListener("touchend",n.touchend,{passive:!1}),t.on("draw.scalechange",n.scalechange),t.on("move",n.move),t.on(un,n.interfacetypechange),t.on(pn,n.nudge),t.on(gn,n.setgeometry)},Nn=(e,t,n)=>{e.container.removeEventListener("pointerdown",n.pointerdown),e.container.removeEventListener("pointermove",n.pointermove),e.container.removeEventListener("pointerup",n.pointerup),e.container.removeEventListener("touchstart",n.touchstart),e.container.removeEventListener("touchmove",n.touchmove),e.container.removeEventListener("touchend",n.touchend),t.off("draw.scalechange",n.scalechange),t.off("move",n.move),t.off(un,n.interfacetypechange),t.off(pn,n.nudge),t.off(gn,n.setgeometry),t.dragPan.enable(),window.removeEventListener("click",n.click),window.removeEventListener("keydown",n.keydown,{capture:!0}),window.removeEventListener("keyup",n.keyup,{capture:!0})},Dn=e=>{const t=bn(e);t&&On(t,e)},Rn={fireGeometryChange(e){const t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t){setTimeout(()=>{const n=this.getFeature(t);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:r,vertexIndex:e})},0)},pushUndo(e){const t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(e.vertexIndex,e.featureId))}},Un={...Rn,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_vertex"===n.type?this.undoMoveVertex(e,n):"insert_vertex"===n.type?this.undoInsertVertex(e,n):"delete_vertex"===n.type?this.undoDeleteVertex(e,n):"replace_geometry"===n.type&&this.replaceGeometry(e,n.featureId,n.previousGeometry),this.emitGeometryValidation(n.vertexIndex,n.featureId)},undoMoveVertex(e,t){const{vertexIndex:n,previousPosition:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=_n(i),c=xn(a,n);if(!c)return;In(s,c.segment.path)[c.localIdx]=r,this._applyUndoAndSync(e,s,o);const l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Sn(this.map.project(l),e.scale))},undoInsertVertex(e,t){const{vertexIndex:n,featureId:r}=t,o=this.getFeature(r);if(!o)return;const i=o.toGeoJSON(),s=_n(o),a=xn(s,n);if(!a)return;In(i,a.segment.path).splice(a.localIdx,1),this._applyUndoAndSync(e,i,r),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})},undoDeleteVertex(e,t){const{vertexIndex:n,position:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=_n(i);let c=xn(a,n);if(!c)for(const e of a)if(n===e.start+e.length){c={segment:e,localIdx:e.length};break}if(!c)return;In(s,c.segment.path).splice(c.localIdx,0,r),this._applyUndoAndSync(e,s,o),this.updateTouchVertexTarget(e,Sn(this.map.project(e.vertices[n]),e.scale)),this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,n)})},replaceGeometry(e,t,n){const r=this.getFeature(t);r&&(this._applyUndoAndSync(e,{...r.toGeoJSON(),geometry:n},t),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null}))},_applyUndoAndSync(e,t,n){this._ctx.api.add(t),e.vertices=this.getVertices(n),e.midpoints=this.getMidpoints(n),this._ctx.store.render(),this.fireGeometryChange(e)}},Bn=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),jn=(e,t,n,r,o)=>{const i=window.getComputedStyle(t),s={x:n.x-Number.parseFloat(i.left),y:n.y-Number.parseFloat(i.top)},a=e.project(r);return{deltaTarget:s,deltaVertex:{x:n.x/o-a.x,y:n.y/o-a.y}}},Gn=(e,t,n)=>{const r={x:n.x/t.scale-t.deltaVertex.x,y:n.y/t.scale-t.deltaVertex.y};let o=e.unproject(r);if(kn(t)){const t=bn(e);Cn(t,e,r),o=Tn(t)||o}return o},Hn=(e,t,n={})=>{if(!e)return;const{editActive:r,editHalo:o,editVertex:i}=L(t,n);O(e,{editActive:r,editHalo:o,editVertex:i})},Yn={addTouchVertexTarget(e){e.touchVertexTarget=w(e.container),Hn(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:`${t.y}px`,left:`${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||Mn(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(An(bn(this.map)),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;const t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Sn(this.map.project(t),e.scale))}},onTap(e,t){const n=bn(this.map);n&&On(n,this.map);const r=t.featureTarget?.properties.meta,o=t.featureTarget?.properties.coord_path;if("vertex"===r){const t=this.getFeature(e.featureId),n=En(t,o);this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:o})}else"midpoint"===r?this.insertVertex({...e,selectedVertexIndex:this.getVertexIndexFromMidpoint(e,o),selectedVertexType:"midpoint"}):this.clickNoTarget(e)},onTouchstart(e,t){An(bn(this.map));const n=this.getVertices(e.featureId),r=n?.[e.selectedVertexIndex];if(!r||!Mn(t.target.parentNode))return;e._moveStartPosition=[...r],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;const o=Bn(t);Object.assign(e,jn(this.map,e.touchVertexTarget,o,r,e.scale))},onTouchmove(e,t){if(e.selectedVertexIndex<0||!Mn(t.target.parentNode))return;e._touchMoved=!0;const n=Bn(t);this.moveVertex(e,Gn(this.map,e,n)),this.updateTouchVertexTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},Xn=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),$n={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Kn=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Jn=e=>{const t=document.activeElement;return!(!t||t===document.body)&&(!e.container?.contains(t)&&(Kn.has(t.tagName)||t.isContentEditable||t.hasAttribute("tabindex")))},qn=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,Zn={handleUndoShortcut(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},zn={getOffset(e,t){const n=this.map.project(e),r=t?.shiftKey?o.nudgeAmount:o.stepAmount,[i,s]=t?$n[t.key].map(e=>e*r):[0,0];return this.map.unproject({x:n.x+i,y:n.y+s})},getOffsetByDelta(e,t,n,r){const i=this.map.project(e),s=r?o.stepAmount:o.nudgeAmount;return this.map.unproject({x:i.x+t*s,y:i.y+n*s})},resolveSnapTarget(e,t,r,o,i){const s=bn(this.map);if(kn(e)&&e._isSnapped&&s){const i=function(e){return e?.options?.radius??n.snapRadius}(s)+1,a=this.map.project(o);return e._isSnapped=!1,On(s,this.map),this.map.unproject({x:a.x+t*i,y:a.y+r*i})}const a=i();return kn(e)&&s&&(Cn(s,this.map,this.map.project(a)),Pn(s))?(e._isSnapped=!0,Tn(s)):(e._isSnapped=!1,a)}},Wn={...zn,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){const[n,r]=this.getVertexOrMidpoint(e,t);n<0||!r||this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:r,..."vertex"===r&&{coordPath:this.getCoordPath(e,n)}})},getNewCoord(e,t){return this.getOffset(yn(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,n,r){if("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)return;const o=this.getFeature(e.featureId),i=o&&yn(o)?.[e.selectedVertexIndex];if(!i)return;const s=[...i],a=e.selectedVertexIndex,c=this.resolveSnapTarget(e,t,n,i,()=>this.getOffsetByDelta(i,t,n,r));this.moveVertex(e,c),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:a,previousPosition:s})},insertVertex(e,t){const n=e.selectedVertexIndex-e.vertices.length,r=this.getOffset(e.midpoints[n],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),s=_n(o);let a=n+1,c=null,l=0,u=0;for(const e of s){const t=e.closed?e.length:e.length-1;if(n<u+t){c=e,l=n-u+1,a=e.start+l;break}u+=t}if(!c)return;In(i,c.path).splice(l,0,[r.lng,r.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:a}),this.changeMode(e,{selectedVertexIndex:a,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,a)})},moveVertex(e,t,n={}){if(n.checkSnap&&!1!==e.enableSnap){const e=this.map._snapInstance;e?.snapStatus&&e.snapCoords?.length>=2&&(t={lng:e.snapCoords[0],lat:e.snapCoords[1]})}const r=this.getFeature(e.featureId),o=r.toGeoJSON(),i=_n(r),s=xn(i,e.selectedVertexIndex);if(!s)return;In(o,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(o),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature)},deleteVertex(e){const t=this.getFeature(e.featureId);if(!t)return;const n=_n(t),r=xn(n,e.selectedVertexIndex);if(!r)return;const{segment:o}=r,s=o.closed?i.Polygon:i.LineString;if(o.length<=s)return;const a=[...e.vertices[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...r.segment.path,r.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})}},Qn={findVertexIndex(e,t,n){const r=[];return e.forEach((e,n)=>{e[0]===t[0]&&e[1]===t[1]&&r.push(n)}),0===r.length?-1:1===r.length?r[0]:n>=0?r.reduce((e,t)=>Math.abs(t-n)<Math.abs(e-n)?t:e,r[0]):r[0]},getCoordPath(e,t){const n=this.getFeature(e.featureId);if(!n)return"0";const r=_n(n),o=xn(r,t);if(!o)return"0";const{segment:i,localIdx:s}=o;return[...i.path,s].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return yn(this.getFeature(e))},getMidpoints(e){return vn(this.getFeature(e))},getVertexOrMidpoint(e,t){if(e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),!e.vertices?.length)return[-1,null];const n=e=>e?Object.values(this.map.project(e)):null,r=[...e.vertices.map(n),...e.midpoints.map(n)].filter(Boolean);if(!r.length)return[-1,null];const o=r[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),i=A(o,r,t);return[i,i<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){const n=this.getFeature(e.featureId),r=_n(n),o=t.split(".").map(Number);let i=0;for(const t of r){if(t.path.every((e,t)=>e===o[t])&&o.length===t.path.length+1){const n=o[o.length-1],r=n>0?n-1:t.length-2;return e.vertices.length+i+r}i+=t.closed?t.length:t.length-1}return e.vertices.length}},er={...Zn,onKeydown(e,t){Jn(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Xn.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?qn(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){const t=bn(this.map);t&&On(t,this.map),e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),e.vertices?.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){if("midpoint"===e.selectedVertexType)return void this.insertVertex(e,t);const n=this.getFeature(e.featureId),r=n&&yn(n)?.[e.selectedVertexIndex];r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,n){const[r,o]=$n[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){Jn(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&k(t),Xn.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))}},tr={onMouseDown(e,t){An(bn(this.map));const n=t.featureTarget?.properties.meta,r=t.featureTarget?.properties.coord_path;if(["vertex","midpoint"].includes(n)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,Lt.onMouseDown.call(this,e,t),"vertex"===n&&r)){const t=this.getFeature(e.featureId),n=En(t,r);e.selectedVertexIndex=n,e.selectedVertexType="vertex",e.coordPath=r;const o=e.vertices?.[n];o&&(e._moveStartPosition=[...o],e._moveStartIndex=n)}if("midpoint"===n){const t=this.getFeature(e.featureId),n=En(t,r);e._insertedVertexIndex=n,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,r),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(on,{index:e.selectedVertexIndex,numVertices:e.vertices.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){const t=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(on,{index:t,numVertices:e.vertices.length})}Lt.onClick.call(this,e,t)},onMouseUp(e,t){An(bn(this.map));const n=e._isInsertingVertex&&null!=e._insertedVertexIndex,r=this._didVertexMove(e);(e.dragMoving||r||n)&&(this.syncVertices(e),n?this._recordInsertionUndo(e):r&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,Lt.onMouseUp.call(this,e,t)},_didVertexMove(e){if(!e._moveStartPosition||null==e._moveStartIndex)return!1;const t=this.getFeature(e.featureId),n=t&&yn(t)?.[e._moveStartIndex];return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){const 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(on,{index:t,numVertices:e.vertices.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=bn(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!kn(e)||!n?.status)return void Lt.onDrag.call(this,e,t);if(!e.selectedCoordPaths?.length||!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation(),Cn(n,this.map,t.point);const r=Tn(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],r.lng,r.lat),e.dragMoveLocation=t.lngLat}},nr={...zt.modes.direct_select,...Un,...Yn,...Wn,...Qn,...er,...tr,onSetup(e){const t=zt.modes.direct_select.onSetup.call(this,e);Object.assign(t,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:t.featureId,selectedVertexIndex:e.selectedVertexIndex??-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:e.scale??1}),this.map._lastEditFeatureId!==t.featureId&&(this.map._undoStack?.clear(),this.map._lastEditFeatureId=t.featureId);const n=this.getFeature(t.featureId);if(t.featureType=n?.type,t.vertices=this.getVertices(t.featureId),t.midpoints=this.getMidpoints(t.featureId),this.setupEventListeners(t),this.applyVertexSelection(t,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(t),Dn(this.map),"touch"===t.interfaceType&&t.selectedVertexIndex>=0&&"vertex"===t.selectedVertexType){const e=t.vertices[t.selectedVertexIndex];e&&setTimeout(()=>{this.updateTouchVertexTarget(t,Sn(this.map.project(e),t.scale))},0)}return t._ignorePointermoveDeselect=!0,setTimeout(()=>{t._ignorePointermoveDeselect=!1},100),t},setupEventListeners(e){const t=this.handlers=Fn(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint,setgeometry:this.onSetGeometry});Vn(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(hn,t.selectvertex),this.map.on(fn,t.insertvertexatmidpoint)},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.vertices.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){this.syncVertices(e);const n=t.points[t.points.length-1]?.geometry.coordinates;if("keyboard"!==e.interfaceType&&n&&!e.coordPath){const r=t.features[0]?.geometry,o=yn(r);e.selectedVertexIndex=this.findVertexIndex(o,n,e.selectedVertexIndex)}e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null,this.map.fire(on,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});const r=n||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,r?Sn(this.map.project(r),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;const n=e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,n?Sn(this.map.project(n),e.scale):null)},onUpdate(e){new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,e.selectedVertexType??=null)},onMove(e){const t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Sn(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);const n=e.vertices[e.selectedVertexIndex];n&&this.updateTouchVertexTarget(e,Sn(this.map.project(n),e.scale))},onSelectVertex(e,t){e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));const n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,{selectedVertexIndex:t.index,selectedVertexType:n,..."vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}})},onInsertVertexAtMidpoint(e,t){e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex({...e,selectedVertexIndex:t.index,selectedVertexType:"midpoint"})},onSetGeometry(e,t){const n=this.getFeature(e.featureId);if(!n)return;const r=n.toGeoJSON().geometry;this.replaceGeometry(e,e.featureId,t.geometry),this.pushUndo({type:"replace_geometry",featureId:e.featureId,previousGeometry:r})},onButtonClick(e,t){t.target.closest(`#${e.deleteVertexButtonId}`)&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest(`#${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",{...e,...t})},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;const t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(hn,t.selectvertex),this.map.off(fn,t.insertvertexatmidpoint),Nn(e,this.map,t),this.hideTouchVertexIndicator(e)}},rr={...Rn,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_point"!==n.type&&"replace_geometry"!==n.type||this.undoMovePoint(e,n),this.emitGeometryValidation(n.vertexIndex,n.featureId)},undoMovePoint(e,t){this.setPointPosition(e,t.featureId,t.previousPosition)},setPointPosition(e,t,n){const r=this.getFeature(t);r&&(r.updateCoordinate("",n[0],n[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,Sn(this.map.project(n),e.scale)))}},or={addTouchPointTarget(e){e.touchPointTarget=w(e.container),Hn(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:`${t.y}px`,left:`${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){An(bn(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,Sn(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){An(bn(this.map));const n=this.getPointCoord(e);if(!n||!Mn(t.target.parentNode))return;e._moveStartPosition=[...n],e._touchMoved=!1;const r=Bn(t);Object.assign(e,jn(this.map,e.touchPointTarget,r,n,e.scale))},onTouchmove(e,t){if(!Mn(t.target.parentNode))return;e._touchMoved=!0;const n=Bn(t);this.movePoint(e,Gn(this.map,e,n)),this.updateTouchPointTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},ir={...zn,getPointCoord(e){return this.getFeature(e.featureId)?.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,n,r){const o=this.getPointCoord(e);if(!o)return;const i=[...o],s=this.resolveSnapTarget(e,t,n,o,()=>this.getOffsetByDelta(o,t,n,r));this.movePoint(e,s),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}},sr={...Zn,onKeydown(e,t){Jn(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Xn.has(t.key)?this.handleArrowKey(e,t):qn(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){const n=this.getPointCoord(e);n&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...n]),this.movePoint(e,this._keyboardMoveTarget(e,t,n)))},_keyboardMoveTarget(e,t,n){const[r,o]=$n[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){Jn(e)||(e.interfaceType="keyboard",k(t),Xn.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}},ar={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],wn(bn(this.map),!0)),Lt.onFeature.call(this,e,t)},onClick(e,t){if(W(t))return;if(!((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},r={mode:"edit_point",vertexIndex:0},o=s(n,r,{onGeometryPreview:e._drawPreviewValidator});return o.valid||e.fire("draw.placementblocked",a(n,o,r)),o.valid})(this.map,[t.lngLat.lng,t.lngLat.lat]))return;const n=[...e.feature.coordinates],r=bn(this.map);let o=t.lngLat;kn(e)&&r&&(Cn(r,this.map,t.point),o=Tn(r)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:n})},onMouseUp(e,t){const n=bn(this.map);An(n),wn(n,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Lt.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;const t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=bn(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!kn(e)||!n?.status)return void Lt.onDrag.call(this,e,t);if(!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};Cn(n,this.map,this.map.project([r.lng,r.lat]));const o=Tn(n)||r;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat},onTrash(){}},cr={...zt.modes.direct_select,...rr,...or,...ir,...sr,...ar,onSetup(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter edit_point mode");const r={featureId:t,feature:n,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};return this.setSelectedCoordinates([]),this.setSelected(t),vt.disable(this),this.setActionableState({trash:!1}),Object.assign(r,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:e.scale??1}),this.map._lastEditFeatureId!==r.featureId&&(this.map._undoStack?.clear(),this.map._lastEditFeatureId=r.featureId),this.setupEventListeners(r),this.map._drawEditContainer=e.container,this.addTouchPointTarget(r),r.container?.focus({preventScroll:!0}),Dn(this.map),"touch"===r.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(r,Sn(this.map.project(r.feature.coordinates),r.scale))},0),this.map.fire(on,{index:0,numVertices:1}),r},setupEventListeners(e){const t=this.handlers=Fn(this,e,{nudge:this.onNudgePoint,setgeometry:this.onSetGeometry});Vn(e,this.map,t)},toDisplayFeatures(e,t,n){t.properties.active=e.featureId===t.properties.id?"true":"false",n(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,Sn(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,Sn(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,Sn(this.map.project(e.feature.coordinates),e.scale))},onSetGeometry(e,t){const n=this.getFeature(e.featureId);if(!n)return;const r=n.getCoordinates();this.setPointPosition(e,e.featureId,t.geometry.coordinates),this.pushUndo({type:"replace_geometry",featureId:e.featureId,previousPosition:r})},onButtonClick(e,t){t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Nn(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}},lr=({ParentMode:e,featureProp:t,excludeFeatureIdFromSetup:n})=>({onSetup(r){const{map:o}=this,i=n?{...r,featureId:null}:r,s={...e.onSetup.call(this,i),...r};s[t].properties=r.properties;const{container:a,vertexMarkerId:c,getInterfaceType:l}=s,u=l?l():s.interfaceType;s.interfaceType=u;const d=a.querySelector(`#${c}`);s.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(s):this._hideCrossHair(s),s.crossHair&&(s.crossHair.activate=()=>this._placeAtCrossHair?.(s));const p=(e,t)=>this[e]=t.bind(this,s),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,t])=>p(e,t)),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"keyup",k,{capture:!0}],[window,"click",this.vertexButtonClickHandler],[a,"blur",this.blurHandler],[a,"pointermove",this.pointermoveHandler],[a,"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,t,n,r])=>e.addEventListener?e.addEventListener(t,n,r):e.on(t,n)),s},onStop(t){e.onStop.call(this,t),this._listeners.forEach(([e,t,n,r])=>e.removeEventListener?e.removeEventListener(t,n,r):e.off(t,n)),t.crossHair?.activate&&(t.crossHair.activate=null),["touch","keyboard"].includes(t.interfaceType)||this._hideCrossHair(t),this.map.fire("draw.interfacetypechange",{interfaceType:t.interfaceType})}}),ur=(e,t,n,o)=>{setTimeout(()=>{const i=t(o);i&&e.fire("draw.geometrychange",((e,t)=>{const 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,n))},0)},dr=({geometryType:e,getFeature:t,getCoords:n})=>({_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(r,o){const i=t(r);if(!i||!o)return!0;const s=c({placed:n(i).slice(0,-1),point:o,geometryType:e,onGeometryPreview:this.map._drawPreviewValidator});return s.valid||this.map.fire("draw.placementblocked",s.blocked),s.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){ur(this.map,t,n,e)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this.doClick(e)},onCreate(e,t){((e,t,n)=>{e.delete(t.id),t.id=n,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}),pr=({ParentMode:e,getFeature:t,getCoords:n,validateClick:r,finishOnInvalidClick:o})=>({onClick(i,s){if(this._isIgnorableClick(s))return;if(!1===this.map._drawCanFinish&&"vertex"===s.featureTarget?.properties?.meta)return;const a=bn(this.map);if(kn(i)&&Pn(a))s=function(e,t){const n=Tn(t);return n?{...e,lngLat:n}:e}(s,a);else if(!((e,i)=>{const s=n(t(e));return s.length>0&&(s[s.length-1]=[i.lngLat.lng,i.lngLat.lat]),o||r(t(e))})(i,s))return;if(!this._canPlaceVertex(i,[s.lngLat.lng,s.lngLat.lat]))return;const c=n(t(i)).length;e.onClick.call(this,i,s),n(t(i)).length>c&&(this.pushDrawUndo(i),this.dispatchVertexChange(n(t(i))),this.emitDrawValidation(i))},doClick(i){if(this.map._undoInProgress)return;const s=t(i),a=n(s);if(this.dispatchVertexChange(a),!r(s))return void(o&&!1!==this.map._drawCanFinish&&(a.pop(),this.map.fire("draw.create",{features:[s.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[s.id]})));const c=bn(this.map),l=kn(i)&&function(e,t){const n=Tn(t);if(!n)return null;const r=e.project([n.lng,n.lat]);return{lngLat:n,point:r,originalEvent:new MouseEvent("click",{clientX:r.x,clientY:r.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(!this._canPlaceVertex(i,[u.lng,u.lat]))return;l?(e.onClick.call(this,i,l),this._ctx.store.render()):this._simulateMouse("click",e.onClick,i);const d=n(t(i));this.pushDrawUndo(i),this.dispatchVertexChange(d),this.emitDrawValidation(i)},_placeAtCrossHair(e){this.doClick(e)}}),hr=e=>({...dr(e),...pr(e)}),fr=({geometryType:e,getFeature:t})=>({pushDrawUndo(n){const r=this.map._undoStack;r&&!this.map._undoInProgress&&r.push({type:"draw_vertex",geometryType:e,featureId:t(n).id})},onUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"draw_vertex"===n?.type&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e))},_handleUndoKeydown(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}),gr=({ParentMode:e,geometryType:t,getCoords:n,getFeature:r,RUBBER_BAND_OFFSET:o})=>({undoVertex(e){const t=r(e),o=n(t);return!(o.length<2)&&(2===o.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,o),!0))},_removeLastVertex(e,r,i){const s="Polygon"===t?r.coordinates[0]:i;s.splice(-o,1),s[s.length-1]=[...s[s.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(r))},_updateRubberBand(n,r){if(["touch","keyboard"].includes(n.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,n),this._ctx.store.render();else{const o=r["Polygon"===t?r.length-2:r.length-1],i={lng:o[0],lat:o[1]},s=this.map.project(i);e.onMouseMove.call(this,n,{lngLat:i,point:s,originalEvent:new MouseEvent("mousemove",{clientX:s.x,clientY:s.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",n.polygon||n.line)}this.dispatchVertexChange(r)}}),mr=({ParentMode:e,featureProp:t,geometryType:n})=>({_reinitializeFeature(r,o){const i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(r,i);const s=this.map.getCenter(),a=[[s.lng,s.lat],[s.lng,s.lat]],c=this.newFeature({type:"Feature",properties:r.properties||{},geometry:{type:n,coordinates:[a]}});return c.id=i,this._ctx.store.add(c),r[t]=c,r.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,r),this._ctx.store.render(),this.dispatchVertexChange(a),!0},_restartLineStringDraw(e,t){const n=this.map._undoStack;return n&&n.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}}),yr=e=>({...fr(e),...gr(e),...mr(e)}),vr=({ParentMode:e,getFeature:t,INTERFACE_KEYS:n})=>({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(n,r){const o=document.activeElement;if(!o||o===n.container||!n.container.contains(o))if("Escape"!==r.key)o!==n.container&&e.onKeyUp.call(this,n,r);else if("keyboard"===n.interfaceType){const e=this.map._undoStack;e&&e.clear(),this._reinitializeFeature(n,t(n))}}}),_r=({ParentMode:e,getFeature:t,getCoords:n})=>({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(t,n){if(kn(t)){const e=bn(this.map);Cn(e,this.map,n.point);const t=Tn(e);t&&(n={...n,lngLat:t})}e.onMouseMove.call(this,t,n),this.map.fire("draw.geometrychange",t.polygon||t.line)},onMove(t,n){const r="move"===n?.type&&!n.originalEvent;if(["touch","keyboard"].includes(t.interfaceType)||r){kn(t)&&Ln(bn(this.map),this.map);const n=bn(this.map),r=kn(t)&&Tn(n);if(r){const n=this.map.project([r.lng,r.lat]);e.onMouseMove.call(this,t,{lngLat:r,point:n,originalEvent:new MouseEvent("mousemove",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",t.polygon||t.line)}else this._simulateMouse("mousemove",e.onMouseMove,t)}},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(t(e)))}}),xr=({ParentMode:e,geometryType:t,getFeature:n,getPlacedCoords:r})=>({_simulateMouse(e,t,n){const{map:r}=this,o=r.getCenter(),i=r.project(o);t.call(this,n,{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",n.polygon||n.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,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},toDisplayFeatures(o,i,s){e.toDisplayFeatures.call(this,o,i,s);const a=n(o);i.geometry.type===t&&i.properties.id===a.id&&r(i).forEach(e=>s({type:"Feature",properties:{meta:"draw-vertex",parent:a.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}),Ir=(e,t)=>{const{featureProp:n,geometryType:r,getCoords:o,validateClick:i,getPlacedCoords:s,excludeFeatureIdFromSetup:a=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:n,geometryType:r,getCoords:o,validateClick:i,getPlacedCoords:s,excludeFeatureIdFromSetup:a,finishOnInvalidClick:c,getFeature:e=>e[n],RUBBER_BAND_OFFSET:2,INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return{...e,...lr(l),...hr(l),...yr(l),...vr(l),..._r(l),...xr(l)}},Er=Ir(zt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>l(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Sr=Ir(zt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>u(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),Mr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),br=zt.modes.draw_point,Pr=lr({ParentMode:br,featureProp:"point",excludeFeatureIdFromSetup:!1}),Tr={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,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},onCreate(e,t){const n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),e.resolvePointSymbol?.(e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){const n="move"===t?.type&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||n)&&kn(e)&&Ln(bn(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){kn(e)&&Cn(bn(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),Mr.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&Mr.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())return;const n=bn(this.map),r=kn(e)&&Pn(n)?Tn(n):null;this._commit(e,r||t.lngLat)},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){const t=bn(this.map);kn(e)&&Ln(t,this.map);const n=kn(e)&&Pn(t)?Tn(t):null;this._commit(e,n||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},r={mode:"draw_point",vertexIndex:0},o=s(n,r,{onGeometryPreview:e._drawPreviewValidator});return o.valid||e.fire("draw.placementblocked",a(n,o,r)),o.valid})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},Cr={...br,...Pr,...Tr},wr=(e,t,n)=>["coalesce",["get",`user_${t}${e.id.charAt(0).toUpperCase()+e.id.slice(1)}`],["get",`user_${t}`],n],Lr=["coalesce",["get","user_sortKey"],0],Or=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":Lr},paint:{"fill-color":wr(e,"fill",t.shapeFill)}}),Ar=(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":Lr},paint:{"line-color":wr(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),kr=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}}),Fr=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),Vr=(e,t,n)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":n,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Nr=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Dr=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),Rr=(e,t,n)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":n,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Ur=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Br=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),jr=(e,t={})=>{const n=L(e,t),{vertexRadius:r,midpointRadius:o,vertexHaloRadius:i,midpointHaloRadius:s}=d;return[Or(e,n),(p=n.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":p}}),(u=n.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":u,"line-width":2,"line-opacity":1}}),(l=n.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":l,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),Ar(e,n),{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":Lr},paint:{}},(c=n.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":c,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(a=n.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":a,"line-width":2,"line-opacity":1}}),kr(n.editStroke),Dr(n.editMidpoint,o),Rr(n.editHalo,n.editActive,s),Ur(n.editMidpoint,o),Fr(n.editVertex,r),Vr(n.editHalo,n.editActive,i),Nr(n.editVertex,r),Br(n.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}}];var a,c,l,u,p};function Gr(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 Hr(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 Yr(e,t,n){void 0===n&&(n={});var r=Gr(e),o=Gr(t),i=p(o[1]-r[1]),s=p(o[0]-r[0]),a=p(r[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}function Xr(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 $r(e,t,n,r={}){const o=Xr(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return void 0!==o[2]?g([d,h,o[2]],r.properties):g([d,h],r.properties)}function Kr(e,t){var n;return void 0===t&&(t={}),function(e,t){if(e.length>1)return v(e,t);return _(e[0],t)}(("Feature"===(n=e).type?n.geometry:n).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Jr(e,t,n={}){if(!0===n.final)return function(e,t){let n=Jr(t,e);return n=(n+180)%360,n}(e,t);const r=Xr(e),o=Xr(t),i=p(r[0]),s=p(o[0]),a=p(r[1]),c=p(o[1]),l=Math.sin(s-i)*Math.cos(c),u=Math.cos(a)*Math.sin(c)-Math.sin(a)*Math.cos(c)*Math.cos(s-i);return m(Math.atan2(l,u))}var qr=Jr;function Zr(e,t,n,r){void 0===r&&(r={});var o=Gr(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return g([d,h],r.properties)}function zr(e){if(!e)throw new Error("geojson is required");var t=[];return x(e,function(e){!function(e,t){var n=[],r=e.geometry;if(null!==r){switch(r.type){case"Polygon":n=Hr(r);break;case"LineString":n=[Hr(r)]}n.forEach(function(n){var r=function(e,t){var n=[];return e.reduce(function(e,r){var o,i,s,a,c,l,u=_([e,r],t);return u.bbox=(i=r,s=(o=e)[0],a=o[1],c=i[0],l=i[1],[s<c?s:c,a<l?a:l,s>c?s:c,a>l?a:l]),n.push(u),r}),n}(n,e.properties);r.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),I(t)}var Wr={exports:{}};function Qr(e,t,n,r,o){eo(e,t,n||0,r||e.length-1,o||no)}function eo(e,t,n,r,o){for(;r>n;){if(r-n>600){var i=r-n+1,s=t-n+1,a=Math.log(i),c=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*c*(i-c)/i)*(s-i/2<0?-1:1);eo(e,t,Math.max(n,Math.floor(t-s*c/i+l)),Math.min(r,Math.floor(t+(i-s)*c/i+l)),o)}var u=e[t],d=n,p=r;for(to(e,n,t),o(e[r],u)>0&&to(e,n,r);d<p;){for(to(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[n],u)?to(e,n,p):to(e,++p,r),p<=t&&(n=p+1),t<=p&&(r=p-1)}}function to(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function no(e,t){return e<t?-1:e>t?1:0}function ro(e,t,n){if(!n)return t.indexOf(e);for(let r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function oo(e,t){io(e,0,e.children.length,t,e)}function io(e,t,n,r,o){o||(o=mo(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<n;i++){const t=e.children[i];so(o,e.leaf?r(t):t)}return o}function so(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 ao(e,t){return e.minX-t.minX}function co(e,t){return e.minY-t.minY}function lo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function uo(e){return e.maxX-e.minX+(e.maxY-e.minY)}function po(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 ho(e,t){const n=Math.max(e.minX,t.minX),r=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-n)*Math.max(0,i-r)}function fo(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function go(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function mo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function yo(e,t,n,r,o){const i=[t,n];for(;i.length;){if((n=i.pop())-(t=i.pop())<=r)continue;const s=t+Math.ceil((n-t)/r/2)*r;Qr(e,s,t,n,o),i.push(t,s,s,n)}}var vo,_o=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 n=[];if(!go(e,t))return n;const r=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const s=t.children[i],a=t.leaf?r(s):s;go(e,a)&&(t.leaf?n.push(s):fo(e,a)?this._all(s,n):o.push(s))}t=o.pop()}return n}collides(e){let t=this.data;if(!go(e,t))return!1;const n=[];for(;t;){for(let r=0;r<t.children.length;r++){const o=t.children[r],i=t.leaf?this.toBBox(o):o;if(go(e,i)){if(t.leaf||fo(e,i))return!0;n.push(o)}}t=n.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=mo([]),this}remove(e,t){if(!e)return this;let n=this.data;const r=this.toBBox(e),o=[],i=[];let s,a,c;for(;n||o.length;){if(n||(n=o.pop(),a=o[o.length-1],s=i.pop(),c=!0),n.leaf){const r=ro(e,n.children,t);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}c||n.leaf||!fo(n,r)?a?(s++,n=a.children[s],c=!1):n=null:(o.push(n),i.push(s),s=0,a=n,n=n.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 n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){const o=n-t+1;let i,s=this._maxEntries;if(o<=s)return i=mo(e.slice(t,n+1)),oo(i,this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,r-1))),i=mo([]),i.leaf=!1,i.height=r;const a=Math.ceil(o/s),c=a*Math.ceil(Math.sqrt(s));yo(e,t,n,c,this.compareMinX);for(let o=t;o<=n;o+=c){const t=Math.min(o+c-1,n);yo(e,o,t,a,this.compareMinY);for(let n=o;n<=t;n+=a){const o=Math.min(n+a-1,t);i.children.push(this._build(e,n,o,r-1))}}return oo(i,this.toBBox),i}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const s=t.children[i],a=lo(s),c=po(e,s)-a;c<o?(o=c,r=a<r?a:r,n=s):c===o&&a<r&&(r=a,n=s)}t=n||t.children[0]}return t}_insert(e,t,n){const r=n?e:this.toBBox(e),o=[],i=this._chooseSubtree(r,this.data,t,o);for(i.children.push(e),so(i,r);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(r,o,t)}_split(e,t){const n=e[t],r=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,r);const i=this._chooseSplitIndex(n,o,r),s=mo(n.children.splice(i,n.children.length-i));s.height=n.height,s.leaf=n.leaf,oo(n,this.toBBox),oo(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this.data=mo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,oo(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,o=1/0,i=1/0;for(let s=t;s<=n-t;s++){const t=io(e,0,s,this.toBBox),a=io(e,s,n,this.toBBox),c=ho(t,a),l=lo(t)+lo(a);c<o?(o=c,r=s,i=l<i?l:i):c===o&&l<i&&(i=l,r=s)}return r||n-t}_chooseSplitAxis(e,t,n){const r=e.leaf?this.compareMinX:ao,o=e.leaf?this.compareMinY:co;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,o)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);const o=this.toBBox,i=io(e,0,t,o),s=io(e,n-t,n,o);let a=uo(i)+uo(s);for(let r=t;r<n-t;r++){const t=e.children[r];so(i,e.leaf?o(t):t),a+=uo(i)}for(let r=n-t-1;r>=t;r--){const t=e.children[r];so(s,e.leaf?o(t):t),a+=uo(s)}return a}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)so(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)0===e[n].children.length?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():oo(e[n],this.toBBox)}}}),xo=fe(_o),Io={};function Eo(){if(vo)return Io;vo=1,Object.defineProperty(Io,"__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},n={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 r(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function o(e,t,n={}){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 r({type:"Point",coordinates:e},t,n)}function i(e,t,n={}){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 r({type:"Polygon",coordinates:e},t,n)}function s(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return r({type:"LineString",coordinates:e},t,n)}function a(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function c(e,t,n={}){return r({type:"MultiLineString",coordinates:e},t,n)}function l(e,t,n={}){return r({type:"MultiPoint",coordinates:e},t,n)}function u(e,t,n={}){return r({type:"MultiPolygon",coordinates:e},t,n)}function d(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e*r}function p(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e/r}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Io.areaFactors=n,Io.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Io.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Io.convertArea=function(e,t="meters",r="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=n[t];if(!o)throw new Error("invalid original units");const i=n[r];if(!i)throw new Error("invalid final units");return e/o*i},Io.convertLength=function(e,t="kilometers",n="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),n)},Io.degreesToRadians=function(e){return e%360*Math.PI/180},Io.earthRadius=e,Io.factors=t,Io.feature=r,Io.featureCollection=a,Io.geometry=function(e,t,n={}){switch(e){case"Point":return o(t).geometry;case"LineString":return s(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")}},Io.geometryCollection=function(e,t,n={}){return r({type:"GeometryCollection",geometries:e},t,n)},Io.isNumber=f,Io.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Io.lengthToDegrees=function(e,t){return h(p(e,t))},Io.lengthToRadians=p,Io.lineString=s,Io.lineStrings=function(e,t,n={}){return a(e.map(e=>s(e,t)),n)},Io.multiLineString=c,Io.multiPoint=l,Io.multiPolygon=u,Io.point=o,Io.points=function(e,t,n={}){return a(e.map(e=>o(e,t)),n)},Io.polygon=i,Io.polygons=function(e,t,n={}){return a(e.map(e=>i(e,t)),n)},Io.radiansToDegrees=h,Io.radiansToLength=d,Io.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const n=Math.pow(10,t||0);return Math.round(e*n)/n},Io.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")})},Io.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")},Io}var So,Mo={};function bo(){if(So)return Mo;So=1,Object.defineProperty(Mo,"__esModule",{value:!0});var e=Eo();function t(e,n,r){if(null!==e)for(var o,i,s,a,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,m="Feature"===f,y=g?e.features.length:1,v=0;v<y;v++){c=(d=!!(u=g?e.features[v].geometry:m?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var _=0;_<c;_++){var x=0,I=0;if(null!==(a=d?u.geometries[_]:u)){l=a.coordinates;var E=a.type;switch(p=!r||"Polygon"!==E&&"MultiPolygon"!==E?0:1,E){case null:break;case"Point":if(!1===n(l,h,v,x,I))return!1;h++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===n(l[o],h,v,x,I))return!1;h++,"MultiPoint"===E&&x++}"LineString"===E&&x++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===n(l[o][i],h,v,x,I))return!1;h++}"MultiLineString"===E&&x++,"Polygon"===E&&I++}"Polygon"===E&&x++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(I=0,i=0;i<l[o].length;i++){for(s=0;s<l[o][i].length-p;s++){if(!1===n(l[o][i][s],h,v,x,I))return!1;h++}I++}x++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===t(a.geometries[o],n,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function n(e,t){var n;switch(e.type){case"FeatureCollection":for(n=0;n<e.features.length&&!1!==t(e.features[n].properties,n);n++);break;case"Feature":t(e.properties,0)}}function r(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function o(e,t){var n,r,o,i,s,a,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(n=0;n<g;n++){for(a=h?e.features[n].geometry:f?e.geometry:e,l=h?e.features[n].properties:f?e.properties:{},u=h?e.features[n].bbox:f?e.bbox:void 0,d=h?e.features[n].id:f?e.id:void 0,s=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,o=0;o<s;o++)if(null!==(i=c?a.geometries[o]:a))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(r=0;r<i.geometries.length;r++)if(!1===t(i.geometries[r],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,n){o(t,function(t,r,o,i,s){var a,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==n(e.feature.call(void 0,t,o,{bbox:i,id:s}),r,0)&&void 0}switch(c){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:a,coordinates:t.coordinates[l]};if(!1===n(e.feature.call(void 0,u,o),r,l))return!1}})}function s(n,r){i(n,function(n,o,i){var s=0;if(n.geometry){var a=n.geometry.type;if("Point"!==a&&"MultiPoint"!==a){var c,l=0,u=0,d=0;return!1!==t(n,function(t,a,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(s=0);var g=e.lineString.call(void 0,[c,t],n.properties);if(!1===r(g,o,i,f,s))return!1;s++,c=t})&&void 0}}})}function a(t,n){if(!t)throw new Error("geojson is required");i(t,function(t,r,o){if(null!==t.geometry){var i=t.geometry.type,s=t.geometry.coordinates;switch(i){case"LineString":if(!1===n(t,r,o,0,0))return!1;break;case"Polygon":for(var a=0;a<s.length;a++)if(!1===n(e.lineString.call(void 0,s[a],t.properties),r,o,a))return!1}}})}return Mo.coordAll=function(e){var n=[];return t(e,function(e){n.push(e)}),n},Mo.coordEach=t,Mo.coordReduce=function(e,n,r,o){var i=r;return t(e,function(e,t,o,s,a){i=0===t&&void 0===r?e:n(i,e,t,o,s,a)},o),i},Mo.featureEach=r,Mo.featureReduce=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},Mo.findPoint=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.coordIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":return e.point.call(void 0,l,c,n);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,n);case"LineString":return a<0&&(a=l.length+a),e.point.call(void 0,l[a],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a),e.point.call(void 0,l[s][a],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),e.point.call(void 0,l[i][a],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a),e.point.call(void 0,l[i][s][a],c,n)}throw new Error("geojson is invalid")},Mo.findSegment=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.segmentIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":case"MultiPoint":return null;case"LineString":return a<0&&(a=l.length+a-1),e.lineString.call(void 0,[l[a],l[a+1]],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a-1),e.lineString.call(void 0,[l[s][a],l[s][a+1]],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a-1),e.lineString.call(void 0,[l[i][a],l[i][a+1]],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a-1),e.lineString.call(void 0,[l[i][s][a],l[i][s][a+1]],c,n)}throw new Error("geojson is invalid")},Mo.flattenEach=i,Mo.flattenReduce=function(e,t,n){var r=n;return i(e,function(e,o,i){r=0===o&&0===i&&void 0===n?e:t(r,e,o,i)}),r},Mo.geomEach=o,Mo.geomReduce=function(e,t,n){var r=n;return o(e,function(e,o,i,s,a){r=0===o&&void 0===n?e:t(r,e,o,i,s,a)}),r},Mo.lineEach=a,Mo.lineReduce=function(e,t,n){var r=n;return a(e,function(e,o,i,s){r=0===o&&void 0===n?e:t(r,e,o,i,s)}),r},Mo.propEach=n,Mo.propReduce=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},Mo.segmentEach=s,Mo.segmentReduce=function(e,t,n){var r=n,o=!1;return s(e,function(e,i,s,a,c){r=!1===o&&void 0===n?e:t(r,e,i,s,a,c),o=!0}),r},Mo}var Po,To,Co={};function wo(){if(Po)return Co;Po=1,Object.defineProperty(Co,"__esModule",{value:!0});var e=bo();function t(t,n={}){if(null!=t.bbox&&!0!==n.recompute)return t.bbox;const r=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r}var n=t;return Co.bbox=t,Co.default=n,Co}var Lo=function(){if(To)return Wr.exports;To=1;var e=xo,t=Eo(),n=bo(),r=wo().default,o=n.featureEach;n.coordEach,t.polygon;var i=t.featureCollection;function s(t){var n=new e(t);return n.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.insert.call(this,t)},n.load=function(t){var n=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}),e.prototype.load.call(this,n)},n.remove=function(t,n){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.remove.call(this,t,n)},n.clear=function(){return e.prototype.clear.call(this)},n.search=function(t){var n=e.prototype.search.call(this,this.toBBox(t));return i(n)},n.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},n.all=function(){var t=e.prototype.all.call(this);return i(t)},n.toJSON=function(){return e.prototype.toJSON.call(this)},n.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},n.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=r(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=r(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},n}return Wr.exports=s,Wr.exports.default=s,Wr.exports}(),Oo=he(Lo);function Ao(e,t){var n={},r=[];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=ko(e,t);return o&&r.push(o),I(r)}var i=Oo();return i.load(zr(t)),S(zr(e),function(e){S(i.search(e),function(t){var o=ko(e,t);if(o){var i=Hr(o).join(",");n[i]||(n[i]=!0,r.push(o))}})}),I(r)}function ko(e,t){var n=Hr(e),r=Hr(t);if(2!==n.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==r.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=n[0][0],i=n[0][1],s=n[1][0],a=n[1][1],c=r[0][0],l=r[0][1],u=r[1][0],d=r[1][1],p=(d-l)*(s-o)-(u-c)*(a-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(s-o)*(i-l)-(a-i)*(o-c);if(0===p)return null;var m=h/p,y=f/p;return m>=0&&m<=1&&y>=0&&y<=1?g([o+m*(s-o),i+m*(a-i)]):null}function Fo(e,t,n){void 0===n&&(n={});var r=g([1/0,1/0],{dist:1/0}),o=0;return x(e,function(e){for(var i=Hr(e),s=0;s<i.length-1;s++){var a=g(i[s]);a.properties.dist=Yr(t,a,n);var c=g(i[s+1]);c.properties.dist=Yr(t,c,n);var l=Yr(a,c,n),u=Math.max(a.properties.dist,c.properties.dist),d=qr(a,c),p=Zr(t,u,d+90,n),h=Zr(t,u,d-90,n),f=Ao(_([p.geometry.coordinates,h.geometry.coordinates]),_([a.geometry.coordinates,c.geometry.coordinates])),m=null;f.features.length>0&&((m=f.features[0]).properties.dist=Yr(t,m,n),m.properties.location=o+Yr(a,m,n)),a.properties.dist<r.properties.dist&&((r=a).properties.index=s,r.properties.location=o),c.properties.dist<r.properties.dist&&((r=c).properties.index=s+1,r.properties.location=o+l),m&&m.properties.dist<r.properties.dist&&((r=m).properties.index=s),o+=l}}),r}function Vo(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 No(e,t){var n=function(e,t,n,r){void 0===r&&(r={});var o=Vo(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return g([d,h],r.properties)}(e,function(e,t,n){void 0===n&&(n={});var r=Vo(e),o=Vo(t),i=p(o[1]-r[1]),s=p(o[0]-r[0]),a=p(r[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}(e,t)/2,qr(e,t));return n}var Do=function(){return Do=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Do.apply(this,arguments)},Ro=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=[],n=0;n<e.features.length;n++){var r=e.features[n],o=r.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var s=this.features.unknow.snapPoints;i=Do(Do({},i),s)}var a=this.doSnap(r,i);t.push(a)}else if(void 0!==this.features.unknow){s=this.features.unknow.snapPoints,a=this.doSnap(r,s);t.push(a)}else t.push(r)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Yr(g(e),g(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var n=e.geometry.coordinates;for(var r in t)this.isPointSnapped(n,t[r])&&(e.geometry.coordinates=t[r]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],s=0;s<o.length;s++){for(var a=o[s],c=[],l=0;l<a.length;l++){var u=a[l],d=!1;for(var r in t)if(this.isPointSnapped(u,t[r])){d=!0,c.push(t[r]);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 r in t)if(this.isPointSnapped(h,t[r])){d=!0,c.push(t[r]);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,n=this.map.unproject(t),r=[t.x+this.options.radius,t.y],o=this.map.unproject(r),i=Yr(g([n.lng,n.lat]),g([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var s=!1,a=this.getCloseFeatures(e,i);a?(this.snapStatus=!0,this.snapCoords=a.coords,s=function(e,t,n={}){const r=n.steps||64,o=n.properties?n.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<r;o++)i.push($r(e,t,-360*o/r,n).geometry.coordinates);return i.push(i[0]),y([i],o)}(a.coords,i,{steps:64,units:"meters",properties:{color:a.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=I(0==s?[]:[s]);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(I([])))}),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 n=e.map.getSource("mapbox-gl-draw-hot");if(n){var r=n._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];r.features.length>0&&(r.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]],n=t[0].toFixed(6),r=t[1].toFixed(6),o={};if(o["".concat(n,"_").concat(r)]=t,e){var i=e._data;if(i.features.length>0){var s=i.features.find(function(e){return"feature"==e.properties.meta});if(s){var a=s.properties.id;this.features[a]?this.features[a].snapPoints["".concat(n,"_").concat(r)]=t:this.features[a]={id:a,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(n,"_").concat(r)]=t:this.features.unknow={id:a,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,n){var r=M(e),o=[];if(r.map(function(e){var r=Yr(g(e),g([t.lng,t.lat]),{units:"meters"});r<n&&o.push({coords:e,dist:r,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,n){var r=[];switch(e.geometry.type){case"LineString":r.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){r.push(_(e))});break;case"Polygon":var o=Kr(e.geometry);r.push(o);break;case"MultiPolygon":Kr(e.geometry).coodinates.map(function(e){r.push(_(e))})}return r},e.prototype.searchInMidPoint=function(e,t,n){var r=this.getLines(e,t,n),o=[];r.map(function(e){o=o.concat(zr(e).features)});var i=[];if(o.map(function(e){var r=No(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Yr(r,g([t.lng,t.lat]),{units:"meters"});o<n&&i.push({coords:r.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,n){for(var r=this.getLines(e,t,n),o=[],i=0;i<r.length;i++){var s=Fo(r[i],g([t.lng,t.lat]),{units:"meters"});void 0!==s.properties.dist&&s.properties.dist<n&&o.push({coords:s.geometry.coordinates,dist:s.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 n=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(n.length>0){for(var r,o=!1,i=0;i<n.length;i++){var s=n[i],a=this.options.rules,c=e.lngLat;if(o=!1,-1!==a.indexOf("vertex")&&null==r&&(r=this.searchInVertex(s,c,t))){o=!0;break}if(-1!==a.indexOf("midpoint")&&null==r&&(r=this.searchInMidPoint(s,c,t))){o=!0;break}if(-1!==a.indexOf("edge")&&null==r&&(r=this.searchInEdge(s,c,t))){o=!0;break}}return!!o&&r}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}();const Uo="snap-helper-circle",Bo="mapbox-gl-draw-hot";function jo(e){if(Ro.prototype.__snapPatched)return;Ro.prototype.__snapPatched=!0;const t=Ro.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){if(!this.status)return;const n=t.setMapData.call(this,e);return e?.features?.length>0&&this.map?.getLayer(Uo)&&this.map.setLayoutProperty(Uo,"visibility","visible"),n},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,n,r){const o=e.geometry;if(!o?.coordinates)return[];const 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=>y(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>_(e)):t.getLines.call(this,e,n,r)}catch{return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];const o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));const i=this.options.radius||n.snapRadius,s=e.point;e.point=[[s.x-i,s.y-i],[s.x+i,s.y+i]];const a=t.getCloseFeatures.call(this,e,r);return e.point=s,a}}(t,r),function(e,t,n){e.searchInVertex=function(...e){const r=t.searchInVertex.apply(this,e);return r&&(r.color=n.vertex),r},e.searchInMidPoint=function(...e){const r=t.searchInMidPoint.apply(this,e);return r&&(r.color=n.midpoint),r},e.searchInEdge=function(...e){const r=t.searchInEdge.apply(this,e);return r&&(r.color=n.edge),r}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){if(this.status&&!this.map?._isZooming&&(!this._autoSnapSuspended||e._explicit))try{const n=t.snapToClosestPoint.call(this,e);return this.closeFeatures?.length>100&&(this.closeFeatures.length=0),this.lines?.length>100&&(this.lines.length=0),n}catch{return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}function Go(e,t){!function n(){const r=e();null!==r&&(r?t(r):requestAnimationFrame(n))}()}function Ho(e){if(!e||e._data&&Array.isArray(e._data?.features))return;let t={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>t,set:e=>{t=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}const Yo=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Xo(e,t,n,r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(Uo)&&e.removeLayer(Uo),e.getSource(Uo)&&e.removeSource(Uo)}(e),Ho(n);const o=new Ro({map:e,drawing:t,options:{layers:r.layers,radius:r.radius,rules:r.rules},status:r.status,onSnapped:r.onSnapped});return function(e,t,n){let r=t;Object.defineProperty(e,"status",{get:()=>r&&Yo.has(n.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{r=e}}(o,r.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,r.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function $o(e,t,n){e.on("style.load",()=>{Go(()=>e._removed?null:e.getSource(Bo),r=>{Ho(r),function(e){e.getSource(Uo)||e.addSource(Uo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Uo)||e.addLayer({id:Uo,type:"fill",source:Uo,paint:{"fill-color":["get","color"]},layout:{visibility:e._snapInstance?.status?"visible":"none"}})}(e),e._snapInstance||Xo(e,t,r,n)})})}function Ko(e,t,r={}){if(e._snapInitialized)return e._snapInstance;e._snapInitialized=!0;const{layers:o=[],radius:i=n.snapRadius,rules:s=["vertex","midpoint","edge"],status:a=!1,onSnapped:c=()=>{},colors:l={}}=r,u={layers:o,radius:i,rules:s,status:a,onSnapped:c};return jo({vertex:b.snapVertex,midpoint:b.snapMidpoint,edge:b.snapEdge,...l}),$o(e,t,u),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(Uo)){e.setLayoutProperty(Uo,"visibility","none");const t=e._snapInstance;t?.status&&e.setLayoutProperty(Uo,"visibility","visible")}})}(e),Go(()=>e._removed?null:e.getSource(Bo),n=>Xo(e,t,n,u)),e._snapInstance}const Jo="point-symbol",qo=new Set([`${Jo}.hot`,`${Jo}.cold`]),Zo=(e,t)=>{const n=(e=>{const t=["match",["get","user_symbolImageId"]];for(const[n,r]of Object.entries(e))t.push(n,["literal",r]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);t.options?.styles?.forEach(e=>{qo.has(e.id)&&(e.layout={...e.layout,"icon-offset":n})}),qo.forEach(t=>{e.getLayer(t)&&e.setLayoutProperty(t,"icon-offset",n)})},zo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:o,properties:i,pixelRatioOverride:s})=>{if(!F(i))return null;const a=n._drawCurrentMapStyle,c=s??(e=>e.getPixelRatio?.()||1)(n);await t.addSymbolsToMap([i],a,r,c);const l=e.get(o);if(!l)return null;const u=r.getSymbolImageId(i,a,"normal",c);if(!u)return null;const d=t.getActiveSymbolImageId(u),p=t.getSelectedSymbolImageId(u),h=t.getSymbolIconLayout(r.getSymbolDef(i));return((e,t,n,r)=>{e._symbolIconOffsetMap??={},e._symbolIconOffsetMap[n]||(e._symbolIconOffsetMap[n]=r,Zo(e,t))})(n,e,u,h["icon-offset"]),{...l,properties:{...i,symbolImageId:u,symbolIconAnchor:h["icon-anchor"],symbolActiveImageId:d,symbolSelectedImageId:p}}},Wo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,pixelRatioOverride:o})=>{n._pointSymbolRefreshId=(n._pointSymbolRefreshId??0)+1;const i=n._pointSymbolRefreshId,s=e.getAll().features.filter(e=>"Point"===e.geometry.type&&F(e.properties)),a=await Promise.allSettled(s.map(i=>zo({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:i.id,properties:i.properties,pixelRatioOverride:o})));if(a.filter(e=>"rejected"===e.status).forEach(e=>{P.error("[draw] failed to resolve point symbol",e.reason)}),n._pointSymbolRefreshId!==i)return;const c=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);c.length&&e.add({type:"FeatureCollection",features:c}),((e,t)=>{const n=e._symbolIconOffsetMap;if(!n)return;const r=new Set(t.getAll().features.map(e=>e.properties?.symbolImageId)),o=Object.keys(n).filter(e=>!r.has(e));o.length&&(o.forEach(e=>delete n[e]),Zo(e,t))})(n,e)},Qo="mapbox-gl-draw-cold",ei="mapbox-gl-draw-hot",ti=({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,onDone:i})=>{const s=e._drawCurrentMapStyle;e.once("idle",()=>{const a=((e,t)=>{if(e.getSource(Qo))return!1;const n={type:"FeatureCollection",features:[]};return e.addSource(Qo,{data:n,type:"geojson"}),e.addSource(ei,{data:n,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(e,t);((e,t,n={})=>{jr(t,n).forEach(t=>{Object.entries(t.paint).forEach(([n,r])=>{e.getLayer(`${t.id}.cold`)&&e.setPaintProperty(`${t.id}.cold`,n,r),e.getLayer(`${t.id}.hot`)&&e.setPaintProperty(`${t.id}.hot`,n,r)})})})(e,s,o);const c=e._drawEditContainer?.querySelector("[data-im-draw-touch-target]");Hn(c,s,o),Wo({draw:t,mapProvider:n,map:e,symbolRegistry:r}).then(()=>{a&&t.set(t.getAll()),e.triggerRepaint(),i()}).catch(e=>P.error("[draw] failed to refresh point symbols after a style change",e))})},ni=({mapStyle:e,mapProvider:t,symbolRegistry:r,events:o,eventBus:i,snapLayers:s,pluginConfig:a={}})=>{const{map:c}=t;zt.constants.classes.CONTROL_BASE="maplibregl-ctrl",zt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",zt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";const l={...zt.modes,disabled:Wt,edit_vertex:nr,edit_point:cr,draw_polygon:Er,draw_line:Sr,draw_point:Cr};let u=t._mapboxDrawInstance;u?Object.assign(u.modes,l):(u=new zt({modes:l,styles:jr(e,a),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),c.addControl(u),t._mapboxDrawInstance=u);const d=((e,t)=>{const n=e.getCanvas();let r=null;const o=e=>{1===e.touches.length&&(r={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"!==t.getMode()||!r)return void(r=null);const o=e.changedTouches[0],i=o.clientX-r.x,s=o.clientY-r.y;Date.now()-r.time<300&&Math.abs(i)<10&&Math.abs(s)<10&&n.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),r=null};return n.addEventListener("touchstart",o,{passive:!0}),n.addEventListener("touchend",i,{passive:!0}),{remove(){n.removeEventListener("touchstart",o),n.removeEventListener("touchend",i)}}})(c,u);t.draw=u,c._drawCurrentMapStyle=e,c._drawPluginConfig=a,t.snapEnabled=!1;let p=t.undoStack;p||(p=V(e=>c.fire("draw.undochange",{length:e})),t.undoStack=p),c._undoStack=p;const h=L(e,a);Ko(c,u,{layers:s,radius:a.snapRadius??n.snapRadius,rules:["vertex","edge"],colors:{vertex:h.snapVertex,edge:h.snapEdge}});const f=()=>i.emit(o.MAP_DATA_CHANGE),{handleSetMapStyle:g,handleStyleChanged:m}=(({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,eventBus:i,events:s,notifyPointSymbolsRefreshed:a})=>{const c=t=>{e._drawCurrentMapStyle=t};i.on(s.MAP_SET_STYLE,c);let l=!1;const u=()=>{l||(l=!0,ti({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,onDone:()=>{l=!1,a()}}))};return i.on(s.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:c,draw:u,mapProvider:t,symbolRegistry:r,pluginConfig:a,eventBus:i,events:o,notifyPointSymbolsRefreshed:f}),y=e=>{c.fire("draw.scalechange",{scale:T[e]})};i.on(o.MAP_SET_SIZE,y);const v=e=>{Wo({draw:u,mapProvider:t,map:c,symbolRegistry:r,pixelRatioOverride:e}).then(()=>{c.triggerRepaint(),f()}).catch(e=>P.error("[draw] failed to refresh point symbols",e))};return i.on(o.MAP_SET_PIXEL_RATIO,v),{draw:u,remove(){d.remove(),i.off(o.MAP_SET_STYLE,g),i.off(o.MAP_STYLE_CHANGE,m),i.off(o.MAP_SET_SIZE,y),i.off(o.MAP_SET_PIXEL_RATIO,v),u.changeMode("disabled"),t.draw=null}}},ri=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),oi=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),ii=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),si=(e,t)=>{if("draw_polygon"===e)return{feature:ri(t),numVertices:(t[0]?.length??1)-1};if("draw_line"===e)return{feature:oi(t),numVertices:(t?.length??1)-1};if("edit_vertex"===e){const e=t[0];return Array.isArray(e?.[0])?{feature:ri(t),numVertices:e.length}:{feature:oi(t),numVertices:t?.length??0}}return"edit_point"===e?{feature:ii(t),numVertices:1}:null};class ai{constructor(e,t){this._mapProvider=e,this._map=e.map,this._symbolRegistry=t.symbolRegistry,this._bus=(()=>{const e=new Map;return{on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)},emit(t,...n){const r=e.get(t);r&&Array.from(r).forEach(e=>e(...n))}}})(),this._editingFeatureId=null,this._sortKeyCounter=0;const{draw:n,remove:r}=ni({mapStyle:t.mapStyle,mapProvider:e,symbolRegistry:t.symbolRegistry,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:t.pluginConfig??{}});this._draw=n,this._cleanupDraw=r,this._liveStroke=N({onChange:(e,t)=>{this._applyStrokeInvalid(e);const n=this._draw.getMode();"edit_vertex"!==n&&"edit_point"!==n||this._bus.emit(C.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=D({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(C.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{const t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(C.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(C.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(C.CANCEL),vertexselection:e=>this._bus.emit(C.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(C.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(C.UNDO_CHANGE,e.length),update:e=>this._bus.emit(C.UPDATE,e.features[0]),geometrychange:e=>{e?.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(C.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(C.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(C.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(Qt,this._mapHandlers.create),this._map.on(nn,this._mapHandlers.editfinish),this._map.on(rn,this._mapHandlers.cancel),this._map.on(on,this._mapHandlers.vertexselection),this._map.on(sn,this._mapHandlers.vertexchange),this._map.on(an,this._mapHandlers.undochange),this._map.on(en,this._mapHandlers.update),this._map.on(ln,this._mapHandlers.geometrychange),this._map.on(dn,this._mapHandlers.placementblocked),this._map.on(un,this._mapHandlers.interfacetypechange),this._map.on(tn,this._mapHandlers.modechange),this._map.on(mn,this._mapHandlers.styledata)}changeMode(e,t={}){"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=t.featureId??null),"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(t={...t,resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)}),this._draw.changeMode(e,t),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){(async e=>{const t=await zo(e);t&&e.draw.add(t)})({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>P.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(!e?.coordinates)return;const t=this._draw.getMode(),n=si(t,e.coordinates);n&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:n.feature,numVertices:n.numVertices,context:{mode:t},onGeometryPreview:this._previewValidator}):this._liveStroke.update({...n,context:{mode:t},onGeometryPreview:this._previewValidator}))}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(un,{interfaceType:e})}done(){this._mapProvider.undoStack?.clear();const e=this._draw.getMode();if(("edit_vertex"===e||"edit_point"===e)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(nn,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==e&&"draw_line"!==e||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){this._mapProvider.undoStack?.clear();const e=this._draw.getMode();"draw_polygon"!==e&&"draw_line"!==e||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(cn)}nudgeSelectedVertex(e,t,n){this._map.fire(pn,{dx:e,dy:t,isLargeStep:n})}getVertexItems(){const e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;const t=this._draw.get(this._editingFeatureId);if(!t)return e;const n=(e=>"Polygon"===e.type?{...e,coordinates:e.coordinates.map(e=>e.slice(0,-1))}:"MultiPolygon"===e.type?{...e,coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}:e)(t.geometry);return{vertices:yn(n),midpoints:vn(n)}}selectVertex(e){this._map.fire(hn,{index:e})}insertVertexAtMidpoint(e){this._map.fire(fn,{index:e})}setGeometry(e){this._map.fire(gn,{geometry:e})}setCanFinish(e){this._map._drawCanFinish=e}set _previewValidator(e){this._map._drawPreviewValidator=e}get _previewValidator(){return this._map._drawPreviewValidator}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(n=>{const r=`${e}.${n}`;this._map.getLayer(r)&&this._map.setLayoutProperty(r,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){const t=null==e.properties?.sortKey?{...e.properties,sortKey:this._nextSortKey()}:e.properties,n={...e,properties:t},r=this._draw.add(n);return"Point"===n.geometry?.type&&F(t)&&this._resolvePointSymbol(r[0],t),r}setStyle(e,t){const n=this._draw.get(e);n&&this.add({...n,properties:{...n.properties,...t}})}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;const t=bn(this._map);t?.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(An(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){const t=bn(this._map);t?.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,n){this._draw.setFeatureProperty(e,t,n)}setDrawingPreviewProperty(e,t){const n=this._currentDrawEvent;n?.properties&&(n.properties[e]=t),n?.ctx?.store?.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)||On(bn(this._map),this._map)}_handleStyleData(){const e=this._map.getStyle();if(!e)return;this._liveStroke.refresh();const t=e.layers||[];t.length&&!t[t.length-1].source?.startsWith("mapbox-gl-draw")&&t.filter(e=>e.source?.startsWith("mapbox-gl-draw")).forEach(e=>this._map.moveLayer(e.id))}remove(){this._map.off(Qt,this._mapHandlers.create),this._map.off(nn,this._mapHandlers.editfinish),this._map.off(rn,this._mapHandlers.cancel),this._map.off(on,this._mapHandlers.vertexselection),this._map.off(sn,this._mapHandlers.vertexchange),this._map.off(an,this._mapHandlers.undochange),this._map.off(en,this._mapHandlers.update),this._map.off(ln,this._mapHandlers.geometrychange),this._map.off(dn,this._mapHandlers.placementblocked),this._map.off(un,this._mapHandlers.interfacetypechange),this._map.off(tn,this._mapHandlers.modechange),this._map.off(mn,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{ai as MaplibreDrawAdapter,si as displayedShape};