@defra/interactive-map 0.0.43-alpha → 0.0.44-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 (159) hide show
  1. package/dist/css/index.css +1 -1
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api.md +16 -8
  7. package/docs/plugins/draw.md +1 -1
  8. package/package.json +1 -1
  9. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  10. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  11. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  12. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  13. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  14. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  15. package/plugins/datasets/dist/css/index.css +1 -1
  16. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  17. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  18. package/plugins/datasets/src/components/LayersMenu/Layers.module.scss +1 -0
  19. package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
  20. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +6 -5
  21. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  22. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  23. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  24. package/plugins/draw/dist/esm/index.js +1 -1
  25. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  26. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  27. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  28. package/plugins/draw/dist/umd/index.js +1 -1
  29. package/plugins/draw/src/DrawInit.jsx +31 -26
  30. package/plugins/draw/src/DrawInit.test.jsx +55 -12
  31. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +113 -114
  32. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +82 -9
  33. package/plugins/draw/src/adapters/maplibre/drawEvents.js +3 -1
  34. package/plugins/draw/src/adapters/maplibre/modes/createDrawMode.test.js +1 -1
  35. package/plugins/draw/src/adapters/maplibre/modes/drawMode/__helpers__/harness.js +18 -9
  36. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +9 -1
  37. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +11 -1
  38. package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.js +8 -2
  39. package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.test.js +35 -0
  40. package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.js +29 -19
  41. package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.test.js +17 -2
  42. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +1 -1
  43. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +35 -29
  44. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +24 -6
  45. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/keyboardHandlers.js +22 -20
  46. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointOperations.js +1 -1
  47. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +2 -2
  48. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.test.js +3 -3
  49. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/geometryHelpers.js +31 -0
  50. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/geometryHelpers.test.js +8 -1
  51. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.js +38 -30
  52. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.test.js +20 -3
  53. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +5 -5
  54. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.js +2 -2
  55. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.test.js +2 -2
  56. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +3 -3
  57. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +7 -7
  58. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.js +4 -4
  59. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.test.js +14 -14
  60. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexQueries.js +12 -32
  61. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexQueries.test.js +10 -10
  62. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +48 -22
  63. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.test.js +74 -6
  64. package/plugins/draw/src/adapters/maplibre/utils/snapMovement.js +2 -2
  65. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +6 -0
  66. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +9 -0
  67. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +15 -2
  68. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +27 -1
  69. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +1 -1
  70. package/plugins/draw/src/adapters/openlayers/draw/drawInput.js +31 -17
  71. package/plugins/draw/src/adapters/openlayers/draw/drawInput.test.js +55 -1
  72. package/plugins/draw/src/adapters/openlayers/draw/vertexPlacement.js +13 -7
  73. package/plugins/draw/src/adapters/openlayers/draw/vertexPlacement.test.js +7 -15
  74. package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +36 -4
  75. package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +41 -1
  76. package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.js +35 -25
  77. package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.test.js +40 -2
  78. package/plugins/draw/src/adapters/openlayers/edit/nudge.js +2 -2
  79. package/plugins/draw/src/adapters/openlayers/edit/nudge.test.js +2 -2
  80. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +32 -57
  81. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +14 -13
  82. package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +1 -1
  83. package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +17 -1
  84. package/plugins/draw/src/events.js +4 -4
  85. package/plugins/draw/src/events.test.js +1 -1
  86. package/plugins/draw/src/hooks/useSpatialList.js +180 -0
  87. package/plugins/draw/src/hooks/useSpatialList.test.js +339 -0
  88. package/plugins/draw/src/utils/spatial.js +1 -31
  89. package/plugins/draw/src/utils/spatial.test.js +1 -24
  90. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  91. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  92. package/plugins/interact/dist/umd/index.js +1 -1
  93. package/plugins/interact/src/InteractInit.jsx +2 -2
  94. package/plugins/interact/src/InteractInit.test.js +3 -3
  95. package/plugins/interact/src/events.js +5 -0
  96. package/plugins/interact/src/hooks/useAttachEvents.js +20 -0
  97. package/plugins/interact/src/hooks/useAttachEvents.test.js +44 -1
  98. package/plugins/interact/src/hooks/useCrossHairVisibility.js +4 -4
  99. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +7 -7
  100. package/plugins/interact/src/hooks/{useMapItemList.js → useSpatialList.js} +87 -52
  101. package/plugins/interact/src/hooks/{useMapItemList.test.js → useSpatialList.test.js} +152 -71
  102. package/plugins/interact/src/manifest.js +12 -1
  103. package/plugins/interact/src/manifest.test.js +20 -0
  104. package/plugins/interact/src/utils/spatial.js +1 -1
  105. package/providers/beta/openlayers/src/utils/queryFeatures.js +1 -1
  106. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  107. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  108. package/providers/maplibre/dist/umd/index.js +1 -1
  109. package/providers/maplibre/src/utils/labels.js +2 -2
  110. package/providers/maplibre/src/utils/labels.test.js +5 -5
  111. package/providers/maplibre/src/utils/spatial.js +0 -57
  112. package/providers/maplibre/src/utils/spatial.test.js +0 -27
  113. package/src/App/components/CrossHair/CrossHair.jsx +10 -4
  114. package/src/App/components/CrossHair/CrossHair.module.scss +16 -12
  115. package/src/App/components/CrossHair/CrossHair.test.jsx +9 -4
  116. package/src/App/components/Hints/Hints.jsx +3 -3
  117. package/src/App/components/Hints/Hints.test.jsx +3 -3
  118. package/src/App/components/MapButton/MapButton.module.scss +1 -2
  119. package/src/App/components/{MoveControls/MoveControls.jsx → MapControls/MapControls.jsx} +10 -10
  120. package/src/App/components/{MoveControls/MoveControls.module.scss → MapControls/MapControls.module.scss} +25 -25
  121. package/src/App/components/{MoveControls/MoveControls.test.jsx → MapControls/MapControls.test.jsx} +48 -48
  122. package/src/App/components/Markers/Markers.jsx +2 -2
  123. package/src/App/components/Markers/Markers.test.jsx +3 -3
  124. package/src/App/components/Markers/SymbolMarker.test.jsx +2 -2
  125. package/src/App/components/Viewport/MapStatus.jsx +1 -1
  126. package/src/App/components/Viewport/SpatialList.jsx +47 -0
  127. package/src/App/components/Viewport/{Features.module.scss → SpatialList.module.scss} +3 -3
  128. package/src/App/components/Viewport/{Features.test.jsx → SpatialList.test.jsx} +60 -43
  129. package/src/App/components/Viewport/Viewport.jsx +20 -10
  130. package/src/App/components/Viewport/Viewport.test.jsx +18 -2
  131. package/src/App/hooks/useCrossHairAPI.js +5 -5
  132. package/src/App/hooks/useCrossHairAPI.test.js +5 -5
  133. package/src/App/hooks/useHintsAPI.js +5 -5
  134. package/src/App/hooks/useSpatialListFocus.js +296 -0
  135. package/src/App/hooks/{useFeatureFocus.test.js → useSpatialListFocus.test.js} +318 -163
  136. package/src/App/hooks/useSpatialListItems.js +51 -0
  137. package/src/App/hooks/useSpatialListItems.test.js +217 -0
  138. package/src/App/initialiseApp.js +6 -3
  139. package/src/App/initialiseApp.test.js +11 -0
  140. package/src/App/registry/spatialListRegistry.js +104 -0
  141. package/src/App/registry/spatialListRegistry.test.js +218 -0
  142. package/src/App/store/AppProvider.jsx +3 -2
  143. package/src/config/appConfig.js +14 -14
  144. package/src/config/appConfig.test.js +19 -19
  145. package/src/config/defaults.js +2 -2
  146. package/src/config/events.js +8 -8
  147. package/src/scss/main.scss +2 -2
  148. package/src/test-utils.js +8 -0
  149. package/src/types.js +11 -9
  150. package/src/utils/findNearestItemInDirection.js +29 -0
  151. package/src/utils/findNearestItemInDirection.test.js +67 -0
  152. package/src/utils/globalAltShortcuts.js +12 -0
  153. package/src/utils/globalAltShortcuts.test.js +27 -0
  154. package/src/utils/spatialNavigate.js +49 -0
  155. package/src/utils/spatialNavigate.test.js +42 -0
  156. package/src/App/components/Viewport/Features.jsx +0 -49
  157. package/src/App/hooks/useFeatureFocus.js +0 -257
  158. package/src/App/hooks/useFeatureItems.js +0 -39
  159. package/src/App/hooks/useFeatureItems.test.js +0 -155
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,S as o,C as i,K as a,M as s,s as c,v as l,a as u,b as d,d as p,e as h,r as f,l as g,p as y,f as m,g as v,m as b,h as _,j as x,k as O,n as P,o as E,q as S,t as w,u as I,w as C,L as M,H as T,A as L}from"./im-draw-plugin.js";import k from"@babel/runtime/helpers/asyncToGenerator";const A={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},j={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},V={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},F={POLYGON:"polygon",LINE:"line_string",POINT:"point"},D={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},N={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},R={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},U={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},B={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},G={ACTIVE:"true",INACTIVE:"false"},H=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var Y=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:G,classes:A,cursors:V,events:R,geojsonTypes:D,interactions:H,meta:B,modes:N,sources:j,types:F,updateActions:U});function X(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function K(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function J(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===G.ACTIVE&&e.featureTarget.properties.meta===B.FEATURE))}function $(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===G.INACTIVE&&e.featureTarget.properties.meta===B.FEATURE))}function q(e){return void 0===e.featureTarget}function z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===B.FEATURE)}function Z(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===B.VERTEX)}function W(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function Q(e){return"Escape"===e.key||27===e.keyCode}function ee(e){return"Enter"===e.key||13===e.keyCode}function te(e){return"Backspace"===e.key||8===e.keyCode}function re(e){return"Delete"===e.key||46===e.keyCode}function ne(e){return"1"===e.key||49===e.keyCode}function oe(e){return"2"===e.key||50===e.keyCode}function ie(e){return"3"===e.key||51===e.keyCode}function ae(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var se=Object.freeze({__proto__:null,isActiveFeature:J,isBackspaceKey:te,isDeleteKey:re,isDigit1Key:ne,isDigit2Key:oe,isDigit3Key:ie,isDigitKey:ae,isEnterKey:ee,isEscapeKey:Q,isFeature:z,isInactiveFeature:$,isOfMetaType:X,isShiftDown:W,isShiftMousedown:K,isTrue:function(){return!0},isVertex:Z,noTarget:q});function ce(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function le(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var ue,de,pe={},he={};function fe(){return ue||(ue=1,he.RADIUS=6378137,he.FLATTENING=1/298.257223563,he.POLAR_RADIUS=6356752.3142),he}var ge=function(){if(de)return pe;de=1;var e=fe();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(r(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(r(e[n]))}return t}function r(t){var r,o,i,a,s,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,a=u-1,s=0):c===u-1?(i=u-1,a=0,s=1):(i=c,a=c+1,s=c+2),r=t[i],o=t[a],l+=(n(t[s][0])-n(r[0]))*Math.sin(n(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function n(e){return e*Math.PI/180}return pe.geometry=function e(r){var n,o=0;switch(r.type){case"Polygon":return t(r.coordinates);case"MultiPolygon":for(n=0;n<r.coordinates.length;n++)o+=t(r.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<r.geometries.length;n++)o+=e(r.geometries[n]);return o}},pe.ring=r,pe}(),ye=ce(ge);const me={Point:0,LineString:1,MultiLineString:1,Polygon:2};function ve(e,t){const r=me[e.geometry.type]-me[t.geometry.type];return 0===r&&e.geometry.type===D.POLYGON?e.area-t.area:r}function be(e){return e.map(e=>(e.geometry.type===D.POLYGON&&(e.area=ye.geometry({type:D.FEATURE,property:{},geometry:e.geometry})),e)).sort(ve).map(e=>(delete e.area,e))}function _e(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function xe(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}xe.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},xe.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},xe.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},xe.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((e,t)=>e.v-t.v).map(e=>e.k)},xe.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Oe=[B.FEATURE,B.MIDPOINT,B.VERTEX];var Pe={click:function(e,t,r){return Ee(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Ee(e,t,r,r.options.touchBuffer)}};function Ee(e,t,r,n){if(null===r.map)return[];const o=e?_e(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==Oe.indexOf(e.properties.meta)),s=new xe,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),be(c)}function Se(e,t){const r=Pe.click(e,null,t),n={mouse:V.NONE};return r[0]&&(n.mouse=r[0].properties.active===G.ACTIVE?V.MOVE:V.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=V.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function we(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function Ie(e,t,r={}){const n=null!=r.fineTolerance?r.fineTolerance:4,o=null!=r.grossTolerance?r.grossTolerance:12,i=null!=r.interval?r.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const a=we(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Ce(e,t,r={}){const n=null!=r.tolerance?r.tolerance:25,o=null!=r.interval?r.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return we(e.point,t.point)<n&&t.time-e.time<o}const Me=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===r[e])throw new Error(`Invalid event type: ${e}`);r[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=r[e];let a=i.length;for(;a--;){const e=i[a];if(e.selector(o)){e.fn.call(n,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const Te=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Le(){return Te()}const ke=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Le(),this.type=t.geometry.type};ke.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ke.prototype.incomingCoords=function(e){this.setCoordinates(e)},ke.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ke.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ke.prototype.setProperty=function(e,t){this.properties[e]=t},ke.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:D.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ke.prototype.internal=function(e){const t={id:this.id,meta:B.FEATURE,"meta:type":this.type,active:G.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:D.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ae=function(e,t){ke.call(this,e,t)};(Ae.prototype=Object.create(ke.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ae.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},Ae.prototype.getCoordinate=function(){return this.getCoordinates()};const je=function(e,t){ke.call(this,e,t)};(je.prototype=Object.create(ke.prototype)).isValid=function(){return this.coordinates.length>1},je.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},je.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},je.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},je.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ve=function(e,t){ke.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ve.prototype=Object.create(ke.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ve.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ve.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ve.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(e=>parseInt(e,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},Ve.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},Ve.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},Ve.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ve.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const Fe={MultiPoint:Ae,MultiLineString:je,MultiPolygon:Ve},De=(e,t,r,n,o)=>{const i=r.split("."),a=parseInt(i[0],10),s=i[1]?i.slice(1).join("."):null;return e[a][t](s,n,o)},Ne=function(e,t){if(ke.call(this,e,t),delete this.coordinates,this.model=Fe[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function Re(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ne.prototype=Object.create(ke.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Le(),type:D.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ne.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ne.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ne.prototype.getCoordinate=function(e){return De(this.features,"getCoordinate",e)},Ne.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===D.POLYGON?e.getCoordinates():e.coordinates)))},Ne.prototype.updateCoordinate=function(e,t,r){De(this.features,"updateCoordinate",e,t,r),this.changed()},Ne.prototype.addCoordinate=function(e,t,r){De(this.features,"addCoordinate",e,t,r),this.changed()},Ne.prototype.removeCoordinate=function(e){De(this.features,"removeCoordinate",e),this.changed()},Ne.prototype.getFeatures=function(){return this.features},Re.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Re.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Re.prototype.getSelected=function(){return this._ctx.store.getSelected()},Re.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Re.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Re.prototype.getFeature=function(e){return this._ctx.store.get(e)},Re.prototype.select=function(e){return this._ctx.store.select(e)},Re.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Re.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Re.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Re.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Re.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Re.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Re.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Re.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Re.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Re.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Re.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return Pe[r](e,t,this._ctx)},Re.prototype.newFeature=function(e){const t=e.geometry.type;return t===D.POINT?new Ae(this._ctx,e):t===D.LINE_STRING?new je(this._ctx,e):t===D.POLYGON?new Ve(this._ctx,e):new Ne(this._ctx,e)},Re.prototype.isInstanceOf=function(e,t){if(e===D.POINT)return t instanceof Ae;if(e===D.LINE_STRING)return t instanceof je;if(e===D.POLYGON)return t instanceof Ve;if("MultiFeature"===e)return t instanceof Ne;throw new Error(`Unknown feature class: ${e}`)},Re.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Re.prototype.onSetup=function(){},Re.prototype.onDrag=function(){},Re.prototype.onClick=function(){},Re.prototype.onMouseMove=function(){},Re.prototype.onMouseDown=function(){},Re.prototype.onMouseUp=function(){},Re.prototype.onMouseOut=function(){},Re.prototype.onKeyUp=function(){},Re.prototype.onKeyDown=function(){},Re.prototype.onTouchStart=function(){},Re.prototype.onTouchMove=function(){},Re.prototype.onTouchEnd=function(){},Re.prototype.onTap=function(){},Re.prototype.onStop=function(){},Re.prototype.onTrash=function(){},Re.prototype.onCombineFeature=function(){},Re.prototype.onUncombineFeature=function(){},Re.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Ue={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Be=Object.keys(Ue);function Ge(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Re(r));return{start(){o=i.onSetup(n),Be.forEach(t=>{const r=Ue[t];let n=()=>!1;var a;e[r]&&(n=()=>!0),this.on(t,n,(a=r,e=>i[a](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function He(e){return[].concat(e).filter(e=>void 0!==e)}function Ye(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(j.HOT)))return s();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let r=[],n=[];e.isDirty?n=e.getAllIds():(r=e.getChangedIds().filter(t=>void 0!==e.get(t)),n=e.sources.hot.filter(t=>t.properties.id&&-1===r.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===r.indexOf(t)});const i=o!==e.sources.cold.length||n.length>0;function a(r,n){const o=e.get(r).internal(t);e.ctx.events.currentModeRender(o,r=>{r.properties.mode=t,e.sources[n].push(r)})}function s(){e.isDirty=!1,e.clearChangedIds()}r.forEach(e=>a(e,"hot")),n.forEach(e=>a(e,"cold")),i&&e.ctx.map.getSource(j.COLD).setData({type:D.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(j.HOT).setData({type:D.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Xe(e){let t;this._features={},this._featureIds=new xe,this._selectedFeatureIds=new xe,this._selectedCoordinates=[],this._changedFeatureIds=new xe,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ye.call(this),this._emitSelectionChange&&(this.ctx.events.fire(R.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(R.RENDER,{})}))},this.isDirty=!1}function Ke(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}Xe.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Xe.prototype.setDirty=function(){return this.isDirty=!0,this},Xe.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(R.CREATE,{features:[t.toGeoJSON()]})}return this},Xe.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(R.UPDATE,{action:t.action?t.action:U.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Xe.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Xe.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Xe.prototype.getAllIds=function(){return this._featureIds.values()},Xe.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Xe.prototype.delete=function(e,t={}){const r=[];return He(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===r.indexOf(this._features[e])&&r.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),r.length&&this.ctx.events.fire(R.DELETE,{features:r}),Ke(this,t),this},Xe.prototype.get=function(e){return this._features[e]},Xe.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Xe.prototype.select=function(e,t={}){return He(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Xe.prototype.deselect=function(e,t={}){return He(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Ke(this,t),this},Xe.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Xe.prototype.setSelected=function(e,t={}){return e=He(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},Xe.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Xe.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Xe.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Xe.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Xe.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Xe.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Xe.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:U.CHANGE_PROPERTIES})},Xe.prototype.storeMapConfig=function(){H.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Xe.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Xe.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Je=["mode","feature","mouse"];function $e(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,r)=>(t[r]=Ge(e.options.modes[r]),t),{});let r={},n={};const o={};let i=null,a=null;o.drag=function(t,r){r({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:V.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ie(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Ce(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=Se(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Se(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Se(t,e);t.featureTarget=n,Ie(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(e){a.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;n={time:(new Date).getTime(),point:t.point};const r=Pe.touch(t,null,e)[0];t.featureTarget=r,a.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const r=Pe.touch(t,null,e)[0];t.featureTarget=r,Ce(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=te(e),r=re(e),n=ae(e);return!(t||r||n)};function c(r,n,o={}){a.stop();const s=t[r];if(void 0===s)throw new Error(`${r} is not valid`);i=r;const c=s(e,n);a=Me(c,e),o.silent||e.map.fire(R.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(A.CANVAS)&&((te(t)||re(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):ne(t)&&e.options.controls.point?c(N.DRAW_POINT):oe(t)&&e.options.controls.line_string?c(N.DRAW_LINE_STRING):ie(t)&&e.options.controls.polygon&&c(N.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,a=Me(t[i](e),e)},changeMode:c,actionable:function(t){let r=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(r=!0),l[e]=t[e]}),r&&e.map.fire(R.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];Je.forEach(e=>{o[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==o[e]&&r.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),r.length>0&&e.container.classList.add(...r),n=Object.assign(n,o)}function s(e,t={}){const n=document.createElement("button");return n.className=`${A.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),n.target===r)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),n}function c(){r&&(r.classList.remove(A.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(A.ACTIVE_BUTTON),r=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:a,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),a()},addButtons:function(){const r=e.options.controls,n=document.createElement("div");return n.className=`${A.CONTROL_GROUP} ${A.CONTROL_BASE}`,r?(r[F.POINT]&&(t[F.POINT]=s(F.POINT,{container:n,className:A.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(N.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[F.LINE]&&(t[F.LINE]=s(F.LINE,{container:n,className:A.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(N.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[F.POLYGON]&&(t[F.POLYGON]=s(F.POLYGON,{container:n,className:A.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(N.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:A.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:A.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:A.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach(e=>{const r=t[e];r.parentNode&&r.parentNode.removeChild(r),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new Xe(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(j.COLD,{data:{type:D.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(j.HOT,{data:{type:D.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(j.COLD)&&e.map.removeSource(j.COLD),e.map.getSource(j.HOT)&&e.map.removeSource(j.HOT)}};return e.setup=n,n}const qe="#3bb2d0",ze="#fbb03b",Ze="#fff";var We=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],ze,qe],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],ze,qe],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Ze}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],ze,qe]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Ze}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":ze}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":ze}}];function Qe(e,t){this.x=e,this.y=t}function et(e,t){const r=t.getBoundingClientRect();return new Qe(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function tt(e,t,r,n){return{type:D.FEATURE,properties:{meta:B.VERTEX,parent:e,coord_path:r,active:n?G.ACTIVE:G.INACTIVE},geometry:{type:D.POINT,coordinates:t}}}function rt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return nt(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>nt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return it(e);default:throw new Error("unknown GeoJSON type")}}function nt(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=ot(e.properties),null==e.geometry?t.geometry=null:t.geometry=it(e.geometry),t}function ot(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=ot(n):t[r]=n}),t):t}function it(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>it(e)),t):(t.coordinates=at(e.coordinates),t)}function at(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>at(e))}function st(e,t={}){return ct(e,"mercator",t)}function ct(e,n,o={}){var i=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&t(e[0])?e="mercator"===n?lt(e):ut(e):(!0!==i&&(e=rt(e)),r(e,function(e){var t="mercator"===n?lt(e):ut(e);e[0]=t[0],e[1]=t[1]})),e}function lt(e){var t,r=Math.PI/180,n=6378137,o=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*r,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*r))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function ut(e){var t=180/Math.PI,r=6378137;return[e[0]*t/r,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/r)))*t]}function dt(e,t,r){const n=t.geometry.coordinates,o=r.geometry.coordinates;if(n[1]>85||n[1]<-85||o[1]>85||o[1]<-85)return null;const i=st(n),a=st(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ct(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:D.FEATURE,properties:{meta:B.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:D.POINT,coordinates:u}}}function pt(e,t={},r=null){const{type:n,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let a=[];function s(e,r){let n="",o=null;e.forEach((e,s)=>{const l=null!=r?`${r}.${s}`:String(s),u=tt(i,e,l,c(l));if(t.midpoints&&o){const e=dt(i,o,u);e&&a.push(e)}o=u;const d=JSON.stringify(e);n!==d&&a.push(u),0===s&&(n=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===D.POINT?a.push(tt(i,o,r,c(r))):n===D.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===D.LINE_STRING?s(o,r):0===n.indexOf(D.MULTI_PREFIX)&&function(){const r=n.replace(D.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:D.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(pt(i,t,o))})}(),a}Qe.prototype={clone(){return new Qe(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,o=r*this.x+t*this.y;return this.x=n,this.y=o,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),o=t.x+r*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Qe},Qe.convert=function(e){if(e instanceof Qe)return e;if(Array.isArray(e))return new Qe(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Qe(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var ht={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:ft,LAT_MAX:gt,LAT_RENDERED_MIN:yt,LAT_RENDERED_MAX:mt,LNG_MIN:vt,LNG_MAX:bt}=Y;function _t(e,t){let r=ft,n=gt,o=ft,i=gt,a=bt,s=vt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),d>s&&(s=d)});const c=t;return r+c.lat>mt&&(c.lat=mt-r),o+c.lat>gt&&(c.lat=gt-o),n+c.lat<yt&&(c.lat=yt-n),i+c.lat<ft&&(c.lat=ft-i),a+c.lng<=vt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=bt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function xt(e,t){const r=_t(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+r.lng,lat:e[1]+r.lat};return[t.lng,t.lat]},o=e=>e.map(e=>n(e)),i=e=>e.map(e=>o(e));let a;e.type===D.POINT?a=n(t):e.type===D.LINE_STRING||e.type===D.MULTI_POINT?a=t.map(n):e.type===D.POLYGON||e.type===D.MULTI_LINE_STRING?a=t.map(o):e.type===D.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Ot={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(R.UPDATE,{action:U.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let r=!1;if(e.length>1){r=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(r=!1)})}const n=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new xe).values()},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){ht.enable(this)},onMouseMove:function(e,t){return z(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Ot.onTap=Ot.onClick=function(e,t){return q(t)?this.clickAnywhere(e,t):X(B.VERTEX)(t)?this.clickOnVertex(e,t):z(t)?this.clickOnFeature(e,t):void 0},Ot.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),ht.enable(this),this.stopExtendedInteractions(e)},Ot.clickOnVertex=function(e,t){this.changeMode(N.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:V.MOVE})},Ot.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Ot.clickOnFeature=function(e,t){ht.disable(this),this.stopExtendedInteractions(e);const r=W(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==D.POINT)return this.changeMode(N.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:V.POINTER}),1===n.length&&ht.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:V.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:V.MOVE})),this.doRender(o)},Ot.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),J(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&K(t)?this.startBoxSelect(e,t):void 0},Ot.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=et(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Ot.onTouchStart=function(e,t){if(J(t))return this.startOnActiveFeature(e,t)},Ot.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Ot.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:V.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(A.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=et(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),o=Math.max(e.boxSelectStartLocation.x,r.x),i=Math.min(e.boxSelectStartLocation.y,r.y),a=Math.max(e.boxSelectStartLocation.y,r.y),s=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=s,e.boxSelectElement.style.WebkitTransform=s,e.boxSelectElement.style.width=o-n+"px",e.boxSelectElement.style.height=a-i+"px"},Ot.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Ot.onTouchEnd=Ot.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,et(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),o=this.getUniqueIds(n).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:V.MOVE}))}this.stopExtendedInteractions(e)},Ot.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?G.ACTIVE:G.INACTIVE,r(t),this.fireActionable(),t.properties.active===G.ACTIVE&&t.geometry.type!==D.POINT&&pt(t).forEach(r)},Ot.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Ot.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),r.push(i.toGeoJSON())}if(r.length>1){const e=this.newFeature({type:D.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(R.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Ot.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],r=[];for(let n=0;n<e.length;n++){const o=e[n];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))}t.length>1&&this.fire(R.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const Pt=X(B.VERTEX),Et=X(B.MIDPOINT),St={fireUpdate:function(){this.fire(R.UPDATE,{action:U.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);W(t)||-1!==n?W(t)&&-1===n&&e.selectedCoordPaths.push(r.coord_path):e.selectedCoordPaths=[r.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,r){xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=_t(n.map(e=>({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:e}})),r);for(let t=0;t<n.length;t++){const r=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],r[0]+o.lng,r[1]+o.lat)}},clickNoTarget:function(){this.changeMode(N.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(N.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===D.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),ht.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){ht.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=G.ACTIVE,r(t),pt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=G.INACTIVE,r(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(N.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=J(t),n=Pt(t),o=Et(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:V.MOVE}):this.updateUIClasses({mouse:V.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};St.onTouchStart=St.onMouseDown=function(e,t){return Pt(t)?this.onVertex(e,t):J(t)?this.onFeature(e,t):Et(t)?this.onMidpoint(e,t):void 0},St.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},St.onClick=function(e,t){return q(t)?this.clickNoTarget(e,t):J(t)?this.clickActiveFeature(e,t):$(t)?this.clickInactive(e,t):void this.stopDragging(e)},St.onTap=function(e,t){return q(t)?this.clickNoTarget(e,t):J(t)?this.clickActiveFeature(e,t):$(t)?this.clickInactive(e,t):void 0},St.onTouchEnd=St.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const wt={};function It(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}wt.onSetup=function(){const e=this.newFeature({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:V.ADD}),this.activateUIButton(F.POINT),this.setActionableState({trash:!0}),{point:e}},wt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},wt.onTap=wt.onClick=function(e,t){this.updateUIClasses({mouse:V.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(R.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.point.id]})},wt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},wt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?G.ACTIVE:G.INACTIVE,!n)return r(t)},wt.onTrash=wt.stopDrawingAndRemove,wt.onKeyUp=function(e,t){if(Q(t)||ee(t))return this.stopDrawingAndRemove(e,t)};const Ct={onSetup:function(){const e=this.newFeature({type:D.FEATURE,properties:{},geometry:{type:D.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),ht.disable(this),this.updateUIClasses({mouse:V.ADD}),this.activateUIButton(F.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:V.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),Z(t)&&this.updateUIClasses({mouse:V.POINTER})}};Ct.onTap=Ct.onClick=function(e,t){return Z(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ct.onKeyUp=function(e,t){Q(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)):ee(t)&&this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ct.onStop=function(e){this.updateUIClasses({mouse:V.NONE}),ht.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(R.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Ct.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?G.ACTIVE:G.INACTIVE,!n)return r(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=B.FEATURE,r(tt(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(tt(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:D.FEATURE,properties:t.properties,geometry:{coordinates:e,type:D.LINE_STRING}}),3===o)return}return r(t)}},Ct.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)};const Mt={onSetup:function(e){const t=(e=e||{}).featureId;let r,n,o="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const a=r.coordinates.length-1;if(r.coordinates[a][0]===i[0]&&r.coordinates[a][1]===i[1])n=a+1,r.addCoordinate(n,...r.coordinates[a]);else{if(r.coordinates[0][0]!==i[0]||r.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",n=0,r.addCoordinate(n,...r.coordinates[0])}}else r=this.newFeature({type:D.FEATURE,properties:{},geometry:{type:D.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),ht.disable(this),this.updateUIClasses({mouse:V.ADD}),this.activateUIButton(F.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&It(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:V.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),Z(t)&&this.updateUIClasses({mouse:V.POINTER})}};Mt.onTap=Mt.onClick=function(e,t){if(Z(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Mt.onKeyUp=function(e,t){ee(t)?this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]}):Q(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT))},Mt.onStop=function(e){ht.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(R.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Mt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},Mt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?G.ACTIVE:G.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=B.FEATURE,r(tt(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),r(t))};var Tt={simple_select:Ot,direct_select:St,draw_point:wt,draw_polygon:Ct,draw_line_string:Mt};const Lt={defaultMode:N.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:We,modes:Tt,controls:{},userProperties:!1,suppressAPIEvents:!0},kt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},At={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function jt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?j.HOT:j.COLD}))}var Vt,Ft;var Dt,Nt,Rt=ce(Ft?Vt:(Ft=1,Vt=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}));var Ut=function(){if(Nt)return Dt;Nt=1,Dt=function(t){if(!t||!t.type)return null;var r=e[t.type];if(!r)return null;if("geometry"===r)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===r)return{type:"FeatureCollection",features:[t]};if("featurecollection"===r)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Dt}(),Bt=ce(Ut);function Gt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Ht={Polygon:Ve,LineString:je,Point:Ae,MultiPolygon:Ne,MultiLineString:Ne,MultiPoint:Ne};var Yt=Object.freeze({__proto__:null,CommonSelectors:se,ModeHandler:Me,StringSet:xe,constrainFeatureMovement:_t,createMidPoint:dt,createSupplementaryPoints:pt,createVertex:tt,doubleClickZoom:ht,euclideanDistance:we,featuresAt:Pe,getFeatureAtAndSetCursors:Se,isClick:Ie,isEventAtCoordinates:It,isTap:Ce,mapEventToBoundingBox:_e,moveFeatures:xt,sortFeatures:be,stringSetsAreEqual:Gt,theme:We,toDenseArray:He});const Xt=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},At,e.controls):t.controls=Object.assign({},kt,e.controls),t=Object.assign({},Lt,t),t.styles=jt(t.styles,"cold").concat(jt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=N;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Pe.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:D.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:D.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:D.FEATURE,properties:{},geometry:{type:D.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==D.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(r),a=new xe(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Bt(t))).features.map(t=>{if(t.id=t.id||Le(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=Ht[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Rt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Rt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:D.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==N.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===N.DIRECT_SELECT?e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===N.SIMPLE_SELECT&&t.getMode()===N.SIMPLE_SELECT?(Gt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===N.DIRECT_SELECT&&t.getMode()===N.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,o,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,o,i){return e.store.setFeatureProperty(n,o,i,{silent:r}),t},t}(r,t),r.api=t;const n=$e(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=F,t.options=e,t};function Kt(e){Xt(e,this)}Kt.modes=Tt,Kt.constants=Y,Kt.lib=Yt;var Jt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},$t="draw.create",qt="draw.update",zt="draw.modechange",Zt="draw.editfinish",Wt="draw.cancel",Qt="draw.vertexselection",er="draw.vertexchange",tr="draw.undochange",rr="draw.undo",nr="draw.geometrychange",or="draw.interfacetypechange",ir="draw.placementblocked",ar="draw.nudgevertex",sr="styledata",cr=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},lr=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!0}),r+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,o)=>{t.push({start:r,length:e.length,path:[n,o],closed:!0}),r+=e.length})})}return t},ur=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},dr=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},pr=(e,t)=>{var r=t.split(".").map(Number),n=lr(e);for(var o of n){if(o.path.every((e,t)=>e===r[t])&&r.length===o.path.length+1){var i=r[r.length-1];return o.start+i}}return r[r.length-1]},hr=(e,t)=>({x:e.x*t,y:e.y*t}),fr=e=>e instanceof window.SVGElement||e.ownerSVGElement;function gr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function yr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?gr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function mr(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function vr(e){var t;return!!(null!=e&&e.status&&null!=e&&e.snapStatus&&(null===(t=e.snapCoords)||void 0===t?void 0:t.length)>=2)}function br(e){return vr(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function _r(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function xr(e,t){e&&(e._autoSnapSuspended=t)}function Or(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Pr(e,t){var r,n,o;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(r=e.snappedFeatures)&&void 0!==r&&r.length&&(e.snappedFeatures.length=0),null!==(n=e.closeFeatures)&&void 0!==n&&n.length&&(e.closeFeatures.length=0),null!==(o=e.lines)&&void 0!==o&&o.length&&(e.lines.length=0));null!=t&&t.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function Er(e){var t,r,n;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(t=e.snappedFeatures)&&void 0!==t&&t.length&&(e.snappedFeatures.length=0),null!==(r=e.closeFeatures)&&void 0!==r&&r.length&&(e.closeFeatures.length=0),null!==(n=e.lines)&&void 0!==n&&n.length&&(e.lines.length=0))}function Sr(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var wr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r=>n=>r.call(e,t,n),o={keydown:n(e.onKeydown),keyup:n(e.onKeyup),pointerdown:n(e.onPointerevent),pointermove:n(e.onPointerevent),pointerup:n(e.onPointerevent),click:n(e.onButtonClick),touchstart:n(e.onTouchstart),touchmove:n(e.onTouchmove),touchend:n(e.onTouchend),scalechange:n(e.onScaleChange),move:n(e.onMove),interfacetypechange:n(e.onInterfaceTypeChange)};for(var[i,a]of Object.entries(r))o[i]=n(a);return o},Ir=(e,t,r)=>{window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),t.on("draw.scalechange",r.scalechange),t.on("move",r.move),t.on(or,r.interfacetypechange),t.on(ar,r.nudge)},Cr=(e,t,r)=>{e.container.removeEventListener("pointerdown",r.pointerdown),e.container.removeEventListener("pointermove",r.pointermove),e.container.removeEventListener("pointerup",r.pointerup),e.container.removeEventListener("touchstart",r.touchstart),e.container.removeEventListener("touchmove",r.touchmove),e.container.removeEventListener("touchend",r.touchend),t.off("draw.scalechange",r.scalechange),t.off("move",r.move),t.off(or,r.interfacetypechange),t.off(ar,r.nudge),t.dragPan.enable(),window.removeEventListener("click",r.click),window.removeEventListener("keydown",r.keydown,{capture:!0}),window.removeEventListener("keyup",r.keyup,{capture:!0})},Mr=e=>{var t=mr(e);t&&Pr(t,e)},Tr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,r){e&&setTimeout(()=>{var n=this.getFeature(r);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){var t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}};function Lr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function kr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Lr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ar={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},jr=kr(kr({},Tr),{},{UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Ar,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r),this.emitGeometryValidation(Ar[r.type],r.vertexIndex,r.featureId)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=lr(i),c=ur(s,r);if(c){dr(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,hr(this.map.project(l),e.scale))}}},undoInsertVertex(e,t){var{vertexIndex:r,featureId:n}=t,o=this.getFeature(n);if(o){var i=o.toGeoJSON(),a=lr(o),s=ur(a,r);if(s)dr(i,s.segment.path).splice(s.localIdx,1),this._applyUndoAndSync(e,i,n),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},undoDeleteVertex(e,t){var{vertexIndex:r,position:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=lr(i),c=ur(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)dr(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,hr(this.map.project(e.vertecies[r]),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertecies=this.getVerticies(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}}),Vr=o.touchTargetSize/2;var Fr=e=>{var t,r,n=e.querySelector("[data-im-draw-touch-target]");return n||(e.insertAdjacentHTML("beforeend",(t=o.touchTargetSize,r=Vr,"\n <svg width='".concat(t,"' height='").concat(t,"' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:").concat(r,"px 0 0 -").concat(r,"px;cursor:grab'\n class='im-draw-touch-target' data-im-draw-touch-target>\n <circle cx='24' cy='24' r='24' fill='var(--draw-halo, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--draw-bg, #fff)'/>\n </svg>\n "))),n=e.querySelector("[data-im-draw-touch-target]")),n},Dr=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},Nr=(e,t)=>{t&&e&&(e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px"),e.style.display="block")},Rr=e=>{e&&(e.style.display="none")},Ur=e=>{if(!e)return!1;var t=e.parentNode;return t instanceof globalThis.SVGElement||null!=(null==t?void 0:t.ownerSVGElement)},Br=function(e){var t,r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=null!==(t=null==e?void 0:e.mapColorScheme)&&void 0!==t?t:"light",c=null!==(r=null==e?void 0:e.id)&&void 0!==r?r:null,l=e=>{var t;return function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return"object"!=typeof e||null===e?e:r&&void 0!==e[r]?e[r]:void 0!==e[t]?e[t]:void 0!==e.light?e.light:Object.values(e)[0]}(null!==(t=a[e])&&void 0!==t?t:i[e],s,c)};return{editStroke:l("editStroke"),editFill:l("editFill"),editVertex:l("editVertex"),editMidpoint:l("editMidpoint"),editActive:l("editActive"),editHalo:l("editHalo"),invalidStroke:l("invalidStroke"),splitValid:l("splitValid"),splitInvalid:l("splitInvalid"),shapeStroke:l("shapeStroke"),strokeWidth:null!==(n=a.strokeWidth)&&void 0!==n?n:o.strokeWidth,shapeFill:l("shapeFill"),snapVertex:l("snapVertex"),snapEdge:l("snapEdge"),mapStyleId:c}},Gr=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Hr=(e,t,r,n,o)=>{var i=window.getComputedStyle(t),a={x:r.x-Number.parseFloat(i.left),y:r.y-Number.parseFloat(i.top)},s=e.project(n);return{deltaTarget:a,deltaVertex:{x:r.x/o-s.x,y:r.y/o-s.y}}},Yr=(e,t,r)=>{var n={x:r.x/t.scale-t.deltaVertex.x,y:r.y/t.scale-t.deltaVertex.y},o=e.unproject(n);if(Sr(t)){var i=mr(e);_r(i,e,n),o=br(i)||o}return o};function Xr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Kr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Jr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=Br(t,r);Dr(e,{editActive:n,editHalo:o,editVertex:i})}},$r={addTouchVertexTarget(e){e.touchVertexTarget=Fr(e.container),Jr(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||fr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(Er(mr(this.map)),null!=e&&e.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,hr(this.map.project(t),e.scale))}},onTap(e,t){var r,n,o=mr(this.map);o&&Pr(o,this.map);var i=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,a=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if("vertex"===i){var s=this.getFeature(e.featureId),c=pr(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(Kr(Kr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){Er(mr(this.map));var r=this.getVerticies(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&fr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=Gr(t);Object.assign(e,Hr(this.map,e.touchVertexTarget,o,n,e.scale))}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&fr(t.target.parentNode)){e._touchMoved=!0;var r=Gr(t);this.moveVertex(e,Yr(this.map,e,r)),this.updateTouchVertexTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}},qr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),zr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Zr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Wr=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Zr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},Qr=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,en={handleUndoShortcut(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},tn={getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?a.nudgeAmount:a.stepAmount,[o,i]=t?zr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getOffsetByDelta(e,t,r,n){var o=this.map.project(e),i=n?a.stepAmount:a.nudgeAmount;return this.map.unproject({x:o.x+t*i,y:o.y+r*i})},resolveSnapTarget(e,t,r,o,i){var a=mr(this.map);if(Sr(e)&&e._isSnapped&&a){var s=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:n.snapRadius}(a)+1,c=this.map.project(o);return e._isSnapped=!1,Pr(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return Sr(e)&&a&&(_r(a,this.map,this.map.project(l)),vr(a))?(e._isSnapped=!0,br(a)):(e._isSnapped=!1,l)}};function rn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function nn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?rn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var on=nn(nn({},tn),{},{updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(e,t){var[r,n]=this.getVertexOrMidpoint(e,t);r<0||!n||this.changeMode(e,nn({selectedVertexIndex:r,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,r)}))},getNewCoord(e,t){return this.getOffset(cr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=cr(i))||void 0===o?void 0:o[e.selectedVertexIndex]);if(a){var s=[...a],c=e.selectedVertexIndex,l=this.resolveSnapTarget(e,t,r,a,()=>this.getOffsetByDelta(a,t,r,n));this.moveVertex(e,l),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:c,previousPosition:s})}}},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertecies.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=lr(o),s=r+1,c=null,l=0,u=0;for(var d of a){var p=d.closed?d.length:d.length-1;if(r<u+p){c=d,l=r-u+1,s=d.start+l;break}u+=p}c&&(dr(i,c.path).splice(l,0,[n.lng,n.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),this.changeMode(e,{selectedVertexIndex:s,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,s)}))},moveVertex(e,t){if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).checkSnap&&!1!==e.enableSnap){var r,n=this.map._snapInstance;null!=n&&n.snapStatus&&(null===(r=n.snapCoords)||void 0===r?void 0:r.length)>=2&&(t={lng:n.snapCoords[0],lat:n.snapCoords[1]})}var o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=lr(o),s=ur(a,e.selectedVertexIndex);s&&(dr(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertecies=this.getVerticies(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=lr(t),n=ur(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?s.Polygon:s.LineString;if(!(o.length<=i)){var a=[...e.vertecies[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}}),an={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e,n[0]):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=lr(r),o=ur(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVerticies(e){return cr(this.getFeature(e))},getMidpoints(e){var t=this.getFeature(e),r=cr(t),n=lr(t);if(null==r||!r.length||!n.length)return[];var o=[];for(var i of n)for(var a=i.closed?i.length:i.length-1,s=0;s<a;s++){var c=i.start+s,l=i.start+(s+1)%i.length,[u,d]=r[c],[p,h]=r[l];o.push([(u+p)/2,(d+h)/2])}return o},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertecies)&&void 0!==r&&r.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertecies)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertecies.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=c(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=lr(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertecies.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertecies.length}};function sn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function cn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?sn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):sn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ln=cn(cn({},en),{},{onKeydown(e,t){Wr(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?qr.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?Qr(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){var t,r,n=mr(this.map);n&&Pr(n,this.map),null!==(t=e.vertecies)&&void 0!==t&&t.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertecies)&&void 0!==r&&r.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){var r;if("midpoint"!==e.selectedVertexType){var n=this.getFeature(e.featureId),o=n&&(null===(r=cr(n))||void 0===r?void 0:r[e.selectedVertexIndex]);o&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...o],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,o)))}else this.insertVertex(e,t)},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Wr(e)||(e.interfaceType="keyboard",qr.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&null!=e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=null)),"Delete"===t.key&&this.deleteVertex(e))}}),un={onMouseDown(e,t){var r,n;Er(mr(this.map));var o=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,i=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if(["vertex","midpoint"].includes(o)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,St.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=pr(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertecies)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=pr(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(Qt,{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(Qt,{index:r,numVertecies:e.vertecies.length})}St.onClick.call(this,e,t)},onMouseUp(e,t){Er(mr(this.map));var r=e._isInsertingVertex&&null!=e._insertedVertexIndex,n=this._didVertexMove(e);(e.dragMoving||n||r)&&(this.syncVertices(e),r?this._recordInsertionUndo(e):n&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,St.onMouseUp.call(this,e,t)},_didVertexMove(e){var t;if(!e._moveStartPosition||null==e._moveStartIndex)return!1;var r=this.getFeature(e.featureId),n=r&&(null===(t=cr(r))||void 0===t?void 0:t[e._moveStartIndex]);return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){var t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(Qt,{index:t,numVertecies:e.vertecies.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=mr(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),Sr(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),_r(n,this.map,t.point);var o=br(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else St.onDrag.call(this,e,t)}}};function dn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function pn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?dn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):dn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var hn=pn(pn(pn(pn(pn(pn(pn(pn({},Kt.modes.direct_select),jr),$r),on),an),ln),un),{},{onSetup(e){var t,r,n,o=Kt.modes.direct_select.onSetup.call(this,e);(Object.assign(o,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:o.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1}),this.map._lastEditFeatureId!==o.featureId)&&(null===(n=this.map._undoStack)||void 0===n||n.clear(),this.map._lastEditFeatureId=o.featureId);var i=this.getFeature(o.featureId);if(o.featureType=null==i?void 0:i.type,o.vertecies=this.getVerticies(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o),Mr(this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var a=o.vertecies[o.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(o,hr(this.map.project(a),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=this.handlers=wr(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate});Ir(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertecies.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=cr(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire(Qt,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?hr(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?hr(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertecies.map(e=>JSON.stringify(e))).size!==e.vertecies.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,hr(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertecies[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,hr(this.map.project(r),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",pn(pn({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),Cr(e,this.map,t),this.hideTouchVertexIndicator(e)}});function fn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function gn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?fn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):fn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var yn={move_point:"commit-move"},mn=gn(gn({},Tr),{},{UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:yn,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_point"===r.type&&this.undoMovePoint(e,r),this.emitGeometryValidation(yn[r.type],r.vertexIndex,r.featureId)}},undoMovePoint(e,t){var{previousPosition:r,featureId:n}=t,o=this.getFeature(n);o&&(o.updateCoordinate("",r[0],r[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,hr(this.map.project(r),e.scale)))}}),vn={addTouchPointTarget(e){e.touchPointTarget=Fr(e.container),Jr(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){Er(mr(this.map)),e._touchMoved&&e._moveStartPosition&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._touchMoved=!1,e.feature&&this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){Er(mr(this.map));var r=this.getPointCoord(e);if(r&&fr(t.target.parentNode)){e._moveStartPosition=[...r],e._touchMoved=!1;var n=Gr(t);Object.assign(e,Hr(this.map,e.touchPointTarget,n,r,e.scale))}},onTouchmove(e,t){if(fr(t.target.parentNode)){e._touchMoved=!0;var r=Gr(t);this.movePoint(e,Yr(this.map,e,r)),this.updateTouchPointTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}};function bn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _n(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?bn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):bn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var xn=_n(_n({},tn),{},{getPointCoord(e){var t;return null===(t=this.getFeature(e.featureId))||void 0===t?void 0:t.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,r,n){var o=this.getPointCoord(e);if(o){var i=[...o],a=this.resolveSnapTarget(e,t,r,o,()=>this.getOffsetByDelta(o,t,r,n));this.movePoint(e,a),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}}});function On(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Pn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?On(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):On(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var En=Pn(Pn({},en),{},{onKeydown(e,t){Wr(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?qr.has(t.key)?this.handleArrowKey(e,t):Qr(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){var r=this.getPointCoord(e);r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r]),this.movePoint(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Wr(e)||(e.interfaceType="keyboard",qr.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}}),Sn="edit_point",wn={onFeature(e,t){e.dragMoving||(e._moveStartPosition=[...e.feature.coordinates],e._grabOffset=[e.feature.coordinates[0]-t.lngLat.lng,e.feature.coordinates[1]-t.lngLat.lat],xr(mr(this.map),!0)),St.onFeature.call(this,e,t)},onClick(e,t){if(!J(t)&&((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=l(r,{mode:Sn,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:Sn,vertexIndex:0}),n})(this.map,[t.lngLat.lng,t.lngLat.lat])){var r=[...e.feature.coordinates],n=mr(this.map),o=t.lngLat;Sr(e)&&n&&(_r(n,this.map,t.point),o=br(n)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:r})}},onMouseUp(e,t){var r=mr(this.map);Er(r),xr(r,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,St.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;var t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var r=mr(this.map);if(r&&(r.snapStatus=!1,r.snapCoords=null),Sr(e)&&null!=r&&r.status){if(e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};_r(r,this.map,this.map.project([n.lng,n.lat]));var o=br(r)||n;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else St.onDrag.call(this,e,t)}},onTrash(){}};function In(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Cn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?In(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):In(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Mn=Cn(Cn(Cn(Cn(Cn(Cn(Cn({},Kt.modes.direct_select),mn),vn),xn),En),wn),{},{onSetup(e){var t,r,n=e.featureId,o=this.getFeature(n);if(!o)throw new Error("You must provide a featureId to enter edit_point mode");var i,a={featureId:n,feature:o,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};(this.setSelectedCoordinates([]),this.setSelected(n),ht.disable(this),this.setActionableState({trash:!1}),Object.assign(a,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:null!==(t=e.scale)&&void 0!==t?t:1}),this.map._lastEditFeatureId!==a.featureId)&&(null===(i=this.map._undoStack)||void 0===i||i.clear(),this.map._lastEditFeatureId=a.featureId);return this.setupEventListeners(a),this.map._drawEditContainer=e.container,this.addTouchPointTarget(a),null===(r=a.container)||void 0===r||r.focus({preventScroll:!0}),Mr(this.map),"touch"===a.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(a,hr(this.map.project(a.feature.coordinates),a.scale))},0),this.map.fire(Qt,{index:0,numVertecies:1}),a},setupEventListeners(e){var t=this.handlers=wr(this,e,{nudge:this.onNudgePoint});Ir(e,this.map,t)},toDisplayFeatures(e,t,r){t.properties.active=e.featureId===t.properties.id?"true":"false",r(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,hr(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Cr(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}});function Tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ln(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Tn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var kn=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?Ln(Ln({},e),{},{featureId:null}):e,a=Ln(Ln({},t.onSetup.call(this,i)),e);a[r].properties=e.properties;var{container:s,vertexMarkerId:c,getInterfaceType:l}=a,u=l?l():a.interfaceType;a.interfaceType=u;var d=s.querySelector("#".concat(c));a.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(a):this._hideCrossHair(a),a.crossHair&&(a.crossHair.activate=()=>{var e;return null===(e=this._placeAtCrossHair)||void 0===e?void 0:e.call(this,a)});var p=(e,t)=>this[e]=t.bind(this,a),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(e=>{var[t,r]=e;return p(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),a},onStop(e){var r;t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),null!==(r=e.crossHair)&&void 0!==r&&r.activate&&(e.crossHair.activate=null),["touch","keyboard"].includes(e.interfaceType)||this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function An(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function jn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?An(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):An(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vn=(e,t,r,n,o)=>{setTimeout(()=>{var i=t(n);i&&e.fire("draw.geometrychange",((e,t,r)=>{var n=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[n]}:{type:"LineString",coordinates:n},properties:{}},phase:r,vertexIndex:Math.max(0,n.length-1)}})(i,r,o))},0)},Fn=e=>{var{geometryType:t,getFeature:r,getCoords:n}=e;return{_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(e,o){var i=r(e);if(!i||!o)return!0;var a=u({placed:n(i).slice(0,-1),point:o,geometryType:t,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Vn(this.map,r,n,e,t)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onCreate(e,t){((e,t,r)=>{e.delete(t.id),t.id=r,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}},Dn=e=>{var{ParentMode:t,getFeature:r,getCoords:n,validateClick:o,finishOnInvalidClick:i}=e;return{onClick(e,a){var s;if(!this._isIgnorableClick(a)&&(!1!==this.map._drawGeometryValid||"vertex"!==(null===(s=a.featureTarget)||void 0===s||null===(s=s.properties)||void 0===s?void 0:s.meta))){var c=mr(this.map);if(Sr(e)&&vr(c))a=function(e,t){var r=br(t);return r?yr(yr({},e),{},{lngLat:r}):e}(a,c);else if(!((e,t)=>{var a=n(r(e));return a.length>0&&(a[a.length-1]=[t.lngLat.lng,t.lngLat.lat]),i||o(r(e))})(e,a))return;if(this._canPlaceVertex(e,[a.lngLat.lng,a.lngLat.lat])){var l=n(r(e)).length;t.onClick.call(this,e,a),n(r(e)).length>l&&(this.pushDrawUndo(e),this.dispatchVertexChange(n(r(e))),this.emitDrawValidation(e))}}},doClick(e){if(!this.map._undoInProgress){var a=r(e),s=n(a);if(this.dispatchVertexChange(s),o(a)){var c=mr(this.map),l=Sr(e)&&function(e,t){var r=br(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(this._canPlaceVertex(e,[u.lng,u.lat])){l?(t.onClick.call(this,e,l),this._ctx.store.render()):this._simulateMouse("click",t.onClick,e);var d=n(r(e));this.pushDrawUndo(e),this.dispatchVertexChange(d),this.emitDrawValidation(e)}}else i&&!1!==this.map._drawGeometryValid&&(s.pop(),this.map.fire("draw.create",{features:[a.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[a.id]}))}}}};function Nn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Rn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Nn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Nn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Un=e=>{var{geometryType:t,getFeature:r}=e;return{pushDrawUndo(e){var n=this.map._undoStack;n&&!this.map._undoInProgress&&n.push({type:"draw_vertex",geometryType:t,featureId:r(e).id})},onUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"draw_vertex"===(null==r?void 0:r.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))}},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}},Bn=e=>{var{ParentMode:t,geometryType:r,getCoords:n,getFeature:o}=e;return{undoVertex(e){var t=o(e),r=n(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_removeLastVertex(e,t,o){var i="Polygon"===r?t.coordinates[0]:o;i.splice(-2,1),i[i.length-1]=[...i[i.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(t))},_updateRubberBand(e,n){if(["touch","keyboard"].includes(e.interfaceType))this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render();else{var o=n["Polygon"===r?n.length-2:n.length-1],i={lng:o[0],lat:o[1]},a=this.map.project(i);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}this.dispatchVertexChange(n)}}},Gn=e=>{var{ParentMode:t,featureProp:r,geometryType:n}=e;return{_reinitializeFeature(e,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(e,i);var a=this.map.getCenter(),s=[[a.lng,a.lat],[a.lng,a.lat]],c=this.newFeature({type:"Feature",properties:e.properties||{},geometry:{type:n,coordinates:[s]}});return c.id=i,this._ctx.store.add(c),e[r]=c,e.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render(),this.dispatchVertexChange(s),!0},_restartLineStringDraw(e,t){var r=this.map._undoStack;return r&&r.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}},Hn=e=>{var{ParentMode:t,getFeature:r,INTERFACE_KEYS:n}=e;return{onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(e,n){var o=document.activeElement;if(!o||o===e.container||!e.container.contains(o))if("Escape"!==n.key)o!==e.container&&t.onKeyUp.call(this,e,n);else if("keyboard"===e.interfaceType){var i=this.map._undoStack;i&&i.clear(),this._reinitializeFeature(e,r(e))}}}};function Yn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Xn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Yn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Kn=e=>{var{ParentMode:t,getFeature:r,getCoords:n}=e;return{onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(e,r){if(Sr(e)){var n=mr(this.map);_r(n,this.map,r.point);var o=br(n);o&&(r=Xn(Xn({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e){if(["touch","keyboard"].includes(e.interfaceType)){Sr(e)&&Or(mr(this.map),this.map);var r=mr(this.map),n=Sr(e)&&br(r);if(n){var o=this.map.project([n.lng,n.lat]);t.onMouseMove.call(this,e,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}else this._simulateMouse("mousemove",t.onMouseMove,e)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(r(e)))}}},Jn=e=>{var{ParentMode:t,geometryType:r,getFeature:n,getPlacedCoords:o}=e;return{_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},toDisplayFeatures(e,i,a){t.toDisplayFeatures.call(this,e,i,a);var s=n(e);i.geometry.type===r&&i.properties.id===s.id&&o(i).forEach(e=>a({type:"Feature",properties:{meta:"draw-vertex",parent:s.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}};function $n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function qn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?$n(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):$n(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zn=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s,finishOnInvalidClick:c,getFeature:e=>e[r],INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return qn(qn(qn(qn(qn(qn(qn({},e),kn(l)),(e=>jn(jn({},Fn(e)),Dn(e)))(l)),(e=>Rn(Rn(Rn({},Un(e)),Bn(e)),Gn(e)))(l)),Hn(l)),Kn(l)),Jn(l))},Zn=zn(Kt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>d(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Wn=zn(Kt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>p(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)});function Qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function eo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Qn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Qn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var to="draw_point",ro=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),no=Kt.modes.draw_point,oo=kn({ParentMode:no,featureProp:"point",excludeFeatureIdFromSetup:!1}),io={onKeyUp(){},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},onCreate(e,t){var r,n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),null===(r=e.resolvePointSymbol)||void 0===r||r.call(e,e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e){["touch","keyboard"].includes(e.interfaceType)&&Sr(e)&&Or(mr(this.map),this.map)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onTouchStart(e){this._setInterface(e,"touch"),this.onMove(e)},onTouchEnd(e){this._setInterface(e,"touch"),this.onMove(e)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onMouseMove(e,t){Sr(e)&&_r(mr(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),ro.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&ro.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(!(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())){var r=mr(this.map),n=Sr(e)&&vr(r)?br(r):null;this._commit(e,n||t.lngLat)}},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){var t=mr(this.map);Sr(e)&&Or(t,this.map);var r=Sr(e)&&vr(t)?br(t):null;this._commit(e,r||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=l(r,{mode:to,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:to,vertexIndex:0}),n})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},ao=eo(eo(eo({},no),oo),io),so=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],co=["get","user_sortKey"],lo=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":co},paint:{"fill-color":so(e,"fill",t.shapeFill)}}),uo=(e,t)=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round","line-sort-key":co},paint:{"line-color":so(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),po=e=>({id:"stroke-preview-line",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),ho=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),fo=(e,t,r)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),go=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),yo=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),mo=(e,t,r)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),vo=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),bo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),_o=function(e){var t,r,n,i,a,s=Br(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:c,midpointRadius:l,vertexHaloRadius:u,midpointHaloRadius:d}=o;return[lo(e,s),(a=s.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":a}}),(i=s.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":i,"line-width":2,"line-opacity":1}}),(n=s.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":n,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),uo(e,s),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":co},paint:{}},(r=s.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":r,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(t=s.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t,"line-width":2,"line-opacity":1}}),po(s.editStroke),yo(s.editMidpoint,l),mo(s.editHalo,s.editActive,d),vo(s.editMidpoint,l),ho(s.editVertex,c),fo(s.editHalo,s.editActive,u),go(s.editVertex,c),bo(s.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function xo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Oo(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Po(e,t,r){void 0===r&&(r={});var n=xo(e),o=xo(t),i=h(o[1]-n[1]),a=h(o[0]-n[0]),s=h(n[1]),c=h(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return f(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Eo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function So(e,t,r,n={}){const o=Eo(e),i=h(o[0]),a=h(o[1]),s=h(r),c=g(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=m(u),p=m(l);return void 0!==o[2]?y([d,p,o[2]],n.properties):y([d,p],n.properties)}function wo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return b(e,t);return _(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Io(e,t,r={}){if(!0===r.final)return function(e,t){let r=Io(t,e);return r=(r+180)%360,r}(e,t);const n=Eo(e),o=Eo(t),i=h(n[0]),a=h(o[0]),s=h(n[1]),c=h(o[1]),l=Math.sin(a-i)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(a-i);return m(Math.atan2(l,u))}var Co=Io;function Mo(e,t,r,n){void 0===n&&(n={});var o=xo(e),i=h(o[0]),a=h(o[1]),s=h(r),c=g(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=m(u),p=m(l);return y([d,p],n.properties)}function To(e){if(!e)throw new Error("geojson is required");var t=[];return x(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=Oo(n);break;case"LineString":r=[Oo(n)]}r.forEach(function(r){var n=function(e,t){var r=[];return e.reduce(function(e,n){var o,i,a,s,c,l,u=_([e,n],t);return u.bbox=(i=n,a=(o=e)[0],s=o[1],c=i[0],l=i[1],[a<c?a:c,s<l?s:l,a>c?a:c,s>l?s:l]),r.push(u),n}),r}(r,e.properties);n.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),O(t)}var Lo={exports:{}};function ko(e,t,r,n,o){Ao(e,t,r||0,n||e.length-1,o||Vo)}function Ao(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);Ao(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(jo(e,r,t),o(e[n],u)>0&&jo(e,r,n);d<p;){for(jo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?jo(e,r,p):jo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function jo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Vo(e,t){return e<t?-1:e>t?1:0}function Fo(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Do(e,t){No(e,0,e.children.length,t,e)}function No(e,t,r,n,o){o||(o=$o(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<r;i++){const t=e.children[i];Ro(o,e.leaf?n(t):t)}return o}function Ro(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Uo(e,t){return e.minX-t.minX}function Bo(e,t){return e.minY-t.minY}function Go(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ho(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Yo(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Xo(e,t){const r=Math.max(e.minX,t.minX),n=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-r)*Math.max(0,i-n)}function Ko(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Jo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function $o(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function qo(e,t,r,n,o){const i=[t,r];for(;i.length;){if((r=i.pop())-(t=i.pop())<=n)continue;const a=t+Math.ceil((r-t)/n/2)*n;ko(e,a,t,r,o),i.push(t,a,a,r)}}var zo,Zo=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const r=[];if(!Jo(e,t))return r;const n=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const a=t.children[i],s=t.leaf?n(a):a;Jo(e,s)&&(t.leaf?r.push(a):Ko(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!Jo(e,t))return!1;const r=[];for(;t;){for(let n=0;n<t.children.length;n++){const o=t.children[n],i=t.leaf?this.toBBox(o):o;if(Jo(e,i)){if(t.leaf||Ko(e,i))return!0;r.push(o)}}t=r.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=$o([]),this}remove(e,t){if(!e)return this;let r=this.data;const n=this.toBBox(e),o=[],i=[];let a,s,c;for(;r||o.length;){if(r||(r=o.pop(),s=o[o.length-1],a=i.pop(),c=!0),r.leaf){const n=Fo(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!Ko(r,n)?s?(a++,r=s.children[a],c=!1):r=null:(o.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const r=[];for(;e;)e.leaf?t.push(...e.children):r.push(...e.children),e=r.pop();return t}_build(e,t,r,n){const o=r-t+1;let i,a=this._maxEntries;if(o<=a)return i=$o(e.slice(t,r+1)),Do(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=$o([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));qo(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);qo(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Do(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=Go(a),c=Yo(e,a)-s;c<o?(o=c,n=s<n?s:n,r=a):c===o&&s<n&&(n=s,r=a)}t=r||t.children[0]}return t}_insert(e,t,r){const n=r?e:this.toBBox(e),o=[],i=this._chooseSubtree(n,this.data,t,o);for(i.children.push(e),Ro(i,n);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(n,o,t)}_split(e,t){const r=e[t],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const i=this._chooseSplitIndex(r,o,n),a=$o(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Do(r,this.toBBox),Do(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=$o([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Do(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=No(e,0,a,this.toBBox),s=No(e,a,r,this.toBBox),c=Xo(t,s),l=Go(t)+Go(s);c<o?(o=c,n=a,i=l<i?l:i):c===o&&l<i&&(i=l,n=a)}return n||r-t}_chooseSplitAxis(e,t,r){const n=e.leaf?this.compareMinX:Uo,o=e.leaf?this.compareMinY:Bo;this._allDistMargin(e,t,r,n)<this._allDistMargin(e,t,r,o)&&e.children.sort(n)}_allDistMargin(e,t,r,n){e.children.sort(n);const o=this.toBBox,i=No(e,0,t,o),a=No(e,r-t,r,o);let s=Ho(i)+Ho(a);for(let n=t;n<r-t;n++){const t=e.children[n];Ro(i,e.leaf?o(t):t),s+=Ho(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Ro(a,e.leaf?o(t):t),s+=Ho(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Ro(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Do(e[r],this.toBBox)}}}),Wo=le(Zo),Qo={};function ei(){if(zo)return Qo;zo=1,Object.defineProperty(Qo,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},r={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function n(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function o(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:e},t,r)}function i(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:e},t,r)}function a(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:e},t,r)}function s(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return n({type:"MultiLineString",coordinates:e},t,r)}function l(e,t,r={}){return n({type:"MultiPoint",coordinates:e},t,r)}function u(e,t,r={}){return n({type:"MultiPolygon",coordinates:e},t,r)}function d(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e/n}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Qo.areaFactors=r,Qo.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Qo.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Qo.convertArea=function(e,t="meters",n="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=r[t];if(!o)throw new Error("invalid original units");const i=r[n];if(!i)throw new Error("invalid final units");return e/o*i},Qo.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),r)},Qo.degreesToRadians=function(e){return e%360*Math.PI/180},Qo.earthRadius=e,Qo.factors=t,Qo.feature=n,Qo.featureCollection=s,Qo.geometry=function(e,t,r={}){switch(e){case"Point":return o(t).geometry;case"LineString":return a(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},Qo.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},Qo.isNumber=f,Qo.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Qo.lengthToDegrees=function(e,t){return h(p(e,t))},Qo.lengthToRadians=p,Qo.lineString=a,Qo.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},Qo.multiLineString=c,Qo.multiPoint=l,Qo.multiPolygon=u,Qo.point=o,Qo.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},Qo.polygon=i,Qo.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},Qo.radiansToDegrees=h,Qo.radiansToLength=d,Qo.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const r=Math.pow(10,t||0);return Math.round(e*r)/r},Qo.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach(e=>{if(!f(e))throw new Error("bbox must only contain numbers")})},Qo.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},Qo}var ti,ri={};function ni(){if(ti)return ri;ti=1,Object.defineProperty(ri,"__esModule",{value:!0});var e=ei();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var b=0;b<c;b++){var _=0,x=0;if(null!==(s=d?u.geometries[b]:u)){l=s.coordinates;var O=s.type;switch(p=!n||"Polygon"!==O&&"MultiPolygon"!==O?0:1,O){case null:break;case"Point":if(!1===r(l,h,v,_,x))return!1;h++,_++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,_,x))return!1;h++,"MultiPoint"===O&&_++}"LineString"===O&&_++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,_,x))return!1;h++}"MultiLineString"===O&&_++,"Polygon"===O&&x++}"Polygon"===O&&_++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(x=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-p;a++){if(!1===r(l[o][i][a],h,v,_,x))return!1;h++}x++}_++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(r=0;r<g;r++){for(s=h?e.features[r].geometry:f?e.geometry:e,l=h?e.features[r].properties:f?e.properties:{},u=h?e.features[r].bbox:f?e.bbox:void 0,d=h?e.features[r].id:f?e.id:void 0,a=(c=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=c?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,r){o(t,function(t,n,o,i,a){var s,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==r(e.feature.call(void 0,t,o,{bbox:i,id:a}),n,0)&&void 0}switch(c){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:s,coordinates:t.coordinates[l]};if(!1===r(e.feature.call(void 0,u,o),n,l))return!1}})}function a(r,n){i(r,function(r,o,i){var a=0;if(r.geometry){var s=r.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var c,l=0,u=0,d=0;return!1!==t(r,function(t,s,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return ri.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},ri.coordEach=t,ri.coordReduce=function(e,r,n,o){var i=n;return t(e,function(e,t,o,a,s){i=0===t&&void 0===n?e:r(i,e,t,o,a,s)},o),i},ri.featureEach=n,ri.featureReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},ri.findPoint=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.coordIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return e.point.call(void 0,l,c,r);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,r);case"LineString":return s<0&&(s=l.length+s),e.point.call(void 0,l[s],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s),e.point.call(void 0,l[a][s],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),e.point.call(void 0,l[i][s],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s),e.point.call(void 0,l[i][a][s],c,r)}throw new Error("geojson is invalid")},ri.findSegment=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.segmentIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=l.length+s-1),e.lineString.call(void 0,[l[s],l[s+1]],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s-1),e.lineString.call(void 0,[l[a][s],l[a][s+1]],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s-1),e.lineString.call(void 0,[l[i][s],l[i][s+1]],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s-1),e.lineString.call(void 0,[l[i][a][s],l[i][a][s+1]],c,r)}throw new Error("geojson is invalid")},ri.flattenEach=i,ri.flattenReduce=function(e,t,r){var n=r;return i(e,function(e,o,i){n=0===o&&0===i&&void 0===r?e:t(n,e,o,i)}),n},ri.geomEach=o,ri.geomReduce=function(e,t,r){var n=r;return o(e,function(e,o,i,a,s){n=0===o&&void 0===r?e:t(n,e,o,i,a,s)}),n},ri.lineEach=s,ri.lineReduce=function(e,t,r){var n=r;return s(e,function(e,o,i,a){n=0===o&&void 0===r?e:t(n,e,o,i,a)}),n},ri.propEach=r,ri.propReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},ri.segmentEach=a,ri.segmentReduce=function(e,t,r){var n=r,o=!1;return a(e,function(e,i,a,s,c){n=!1===o&&void 0===r?e:t(n,e,i,a,s,c),o=!0}),n},ri}var oi,ii,ai={};function si(){if(oi)return ai;oi=1,Object.defineProperty(ai,"__esModule",{value:!0});var e=ni();function t(t,r={}){if(null!=t.bbox&&!0!==r.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}var r=t;return ai.bbox=t,ai.default=r,ai}var ci=function(){if(ii)return Lo.exports;ii=1;var e=Wo,t=ei(),r=ni(),n=si().default,o=r.featureEach;r.coordEach,t.polygon;var i=t.featureCollection;function a(t){var r=new e(t);return r.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.insert.call(this,t)},r.load=function(t){var r=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}),e.prototype.load.call(this,r)},r.remove=function(t,r){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.remove.call(this,t,r)},r.clear=function(){return e.prototype.clear.call(this)},r.search=function(t){var r=e.prototype.search.call(this,this.toBBox(t));return i(r)},r.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},r.all=function(){var t=e.prototype.all.call(this);return i(t)},r.toJSON=function(){return e.prototype.toJSON.call(this)},r.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},r.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=n(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=n(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},r}return Lo.exports=a,Lo.exports.default=a,Lo.exports}(),li=ce(ci);function ui(e,t){var r={},n=[];if("LineString"===e.type&&(e=P(e)),"LineString"===t.type&&(t=P(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=di(e,t);return o&&n.push(o),O(n)}var i=li();return i.load(To(t)),E(To(e),function(e){E(i.search(e),function(t){var o=di(e,t);if(o){var i=Oo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),O(n)}function di(e,t){var r=Oo(e),n=Oo(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],d=n[1][1],p=(d-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var g=h/p,m=f/p;return g>=0&&g<=1&&m>=0&&m<=1?y([o+g*(a-o),i+g*(s-i)]):null}function pi(e,t,r){void 0===r&&(r={});var n=y([1/0,1/0],{dist:1/0}),o=0;return x(e,function(e){for(var i=Oo(e),a=0;a<i.length-1;a++){var s=y(i[a]);s.properties.dist=Po(t,s,r);var c=y(i[a+1]);c.properties.dist=Po(t,c,r);var l=Po(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=Co(s,c),p=Mo(t,u,d+90,r),h=Mo(t,u,d-90,r),f=ui(_([p.geometry.coordinates,h.geometry.coordinates]),_([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Po(t,g,r),g.properties.location=o+Po(s,g,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),g&&g.properties.dist<n.properties.dist&&((n=g).properties.index=a),o+=l}}),n}function hi(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function fi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=hi(e),i=h(o[0]),a=h(o[1]),s=h(r),c=g(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=m(u),p=m(l);return y([d,p],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=hi(e),o=hi(t),i=h(o[1]-n[1]),a=h(o[0]-n[0]),s=h(n[1]),c=h(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return f(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,Co(e,t));return r}var gi=function(){return gi=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},gi.apply(this,arguments)},yi=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],r=0;r<e.features.length;r++){var n=e.features[r],o=n.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var a=this.features.unknow.snapPoints;i=gi(gi({},i),a)}var s=this.doSnap(n,i);t.push(s)}else if(void 0!==this.features.unknow){a=this.features.unknow.snapPoints,s=this.doSnap(n,a);t.push(s)}else t.push(n)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Po(y(e),y(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],d=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=Po(y([r.lng,r.lat]),y([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var a=!1,s=this.getCloseFeatures(e,i);s?(this.snapStatus=!0,this.snapCoords=s.coords,a=function(e,t,r={}){const n=r.steps||64,o=r.properties?r.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<n;o++)i.push(So(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),v([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=O(0==a?[]:[a]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(O([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n=S(e),o=[];if(n.map(function(e){var n=Po(y(e),y([t.lng,t.lat]),{units:"meters"});n<r&&o.push({coords:e,dist:n,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(_(e))});break;case"Polygon":var o=wo(e.geometry);n.push(o);break;case"MultiPolygon":wo(e.geometry).coodinates.map(function(e){n.push(_(e))})}return n},e.prototype.searchInMidPoint=function(e,t,r){var n=this.getLines(e,t,r),o=[];n.map(function(e){o=o.concat(To(e).features)});var i=[];if(o.map(function(e){var n=fi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Po(n,y([t.lng,t.lat]),{units:"meters"});o<r&&i.push({coords:n.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,r){for(var n=this.getLines(e,t,r),o=[],i=0;i<n.length;i++){var a=pi(n[i],y([t.lng,t.lat]),{units:"meters"});void 0!==a.properties.dist&&a.properties.dist<r&&o.push({coords:a.geometry.coordinates,dist:a.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var r=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(r.length>0){for(var n,o=!1,i=0;i<r.length;i++){var a=r[i],s=this.options.rules,c=e.lngLat;if(o=!1,-1!==s.indexOf("vertex")&&null==n&&(n=this.searchInVertex(a,c,t))){o=!0;break}if(-1!==s.indexOf("midpoint")&&null==n&&(n=this.searchInMidPoint(a,c,t))){o=!0;break}if(-1!==s.indexOf("edge")&&null==n&&(n=this.searchInEdge(a,c,t))){o=!0;break}}return!!o&&n}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}(),mi="snap-helper-circle",vi="mapbox-gl-draw-hot";function bi(e){if(!yi.prototype.__snapPatched){yi.prototype.__snapPatched=!0;var t=yi.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){var r,n;if(this.status){var o=t.setMapData.call(this,e);return(null==e||null===(r=e.features)||void 0===r?void 0:r.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(mi)&&this.map.setLayoutProperty(mi,"visibility","visible"),o}},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,r,n){var o=e.geometry;if(null==o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>v(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>_(e)):t.getLines.call(this,e,r,n)}catch(e){return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];var o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));var i=this.options.radius||n.snapRadius,a=e.point;e.point=[[a.x-i,a.y-i],[a.x+i,a.y+i]];var s=t.getCloseFeatures.call(this,e,r);return e.point=a,s}}(t,r),function(e,t,r){e.searchInVertex=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInVertex.apply(this,n);return i&&(i.color=r.vertex),i},e.searchInMidPoint=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInMidPoint.apply(this,n);return i&&(i.color=r.midpoint),i},e.searchInEdge=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInEdge.apply(this,n);return i&&(i.color=r.edge),i}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){var r;if(this.status&&(null===(r=this.map)||void 0===r||!r._isZooming)&&(!this._autoSnapSuspended||e._explicit))try{var n,o,i=t.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}}function _i(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function xi(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}var Oi=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Pi(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(mi)&&e.removeLayer(mi),e.getSource(mi)&&e.removeSource(mi)}(e),xi(r);var o=new yi({map:e,drawing:t,options:{layers:n.layers,radius:n.radius,rules:n.rules},status:n.status,onSnapped:n.onSnapped});return function(e,t,r){var n=t;Object.defineProperty(e,"status",{get:()=>n&&Oi.has(r.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{n=e}}(o,n.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,n.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function Ei(e,t,r){e.on("style.load",()=>{_i(()=>e._removed?null:e.getSource(vi),n=>{xi(n),function(e){var t;e.getSource(mi)||e.addSource(mi,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(mi)||e.addLayer({id:mi,type:"fill",source:mi,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Pi(e,t,n,r)})})}function Si(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function wi(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:a=[],radius:s=n.snapRadius,rules:c=["vertex","midpoint","edge"],status:l=!1,onSnapped:u=()=>{},colors:d={}}=o,p={layers:a,radius:s,rules:c,status:l,onSnapped:u};return bi(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Si(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Si(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:i.snapVertex,midpoint:i.snapMidpoint,edge:i.snapEdge},d)),Ei(t,r,p),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(mi)){e.setLayoutProperty(mi,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(mi,"visibility","visible")}})}(t),_i(()=>t._removed?null:t.getSource(vi),e=>Pi(t,r,e,p)),t._snapInstance}var Ii=e=>{var t=[];return{push(r){t.push(r),e(t.length)},pop(){var r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}},Ci=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];var r=Object.values(e)[0];return null!=r?r:null}return null},Mi={symbol:"pin",backgroundColor:"#ca3535",foregroundColor:"#ffffff"},Ti={dot:"M8 3c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.241 5-5-2.24-5-5-5z",cross:"M6 3H10V6H13V10H10V13H6V10H3V6H6Z",diamond:"M8 2L14 8L8 14L2 8Z",triangle:"M8 2L14 14H2Z",square:"M3 3H13V13H3Z"},Li={id:"pin",viewBox:"0 0 44 44",anchor:[.5,.9],graphic:Ti.dot,svg:'<path d="M22 40.999c-3.621 0-8.306-5.864-10.258-8.3C9.02 29.302 6 23.66 6 19.002a16.01 16.01 0 0 1 16-16 16.01 16.01 0 0 1 16 16c0 4.658-3.02 10.3-5.742 13.697-1.952 2.437-6.637 8.3-10.258 8.3z" fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>\n <path d="M22 7.001a12.01 12.01 0 0 1 12 12c0 7.623-10.377 17.998-12 17.998S10 26.624 10 19.001a12.01 12.01 0 0 1 12-12z" fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>\n <g transform="translate(22, 19) scale(0.8) translate(-8, -8)"><path d="{{graphic}}" fill="{{foregroundColor}}"/></g>'},ki={id:"circle",viewBox:"0 0 44 44",anchor:[.5,.5],graphic:Ti.dot,svg:'<circle cx="22" cy="22" r="16" fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>\n <circle cx="22" cy="22" r="12" fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>\n <g transform="translate(22, 22) scale(0.8) translate(-8, -8)"><path d="{{graphic}}" fill="{{foregroundColor}}"/></g>'},Ai={id:"square",viewBox:"0 0 44 44",anchor:[.5,.5],graphic:Ti.dot,svg:'<path d="M13 6h18c3.863 0 7 3.137 7 7v18c0 3.863-3.137 7-7 7H13c-3.863 0-7-3.137-7-7V13c0-3.863 3.137-7 7-7" fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>\n <path d="M13 34a3 3 0 0 1-3-3V13a3 3 0 0 1 3-3h18a3 3 0 0 1 3 3v18a3 3 0 0 1-3 3H13z" fill-rule="nonzero" fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>\n <g transform="translate(22, 22) scale(0.8) translate(-8, -8)"><path d="{{graphic}}" fill="{{foregroundColor}}"/></g>'},ji=new Set(["symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),Vi=e=>{if(!(e=>!(!e.symbol&&!e.symbolSvgContent))(e))return{};var t={};return ji.forEach(r=>{if(null!=e[r]){var n=r.charAt(6).toLowerCase()+r.slice(7);t[n]=e[r]}}),t},Fi=(e,t)=>{var r;return e.symbolViewBox?e.symbolViewBox:null!==(r=null==t?void 0:t.viewBox)&&void 0!==r?r:"0 0 38 38"},Di=(e,t)=>{var r;return e.symbolAnchor?e.symbolAnchor:null!==(r=null==t?void 0:t.anchor)&&void 0!==r?r:[.5,.5]},Ni={light:{haloColor:"#ffffff",selectedColor:"#0b0c0c",activeColor:"#ffdd00",foregroundColor:"#0b0c0c"},dark:{haloColor:"#0b0c0c",selectedColor:"#ffffff",activeColor:"#ffdd00",foregroundColor:"#ffffff"}};function Ri(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ui(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ri(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ri(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Bi=new Map,Gi=new Map,Hi={},Yi=e=>{var t=0;for(var r of e)t=Math.trunc((t<<5)-t+r.codePointAt(0));return Math.abs(t).toString(36)},Xi=new Set(["id","svg","viewBox","anchor","symbol","symbolSvgContent"]);function Ki(e,t,r){var n,o,i,a,s=null==r?void 0:r.id,c=Object.fromEntries(Object.entries(e||{}).filter(e=>{var[t]=e;return!Xi.has(t)})),l=Object.fromEntries(Object.entries(Hi).filter(e=>{var[t]=e;return!Xi.has(t)})),u=Object.fromEntries(Object.entries(t).filter(e=>{var[,t]=e;return null!=t})),d=Ui(Ui(Ui(Ui({},Mi),l),c),u),p=null!==(n=Ni[null==r?void 0:r.mapColorScheme])&&void 0!==n?n:Ni.light;return d.haloColor=null!==(o=null==r?void 0:r.haloColor)&&void 0!==o?o:p.haloColor,d.selectedColor=null!==(i=null==r?void 0:r.selectedColor)&&void 0!==i?i:p.selectedColor,d.activeColor=null!==(a=null==r?void 0:r.activeColor)&&void 0!==a?a:p.activeColor,"string"==typeof d.graphic&&Ti[d.graphic]&&(d.graphic=Ti[d.graphic]),Object.fromEntries(Object.entries(d).map(e=>{var[t,r]=e;return[t,Ci(r,s)||""]}))}function Ji(e,t){return Object.entries(t).reduce((e,t)=>{var[r,n]=t;return e.replaceAll("{{".concat(r,"}}"),n)},e)}var $i={setDefaults(e){Hi=e||{}},getDefaults:()=>Ui(Ui({},Mi),Hi),register(e){Bi.set(e.id,e)},get:e=>Bi.get(e),list:()=>[...Bi.values()],clear(){Bi.clear()},initialise(){this.register(Li),this.register(ki),this.register(Ai)},resolve(e,t,r){var n=Ki(e,t||{},r);return e?(n.selectedColor="none",n.activeColor="none",Ji(e.svg,n)):""},resolveActive(e,t,r){var n=Ki(e,t||{},r);return e?Ji(e.svg,n):""},resolveSelected(e,t,r){var n=Ki(e,t||{},r);return e?(n.activeColor="none",Ji(e.svg,n)):""},getSymbolImageId(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2,o=this.getSymbolDef(e);if(!o)return null;var i=Vi(e),a=r?this.resolveActive(o,i,t):this.resolve(o,i,t);return"symbol-".concat(r?"act-":"").concat(Yi(a),"-").concat(n,"x")},getSymbolDef(e){return e.symbolSvgContent?{svg:e.symbolSvgContent}:e.symbol?this.get(e.symbol):void 0},rasteriseSymbolImage(e,t,r,n){var o=this;return k(function*(){var i=o.getSymbolDef(e);if(!i)return null;var a,s,c=Vi(e);"active"===r?(a=o.resolveActive(i,c,t),s="act-"):"selected"===r?(a=o.resolveSelected(i,c,t),s="sel-"):(a=o.resolve(i,c,t),s="");var l="symbol-".concat(s).concat(Yi(a),"-").concat(n,"x"),u=Gi.get(l);if(!u){var d=Fi(e,i),[,,p,h]=d.split(" ").map(Number),f='<svg xmlns="http://www.w3.org/2000/svg" width="'.concat(p*n,'" height="').concat(h*n,'" viewBox="').concat(d,'">').concat(a,"</svg>");u=yield((e,t,r)=>new Promise((n,o)=>{var i="data:image/svg+xml;charset=utf-8,".concat(encodeURIComponent(e)),a=new Image(t,r);a.onload=()=>{var e=document.createElement("canvas");e.width=t,e.height=r;var o=e.getContext("2d");o.drawImage(a,0,0,t,r),n(o.getImageData(0,0,t,r))},a.onerror=()=>{o(new Error("Failed to rasterise SVG: ".concat(e.slice(0,80))))},a.src=i}))(f,p*n,h*n),Gi.set(l,u)}return{imageId:l,imageData:u}})()}};$i.initialise();var qi=.25,zi=.75,Zi=e=>{var[t,r]=e,n=(e=>e<=qi?"left":e>=zi?"right":"")(t),o=(e=>e<=qi?"top":e>=zi?"bottom":"")(r);return o+(n&&o?"-":"")+n||"center"},Wi=e=>e<=qi?0:e>=zi?1:.5,Qi=e=>Math.round(100*e)/100;function ea(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ta(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ea(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ea(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ra=e=>!!(null!=e&&e.symbol||null!=e&&e.symbolSvgContent),na=(e,t,r)=>{var n;if(null!==(n=e._symbolIconOffsetMap)&&void 0!==n||(e._symbolIconOffsetMap={}),!e._symbolIconOffsetMap[t]){e._symbolIconOffsetMap[t]=r;var o=(e=>{var t=["match",["get","user_symbolImageId"]];for(var[r,n]of Object.entries(e))t.push(r,["literal",n]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);["hot","cold"].forEach(t=>{var r="".concat("point-symbol",".").concat(t);e.getLayer(r)&&e.setLayoutProperty(r,"icon-offset",o)})}},oa=function(){var e=k(function*(e){var t,r,n,o,{draw:i,mapProvider:a,map:s,featureId:c,properties:l,pixelRatioOverride:u}=e;if(!ra(l))return null;var d=s._drawCurrentMapStyle,p=null!=u?u:(e=>{var t;return(null===(t=e.getPixelRatio)||void 0===t?void 0:t.call(e))||1})(s);yield a.addSymbolsToMap([l],d,$i);var h=i.get(c);if(!h)return null;var f=$i.getSymbolImageId(l,d,!1,p);if(!f)return null;var g=null!==(t=null===(r=s._activeSymbolImageMap)||void 0===r?void 0:r[f])&&void 0!==t?t:null,y=null!==(n=null===(o=s._selectedSymbolImageMap)||void 0===o?void 0:o[f])&&void 0!==n?n:null,m=$i.getSymbolDef(l),v=Di(l,m),b=Zi(v),_=((e,t)=>{var[r,n]=e,[,,o,i]=t.split(" ").map(Number);return[Qi((Wi(r)-r)*o),Qi((Wi(n)-n)*i)]})(v,Fi(l,m));return na(s,f,_),ta(ta({},h),{},{properties:ta(ta({},l),{},{symbolImageId:f,symbolIconAnchor:b,symbolActiveImageId:g,symbolSelectedImageId:y})})});return function(t){return e.apply(this,arguments)}}(),ia=function(){var e=k(function*(e){try{var t=yield oa(e);if(!t)return;e.draw.add(t)}catch(t){console.error("[draw] failed to resolve point symbol",e.featureId,t)}});return function(t){return e.apply(this,arguments)}}(),aa=function(){var e=k(function*(e){var{draw:t,mapProvider:r,map:n,pixelRatioOverride:o}=e,i=t.getAll().features.filter(e=>"Point"===e.geometry.type&&ra(e.properties)),a=yield Promise.allSettled(i.map(e=>oa({draw:t,mapProvider:r,map:n,featureId:e.id,properties:e.properties,pixelRatioOverride:o})));a.filter(e=>"rejected"===e.status).forEach(e=>{console.error("[draw] failed to resolve point symbol",e.reason)});var s=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);s.length&&t.add({type:"FeatureCollection",features:s})});return function(t){return e.apply(this,arguments)}}();function sa(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ca(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?sa(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):sa(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var la="mapbox-gl-draw-cold",ua="mapbox-gl-draw-hot",da=e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:i}=e,a=t._drawCurrentMapStyle;t.once("idle",()=>{var e,s=((e,t)=>{if(e.getSource(la))return!1;var r={type:"FeatureCollection",features:[]};return e.addSource(la,{data:r,type:"geojson"}),e.addSource(ua,{data:r,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(t,r);!function(e,t){_o(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})}(t,a,o);var c=null===(e=t._drawEditContainer)||void 0===e?void 0:e.querySelector("[data-im-draw-touch-target]");Jr(c,a,o),aa({draw:r,mapProvider:n,map:t}).then(()=>{s&&r.set(r.getAll()),t.triggerRepaint(),i()})})},pa=e=>{var t,{mapStyle:r,mapProvider:o,events:i,eventBus:a,snapLayers:s,pluginConfig:c={}}=e,{map:l}=o;Kt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Kt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Kt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var u=ca(ca({},Kt.modes),{},{disabled:Jt,edit_vertex:hn,edit_point:Mn,draw_polygon:Zn,draw_line:Wn,draw_point:ao}),d=o._mapboxDrawInstance;d?Object.assign(d.modes,u):(d=new Kt({modes:u,styles:_o(r,c),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),l.addControl(d),o._mapboxDrawInstance=d);var p=((e,t)=>{var r=e.getCanvas(),n=null,o=e=>{1===e.touches.length&&(n={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"===t.getMode()&&n){var o=e.changedTouches[0],i=o.clientX-n.x,a=o.clientY-n.y;Date.now()-n.time<300&&Math.abs(i)<10&&Math.abs(a)<10&&r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),n=null}else n=null};return r.addEventListener("touchstart",o,{passive:!0}),r.addEventListener("touchend",i,{passive:!0}),{remove(){r.removeEventListener("touchstart",o),r.removeEventListener("touchend",i)}}})(l,d);o.draw=d,l._drawCurrentMapStyle=r,l._drawPluginConfig=c,o.snapEnabled=!1;var h=o.undoStack;h||(h=Ii(e=>l.fire("draw.undochange",{length:e})),o.undoStack=h),l._undoStack=h;var f=Br(r,c);wi(l,d,{layers:s,radius:null!==(t=c.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:f.snapVertex,edge:f.snapEdge}});var g=()=>a.emit(i.MAP_DATA_CHANGE),{handleSetMapStyle:y,handleStyleChanged:m}=(e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,eventBus:i,events:a,notifyPointSymbolsRefreshed:s}=e,c=e=>{t._drawCurrentMapStyle=e};i.on(a.MAP_SET_STYLE,c);var l=!1,u=()=>{l||(l=!0,da({map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:()=>{l=!1,s()}}))};return i.on(a.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:l,draw:d,mapProvider:o,pluginConfig:c,eventBus:a,events:i,notifyPointSymbolsRefreshed:g}),v=e=>{l.fire("draw.scalechange",{scale:w[e]})};a.on(i.MAP_SET_SIZE,v);var b=e=>{aa({draw:d,mapProvider:o,map:l,pixelRatioOverride:e}).then(()=>{l.triggerRepaint(),g()})};return a.on(i.MAP_SET_PIXEL_RATIO,b),{draw:d,remove(){p.remove(),a.off(i.MAP_SET_STYLE,y),a.off(i.MAP_STYLE_CHANGE,m),a.off(i.MAP_SET_SIZE,v),a.off(i.MAP_SET_PIXEL_RATIO,b),d.changeMode("disabled"),o.draw=null}}};function ha(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function fa(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ha(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ha(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ga=e=>"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,16),ya=e=>"function"==typeof cancelAnimationFrame?cancelAnimationFrame(e):clearTimeout(e),ma=e=>{var{onChange:t,validate:r=I}=e,n=!1,o=null,i=null,a=()=>{null!=o&&(ya(o),o=null),i=null},s=(e,r)=>{e!==n&&(n=e,t(e,null!=r?r:null))},c=()=>{if(o=null,i){var{feature:e,context:t,onGeometryChange:n}=i,{valid:a,reason:c}=r(e,t,{onGeometryChange:n});s(!a,c)}};return{update(e){var{feature:t,context:n={},numVertices:l,onGeometryChange:u}=e,d=fa(fa({},n),{},{numVertices:l}),p=r(t,d);return p.valid?"function"!=typeof u?(a(),void s(!1,null)):(i={feature:t,context:d,onGeometryChange:u},void(null==o&&(o=ga(c)))):(a(),void s(!0,p.reason))},set(e,t){a(),s(e,null!=t?t:null)},refresh(){t(n,null)},destroy(){a()}}};function va(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ba(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?va(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):va(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var _a=e=>{var{onStrokeChange:t,onPlaceChange:r}=e,n=e=>{var t=!1;return(r,n)=>{r!==t&&(t=r,e(r,null!=n?n:null))}},o=n(t),i=n(r),a=!1,c=null,l=null,u=null,d=()=>{null!=l&&(ya(l),l=null),u=null},p=(e,t,r,n,o)=>{var i,s=(null!==(i=t.numVertices)&&void 0!==i?i:0)<n?{valid:!0}:C(e,ba(ba({},t),{},{phase:"preview"}),{rules:r});o(!s.valid||a,s.valid?c:s.reason)},h=()=>{var e,t;if(u){var{feature:r,context:n}=u,a=null!==(e=s[null==r||null===(t=r.geometry)||void 0===t?void 0:t.type])&&void 0!==e?e:0;p(r,n,M,a,o),p(r,n,T,0,i)}},f=()=>{if(l=null,u){var{feature:e,context:t,onGeometryChange:r}=u,n=C(e,ba(ba({},t),{},{phase:"preview"}),{rules:[],onGeometryChange:r});a=!n.valid,c=n.reason,h()}};return{update(e){var{feature:t,context:r={},numVertices:n,onGeometryChange:o}=e;u={feature:t,context:ba(ba({},r),{},{numVertices:n}),onGeometryChange:o},h(),"function"==typeof o&&null==l&&(l=ga(f))},reset(){d(),a=!1,c=null,o(!1,null),i(!1,null)},destroy(){d()}}};function xa(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Oa(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?xa(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):xa(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Pa=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),Ea=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),Sa=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),wa=(e,t)=>{var r,n,o;if("draw_polygon"===e)return{feature:Pa(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1};if("draw_line"===e)return{feature:Ea(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1};if("edit_vertex"===e){var i,a=t[0];return Array.isArray(null==a?void 0:a[0])?{feature:Pa(t),numVertices:a.length}:{feature:Ea(t),numVertices:null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0}}return"edit_point"===e?{feature:Sa(t),numVertices:1}:null};var Ia=Object.freeze({__proto__:null,MaplibreDrawAdapter:class{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._bus=(n=new Map,{on(e,t){n.has(e)||n.set(e,new Set),n.get(e).add(t)},off(e,t){var r;null===(r=n.get(e))||void 0===r||r.delete(t)},emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var i=n.get(e);i&&Array.from(i).forEach(e=>e(...r))}}),this._editingFeatureId=null,this._sortKeyCounter=0;var{draw:o,remove:i}=pa({mapStyle:t.mapStyle,mapProvider:e,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:null!==(r=t.pluginConfig)&&void 0!==r?r:{}});this._draw=o,this._cleanupDraw=i,this._liveStroke=ma({onChange:(e,t)=>{this._applyStrokeInvalid(e);var r=this._draw.getMode();"edit_vertex"!==r&&"edit_point"!==r||this._bus.emit(L.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=_a({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(L.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{var t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(L.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(L.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(L.CANCEL),vertexselection:e=>this._bus.emit(L.VERTEX_SELECTION,Oa(Oa({},e),{},{numVertices:e.numVertecies})),vertexchange:e=>this._bus.emit(L.VERTEX_CHANGE,Oa(Oa({},e),{},{numVertices:e.numVertecies})),undochange:e=>this._bus.emit(L.UNDO_CHANGE,e.length),update:e=>this._bus.emit(L.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(L.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(L.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(L.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on($t,this._mapHandlers.create),this._map.on(Zt,this._mapHandlers.editfinish),this._map.on(Wt,this._mapHandlers.cancel),this._map.on(Qt,this._mapHandlers.vertexselection),this._map.on(er,this._mapHandlers.vertexchange),this._map.on(tr,this._mapHandlers.undochange),this._map.on(qt,this._mapHandlers.update),this._map.on(nr,this._mapHandlers.geometrychange),this._map.on(ir,this._mapHandlers.placementblocked),this._map.on(or,this._mapHandlers.interfacetypechange),this._map.on(zt,this._mapHandlers.modechange),this._map.on(sr,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=null!==(t=r.featureId)&&void 0!==t?t:null);"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(r=Oa(Oa({},r),{},{resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)})),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){return ia({draw:this._draw,mapProvider:this._mapProvider,map:this._map,featureId:e,properties:t})}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=wa(t,e.coordinates);r&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:r.feature,numVertices:r.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update(Oa(Oa({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(or,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if(("edit_vertex"===t||"edit_point"===t)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(Zt,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==t&&"draw_line"!==t||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();"draw_polygon"!==t&&"draw_line"!==t||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(rr)}nudgeSelectedVertex(e,t,r){this._map.fire(ar,{dx:e,dy:t,isLargeStep:r})}setGeometryValid(e){this._map._drawGeometryValid=e}set _geometryValidator(e){this._map._drawGeometryValidator=e}get _geometryValidator(){return this._map._drawGeometryValidator}setInvalid(e){this._liveStroke.set(e)}_applyStrokeInvalid(e){this._setLayerVisibility("stroke-active",!e),this._setLayerVisibility("stroke-active-invalid",e),this._setLayerVisibility("fill-active",!e)}_setLayerVisibility(e,t){["hot","cold"].forEach(r=>{var n="".concat(e,".").concat(r);this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){var t,r,n=null==(null===(t=e.properties)||void 0===t?void 0:t.sortKey)?Oa(Oa({},e.properties),{},{sortKey:this._nextSortKey()}):e.properties,o=Oa(Oa({},e),{},{properties:n}),i=this._draw.add(o);return"Point"===(null===(r=o.geometry)||void 0===r?void 0:r.type)&&ra(n)&&this._resolvePointSymbol(i[0],n),i}setStyle(e,t){var r=this._draw.get(e);r&&this.add(Oa(Oa({},r),{},{properties:Oa(Oa({},r.properties),t)}))}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=mr(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(Er(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=mr(this._map);null!=t&&t.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,r){this._draw.setFeatureProperty(e,t,r)}setDrawingPreviewProperty(e,t){var r,n=this._currentDrawEvent;null!=n&&n.properties&&(n.properties[e]=t),null==n||null===(r=n.ctx)||void 0===r||null===(r=r.store)||void 0===r||r.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]).has(e.mode)||Pr(mr(this._map),this._map)}_handleStyleData(){var e,t=this._map.getStyle();if(t){this._liveStroke.refresh();var r=t.layers||[];!r.length||null!==(e=r[r.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||r.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>this._map.moveLayer(e.id))}}remove(){this._map.off($t,this._mapHandlers.create),this._map.off(Zt,this._mapHandlers.editfinish),this._map.off(Wt,this._mapHandlers.cancel),this._map.off(Qt,this._mapHandlers.vertexselection),this._map.off(er,this._mapHandlers.vertexchange),this._map.off(tr,this._mapHandlers.undochange),this._map.off(qt,this._mapHandlers.update),this._map.off(nr,this._mapHandlers.geometrychange),this._map.off(ir,this._mapHandlers.placementblocked),this._map.off(or,this._mapHandlers.interfacetypechange),this._map.off(zt,this._mapHandlers.modechange),this._map.off(sr,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}},displayedShape:wa});export{Ia as M,_a as a,Fr as b,ma as c,Dr as d,Nr as e,Ii as f,Di as g,Rr as h,Ur as i,Br as r,$i as s};
1
+ import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,S as o,C as i,K as a,M as s,v as c,a as l,b as u,d,e as p,r as h,l as f,p as g,f as y,g as m,m as v,h as _,j as b,k as x,n as P,o as O,q as E,s as S,t as w,u as I,w as M,x as C,y as T,L,H as k,A}from"./im-draw-plugin.js";import j from"@babel/runtime/helpers/asyncToGenerator";const V={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"},F={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},N={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},D={POLYGON:"polygon",LINE:"line_string",POINT:"point"},R={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"},U={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},B={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"},G={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},H={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},Y={ACTIVE:"true",INACTIVE:"false"},X=["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:Y,classes:V,cursors:N,events:B,geojsonTypes:R,interactions:X,meta:H,modes:U,sources:F,types:D,updateActions:G});function J(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function $(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===Y.ACTIVE&&e.featureTarget.properties.meta===H.FEATURE))}function z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===Y.INACTIVE&&e.featureTarget.properties.meta===H.FEATURE))}function Z(e){return void 0===e.featureTarget}function W(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===H.FEATURE)}function Q(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===H.VERTEX)}function ee(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function te(e){return"Escape"===e.key||27===e.keyCode}function re(e){return"Enter"===e.key||13===e.keyCode}function ne(e){return"Backspace"===e.key||8===e.keyCode}function oe(e){return"Delete"===e.key||46===e.keyCode}function ie(e){return"1"===e.key||49===e.keyCode}function ae(e){return"2"===e.key||50===e.keyCode}function se(e){return"3"===e.key||51===e.keyCode}function ce(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var le=Object.freeze({__proto__:null,isActiveFeature:q,isBackspaceKey:ne,isDeleteKey:oe,isDigit1Key:ie,isDigit2Key:ae,isDigit3Key:se,isDigitKey:ce,isEnterKey:re,isEscapeKey:te,isFeature:W,isInactiveFeature:z,isOfMetaType:J,isShiftDown:ee,isShiftMousedown:$,isTrue:function(){return!0},isVertex:Q,noTarget:Z});function ue(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function de(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var pe,he,fe={},ge={};function ye(){return pe||(pe=1,ge.RADIUS=6378137,ge.FLATTENING=1/298.257223563,ge.POLAR_RADIUS=6356752.3142),ge}var me=function(){if(he)return fe;he=1;var e=ye();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(r(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(r(e[n]))}return t}function r(t){var r,o,i,a,s,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,a=u-1,s=0):c===u-1?(i=u-1,a=0,s=1):(i=c,a=c+1,s=c+2),r=t[i],o=t[a],l+=(n(t[s][0])-n(r[0]))*Math.sin(n(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function n(e){return e*Math.PI/180}return fe.geometry=function e(r){var n,o=0;switch(r.type){case"Polygon":return t(r.coordinates);case"MultiPolygon":for(n=0;n<r.coordinates.length;n++)o+=t(r.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<r.geometries.length;n++)o+=e(r.geometries[n]);return o}},fe.ring=r,fe}(),ve=ue(me);const _e={Point:0,LineString:1,MultiLineString:1,Polygon:2};function be(e,t){const r=_e[e.geometry.type]-_e[t.geometry.type];return 0===r&&e.geometry.type===R.POLYGON?e.area-t.area:r}function xe(e){return e.map(e=>(e.geometry.type===R.POLYGON&&(e.area=ve.geometry({type:R.FEATURE,property:{},geometry:e.geometry})),e)).sort(be).map(e=>(delete e.area,e))}function Pe(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Oe(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}Oe.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Oe.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Oe.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Oe.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)},Oe.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Ee=[H.FEATURE,H.MIDPOINT,H.VERTEX];var Se={click:function(e,t,r){return we(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return we(e,t,r,r.options.touchBuffer)}};function we(e,t,r,n){if(null===r.map)return[];const o=e?Pe(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==Ee.indexOf(e.properties.meta)),s=new Oe,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),xe(c)}function Ie(e,t){const r=Se.click(e,null,t),n={mouse:N.NONE};return r[0]&&(n.mouse=r[0].properties.active===Y.ACTIVE?N.MOVE:N.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=N.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function Me(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function Ce(e,t,r={}){const n=null!=r.fineTolerance?r.fineTolerance:4,o=null!=r.grossTolerance?r.grossTolerance:12,i=null!=r.interval?r.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const a=Me(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Te(e,t,r={}){const n=null!=r.tolerance?r.tolerance:25,o=null!=r.interval?r.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return Me(e.point,t.point)<n&&t.time-e.time<o}const Le=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===r[e])throw new Error(`Invalid event type: ${e}`);r[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=r[e];let a=i.length;for(;a--;){const e=i[a];if(e.selector(o)){e.fn.call(n,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const ke=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Ae(){return ke()}const je=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ae(),this.type=t.geometry.type};je.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},je.prototype.incomingCoords=function(e){this.setCoordinates(e)},je.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},je.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},je.prototype.setProperty=function(e,t){this.properties[e]=t},je.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:R.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},je.prototype.internal=function(e){const t={id:this.id,meta:H.FEATURE,"meta:type":this.type,active:Y.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:R.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ve=function(e,t){je.call(this,e,t)};(Ve.prototype=Object.create(je.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ve.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},Ve.prototype.getCoordinate=function(){return this.getCoordinates()};const Fe=function(e,t){je.call(this,e,t)};(Fe.prototype=Object.create(je.prototype)).isValid=function(){return this.coordinates.length>1},Fe.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},Fe.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Fe.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Fe.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ne=function(e,t){je.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ne.prototype=Object.create(je.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ne.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ne.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ne.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(e=>parseInt(e,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},Ne.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},Ne.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},Ne.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ne.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const De={MultiPoint:Ve,MultiLineString:Fe,MultiPolygon:Ne},Re=(e,t,r,n,o)=>{const i=r.split("."),a=parseInt(i[0],10),s=i[1]?i.slice(1).join("."):null;return e[a][t](s,n,o)},Ue=function(e,t){if(je.call(this,e,t),delete this.coordinates,this.model=De[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 Be(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ue.prototype=Object.create(je.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ae(),type:R.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ue.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ue.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ue.prototype.getCoordinate=function(e){return Re(this.features,"getCoordinate",e)},Ue.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===R.POLYGON?e.getCoordinates():e.coordinates)))},Ue.prototype.updateCoordinate=function(e,t,r){Re(this.features,"updateCoordinate",e,t,r),this.changed()},Ue.prototype.addCoordinate=function(e,t,r){Re(this.features,"addCoordinate",e,t,r),this.changed()},Ue.prototype.removeCoordinate=function(e){Re(this.features,"removeCoordinate",e),this.changed()},Ue.prototype.getFeatures=function(){return this.features},Be.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Be.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),{})},Be.prototype.getSelected=function(){return this._ctx.store.getSelected()},Be.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Be.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Be.prototype.getFeature=function(e){return this._ctx.store.get(e)},Be.prototype.select=function(e){return this._ctx.store.select(e)},Be.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Be.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Be.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Be.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Be.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Be.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Be.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Be.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Be.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Be.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Be.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return Se[r](e,t,this._ctx)},Be.prototype.newFeature=function(e){const t=e.geometry.type;return t===R.POINT?new Ve(this._ctx,e):t===R.LINE_STRING?new Fe(this._ctx,e):t===R.POLYGON?new Ne(this._ctx,e):new Ue(this._ctx,e)},Be.prototype.isInstanceOf=function(e,t){if(e===R.POINT)return t instanceof Ve;if(e===R.LINE_STRING)return t instanceof Fe;if(e===R.POLYGON)return t instanceof Ne;if("MultiFeature"===e)return t instanceof Ue;throw new Error(`Unknown feature class: ${e}`)},Be.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Be.prototype.onSetup=function(){},Be.prototype.onDrag=function(){},Be.prototype.onClick=function(){},Be.prototype.onMouseMove=function(){},Be.prototype.onMouseDown=function(){},Be.prototype.onMouseUp=function(){},Be.prototype.onMouseOut=function(){},Be.prototype.onKeyUp=function(){},Be.prototype.onKeyDown=function(){},Be.prototype.onTouchStart=function(){},Be.prototype.onTouchMove=function(){},Be.prototype.onTouchEnd=function(){},Be.prototype.onTap=function(){},Be.prototype.onStop=function(){},Be.prototype.onTrash=function(){},Be.prototype.onCombineFeature=function(){},Be.prototype.onUncombineFeature=function(){},Be.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Ge={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},He=Object.keys(Ge);function Ye(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Be(r));return{start(){o=i.onSetup(n),He.forEach(t=>{const r=Ge[t];let n=()=>!1;var a;e[r]&&(n=()=>!0),this.on(t,n,(a=r,e=>i[a](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function Xe(e){return[].concat(e).filter(e=>void 0!==e)}function Ke(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(F.HOT)))return s();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let r=[],n=[];e.isDirty?n=e.getAllIds():(r=e.getChangedIds().filter(t=>void 0!==e.get(t)),n=e.sources.hot.filter(t=>t.properties.id&&-1===r.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===r.indexOf(t)});const i=o!==e.sources.cold.length||n.length>0;function a(r,n){const o=e.get(r).internal(t);e.ctx.events.currentModeRender(o,r=>{r.properties.mode=t,e.sources[n].push(r)})}function s(){e.isDirty=!1,e.clearChangedIds()}r.forEach(e=>a(e,"hot")),n.forEach(e=>a(e,"cold")),i&&e.ctx.map.getSource(F.COLD).setData({type:R.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(F.HOT).setData({type:R.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Je(e){let t;this._features={},this._featureIds=new Oe,this._selectedFeatureIds=new Oe,this._selectedCoordinates=[],this._changedFeatureIds=new Oe,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(B.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:R.FEATURE,properties:{},geometry:{type:R.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(B.RENDER,{})}))},this.isDirty=!1}function $e(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}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(B.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(B.UPDATE,{action:t.action?t.action:G.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 r=[];return Xe(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===r.indexOf(this._features[e])&&r.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),r.length&&this.ctx.events.fire(B.DELETE,{features:r}),$e(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 Xe(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 Xe(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),$e(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=Xe(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,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:G.CHANGE_PROPERTIES})},Je.prototype.storeMapConfig=function(){X.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 qe=["mode","feature","mouse"];function ze(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,r)=>(t[r]=Ye(e.options.modes[r]),t),{});let r={},n={};const o={};let i=null,a=null;o.drag=function(t,r){r({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:N.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ce(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Te(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=Ie(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Ie(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Ie(t,e);t.featureTarget=n,Ce(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(e){a.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;n={time:(new Date).getTime(),point:t.point};const r=Se.touch(t,null,e)[0];t.featureTarget=r,a.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const r=Se.touch(t,null,e)[0];t.featureTarget=r,Te(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=ne(e),r=oe(e),n=ce(e);return!(t||r||n)};function c(r,n,o={}){a.stop();const s=t[r];if(void 0===s)throw new Error(`${r} is not valid`);i=r;const c=s(e,n);a=Le(c,e),o.silent||e.map.fire(B.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(V.CANVAS)&&((ne(t)||oe(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):ie(t)&&e.options.controls.point?c(U.DRAW_POINT):ae(t)&&e.options.controls.line_string?c(U.DRAW_LINE_STRING):se(t)&&e.options.controls.polygon&&c(U.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,a=Le(t[i](e),e)},changeMode:c,actionable:function(t){let r=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(r=!0),l[e]=t[e]}),r&&e.map.fire(B.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];qe.forEach(e=>{o[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==o[e]&&r.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),r.length>0&&e.container.classList.add(...r),n=Object.assign(n,o)}function s(e,t={}){const n=document.createElement("button");return n.className=`${V.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),n.target===r)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),n}function c(){r&&(r.classList.remove(V.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(V.ACTIVE_BUTTON),r=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:a,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),a()},addButtons:function(){const r=e.options.controls,n=document.createElement("div");return n.className=`${V.CONTROL_GROUP} ${V.CONTROL_BASE}`,r?(r[D.POINT]&&(t[D.POINT]=s(D.POINT,{container:n,className:V.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(U.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[D.LINE]&&(t[D.LINE]=s(D.LINE,{container:n,className:V.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(U.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[D.POLYGON]&&(t[D.POLYGON]=s(D.POLYGON,{container:n,className:V.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(U.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:V.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:V.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:V.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach(e=>{const r=t[e];r.parentNode&&r.parentNode.removeChild(r),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new 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()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(F.COLD,{data:{type:R.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(F.HOT,{data:{type:R.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(F.COLD)&&e.map.removeSource(F.COLD),e.map.getSource(F.HOT)&&e.map.removeSource(F.HOT)}};return e.setup=n,n}const Ze="#3bb2d0",We="#fbb03b",Qe="#fff";var et=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],We,Ze],"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"],We,Ze],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Qe}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],We,Ze]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Qe}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":We}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":We}}];function tt(e,t){this.x=e,this.y=t}function rt(e,t){const r=t.getBoundingClientRect();return new tt(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function nt(e,t,r,n){return{type:R.FEATURE,properties:{meta:H.VERTEX,parent:e,coord_path:r,active:n?Y.ACTIVE:Y.INACTIVE},geometry:{type:R.POINT,coordinates:t}}}function ot(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return it(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>it(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return st(e);default:throw new Error("unknown GeoJSON type")}}function it(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=at(e.properties),null==e.geometry?t.geometry=null:t.geometry=st(e.geometry),t}function at(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=at(n):t[r]=n}),t):t}function st(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>st(e)),t):(t.coordinates=ct(e.coordinates),t)}function ct(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>ct(e))}function lt(e,t={}){return ut(e,"mercator",t)}function ut(e,n,o={}){var i=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&t(e[0])?e="mercator"===n?dt(e):pt(e):(!0!==i&&(e=ot(e)),r(e,function(e){var t="mercator"===n?dt(e):pt(e);e[0]=t[0],e[1]=t[1]})),e}function dt(e){var t,r=Math.PI/180,n=6378137,o=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*r,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*r))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function pt(e){var t=180/Math.PI,r=6378137;return[e[0]*t/r,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/r)))*t]}function ht(e,t,r){const n=t.geometry.coordinates,o=r.geometry.coordinates;if(n[1]>85||n[1]<-85||o[1]>85||o[1]<-85)return null;const i=lt(n),a=lt(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ut(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:R.FEATURE,properties:{meta:H.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:R.POINT,coordinates:u}}}function ft(e,t={},r=null){const{type:n,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let a=[];function s(e,r){let n="",o=null;e.forEach((e,s)=>{const l=null!=r?`${r}.${s}`:String(s),u=nt(i,e,l,c(l));if(t.midpoints&&o){const e=ht(i,o,u);e&&a.push(e)}o=u;const d=JSON.stringify(e);n!==d&&a.push(u),0===s&&(n=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===R.POINT?a.push(nt(i,o,r,c(r))):n===R.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===R.LINE_STRING?s(o,r):0===n.indexOf(R.MULTI_PREFIX)&&function(){const r=n.replace(R.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:R.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(ft(i,t,o))})}(),a}tt.prototype={clone(){return new tt(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,o=r*this.x+t*this.y;return this.x=n,this.y=o,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),o=t.x+r*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:tt},tt.convert=function(e){if(e instanceof tt)return e;if(Array.isArray(e))return new tt(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new tt(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var gt={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:mt,LAT_RENDERED_MIN:vt,LAT_RENDERED_MAX:_t,LNG_MIN:bt,LNG_MAX:xt}=K;function Pt(e,t){let r=yt,n=mt,o=yt,i=mt,a=xt,s=bt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),d>s&&(s=d)});const c=t;return r+c.lat>_t&&(c.lat=_t-r),o+c.lat>mt&&(c.lat=mt-o),n+c.lat<vt&&(c.lat=vt-n),i+c.lat<yt&&(c.lat=yt-i),a+c.lng<=bt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=xt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Ot(e,t){const r=Pt(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+r.lng,lat:e[1]+r.lat};return[t.lng,t.lat]},o=e=>e.map(e=>n(e)),i=e=>e.map(e=>o(e));let a;e.type===R.POINT?a=n(t):e.type===R.LINE_STRING||e.type===R.MULTI_POINT?a=t.map(n):e.type===R.POLYGON||e.type===R.MULTI_LINE_STRING?a=t.map(o):e.type===R.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Et={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(B.UPDATE,{action:G.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let r=!1;if(e.length>1){r=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(r=!1)})}const n=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new Oe).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(){gt.enable(this)},onMouseMove:function(e,t){return W(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Et.onTap=Et.onClick=function(e,t){return Z(t)?this.clickAnywhere(e,t):J(H.VERTEX)(t)?this.clickOnVertex(e,t):W(t)?this.clickOnFeature(e,t):void 0},Et.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),gt.enable(this),this.stopExtendedInteractions(e)},Et.clickOnVertex=function(e,t){this.changeMode(U.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:N.MOVE})},Et.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Et.clickOnFeature=function(e,t){gt.disable(this),this.stopExtendedInteractions(e);const r=ee(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==R.POINT)return this.changeMode(U.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:N.POINTER}),1===n.length&&gt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:N.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:N.MOVE})),this.doRender(o)},Et.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),q(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&$(t)?this.startBoxSelect(e,t):void 0},Et.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=rt(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Et.onTouchStart=function(e,t){if(q(t))return this.startOnActiveFeature(e,t)},Et.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Et.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:N.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(V.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=rt(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),o=Math.max(e.boxSelectStartLocation.x,r.x),i=Math.min(e.boxSelectStartLocation.y,r.y),a=Math.max(e.boxSelectStartLocation.y,r.y),s=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=s,e.boxSelectElement.style.WebkitTransform=s,e.boxSelectElement.style.width=o-n+"px",e.boxSelectElement.style.height=a-i+"px"},Et.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};Ot(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Et.onTouchEnd=Et.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,rt(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),o=this.getUniqueIds(n).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:N.MOVE}))}this.stopExtendedInteractions(e)},Et.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?Y.ACTIVE:Y.INACTIVE,r(t),this.fireActionable(),t.properties.active===Y.ACTIVE&&t.geometry.type!==R.POINT&&ft(t).forEach(r)},Et.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Et.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),r.push(i.toGeoJSON())}if(r.length>1){const e=this.newFeature({type:R.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(B.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Et.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],r=[];for(let n=0;n<e.length;n++){const o=e[n];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))}t.length>1&&this.fire(B.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const St=J(H.VERTEX),wt=J(H.MIDPOINT),It={fireUpdate:function(){this.fire(B.UPDATE,{action:G.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);ee(t)||-1!==n?ee(t)&&-1===n&&e.selectedCoordPaths.push(r.coord_path):e.selectedCoordPaths=[r.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,r){Ot(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=Pt(n.map(e=>({type:R.FEATURE,properties:{},geometry:{type:R.POINT,coordinates:e}})),r);for(let t=0;t<n.length;t++){const r=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],r[0]+o.lng,r[1]+o.lat)}},clickNoTarget:function(){this.changeMode(U.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(U.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===R.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),gt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){gt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=Y.ACTIVE,r(t),ft(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=Y.INACTIVE,r(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(U.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=q(t),n=St(t),o=wt(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:N.MOVE}):this.updateUIClasses({mouse:N.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};It.onTouchStart=It.onMouseDown=function(e,t){return St(t)?this.onVertex(e,t):q(t)?this.onFeature(e,t):wt(t)?this.onMidpoint(e,t):void 0},It.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},It.onClick=function(e,t){return Z(t)?this.clickNoTarget(e,t):q(t)?this.clickActiveFeature(e,t):z(t)?this.clickInactive(e,t):void this.stopDragging(e)},It.onTap=function(e,t){return Z(t)?this.clickNoTarget(e,t):q(t)?this.clickActiveFeature(e,t):z(t)?this.clickInactive(e,t):void 0},It.onTouchEnd=It.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Mt={};function Ct(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Mt.onSetup=function(){const e=this.newFeature({type:R.FEATURE,properties:{},geometry:{type:R.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:N.ADD}),this.activateUIButton(D.POINT),this.setActionableState({trash:!0}),{point:e}},Mt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT)},Mt.onTap=Mt.onClick=function(e,t){this.updateUIClasses({mouse:N.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(B.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(U.SIMPLE_SELECT,{featureIds:[e.point.id]})},Mt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Mt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?Y.ACTIVE:Y.INACTIVE,!n)return r(t)},Mt.onTrash=Mt.stopDrawingAndRemove,Mt.onKeyUp=function(e,t){if(te(t)||re(t))return this.stopDrawingAndRemove(e,t)};const Tt={onSetup:function(){const e=this.newFeature({type:R.FEATURE,properties:{},geometry:{type:R.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),gt.disable(this),this.updateUIClasses({mouse:N.ADD}),this.activateUIButton(D.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Ct(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(U.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:N.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(U.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),Q(t)&&this.updateUIClasses({mouse:N.POINTER})}};Tt.onTap=Tt.onClick=function(e,t){return Q(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Tt.onKeyUp=function(e,t){te(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT)):re(t)&&this.changeMode(U.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Tt.onStop=function(e){this.updateUIClasses({mouse:N.NONE}),gt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(B.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT,{},{silent:!0})))},Tt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?Y.ACTIVE:Y.INACTIVE,!n)return r(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=H.FEATURE,r(nt(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(nt(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:R.FEATURE,properties:t.properties,geometry:{coordinates:e,type:R.LINE_STRING}}),3===o)return}return r(t)}},Tt.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT)};const Lt={onSetup:function(e){const t=(e=e||{}).featureId;let r,n,o="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const a=r.coordinates.length-1;if(r.coordinates[a][0]===i[0]&&r.coordinates[a][1]===i[1])n=a+1,r.addCoordinate(n,...r.coordinates[a]);else{if(r.coordinates[0][0]!==i[0]||r.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",n=0,r.addCoordinate(n,...r.coordinates[0])}}else r=this.newFeature({type:R.FEATURE,properties:{},geometry:{type:R.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),gt.disable(this),this.updateUIClasses({mouse:N.ADD}),this.activateUIButton(D.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Ct(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&Ct(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(U.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:N.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(U.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),Q(t)&&this.updateUIClasses({mouse:N.POINTER})}};Lt.onTap=Lt.onClick=function(e,t){if(Q(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Lt.onKeyUp=function(e,t){re(t)?this.changeMode(U.SIMPLE_SELECT,{featureIds:[e.line.id]}):te(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT))},Lt.onStop=function(e){gt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(B.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT,{},{silent:!0})))},Lt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(U.SIMPLE_SELECT)},Lt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?Y.ACTIVE:Y.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=H.FEATURE,r(nt(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),r(t))};var kt={simple_select:Et,direct_select:It,draw_point:Mt,draw_polygon:Tt,draw_line_string:Lt};const At={defaultMode:U.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:et,modes:kt,controls:{},userProperties:!1,suppressAPIEvents:!0},jt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Vt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Ft(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?F.HOT:F.COLD}))}var Nt,Dt;var Rt,Ut,Bt=ue(Dt?Nt:(Dt=1,Nt=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}));var Gt=function(){if(Ut)return Rt;Ut=1,Rt=function(t){if(!t||!t.type)return null;var r=e[t.type];if(!r)return null;if("geometry"===r)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===r)return{type:"FeatureCollection",features:[t]};if("featurecollection"===r)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Rt}(),Ht=ue(Gt);function Yt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Xt={Polygon:Ne,LineString:Fe,Point:Ve,MultiPolygon:Ue,MultiLineString:Ue,MultiPoint:Ue};var Kt=Object.freeze({__proto__:null,CommonSelectors:le,ModeHandler:Le,StringSet:Oe,constrainFeatureMovement:Pt,createMidPoint:ht,createSupplementaryPoints:ft,createVertex:nt,doubleClickZoom:gt,euclideanDistance:Me,featuresAt:Se,getFeatureAtAndSetCursors:Ie,isClick:Ce,isEventAtCoordinates:Ct,isTap:Te,mapEventToBoundingBox:Pe,moveFeatures:Ot,sortFeatures:xe,stringSetsAreEqual:Yt,theme:et,toDenseArray:Xe});const Jt=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Vt,e.controls):t.controls=Object.assign({},jt,e.controls),t=Object.assign({},At,t),t.styles=Ft(t.styles,"cold").concat(Ft(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=U;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Se.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:R.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:R.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:R.FEATURE,properties:{},geometry:{type:R.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==R.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(r),a=new Oe(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Ht(t))).features.map(t=>{if(t.id=t.id||Ae(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=Xt[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Bt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Bt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:R.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==U.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(U.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===U.DIRECT_SELECT?e.events.changeMode(U.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===U.SIMPLE_SELECT&&t.getMode()===U.SIMPLE_SELECT?(Yt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===U.DIRECT_SELECT&&t.getMode()===U.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,o,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,o,i){return e.store.setFeatureProperty(n,o,i,{silent:r}),t},t}(r,t),r.api=t;const n=ze(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=D,t.options=e,t};function $t(e){Jt(e,this)}$t.modes=kt,$t.constants=K,$t.lib=Kt;var qt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},zt="draw.create",Zt="draw.update",Wt="draw.modechange",Qt="draw.editfinish",er="draw.cancel",tr="draw.vertexselection",rr="draw.vertexchange",nr="draw.undochange",or="draw.undo",ir="draw.geometrychange",ar="draw.interfacetypechange",sr="draw.placementblocked",cr="draw.nudgevertex",lr="draw.selectvertex",ur="draw.insertvertexatmidpoint",dr="styledata",pr=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},hr=e=>{var t=pr(e),r=fr(e);if(!t.length||!r.length)return[];var n=[];for(var o of r)for(var i=o.closed?o.length:o.length-1,a=0;a<i;a++){var s=o.start+a,c=o.start+(a+1)%o.length,[l,u]=t[s],[d,p]=t[c];n.push([(l+d)/2,(u+p)/2])}return n},fr=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!0}),r+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,o)=>{t.push({start:r,length:e.length,path:[n,o],closed:!0}),r+=e.length})})}return t},gr=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},yr=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},mr=(e,t)=>{var r=t.split(".").map(Number),n=fr(e);for(var o of n){if(o.path.every((e,t)=>e===r[t])&&r.length===o.path.length+1){var i=r[r.length-1];return o.start+i}}return r[r.length-1]},vr=(e,t)=>({x:e.x*t,y:e.y*t}),_r=e=>e instanceof window.SVGElement||e.ownerSVGElement;function br(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function xr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?br(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):br(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Pr(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function Or(e){var t;return!!(null!=e&&e.status&&null!=e&&e.snapStatus&&(null===(t=e.snapCoords)||void 0===t?void 0:t.length)>=2)}function Er(e){return Or(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Sr(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function wr(e,t){e&&(e._autoSnapSuspended=t)}function Ir(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Mr(e,t){var r,n,o;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(r=e.snappedFeatures)&&void 0!==r&&r.length&&(e.snappedFeatures.length=0),null!==(n=e.closeFeatures)&&void 0!==n&&n.length&&(e.closeFeatures.length=0),null!==(o=e.lines)&&void 0!==o&&o.length&&(e.lines.length=0));null!=t&&t.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function Cr(e){var t,r,n;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(t=e.snappedFeatures)&&void 0!==t&&t.length&&(e.snappedFeatures.length=0),null!==(r=e.closeFeatures)&&void 0!==r&&r.length&&(e.closeFeatures.length=0),null!==(n=e.lines)&&void 0!==n&&n.length&&(e.lines.length=0))}function Tr(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var Lr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r=>n=>r.call(e,t,n),o={keydown:n(e.onKeydown),keyup:n(e.onKeyup),pointerdown:n(e.onPointerevent),pointermove:n(e.onPointerevent),pointerup:n(e.onPointerevent),click:n(e.onButtonClick),touchstart:n(e.onTouchstart),touchmove:n(e.onTouchmove),touchend:n(e.onTouchend),scalechange:n(e.onScaleChange),move:n(e.onMove),interfacetypechange:n(e.onInterfaceTypeChange)};for(var[i,a]of Object.entries(r))o[i]=n(a);return o},kr=(e,t,r)=>{window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),t.on("draw.scalechange",r.scalechange),t.on("move",r.move),t.on(ar,r.interfacetypechange),t.on(cr,r.nudge)},Ar=(e,t,r)=>{e.container.removeEventListener("pointerdown",r.pointerdown),e.container.removeEventListener("pointermove",r.pointermove),e.container.removeEventListener("pointerup",r.pointerup),e.container.removeEventListener("touchstart",r.touchstart),e.container.removeEventListener("touchmove",r.touchmove),e.container.removeEventListener("touchend",r.touchend),t.off("draw.scalechange",r.scalechange),t.off("move",r.move),t.off(ar,r.interfacetypechange),t.off(cr,r.nudge),t.dragPan.enable(),window.removeEventListener("click",r.click),window.removeEventListener("keydown",r.keydown,{capture:!0}),window.removeEventListener("keyup",r.keyup,{capture:!0})},jr=e=>{var t=Pr(e);t&&Mr(t,e)},Vr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,r){e&&setTimeout(()=>{var n=this.getFeature(r);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){var t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}};function Fr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Nr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Fr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Fr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Dr={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},Rr=Nr(Nr({},Vr),{},{UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Dr,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r),this.emitGeometryValidation(Dr[r.type],r.vertexIndex,r.featureId)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=fr(i),c=gr(s,r);if(c){yr(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,vr(this.map.project(l),e.scale))}}},undoInsertVertex(e,t){var{vertexIndex:r,featureId:n}=t,o=this.getFeature(n);if(o){var i=o.toGeoJSON(),a=fr(o),s=gr(a,r);if(s)yr(i,s.segment.path).splice(s.localIdx,1),this._applyUndoAndSync(e,i,n),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},undoDeleteVertex(e,t){var{vertexIndex:r,position:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=fr(i),c=gr(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)yr(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,vr(this.map.project(e.vertices[r]),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertices=this.getVertices(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}}),Ur=o.touchTargetSize/2;var Br=e=>{var t,r,n=e.querySelector("[data-im-draw-touch-target]");return n||(e.insertAdjacentHTML("beforeend",(t=o.touchTargetSize,r=Ur,"\n <svg width='".concat(t,"' height='").concat(t,"' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:").concat(r,"px 0 0 -").concat(r,"px;cursor:grab'\n class='im-draw-touch-target' data-im-draw-touch-target>\n <circle cx='24' cy='24' r='24' fill='var(--draw-halo, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--draw-bg, #fff)'/>\n </svg>\n "))),n=e.querySelector("[data-im-draw-touch-target]")),n},Gr=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},Hr=(e,t)=>{t&&e&&(e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px"),e.style.display="block")},Yr=e=>{e&&(e.style.display="none")},Xr=e=>{if(!e)return!1;var t=e.parentNode;return t instanceof globalThis.SVGElement||null!=(null==t?void 0:t.ownerSVGElement)},Kr=function(e){var t,r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=null!==(t=null==e?void 0:e.mapColorScheme)&&void 0!==t?t:"light",c=null!==(r=null==e?void 0:e.id)&&void 0!==r?r:null,l=e=>{var t;return function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return"object"!=typeof e||null===e?e:r&&void 0!==e[r]?e[r]:void 0!==e[t]?e[t]:void 0!==e.light?e.light:Object.values(e)[0]}(null!==(t=a[e])&&void 0!==t?t:i[e],s,c)};return{editStroke:l("editStroke"),editFill:l("editFill"),editVertex:l("editVertex"),editMidpoint:l("editMidpoint"),editActive:l("editActive"),editHalo:l("editHalo"),invalidStroke:l("invalidStroke"),splitValid:l("splitValid"),splitInvalid:l("splitInvalid"),shapeStroke:l("shapeStroke"),strokeWidth:null!==(n=a.strokeWidth)&&void 0!==n?n:o.strokeWidth,shapeFill:l("shapeFill"),snapVertex:l("snapVertex"),snapEdge:l("snapEdge"),mapStyleId:c}},Jr=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),$r=(e,t,r,n,o)=>{var i=window.getComputedStyle(t),a={x:r.x-Number.parseFloat(i.left),y:r.y-Number.parseFloat(i.top)},s=e.project(n);return{deltaTarget:a,deltaVertex:{x:r.x/o-s.x,y:r.y/o-s.y}}},qr=(e,t,r)=>{var n={x:r.x/t.scale-t.deltaVertex.x,y:r.y/t.scale-t.deltaVertex.y},o=e.unproject(n);if(Tr(t)){var i=Pr(e);Sr(i,e,n),o=Er(i)||o}return o};function zr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Zr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?zr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):zr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Wr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=Kr(t,r);Gr(e,{editActive:n,editHalo:o,editVertex:i})}},Qr={addTouchVertexTarget(e){e.touchVertexTarget=Br(e.container),Wr(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||_r(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(Cr(Pr(this.map)),null!=e&&e.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,vr(this.map.project(t),e.scale))}},onTap(e,t){var r,n,o=Pr(this.map);o&&Mr(o,this.map);var i=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,a=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if("vertex"===i){var s=this.getFeature(e.featureId),c=mr(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(Zr(Zr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){Cr(Pr(this.map));var r=this.getVertices(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&_r(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=Jr(t);Object.assign(e,$r(this.map,e.touchVertexTarget,o,n,e.scale))}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&_r(t.target.parentNode)){e._touchMoved=!0;var r=Jr(t);this.moveVertex(e,qr(this.map,e,r)),this.updateTouchVertexTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}},en=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),tn={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},rn=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),nn=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(rn.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},on=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,an={handleUndoShortcut(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},sn={getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?a.nudgeAmount:a.stepAmount,[o,i]=t?tn[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getOffsetByDelta(e,t,r,n){var o=this.map.project(e),i=n?a.stepAmount:a.nudgeAmount;return this.map.unproject({x:o.x+t*i,y:o.y+r*i})},resolveSnapTarget(e,t,r,o,i){var a=Pr(this.map);if(Tr(e)&&e._isSnapped&&a){var s=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:n.snapRadius}(a)+1,c=this.map.project(o);return e._isSnapped=!1,Mr(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return Tr(e)&&a&&(Sr(a,this.map,this.map.project(l)),Or(a))?(e._isSnapped=!0,Er(a)):(e._isSnapped=!1,l)}};function cn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ln(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?cn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var un=ln(ln({},sn),{},{updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(e,t){var[r,n]=this.getVertexOrMidpoint(e,t);r<0||!n||this.changeMode(e,ln({selectedVertexIndex:r,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,r)}))},getNewCoord(e,t){return this.getOffset(pr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=pr(i))||void 0===o?void 0:o[e.selectedVertexIndex]);if(a){var s=[...a],c=e.selectedVertexIndex,l=this.resolveSnapTarget(e,t,r,a,()=>this.getOffsetByDelta(a,t,r,n));this.moveVertex(e,l),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:c,previousPosition:s})}}},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertices.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=fr(o),s=r+1,c=null,l=0,u=0;for(var d of a){var p=d.closed?d.length:d.length-1;if(r<u+p){c=d,l=r-u+1,s=d.start+l;break}u+=p}c&&(yr(i,c.path).splice(l,0,[n.lng,n.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),this.changeMode(e,{selectedVertexIndex:s,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,s)}))},moveVertex(e,t){if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).checkSnap&&!1!==e.enableSnap){var r,n=this.map._snapInstance;null!=n&&n.snapStatus&&(null===(r=n.snapCoords)||void 0===r?void 0:r.length)>=2&&(t={lng:n.snapCoords[0],lat:n.snapCoords[1]})}var o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=fr(o),s=gr(a,e.selectedVertexIndex);s&&(yr(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=fr(t),n=gr(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?s.Polygon:s.LineString;if(!(o.length<=i)){var a=[...e.vertices[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}}),dn=(e,t,r)=>{var n=(e,t)=>e[0]===t[0]&&e[1]===t[1],o=t.filter(t=>{var o=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);return("ArrowUp"===r?t[1]<=e[1]&&i>=o:"ArrowDown"===r?t[1]>e[1]&&i>=o:"ArrowLeft"===r?t[0]<=e[0]&&i<o:"ArrowRight"!==r||t[0]>e[0]&&i<o)&&!n(t,e)});o.length||o.push(e);var i=t=>Math.hypot(e[0]-t[0],e[1]-t[1]),a=o.reduce((e,t)=>i(t)<i(e)?t:e,o[0]);return t.findIndex(e=>n(e,a))},pn={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e,n[0]):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=fr(r),o=gr(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return pr(this.getFeature(e))},getMidpoints(e){return hr(this.getFeature(e))},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertices)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertices.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=dn(a,i,t);return[s,s<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=fr(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertices.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertices.length}},hn=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter"]),fn=e=>{e.altKey&&hn.has(e.key)&&e.stopPropagation()};function gn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function yn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?gn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var mn=yn(yn({},an),{},{onKeydown(e,t){nn(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?en.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?on(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){var t,r,n=Pr(this.map);n&&Mr(n,this.map),null!==(t=e.vertices)&&void 0!==t&&t.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertices)&&void 0!==r&&r.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){var r;if("midpoint"!==e.selectedVertexType){var n=this.getFeature(e.featureId),o=n&&(null===(r=pr(n))||void 0===r?void 0:r[e.selectedVertexIndex]);o&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...o],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,o)))}else this.insertVertex(e,t)},_keyboardMoveTarget(e,t,r){var[n,o]=tn[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){nn(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&fn(t),en.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))}}),vn={onMouseDown(e,t){var r,n;Cr(Pr(this.map));var o=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,i=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if(["vertex","midpoint"].includes(o)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,It.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=mr(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertices)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=mr(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(tr,{index:e.selectedVertexIndex,numVertices:e.vertices.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(tr,{index:r,numVertices:e.vertices.length})}It.onClick.call(this,e,t)},onMouseUp(e,t){Cr(Pr(this.map));var r=e._isInsertingVertex&&null!=e._insertedVertexIndex,n=this._didVertexMove(e);(e.dragMoving||n||r)&&(this.syncVertices(e),r?this._recordInsertionUndo(e):n&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,It.onMouseUp.call(this,e,t)},_didVertexMove(e){var t;if(!e._moveStartPosition||null==e._moveStartIndex)return!1;var r=this.getFeature(e.featureId),n=r&&(null===(t=pr(r))||void 0===t?void 0:t[e._moveStartIndex]);return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){var t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(tr,{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){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=Pr(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),Tr(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),Sr(n,this.map,t.point);var o=Er(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else It.onDrag.call(this,e,t)}}};function _n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function bn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?_n(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_n(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var xn=bn(bn(bn(bn(bn(bn(bn(bn({},$t.modes.direct_select),Rr),Qr),un),pn),mn),vn),{},{onSetup(e){var t,r,n,o=$t.modes.direct_select.onSetup.call(this,e);(Object.assign(o,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:o.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1}),this.map._lastEditFeatureId!==o.featureId)&&(null===(n=this.map._undoStack)||void 0===n||n.clear(),this.map._lastEditFeatureId=o.featureId);var i=this.getFeature(o.featureId);if(o.featureType=null==i?void 0:i.type,o.vertices=this.getVertices(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o),jr(this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var a=o.vertices[o.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(o,vr(this.map.project(a),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=this.handlers=Lr(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint});kr(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(lr,t.selectvertex),this.map.on(ur,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){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=pr(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire(tr,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});var c=o||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?vr(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?vr(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,vr(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertices[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,vr(this.map.project(r),e.scale))},onSelectVertex(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));var n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,bn({selectedVertexIndex:t.index,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}))},onInsertVertexAtMidpoint(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex(bn(bn({},e),{},{selectedVertexIndex:t.index,selectedVertexType:"midpoint"}))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",bn(bn({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(lr,t.selectvertex),this.map.off(ur,t.insertvertexatmidpoint),Ar(e,this.map,t),this.hideTouchVertexIndicator(e)}});function Pn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function On(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Pn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Pn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var En={move_point:"commit-move"},Sn=On(On({},Vr),{},{UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:En,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_point"===r.type&&this.undoMovePoint(e,r),this.emitGeometryValidation(En[r.type],r.vertexIndex,r.featureId)}},undoMovePoint(e,t){var{previousPosition:r,featureId:n}=t,o=this.getFeature(n);o&&(o.updateCoordinate("",r[0],r[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,vr(this.map.project(r),e.scale)))}}),wn={addTouchPointTarget(e){e.touchPointTarget=Br(e.container),Wr(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){Cr(Pr(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,vr(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){Cr(Pr(this.map));var r=this.getPointCoord(e);if(r&&_r(t.target.parentNode)){e._moveStartPosition=[...r],e._touchMoved=!1;var n=Jr(t);Object.assign(e,$r(this.map,e.touchPointTarget,n,r,e.scale))}},onTouchmove(e,t){if(_r(t.target.parentNode)){e._touchMoved=!0;var r=Jr(t);this.movePoint(e,qr(this.map,e,r)),this.updateTouchPointTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}};function In(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Mn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?In(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):In(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Cn=Mn(Mn({},sn),{},{getPointCoord(e){var t;return null===(t=this.getFeature(e.featureId))||void 0===t?void 0:t.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,r,n){var o=this.getPointCoord(e);if(o){var i=[...o],a=this.resolveSnapTarget(e,t,r,o,()=>this.getOffsetByDelta(o,t,r,n));this.movePoint(e,a),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}}});function Tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ln(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Tn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var kn=Ln(Ln({},an),{},{onKeydown(e,t){nn(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?en.has(t.key)?this.handleArrowKey(e,t):on(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){var r=this.getPointCoord(e);r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r]),this.movePoint(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,r){var[n,o]=tn[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){nn(e)||(e.interfaceType="keyboard",fn(t),en.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}}),An="edit_point",jn={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],wr(Pr(this.map),!0)),It.onFeature.call(this,e,t)},onClick(e,t){if(!q(t)&&((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=c(r,{mode:An,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:An,vertexIndex:0}),n})(this.map,[t.lngLat.lng,t.lngLat.lat])){var r=[...e.feature.coordinates],n=Pr(this.map),o=t.lngLat;Tr(e)&&n&&(Sr(n,this.map,t.point),o=Er(n)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:r})}},onMouseUp(e,t){var r=Pr(this.map);Cr(r),wr(r,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,It.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;var t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var r=Pr(this.map);if(r&&(r.snapStatus=!1,r.snapCoords=null),Tr(e)&&null!=r&&r.status){if(e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};Sr(r,this.map,this.map.project([n.lng,n.lat]));var o=Er(r)||n;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else It.onDrag.call(this,e,t)}},onTrash(){}};function Vn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Fn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Vn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Vn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Nn=Fn(Fn(Fn(Fn(Fn(Fn(Fn({},$t.modes.direct_select),Sn),wn),Cn),kn),jn),{},{onSetup(e){var t,r,n=e.featureId,o=this.getFeature(n);if(!o)throw new Error("You must provide a featureId to enter edit_point mode");var i,a={featureId:n,feature:o,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};(this.setSelectedCoordinates([]),this.setSelected(n),gt.disable(this),this.setActionableState({trash:!1}),Object.assign(a,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:null!==(t=e.scale)&&void 0!==t?t:1}),this.map._lastEditFeatureId!==a.featureId)&&(null===(i=this.map._undoStack)||void 0===i||i.clear(),this.map._lastEditFeatureId=a.featureId);return this.setupEventListeners(a),this.map._drawEditContainer=e.container,this.addTouchPointTarget(a),null===(r=a.container)||void 0===r||r.focus({preventScroll:!0}),jr(this.map),"touch"===a.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(a,vr(this.map.project(a.feature.coordinates),a.scale))},0),this.map.fire(tr,{index:0,numVertices:1}),a},setupEventListeners(e){var t=this.handlers=Lr(this,e,{nudge:this.onNudgePoint});kr(e,this.map,t)},toDisplayFeatures(e,t,r){t.properties.active=e.featureId===t.properties.id?"true":"false",r(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,vr(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,vr(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,vr(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Ar(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}});function Dn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Rn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Dn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Un=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?Rn(Rn({},e),{},{featureId:null}):e,a=Rn(Rn({},t.onSetup.call(this,i)),e);a[r].properties=e.properties;var{container:s,vertexMarkerId:c,getInterfaceType:l}=a,u=l?l():a.interfaceType;a.interfaceType=u;var d=s.querySelector("#".concat(c));a.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(a):this._hideCrossHair(a),a.crossHair&&(a.crossHair.activate=()=>{var e;return null===(e=this._placeAtCrossHair)||void 0===e?void 0:e.call(this,a)});var p=(e,t)=>this[e]=t.bind(this,a),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(e=>{var[t,r]=e;return p(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"keyup",fn,{capture:!0}],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(e=>{var[t,r,n,o]=e;return t.addEventListener?t.addEventListener(r,n,o):t.on(r,n)}),a},onStop(e){var r;t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n,o]=e;return t.removeEventListener?t.removeEventListener(r,n,o):t.off(r,n)}),null!==(r=e.crossHair)&&void 0!==r&&r.activate&&(e.crossHair.activate=null),["touch","keyboard"].includes(e.interfaceType)||this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function Bn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Gn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Bn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Bn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Hn=(e,t,r,n,o)=>{setTimeout(()=>{var i=t(n);i&&e.fire("draw.geometrychange",((e,t,r)=>{var n=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[n]}:{type:"LineString",coordinates:n},properties:{}},phase:r,vertexIndex:Math.max(0,n.length-1)}})(i,r,o))},0)},Yn=e=>{var{geometryType:t,getFeature:r,getCoords:n}=e;return{_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(e,o){var i=r(e);if(!i||!o)return!0;var a=l({placed:n(i).slice(0,-1),point:o,geometryType:t,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Hn(this.map,r,n,e,t)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onCreate(e,t){((e,t,r)=>{e.delete(t.id),t.id=r,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}},Xn=e=>{var{ParentMode:t,getFeature:r,getCoords:n,validateClick:o,finishOnInvalidClick:i}=e;return{onClick(e,a){var s;if(!this._isIgnorableClick(a)&&(!1!==this.map._drawGeometryValid||"vertex"!==(null===(s=a.featureTarget)||void 0===s||null===(s=s.properties)||void 0===s?void 0:s.meta))){var c=Pr(this.map);if(Tr(e)&&Or(c))a=function(e,t){var r=Er(t);return r?xr(xr({},e),{},{lngLat:r}):e}(a,c);else if(!((e,t)=>{var a=n(r(e));return a.length>0&&(a[a.length-1]=[t.lngLat.lng,t.lngLat.lat]),i||o(r(e))})(e,a))return;if(this._canPlaceVertex(e,[a.lngLat.lng,a.lngLat.lat])){var l=n(r(e)).length;t.onClick.call(this,e,a),n(r(e)).length>l&&(this.pushDrawUndo(e),this.dispatchVertexChange(n(r(e))),this.emitDrawValidation(e))}}},doClick(e){if(!this.map._undoInProgress){var a=r(e),s=n(a);if(this.dispatchVertexChange(s),o(a)){var c=Pr(this.map),l=Tr(e)&&function(e,t){var r=Er(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(this._canPlaceVertex(e,[u.lng,u.lat])){l?(t.onClick.call(this,e,l),this._ctx.store.render()):this._simulateMouse("click",t.onClick,e);var d=n(r(e));this.pushDrawUndo(e),this.dispatchVertexChange(d),this.emitDrawValidation(e)}}else i&&!1!==this.map._drawGeometryValid&&(s.pop(),this.map.fire("draw.create",{features:[a.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[a.id]}))}},_placeAtCrossHair(e){this.doClick(e)}}};function Kn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Jn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Kn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Kn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var $n=e=>{var{geometryType:t,getFeature:r}=e;return{pushDrawUndo(e){var n=this.map._undoStack;n&&!this.map._undoInProgress&&n.push({type:"draw_vertex",geometryType:t,featureId:r(e).id})},onUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"draw_vertex"===(null==r?void 0:r.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))}},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}},qn=e=>{var{ParentMode:t,geometryType:r,getCoords:n,getFeature:o}=e;return{undoVertex(e){var t=o(e),r=n(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_removeLastVertex(e,t,o){var i="Polygon"===r?t.coordinates[0]:o;i.splice(-2,1),i[i.length-1]=[...i[i.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(t))},_updateRubberBand(e,n){if(["touch","keyboard"].includes(e.interfaceType))this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render();else{var o=n["Polygon"===r?n.length-2:n.length-1],i={lng:o[0],lat:o[1]},a=this.map.project(i);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}this.dispatchVertexChange(n)}}},zn=e=>{var{ParentMode:t,featureProp:r,geometryType:n}=e;return{_reinitializeFeature(e,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(e,i);var a=this.map.getCenter(),s=[[a.lng,a.lat],[a.lng,a.lat]],c=this.newFeature({type:"Feature",properties:e.properties||{},geometry:{type:n,coordinates:[s]}});return c.id=i,this._ctx.store.add(c),e[r]=c,e.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render(),this.dispatchVertexChange(s),!0},_restartLineStringDraw(e,t){var r=this.map._undoStack;return r&&r.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}},Zn=e=>{var{ParentMode:t,getFeature:r,INTERFACE_KEYS:n}=e;return{onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(e,n){var o=document.activeElement;if(!o||o===e.container||!e.container.contains(o))if("Escape"!==n.key)o!==e.container&&t.onKeyUp.call(this,e,n);else if("keyboard"===e.interfaceType){var i=this.map._undoStack;i&&i.clear(),this._reinitializeFeature(e,r(e))}}}};function Wn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Qn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Wn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Wn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var eo=e=>{var{ParentMode:t,getFeature:r,getCoords:n}=e;return{onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(e,r){if(Tr(e)){var n=Pr(this.map);Sr(n,this.map,r.point);var o=Er(n);o&&(r=Qn(Qn({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e,r){var n="move"===(null==r?void 0:r.type)&&!r.originalEvent;if(["touch","keyboard"].includes(e.interfaceType)||n){Tr(e)&&Ir(Pr(this.map),this.map);var o=Pr(this.map),i=Tr(e)&&Er(o);if(i){var a=this.map.project([i.lng,i.lat]);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}else this._simulateMouse("mousemove",t.onMouseMove,e)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(r(e)))}}},to=e=>{var{ParentMode:t,geometryType:r,getFeature:n,getPlacedCoords:o}=e;return{_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},toDisplayFeatures(e,i,a){t.toDisplayFeatures.call(this,e,i,a);var s=n(e);i.geometry.type===r&&i.properties.id===s.id&&o(i).forEach(e=>a({type:"Feature",properties:{meta:"draw-vertex",parent:s.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}};function ro(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function no(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ro(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ro(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var oo=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s,finishOnInvalidClick:c,getFeature:e=>e[r],INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return no(no(no(no(no(no(no({},e),Un(l)),(e=>Gn(Gn({},Yn(e)),Xn(e)))(l)),(e=>Jn(Jn(Jn({},$n(e)),qn(e)),zn(e)))(l)),Zn(l)),eo(l)),to(l))},io=oo($t.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>u(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),ao=oo($t.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>d(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)});function so(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function co(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?so(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):so(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var lo="draw_point",uo=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),po=$t.modes.draw_point,ho=Un({ParentMode:po,featureProp:"point",excludeFeatureIdFromSetup:!1}),fo={onKeyUp(){},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},onCreate(e,t){var r,n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),null===(r=e.resolvePointSymbol)||void 0===r||r.call(e,e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){var r="move"===(null==t?void 0:t.type)&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||r)&&Tr(e)&&Ir(Pr(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){Tr(e)&&Sr(Pr(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),uo.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&uo.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(!(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())){var r=Pr(this.map),n=Tr(e)&&Or(r)?Er(r):null;this._commit(e,n||t.lngLat)}},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){var t=Pr(this.map);Tr(e)&&Ir(t,this.map);var r=Tr(e)&&Or(t)?Er(t):null;this._commit(e,r||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=c(r,{mode:lo,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:lo,vertexIndex:0}),n})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},go=co(co(co({},po),ho),fo),yo=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],mo=["get","user_sortKey"],vo=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":mo},paint:{"fill-color":yo(e,"fill",t.shapeFill)}}),_o=(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":mo},paint:{"line-color":yo(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),bo=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}}),xo=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),Po=(e,t,r)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Oo=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Eo=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),So=(e,t,r)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),wo=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Io=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Mo=function(e){var t,r,n,i,a,s=Kr(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:c,midpointRadius:l,vertexHaloRadius:u,midpointHaloRadius:d}=o;return[vo(e,s),(a=s.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":a}}),(i=s.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":i,"line-width":2,"line-opacity":1}}),(n=s.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":n,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),_o(e,s),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":mo},paint:{}},(r=s.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":r,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(t=s.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t,"line-width":2,"line-opacity":1}}),bo(s.editStroke),Eo(s.editMidpoint,l),So(s.editHalo,s.editActive,d),wo(s.editMidpoint,l),xo(s.editVertex,c),Po(s.editHalo,s.editActive,u),Oo(s.editVertex,c),Io(s.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function Co(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 To(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 Lo(e,t,r){void 0===r&&(r={});var n=Co(e),o=Co(t),i=p(o[1]-n[1]),a=p(o[0]-n[0]),s=p(n[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function ko(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 Ao(e,t,r,n={}){const o=ko(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return void 0!==o[2]?g([d,h,o[2]],n.properties):g([d,h],n.properties)}function jo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return v(e,t);return _(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Vo(e,t,r={}){if(!0===r.final)return function(e,t){let r=Vo(t,e);return r=(r+180)%360,r}(e,t);const n=ko(e),o=ko(t),i=p(n[0]),a=p(o[0]),s=p(n[1]),c=p(o[1]),l=Math.sin(a-i)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(a-i);return y(Math.atan2(l,u))}var Fo=Vo;function No(e,t,r,n){void 0===n&&(n={});var o=Co(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return g([d,h],n.properties)}function Do(e){if(!e)throw new Error("geojson is required");var t=[];return b(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=To(n);break;case"LineString":r=[To(n)]}r.forEach(function(r){var n=function(e,t){var r=[];return e.reduce(function(e,n){var o,i,a,s,c,l,u=_([e,n],t);return u.bbox=(i=n,a=(o=e)[0],s=o[1],c=i[0],l=i[1],[a<c?a:c,s<l?s:l,a>c?a:c,s>l?s:l]),r.push(u),n}),r}(r,e.properties);n.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),x(t)}var Ro={exports:{}};function Uo(e,t,r,n,o){Bo(e,t,r||0,n||e.length-1,o||Ho)}function Bo(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);Bo(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(Go(e,r,t),o(e[n],u)>0&&Go(e,r,n);d<p;){for(Go(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?Go(e,r,p):Go(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function Go(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Ho(e,t){return e<t?-1:e>t?1:0}function Yo(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Xo(e,t){Ko(e,0,e.children.length,t,e)}function Ko(e,t,r,n,o){o||(o=ri(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<r;i++){const t=e.children[i];Jo(o,e.leaf?n(t):t)}return o}function Jo(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 $o(e,t){return e.minX-t.minX}function qo(e,t){return e.minY-t.minY}function zo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Zo(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Wo(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 Qo(e,t){const r=Math.max(e.minX,t.minX),n=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-r)*Math.max(0,i-n)}function ei(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function ti(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function ri(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ni(e,t,r,n,o){const i=[t,r];for(;i.length;){if((r=i.pop())-(t=i.pop())<=n)continue;const a=t+Math.ceil((r-t)/n/2)*n;Uo(e,a,t,r,o),i.push(t,a,a,r)}}var oi,ii=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const r=[];if(!ti(e,t))return r;const n=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const a=t.children[i],s=t.leaf?n(a):a;ti(e,s)&&(t.leaf?r.push(a):ei(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!ti(e,t))return!1;const r=[];for(;t;){for(let n=0;n<t.children.length;n++){const o=t.children[n],i=t.leaf?this.toBBox(o):o;if(ti(e,i)){if(t.leaf||ei(e,i))return!0;r.push(o)}}t=r.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=ri([]),this}remove(e,t){if(!e)return this;let r=this.data;const n=this.toBBox(e),o=[],i=[];let a,s,c;for(;r||o.length;){if(r||(r=o.pop(),s=o[o.length-1],a=i.pop(),c=!0),r.leaf){const n=Yo(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!ei(r,n)?s?(a++,r=s.children[a],c=!1):r=null:(o.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const r=[];for(;e;)e.leaf?t.push(...e.children):r.push(...e.children),e=r.pop();return t}_build(e,t,r,n){const o=r-t+1;let i,a=this._maxEntries;if(o<=a)return i=ri(e.slice(t,r+1)),Xo(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=ri([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));ni(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);ni(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Xo(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=zo(a),c=Wo(e,a)-s;c<o?(o=c,n=s<n?s:n,r=a):c===o&&s<n&&(n=s,r=a)}t=r||t.children[0]}return t}_insert(e,t,r){const n=r?e:this.toBBox(e),o=[],i=this._chooseSubtree(n,this.data,t,o);for(i.children.push(e),Jo(i,n);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(n,o,t)}_split(e,t){const r=e[t],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const i=this._chooseSplitIndex(r,o,n),a=ri(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Xo(r,this.toBBox),Xo(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=ri([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Xo(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=Ko(e,0,a,this.toBBox),s=Ko(e,a,r,this.toBBox),c=Qo(t,s),l=zo(t)+zo(s);c<o?(o=c,n=a,i=l<i?l:i):c===o&&l<i&&(i=l,n=a)}return n||r-t}_chooseSplitAxis(e,t,r){const n=e.leaf?this.compareMinX:$o,o=e.leaf?this.compareMinY:qo;this._allDistMargin(e,t,r,n)<this._allDistMargin(e,t,r,o)&&e.children.sort(n)}_allDistMargin(e,t,r,n){e.children.sort(n);const o=this.toBBox,i=Ko(e,0,t,o),a=Ko(e,r-t,r,o);let s=Zo(i)+Zo(a);for(let n=t;n<r-t;n++){const t=e.children[n];Jo(i,e.leaf?o(t):t),s+=Zo(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Jo(a,e.leaf?o(t):t),s+=Zo(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Jo(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Xo(e[r],this.toBBox)}}}),ai=de(ii),si={};function ci(){if(oi)return si;oi=1,Object.defineProperty(si,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},r={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function n(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function o(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:e},t,r)}function i(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:e},t,r)}function a(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:e},t,r)}function s(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return n({type:"MultiLineString",coordinates:e},t,r)}function l(e,t,r={}){return n({type:"MultiPoint",coordinates:e},t,r)}function u(e,t,r={}){return n({type:"MultiPolygon",coordinates:e},t,r)}function d(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e/n}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return si.areaFactors=r,si.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},si.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},si.convertArea=function(e,t="meters",n="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=r[t];if(!o)throw new Error("invalid original units");const i=r[n];if(!i)throw new Error("invalid final units");return e/o*i},si.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),r)},si.degreesToRadians=function(e){return e%360*Math.PI/180},si.earthRadius=e,si.factors=t,si.feature=n,si.featureCollection=s,si.geometry=function(e,t,r={}){switch(e){case"Point":return o(t).geometry;case"LineString":return a(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},si.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},si.isNumber=f,si.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},si.lengthToDegrees=function(e,t){return h(p(e,t))},si.lengthToRadians=p,si.lineString=a,si.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},si.multiLineString=c,si.multiPoint=l,si.multiPolygon=u,si.point=o,si.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},si.polygon=i,si.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},si.radiansToDegrees=h,si.radiansToLength=d,si.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const r=Math.pow(10,t||0);return Math.round(e*r)/r},si.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")})},si.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")},si}var li,ui={};function di(){if(li)return ui;li=1,Object.defineProperty(ui,"__esModule",{value:!0});var e=ci();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var _=0;_<c;_++){var b=0,x=0;if(null!==(s=d?u.geometries[_]:u)){l=s.coordinates;var P=s.type;switch(p=!n||"Polygon"!==P&&"MultiPolygon"!==P?0:1,P){case null:break;case"Point":if(!1===r(l,h,v,b,x))return!1;h++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,b,x))return!1;h++,"MultiPoint"===P&&b++}"LineString"===P&&b++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,b,x))return!1;h++}"MultiLineString"===P&&b++,"Polygon"===P&&x++}"Polygon"===P&&b++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(x=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-p;a++){if(!1===r(l[o][i][a],h,v,b,x))return!1;h++}x++}b++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(r=0;r<g;r++){for(s=h?e.features[r].geometry:f?e.geometry:e,l=h?e.features[r].properties:f?e.properties:{},u=h?e.features[r].bbox:f?e.bbox:void 0,d=h?e.features[r].id:f?e.id:void 0,a=(c=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=c?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,r){o(t,function(t,n,o,i,a){var s,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==r(e.feature.call(void 0,t,o,{bbox:i,id:a}),n,0)&&void 0}switch(c){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:s,coordinates:t.coordinates[l]};if(!1===r(e.feature.call(void 0,u,o),n,l))return!1}})}function a(r,n){i(r,function(r,o,i){var a=0;if(r.geometry){var s=r.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var c,l=0,u=0,d=0;return!1!==t(r,function(t,s,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return ui.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},ui.coordEach=t,ui.coordReduce=function(e,r,n,o){var i=n;return t(e,function(e,t,o,a,s){i=0===t&&void 0===n?e:r(i,e,t,o,a,s)},o),i},ui.featureEach=n,ui.featureReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},ui.findPoint=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.coordIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return e.point.call(void 0,l,c,r);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,r);case"LineString":return s<0&&(s=l.length+s),e.point.call(void 0,l[s],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s),e.point.call(void 0,l[a][s],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),e.point.call(void 0,l[i][s],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s),e.point.call(void 0,l[i][a][s],c,r)}throw new Error("geojson is invalid")},ui.findSegment=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.segmentIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=l.length+s-1),e.lineString.call(void 0,[l[s],l[s+1]],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s-1),e.lineString.call(void 0,[l[a][s],l[a][s+1]],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s-1),e.lineString.call(void 0,[l[i][s],l[i][s+1]],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s-1),e.lineString.call(void 0,[l[i][a][s],l[i][a][s+1]],c,r)}throw new Error("geojson is invalid")},ui.flattenEach=i,ui.flattenReduce=function(e,t,r){var n=r;return i(e,function(e,o,i){n=0===o&&0===i&&void 0===r?e:t(n,e,o,i)}),n},ui.geomEach=o,ui.geomReduce=function(e,t,r){var n=r;return o(e,function(e,o,i,a,s){n=0===o&&void 0===r?e:t(n,e,o,i,a,s)}),n},ui.lineEach=s,ui.lineReduce=function(e,t,r){var n=r;return s(e,function(e,o,i,a){n=0===o&&void 0===r?e:t(n,e,o,i,a)}),n},ui.propEach=r,ui.propReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},ui.segmentEach=a,ui.segmentReduce=function(e,t,r){var n=r,o=!1;return a(e,function(e,i,a,s,c){n=!1===o&&void 0===r?e:t(n,e,i,a,s,c),o=!0}),n},ui}var pi,hi,fi={};function gi(){if(pi)return fi;pi=1,Object.defineProperty(fi,"__esModule",{value:!0});var e=di();function t(t,r={}){if(null!=t.bbox&&!0!==r.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}var r=t;return fi.bbox=t,fi.default=r,fi}var yi=function(){if(hi)return Ro.exports;hi=1;var e=ai,t=ci(),r=di(),n=gi().default,o=r.featureEach;r.coordEach,t.polygon;var i=t.featureCollection;function a(t){var r=new e(t);return r.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.insert.call(this,t)},r.load=function(t){var r=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}),e.prototype.load.call(this,r)},r.remove=function(t,r){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.remove.call(this,t,r)},r.clear=function(){return e.prototype.clear.call(this)},r.search=function(t){var r=e.prototype.search.call(this,this.toBBox(t));return i(r)},r.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},r.all=function(){var t=e.prototype.all.call(this);return i(t)},r.toJSON=function(){return e.prototype.toJSON.call(this)},r.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},r.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=n(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=n(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},r}return Ro.exports=a,Ro.exports.default=a,Ro.exports}(),mi=ue(yi);function vi(e,t){var r={},n=[];if("LineString"===e.type&&(e=P(e)),"LineString"===t.type&&(t=P(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=_i(e,t);return o&&n.push(o),x(n)}var i=mi();return i.load(Do(t)),O(Do(e),function(e){O(i.search(e),function(t){var o=_i(e,t);if(o){var i=To(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),x(n)}function _i(e,t){var r=To(e),n=To(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],d=n[1][1],p=(d-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var y=h/p,m=f/p;return y>=0&&y<=1&&m>=0&&m<=1?g([o+y*(a-o),i+y*(s-i)]):null}function bi(e,t,r){void 0===r&&(r={});var n=g([1/0,1/0],{dist:1/0}),o=0;return b(e,function(e){for(var i=To(e),a=0;a<i.length-1;a++){var s=g(i[a]);s.properties.dist=Lo(t,s,r);var c=g(i[a+1]);c.properties.dist=Lo(t,c,r);var l=Lo(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=Fo(s,c),p=No(t,u,d+90,r),h=No(t,u,d-90,r),f=vi(_([p.geometry.coordinates,h.geometry.coordinates]),_([s.geometry.coordinates,c.geometry.coordinates])),y=null;f.features.length>0&&((y=f.features[0]).properties.dist=Lo(t,y,r),y.properties.location=o+Lo(s,y,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),y&&y.properties.dist<n.properties.dist&&((n=y).properties.index=a),o+=l}}),n}function xi(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 Pi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=xi(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return g([d,h],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=xi(e),o=xi(t),i=p(o[1]-n[1]),a=p(o[0]-n[0]),s=p(n[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,Fo(e,t));return r}var Oi=function(){return Oi=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Oi.apply(this,arguments)},Ei=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],r=0;r<e.features.length;r++){var n=e.features[r],o=n.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var a=this.features.unknow.snapPoints;i=Oi(Oi({},i),a)}var s=this.doSnap(n,i);t.push(s)}else if(void 0!==this.features.unknow){a=this.features.unknow.snapPoints,s=this.doSnap(n,a);t.push(s)}else t.push(n)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Lo(g(e),g(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],d=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=Lo(g([r.lng,r.lat]),g([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var a=!1,s=this.getCloseFeatures(e,i);s?(this.snapStatus=!0,this.snapCoords=s.coords,a=function(e,t,r={}){const n=r.steps||64,o=r.properties?r.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<n;o++)i.push(Ao(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),m([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=x(0==a?[]:[a]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(x([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n=E(e),o=[];if(n.map(function(e){var n=Lo(g(e),g([t.lng,t.lat]),{units:"meters"});n<r&&o.push({coords:e,dist:n,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(_(e))});break;case"Polygon":var o=jo(e.geometry);n.push(o);break;case"MultiPolygon":jo(e.geometry).coodinates.map(function(e){n.push(_(e))})}return n},e.prototype.searchInMidPoint=function(e,t,r){var n=this.getLines(e,t,r),o=[];n.map(function(e){o=o.concat(Do(e).features)});var i=[];if(o.map(function(e){var n=Pi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Lo(n,g([t.lng,t.lat]),{units:"meters"});o<r&&i.push({coords:n.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,r){for(var n=this.getLines(e,t,r),o=[],i=0;i<n.length;i++){var a=bi(n[i],g([t.lng,t.lat]),{units:"meters"});void 0!==a.properties.dist&&a.properties.dist<r&&o.push({coords:a.geometry.coordinates,dist:a.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var r=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(r.length>0){for(var n,o=!1,i=0;i<r.length;i++){var a=r[i],s=this.options.rules,c=e.lngLat;if(o=!1,-1!==s.indexOf("vertex")&&null==n&&(n=this.searchInVertex(a,c,t))){o=!0;break}if(-1!==s.indexOf("midpoint")&&null==n&&(n=this.searchInMidPoint(a,c,t))){o=!0;break}if(-1!==s.indexOf("edge")&&null==n&&(n=this.searchInEdge(a,c,t))){o=!0;break}}return!!o&&n}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}(),Si="snap-helper-circle",wi="mapbox-gl-draw-hot";function Ii(e){if(!Ei.prototype.__snapPatched){Ei.prototype.__snapPatched=!0;var t=Ei.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){var r,n;if(this.status){var o=t.setMapData.call(this,e);return(null==e||null===(r=e.features)||void 0===r?void 0:r.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(Si)&&this.map.setLayoutProperty(Si,"visibility","visible"),o}},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,r,n){var o=e.geometry;if(null==o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>m(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>_(e)):t.getLines.call(this,e,r,n)}catch(e){return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];var o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));var i=this.options.radius||n.snapRadius,a=e.point;e.point=[[a.x-i,a.y-i],[a.x+i,a.y+i]];var s=t.getCloseFeatures.call(this,e,r);return e.point=a,s}}(t,r),function(e,t,r){e.searchInVertex=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInVertex.apply(this,n);return i&&(i.color=r.vertex),i},e.searchInMidPoint=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInMidPoint.apply(this,n);return i&&(i.color=r.midpoint),i},e.searchInEdge=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInEdge.apply(this,n);return i&&(i.color=r.edge),i}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){var r;if(this.status&&(null===(r=this.map)||void 0===r||!r._isZooming)&&(!this._autoSnapSuspended||e._explicit))try{var n,o,i=t.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}}function Mi(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function Ci(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}var Ti=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Li(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(Si)&&e.removeLayer(Si),e.getSource(Si)&&e.removeSource(Si)}(e),Ci(r);var o=new Ei({map:e,drawing:t,options:{layers:n.layers,radius:n.radius,rules:n.rules},status:n.status,onSnapped:n.onSnapped});return function(e,t,r){var n=t;Object.defineProperty(e,"status",{get:()=>n&&Ti.has(r.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{n=e}}(o,n.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,n.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function ki(e,t,r){e.on("style.load",()=>{Mi(()=>e._removed?null:e.getSource(wi),n=>{Ci(n),function(e){var t;e.getSource(Si)||e.addSource(Si,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Si)||e.addLayer({id:Si,type:"fill",source:Si,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Li(e,t,n,r)})})}function Ai(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ji(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:a=[],radius:s=n.snapRadius,rules:c=["vertex","midpoint","edge"],status:l=!1,onSnapped:u=()=>{},colors:d={}}=o,p={layers:a,radius:s,rules:c,status:l,onSnapped:u};return Ii(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ai(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ai(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:i.snapVertex,midpoint:i.snapMidpoint,edge:i.snapEdge},d)),ki(t,r,p),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(Si)){e.setLayoutProperty(Si,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(Si,"visibility","visible")}})}(t),Mi(()=>t._removed?null:t.getSource(wi),e=>Li(t,r,e,p)),t._snapInstance}var Vi=e=>{var t=[];return{push(r){t.push(r),e(t.length)},pop(){var r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}},Fi=.25,Ni=.75,Di=e=>{var[t,r]=e,n=(e=>e<=Fi?"left":e>=Ni?"right":"")(t),o=(e=>e<=Fi?"top":e>=Ni?"bottom":"")(r);return o+(n&&o?"-":"")+n||"center"},Ri=e=>e<=Fi?0:e>=Ni?1:.5,Ui=e=>Math.round(100*e)/100;function Bi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Gi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Bi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Bi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Hi=e=>!!(null!=e&&e.symbol||null!=e&&e.symbolSvgContent),Yi=(e,t,r)=>{var n;if(null!==(n=e._symbolIconOffsetMap)&&void 0!==n||(e._symbolIconOffsetMap={}),!e._symbolIconOffsetMap[t]){e._symbolIconOffsetMap[t]=r;var o=(e=>{var t=["match",["get","user_symbolImageId"]];for(var[r,n]of Object.entries(e))t.push(r,["literal",n]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);["hot","cold"].forEach(t=>{var r="".concat("point-symbol",".").concat(t);e.getLayer(r)&&e.setLayoutProperty(r,"icon-offset",o)})}},Xi=function(){var e=j(function*(e){var t,r,n,o,{draw:i,mapProvider:a,map:s,featureId:c,properties:l,pixelRatioOverride:u}=e;if(!Hi(l))return null;var d=s._drawCurrentMapStyle,p=null!=u?u:(e=>{var t;return(null===(t=e.getPixelRatio)||void 0===t?void 0:t.call(e))||1})(s);yield a.addSymbolsToMap([l],d,S);var h=i.get(c);if(!h)return null;var f=S.getSymbolImageId(l,d,!1,p);if(!f)return null;var g=null!==(t=null===(r=s._activeSymbolImageMap)||void 0===r?void 0:r[f])&&void 0!==t?t:null,y=null!==(n=null===(o=s._selectedSymbolImageMap)||void 0===o?void 0:o[f])&&void 0!==n?n:null,m=S.getSymbolDef(l),v=w(l,m),_=Di(v),b=((e,t)=>{var[r,n]=e,[,,o,i]=t.split(" ").map(Number);return[Ui((Ri(r)-r)*o),Ui((Ri(n)-n)*i)]})(v,I(l,m));return Yi(s,f,b),Gi(Gi({},h),{},{properties:Gi(Gi({},l),{},{symbolImageId:f,symbolIconAnchor:_,symbolActiveImageId:g,symbolSelectedImageId:y})})});return function(t){return e.apply(this,arguments)}}(),Ki=function(){var e=j(function*(e){try{var t=yield Xi(e);if(!t)return;e.draw.add(t)}catch(t){console.error("[draw] failed to resolve point symbol",e.featureId,t)}});return function(t){return e.apply(this,arguments)}}(),Ji=function(){var e=j(function*(e){var{draw:t,mapProvider:r,map:n,pixelRatioOverride:o}=e,i=t.getAll().features.filter(e=>"Point"===e.geometry.type&&Hi(e.properties)),a=yield Promise.allSettled(i.map(e=>Xi({draw:t,mapProvider:r,map:n,featureId:e.id,properties:e.properties,pixelRatioOverride:o})));a.filter(e=>"rejected"===e.status).forEach(e=>{console.error("[draw] failed to resolve point symbol",e.reason)});var s=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);s.length&&t.add({type:"FeatureCollection",features:s})});return function(t){return e.apply(this,arguments)}}();function $i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function qi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?$i(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):$i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zi="mapbox-gl-draw-cold",Zi="mapbox-gl-draw-hot",Wi=e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:i}=e,a=t._drawCurrentMapStyle;t.once("idle",()=>{var e,s=((e,t)=>{if(e.getSource(zi))return!1;var r={type:"FeatureCollection",features:[]};return e.addSource(zi,{data:r,type:"geojson"}),e.addSource(Zi,{data:r,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(t,r);!function(e,t){Mo(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})}(t,a,o);var c=null===(e=t._drawEditContainer)||void 0===e?void 0:e.querySelector("[data-im-draw-touch-target]");Wr(c,a,o),Ji({draw:r,mapProvider:n,map:t}).then(()=>{s&&r.set(r.getAll()),t.triggerRepaint(),i()})})},Qi=e=>{var t,{mapStyle:r,mapProvider:o,events:i,eventBus:a,snapLayers:s,pluginConfig:c={}}=e,{map:l}=o;$t.constants.classes.CONTROL_BASE="maplibregl-ctrl",$t.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",$t.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var u=qi(qi({},$t.modes),{},{disabled:qt,edit_vertex:xn,edit_point:Nn,draw_polygon:io,draw_line:ao,draw_point:go}),d=o._mapboxDrawInstance;d?Object.assign(d.modes,u):(d=new $t({modes:u,styles:Mo(r,c),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),l.addControl(d),o._mapboxDrawInstance=d);var p=((e,t)=>{var r=e.getCanvas(),n=null,o=e=>{1===e.touches.length&&(n={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"===t.getMode()&&n){var o=e.changedTouches[0],i=o.clientX-n.x,a=o.clientY-n.y;Date.now()-n.time<300&&Math.abs(i)<10&&Math.abs(a)<10&&r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),n=null}else n=null};return r.addEventListener("touchstart",o,{passive:!0}),r.addEventListener("touchend",i,{passive:!0}),{remove(){r.removeEventListener("touchstart",o),r.removeEventListener("touchend",i)}}})(l,d);o.draw=d,l._drawCurrentMapStyle=r,l._drawPluginConfig=c,o.snapEnabled=!1;var h=o.undoStack;h||(h=Vi(e=>l.fire("draw.undochange",{length:e})),o.undoStack=h),l._undoStack=h;var f=Kr(r,c);ji(l,d,{layers:s,radius:null!==(t=c.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:f.snapVertex,edge:f.snapEdge}});var g=()=>a.emit(i.MAP_DATA_CHANGE),{handleSetMapStyle:y,handleStyleChanged:m}=(e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,eventBus:i,events:a,notifyPointSymbolsRefreshed:s}=e,c=e=>{t._drawCurrentMapStyle=e};i.on(a.MAP_SET_STYLE,c);var l=!1,u=()=>{l||(l=!0,Wi({map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:()=>{l=!1,s()}}))};return i.on(a.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:l,draw:d,mapProvider:o,pluginConfig:c,eventBus:a,events:i,notifyPointSymbolsRefreshed:g}),v=e=>{l.fire("draw.scalechange",{scale:M[e]})};a.on(i.MAP_SET_SIZE,v);var _=e=>{Ji({draw:d,mapProvider:o,map:l,pixelRatioOverride:e}).then(()=>{l.triggerRepaint(),g()})};return a.on(i.MAP_SET_PIXEL_RATIO,_),{draw:d,remove(){p.remove(),a.off(i.MAP_SET_STYLE,y),a.off(i.MAP_STYLE_CHANGE,m),a.off(i.MAP_SET_SIZE,v),a.off(i.MAP_SET_PIXEL_RATIO,_),d.changeMode("disabled"),o.draw=null}}};function ea(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ta(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ea(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ea(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ra=e=>"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,16),na=e=>"function"==typeof cancelAnimationFrame?cancelAnimationFrame(e):clearTimeout(e),oa=e=>{var{onChange:t,validate:r=C}=e,n=!1,o=null,i=null,a=()=>{null!=o&&(na(o),o=null),i=null},s=(e,r)=>{e!==n&&(n=e,t(e,null!=r?r:null))},c=()=>{if(o=null,i){var{feature:e,context:t,onGeometryChange:n}=i,{valid:a,reason:c}=r(e,t,{onGeometryChange:n});s(!a,c)}};return{update(e){var{feature:t,context:n={},numVertices:l,onGeometryChange:u}=e,d=ta(ta({},n),{},{numVertices:l}),p=r(t,d);return p.valid?"function"!=typeof u?(a(),void s(!1,null)):(i={feature:t,context:d,onGeometryChange:u},void(null==o&&(o=ra(c)))):(a(),void s(!0,p.reason))},set(e,t){a(),s(e,null!=t?t:null)},refresh(){t(n,null)},destroy(){a()}}};function ia(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function aa(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ia(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ia(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var sa=e=>{var{onStrokeChange:t,onPlaceChange:r}=e,n=e=>{var t=!1;return(r,n)=>{r!==t&&(t=r,e(r,null!=n?n:null))}},o=n(t),i=n(r),a=!1,c=null,l=null,u=null,d=()=>{null!=l&&(na(l),l=null),u=null},p=(e,t,r,n,o)=>{var i,s=(null!==(i=t.numVertices)&&void 0!==i?i:0)<n?{valid:!0}:T(e,aa(aa({},t),{},{phase:"preview"}),{rules:r});o(!s.valid||a,s.valid?c:s.reason)},h=()=>{var e,t;if(u){var{feature:r,context:n}=u,a=null!==(e=s[null==r||null===(t=r.geometry)||void 0===t?void 0:t.type])&&void 0!==e?e:0;p(r,n,L,a,o),p(r,n,k,0,i)}},f=()=>{if(l=null,u){var{feature:e,context:t,onGeometryChange:r}=u,n=T(e,aa(aa({},t),{},{phase:"preview"}),{rules:[],onGeometryChange:r});a=!n.valid,c=n.reason,h()}};return{update(e){var{feature:t,context:r={},numVertices:n,onGeometryChange:o}=e;u={feature:t,context:aa(aa({},r),{},{numVertices:n}),onGeometryChange:o},h(),"function"==typeof o&&null==l&&(l=ra(f))},reset(){d(),a=!1,c=null,o(!1,null),i(!1,null)},destroy(){d()}}};function ca(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function la(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ca(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ca(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ua=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),da=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),pa=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),ha=(e,t)=>{var r,n,o;if("draw_polygon"===e)return{feature:ua(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1};if("draw_line"===e)return{feature:da(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1};if("edit_vertex"===e){var i,a=t[0];return Array.isArray(null==a?void 0:a[0])?{feature:ua(t),numVertices:a.length}:{feature:da(t),numVertices:null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0}}return"edit_point"===e?{feature:pa(t),numVertices:1}:null};var fa=Object.freeze({__proto__:null,MaplibreDrawAdapter:class{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._bus=(n=new Map,{on(e,t){n.has(e)||n.set(e,new Set),n.get(e).add(t)},off(e,t){var r;null===(r=n.get(e))||void 0===r||r.delete(t)},emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var i=n.get(e);i&&Array.from(i).forEach(e=>e(...r))}}),this._editingFeatureId=null,this._sortKeyCounter=0;var{draw:o,remove:i}=Qi({mapStyle:t.mapStyle,mapProvider:e,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:null!==(r=t.pluginConfig)&&void 0!==r?r:{}});this._draw=o,this._cleanupDraw=i,this._liveStroke=oa({onChange:(e,t)=>{this._applyStrokeInvalid(e);var r=this._draw.getMode();"edit_vertex"!==r&&"edit_point"!==r||this._bus.emit(A.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=sa({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(A.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{var t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(A.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(A.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(A.CANCEL),vertexselection:e=>this._bus.emit(A.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(A.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(A.UNDO_CHANGE,e.length),update:e=>this._bus.emit(A.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(A.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(A.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(A.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(zt,this._mapHandlers.create),this._map.on(Qt,this._mapHandlers.editfinish),this._map.on(er,this._mapHandlers.cancel),this._map.on(tr,this._mapHandlers.vertexselection),this._map.on(rr,this._mapHandlers.vertexchange),this._map.on(nr,this._mapHandlers.undochange),this._map.on(Zt,this._mapHandlers.update),this._map.on(ir,this._mapHandlers.geometrychange),this._map.on(sr,this._mapHandlers.placementblocked),this._map.on(ar,this._mapHandlers.interfacetypechange),this._map.on(Wt,this._mapHandlers.modechange),this._map.on(dr,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=null!==(t=r.featureId)&&void 0!==t?t:null);"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(r=la(la({},r),{},{resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)})),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){return Ki({draw:this._draw,mapProvider:this._mapProvider,map:this._map,featureId:e,properties:t})}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=ha(t,e.coordinates);r&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:r.feature,numVertices:r.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update(la(la({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(ar,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if(("edit_vertex"===t||"edit_point"===t)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(Qt,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==t&&"draw_line"!==t||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();"draw_polygon"!==t&&"draw_line"!==t||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(or)}nudgeSelectedVertex(e,t,r){this._map.fire(cr,{dx:e,dy:t,isLargeStep:r})}getVertexItems(){var e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;var t=this._draw.get(this._editingFeatureId);if(!t)return e;var r=(e=>"Polygon"===e.type?la(la({},e),{},{coordinates:e.coordinates.map(e=>e.slice(0,-1))}):"MultiPolygon"===e.type?la(la({},e),{},{coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}):e)(t.geometry);return{vertices:pr(r),midpoints:hr(r)}}selectVertex(e){this._map.fire(lr,{index:e})}insertVertexAtMidpoint(e){this._map.fire(ur,{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(r=>{var n="".concat(e,".").concat(r);this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){var t,r,n=null==(null===(t=e.properties)||void 0===t?void 0:t.sortKey)?la(la({},e.properties),{},{sortKey:this._nextSortKey()}):e.properties,o=la(la({},e),{},{properties:n}),i=this._draw.add(o);return"Point"===(null===(r=o.geometry)||void 0===r?void 0:r.type)&&Hi(n)&&this._resolvePointSymbol(i[0],n),i}setStyle(e,t){var r=this._draw.get(e);r&&this.add(la(la({},r),{},{properties:la(la({},r.properties),t)}))}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=Pr(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(Cr(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=Pr(this._map);null!=t&&t.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,r){this._draw.setFeatureProperty(e,t,r)}setDrawingPreviewProperty(e,t){var r,n=this._currentDrawEvent;null!=n&&n.properties&&(n.properties[e]=t),null==n||null===(r=n.ctx)||void 0===r||null===(r=r.store)||void 0===r||r.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]).has(e.mode)||Mr(Pr(this._map),this._map)}_handleStyleData(){var e,t=this._map.getStyle();if(t){this._liveStroke.refresh();var r=t.layers||[];!r.length||null!==(e=r[r.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||r.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>this._map.moveLayer(e.id))}}remove(){this._map.off(zt,this._mapHandlers.create),this._map.off(Qt,this._mapHandlers.editfinish),this._map.off(er,this._mapHandlers.cancel),this._map.off(tr,this._mapHandlers.vertexselection),this._map.off(rr,this._mapHandlers.vertexchange),this._map.off(nr,this._mapHandlers.undochange),this._map.off(Zt,this._mapHandlers.update),this._map.off(ir,this._mapHandlers.geometrychange),this._map.off(sr,this._mapHandlers.placementblocked),this._map.off(ar,this._mapHandlers.interfacetypechange),this._map.off(Wt,this._mapHandlers.modechange),this._map.off(dr,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}},displayedShape:ha});export{fa as M,sa as a,Br as b,oa as c,Gr as d,Hr as e,dn as f,Vi as g,Yr as h,Xr as i,Kr as r,fn as s};