@defra/interactive-map 0.0.31-alpha → 0.0.33-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 (131) hide show
  1. package/README.md +2 -2
  2. package/assets/images/bright-ofm-thumb.jpg +0 -0
  3. package/assets/images/dark-ofm-thumb.jpg +0 -0
  4. package/assets/images/road-ofm-thumb.jpg +0 -0
  5. package/assets/templates/add-polygons.njk +143 -0
  6. package/assets/templates/add-symbols.njk +119 -0
  7. package/assets/templates/{map.njk → basic-map.njk} +9 -17
  8. package/assets/templates/button-map.njk +56 -0
  9. package/assets/templates/draw-tools.njk +161 -0
  10. package/assets/templates/marker-panel.njk +91 -0
  11. package/assets/templates/place-marker.njk +104 -0
  12. package/assets/templates/search-control.njk +98 -0
  13. package/assets/templates/select-feature.njk +101 -0
  14. package/assets/templates/style-switcher.njk +87 -0
  15. package/assets/templates/toggle-marker-label.njk +74 -0
  16. package/dist/css/index.css +1 -1
  17. package/dist/esm/im-core.js +1 -1
  18. package/dist/esm/im-shell.js +1 -1
  19. package/dist/umd/im-core.js +1 -1
  20. package/dist/umd/index.js +1 -1
  21. package/docs/api/map-style-config.md +27 -3
  22. package/docs/api.md +55 -0
  23. package/docs/assets/css/docusaurus.scss +22 -6
  24. package/docs/assets/images/add-polygons.jpg +0 -0
  25. package/docs/assets/images/add-symbols.jpg +0 -0
  26. package/docs/assets/images/hero.png +0 -0
  27. package/docs/assets/images/place-marker.jpg +0 -0
  28. package/docs/assets/images/screenshot.jpg +0 -0
  29. package/docs/examples/add-marker-with-panel.mdx +1 -1
  30. package/docs/examples/add-polygons.mdx +225 -0
  31. package/docs/examples/add-symbols.mdx +177 -0
  32. package/docs/examples/{draw.mdx → draw-tools.mdx} +2 -2
  33. package/docs/examples/index.mdx +38 -2
  34. package/docs/examples/place-marker.mdx +151 -0
  35. package/docs/plugins/datasets.md +144 -96
  36. package/docs/plugins/interact.md +1 -4
  37. package/docusaurus.config.cjs +5 -2
  38. package/govuk-prototype-kit.config.json +52 -2
  39. package/package.json +1 -1
  40. package/plugins/beta/datasets/dist/css/index.css +1 -2
  41. package/plugins/beta/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  42. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
  43. package/plugins/beta/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  44. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
  45. package/plugins/beta/datasets/dist/umd/index.js +1 -1
  46. package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +27 -9
  47. package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +46 -4
  48. package/plugins/beta/datasets/src/api/setFeatureVisibility.js +10 -1
  49. package/plugins/beta/datasets/src/api/setFeatureVisibility.test.js +48 -6
  50. package/plugins/beta/datasets/src/components/LayersMenu/Layers.module.scss +12 -12
  51. package/plugins/beta/datasets/src/reducers/datasetsToMenu.js +11 -6
  52. package/plugins/beta/datasets/src/reducers/datasetsToMenu.test.js +49 -0
  53. package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.js +8 -1
  54. package/plugins/beta/datasets/src/reducers/pluginState.js +1 -1
  55. package/plugins/beta/datasets/src/registry/dataset.js +7 -3
  56. package/plugins/beta/datasets/src/registry/dataset.test.js +14 -0
  57. package/plugins/beta/datasets/src/registry/dynamicGeoJson.js +1 -1
  58. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  59. package/plugins/beta/draw-es/src/api/addFeature.js +12 -3
  60. package/plugins/beta/draw-es/src/events.js +8 -3
  61. package/plugins/beta/draw-es/src/events.test.js +2 -0
  62. package/plugins/beta/draw-es/src/graphic.js +26 -2
  63. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  64. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  65. package/plugins/beta/draw-ml/src/DrawInit.jsx +19 -0
  66. package/plugins/beta/draw-ml/src/api/newLine.js +1 -0
  67. package/plugins/beta/draw-ml/src/api/newPolygon.js +1 -0
  68. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +52 -37
  69. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +1 -1
  70. package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +5 -4
  71. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +53 -21
  72. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  73. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  74. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  75. package/plugins/beta/draw-ol/src/core/OLDrawManager.js +3 -0
  76. package/plugins/beta/draw-ol/src/draw/DrawMode.js +57 -49
  77. package/plugins/beta/draw-ol/src/draw/drawInput.js +76 -32
  78. package/plugins/beta/draw-ol/src/edit/EditMode.js +4 -4
  79. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +4 -2
  80. package/plugins/beta/draw-ol/src/manifest.js +5 -1
  81. package/plugins/beta/draw-ol/src/reducer.js +1 -1
  82. package/plugins/beta/draw-ol/src/snap/snapEngine.js +75 -31
  83. package/plugins/beta/draw-ol/src/snap/snapGeometry.js +23 -46
  84. package/plugins/beta/draw-ol/src/snap/snapInteraction.js +30 -29
  85. package/plugins/beta/draw-ol/src/snap/snapManager.js +10 -1
  86. package/plugins/beta/draw-ol/src/utils/geometryHelpers.js +9 -3
  87. package/plugins/beta/draw-ol/src/utils/olCoords.js +2 -2
  88. package/plugins/beta/draw-ol/src/utils/spatial.js +4 -8
  89. package/plugins/beta/map-styles/src/mapStyles.scss +41 -41
  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 +1 -3
  94. package/plugins/interact/src/InteractInit.test.js +0 -2
  95. package/plugins/interact/src/events.test.js +1 -1
  96. package/plugins/interact/src/hooks/useCrossHairVisibility.js +4 -10
  97. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +5 -10
  98. package/plugins/interact/src/hooks/useHighlightSync.js +1 -10
  99. package/plugins/interact/src/hooks/useHighlightSync.test.js +2 -21
  100. package/plugins/interact/src/hooks/useInteractionHandlers.js +5 -11
  101. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +5 -25
  102. package/plugins/interact/src/reducer.js +4 -22
  103. package/plugins/interact/src/reducer.test.js +11 -39
  104. package/plugins/search/dist/css/index.css +5 -2
  105. package/plugins/search/src/components/Form/Form.module.scss +5 -2
  106. package/plugins/search/src/search.scss +4 -4
  107. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  108. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  109. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  110. package/providers/beta/openlayers/src/utils/tileLayers.js +29 -2
  111. package/providers/beta/openlayers/src/utils/tileLayers.test.js +53 -1
  112. package/src/App/components/CrossHair/CrossHair.module.scss +8 -8
  113. package/src/App/components/MapButton/MapButton.jsx +14 -10
  114. package/src/App/components/MapButton/MapButton.module.scss +1 -1
  115. package/src/App/components/MapButton/MapButton.test.jsx +1 -1
  116. package/src/App/components/PopupMenu/PopupMenu.test.jsx +79 -0
  117. package/src/App/components/PopupMenu/usePopupMenu.js +61 -12
  118. package/src/App/hooks/useLayoutMeasurements.js +10 -2
  119. package/src/App/hooks/useResizeObserver.js +4 -2
  120. package/src/InteractiveMap/InteractiveMap.js +4 -4
  121. package/src/InteractiveMap/InteractiveMap.test.js +3 -3
  122. package/src/InteractiveMap/behaviourController.js +3 -1
  123. package/src/InteractiveMap/behaviourController.test.js +6 -3
  124. package/src/InteractiveMap/domStateManager.js +2 -0
  125. package/src/config/events.js +21 -3
  126. package/src/types.js +12 -3
  127. package/src/utils/findNextTabStop.js +3 -3
  128. package/src/utils/findNextTabStop.test.js +25 -1
  129. package/webpack.dev.mjs +1 -0
  130. package/docs/assets/images/screens-blue.jpg +0 -0
  131. package/docs/assets/images/screens-white.jpg +0 -0
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import{useEffect as t}from"preact/compat";import r from"@babel/runtime/helpers/objectWithoutProperties";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 o(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach(function(r){e(t,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))})}return t}var i=new Set(["draw_polygon","draw_line"]),a={SET_MODE:(e,t)=>o(o({},e),{},{mode:t,numVertecies:i.has(t)?0:e.numVertecies}),SET_ACTION:(e,t)=>o(o({},e),{},{action:t.name,actionValid:t.isValid}),SET_FEATURE:(e,t)=>o(o({},e),{},{feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>o(o({},e),{},{selectedVertexIndex:t.index,numVertecies:t.numVertecies}),TOGGLE_SNAP:e=>o(o({},e),{},{snap:!e.snap}),SET_SNAP:(e,t)=>o(o({},e),{},{snap:!!t}),SET_HAS_SNAP_LAYERS:(e,t)=>o(o({},e),{},{hasSnapLayers:!!t}),SET_UNDO_STACK_LENGTH:(e,t)=>o(o({},e),{},{undoStackLength:t})},s={APP_ADD_MARKER:"app:addmarker",APP_UPDATE_MARKER:"app:updatemarker",APP_REMOVE_MARKER:"app:removemarker",APP_SET_MODE:"app:setmode",APP_REVERT_MODE:"app:revertmode",APP_ADD_BUTTON:"app:addbutton",APP_TOGGLE_BUTTON_STATE:"app:togglebuttonstate",APP_ADD_PANEL:"app:addpanel",APP_REMOVE_PANEL:"app:removepanel",APP_SHOW_PANEL:"app:showpanel",APP_HIDE_PANEL:"app:hidepanel",APP_ADD_CONTROL:"app:addcontrol",APP_READY:"app:ready",APP_OPENED:"app:opened",APP_CLOSED:"app:closed",APP_PANEL_OPENED:"app:panelopened",APP_PANEL_CLOSED:"app:panelclosed",MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize",MAP_SET_FEATURES:"map:setfeatures",MAP_SET_ACTIVE_FEATURE:"map:setactivefeature",MAP_SELECT_FEATURE:"map:selectfeature",MAP_SET_PIXEL_RATIO:"map:setpixelratio",MAP_FIT_TO_BOUNDS:"map:fittobounds",MAP_SET_VIEW:"map:setview",MAP_INIT_MAP_STYLES:"map:initmapstyles",MAP_STYLE_CHANGE:"map:stylechange",MAP_LOADED:"map:loaded",MAP_READY:"map:ready",MAP_SIZE_CHANGE:"map:sizechange",MAP_FIRST_IDLE:"map:firstidle",MAP_MOVE_START:"map:movestart",MAP_MOVE:"map:move",MAP_MOVE_END:"map:moveend",MAP_STATE_UPDATED:"map:stateupdated",MAP_DATA_CHANGE:"map:datachange",MAP_RENDER:"map:render",MAP_CLICK:"map:click",MAP_DESTROY:"map:destroy"};function c(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 l(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?c(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function u(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function d(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 p(e){return d(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function h(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function f(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 g(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 y(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}const m={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"},v={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},E={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},b={POLYGON:"polygon",LINE:"line_string",POINT:"point"},x={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"},S={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},P={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"},w={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},_={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},M={ACTIVE:"true",INACTIVE:"false"},O=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var I=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:M,classes:m,cursors:E,events:P,geojsonTypes:x,interactions:O,meta:_,modes:S,sources:v,types:b,updateActions:w});function C(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function T(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function L(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===M.ACTIVE&&e.featureTarget.properties.meta===_.FEATURE))}function A(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===M.INACTIVE&&e.featureTarget.properties.meta===_.FEATURE))}function k(e){return void 0===e.featureTarget}function F(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===_.FEATURE)}function N(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===_.VERTEX)}function V(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function D(e){return"Escape"===e.key||27===e.keyCode}function j(e){return"Enter"===e.key||13===e.keyCode}function R(e){return"Backspace"===e.key||8===e.keyCode}function U(e){return"Delete"===e.key||46===e.keyCode}function B(e){return"1"===e.key||49===e.keyCode}function G(e){return"2"===e.key||50===e.keyCode}function Y(e){return"3"===e.key||51===e.keyCode}function X(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var H=Object.freeze({__proto__:null,isActiveFeature:L,isBackspaceKey:R,isDeleteKey:U,isDigit1Key:B,isDigit2Key:G,isDigit3Key:Y,isDigitKey:X,isEnterKey:j,isEscapeKey:D,isFeature:F,isInactiveFeature:A,isOfMetaType:C,isShiftDown:V,isShiftMousedown:T,isTrue:function(){return!0},isVertex:N,noTarget:k});function J(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function q(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 $,K,W={},z={};function Z(){return $||($=1,z.RADIUS=6378137,z.FLATTENING=1/298.257223563,z.POLAR_RADIUS=6356752.3142),z}var Q=function(){if(K)return W;K=1;var e=Z();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 W.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}},W.ring=r,W}(),ee=J(Q);const te={Point:0,LineString:1,MultiLineString:1,Polygon:2};function re(e,t){const r=te[e.geometry.type]-te[t.geometry.type];return 0===r&&e.geometry.type===x.POLYGON?e.area-t.area:r}function ne(e){return e.map(e=>(e.geometry.type===x.POLYGON&&(e.area=ee.geometry({type:x.FEATURE,property:{},geometry:e.geometry})),e)).sort(re).map(e=>(delete e.area,e))}function oe(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function ie(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)}ie.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},ie.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},ie.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},ie.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)},ie.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const ae=[_.FEATURE,_.MIDPOINT,_.VERTEX];var se={click:function(e,t,r){return ce(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return ce(e,t,r,r.options.touchBuffer)}};function ce(e,t,r,n){if(null===r.map)return[];const o=e?oe(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!==ae.indexOf(e.properties.meta)),s=new ie,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),ne(c)}function le(e,t){const r=se.click(e,null,t),n={mouse:E.NONE};return r[0]&&(n.mouse=r[0].properties.active===M.ACTIVE?E.MOVE:E.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=E.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function ue(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function de(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=ue(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function pe(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 ue(e.point,t.point)<n&&t.time-e.time<o}const he=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 fe=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function ge(){return fe()}const ye=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||ge(),this.type=t.geometry.type};ye.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ye.prototype.incomingCoords=function(e){this.setCoordinates(e)},ye.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ye.prototype.setProperty=function(e,t){this.properties[e]=t},ye.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:x.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ye.prototype.internal=function(e){const t={id:this.id,meta:_.FEATURE,"meta:type":this.type,active:M.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:x.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const me=function(e,t){ye.call(this,e,t)};(me.prototype=Object.create(ye.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},me.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},me.prototype.getCoordinate=function(){return this.getCoordinates()};const ve=function(e,t){ye.call(this,e,t)};(ve.prototype=Object.create(ye.prototype)).isValid=function(){return this.coordinates.length>1},ve.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},ve.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},ve.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},ve.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ee=function(e,t){ye.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ee.prototype=Object.create(ye.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ee.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ee.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ee.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])},Ee.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))},Ee.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]]))},Ee.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ee.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 be={MultiPoint:me,MultiLineString:ve,MultiPolygon:Ee},xe=(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)},Se=function(e,t){if(ye.call(this,e,t),delete this.coordinates,this.model=be[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 Pe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Se.prototype=Object.create(ye.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:ge(),type:x.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Se.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Se.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Se.prototype.getCoordinate=function(e){return xe(this.features,"getCoordinate",e)},Se.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===x.POLYGON?e.getCoordinates():e.coordinates)))},Se.prototype.updateCoordinate=function(e,t,r){xe(this.features,"updateCoordinate",e,t,r),this.changed()},Se.prototype.addCoordinate=function(e,t,r){xe(this.features,"addCoordinate",e,t,r),this.changed()},Se.prototype.removeCoordinate=function(e){xe(this.features,"removeCoordinate",e),this.changed()},Se.prototype.getFeatures=function(){return this.features},Pe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Pe.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),{})},Pe.prototype.getSelected=function(){return this._ctx.store.getSelected()},Pe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Pe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Pe.prototype.getFeature=function(e){return this._ctx.store.get(e)},Pe.prototype.select=function(e){return this._ctx.store.select(e)},Pe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Pe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Pe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Pe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Pe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Pe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Pe.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Pe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Pe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Pe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Pe.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)},Pe.prototype.newFeature=function(e){const t=e.geometry.type;return t===x.POINT?new me(this._ctx,e):t===x.LINE_STRING?new ve(this._ctx,e):t===x.POLYGON?new Ee(this._ctx,e):new Se(this._ctx,e)},Pe.prototype.isInstanceOf=function(e,t){if(e===x.POINT)return t instanceof me;if(e===x.LINE_STRING)return t instanceof ve;if(e===x.POLYGON)return t instanceof Ee;if("MultiFeature"===e)return t instanceof Se;throw new Error(`Unknown feature class: ${e}`)},Pe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Pe.prototype.onSetup=function(){},Pe.prototype.onDrag=function(){},Pe.prototype.onClick=function(){},Pe.prototype.onMouseMove=function(){},Pe.prototype.onMouseDown=function(){},Pe.prototype.onMouseUp=function(){},Pe.prototype.onMouseOut=function(){},Pe.prototype.onKeyUp=function(){},Pe.prototype.onKeyDown=function(){},Pe.prototype.onTouchStart=function(){},Pe.prototype.onTouchMove=function(){},Pe.prototype.onTouchEnd=function(){},Pe.prototype.onTap=function(){},Pe.prototype.onStop=function(){},Pe.prototype.onTrash=function(){},Pe.prototype.onCombineFeature=function(){},Pe.prototype.onUncombineFeature=function(){},Pe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const we={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},_e=Object.keys(we);function Me(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Pe(r));return{start(){o=i.onSetup(n),_e.forEach(t=>{const r=we[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 Oe(e){return[].concat(e).filter(e=>void 0!==e)}function Ie(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(v.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(v.COLD).setData({type:x.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(v.HOT).setData({type:x.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Ce(e){let t;this._features={},this._featureIds=new ie,this._selectedFeatureIds=new ie,this._selectedCoordinates=[],this._changedFeatureIds=new ie,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ie.call(this),this._emitSelectionChange&&(this.ctx.events.fire(P.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(P.RENDER,{})}))},this.isDirty=!1}function Te(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}Ce.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ce.prototype.setDirty=function(){return this.isDirty=!0,this},Ce.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(P.CREATE,{features:[t.toGeoJSON()]})}return this},Ce.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(P.UPDATE,{action:t.action?t.action:w.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ce.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ce.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ce.prototype.getAllIds=function(){return this._featureIds.values()},Ce.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ce.prototype.delete=function(e,t={}){const r=[];return Oe(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(P.DELETE,{features:r}),Te(this,t),this},Ce.prototype.get=function(e){return this._features[e]},Ce.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Ce.prototype.select=function(e,t={}){return Oe(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Ce.prototype.deselect=function(e,t={}){return Oe(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Te(this,t),this},Ce.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ce.prototype.setSelected=function(e,t={}){return e=Oe(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},Ce.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ce.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ce.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ce.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Ce.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Ce.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ce.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:w.CHANGE_PROPERTIES})},Ce.prototype.storeMapConfig=function(){O.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Ce.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Ce.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Le=["mode","feature","mouse"];function Ae(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]=Me(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:E.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!de(r,e))},o.touchdrag=function(e){o.drag(e,e=>!pe(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=le(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=le(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=le(t,e);t.featureTarget=n,de(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,pe(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=R(e),r=U(e),n=X(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=he(c,e),o.silent||e.map.fire(P.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(m.CANVAS)&&((R(t)||U(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):B(t)&&e.options.controls.point?c(S.DRAW_POINT):G(t)&&e.options.controls.line_string?c(S.DRAW_LINE_STRING):Y(t)&&e.options.controls.polygon&&c(S.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},u={start(){i=e.options.defaultMode,a=he(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(P.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};return u}(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=[];Le.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=`${m.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(m.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(m.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=`${m.CONTROL_GROUP} ${m.CONTROL_BASE}`,r?(r[b.POINT]&&(t[b.POINT]=s(b.POINT,{container:n,className:m.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(S.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[b.LINE]&&(t[b.LINE]=s(b.LINE,{container:n,className:m.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(S.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[b.POLYGON]&&(t[b.POLYGON]=s(b.POLYGON,{container:n,className:m.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(S.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:m.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:m.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:m.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 Ce(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(v.COLD,{data:{type:x.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(v.HOT,{data:{type:x.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(v.COLD)&&e.map.removeSource(v.COLD),e.map.getSource(v.HOT)&&e.map.removeSource(v.HOT)}};return e.setup=n,n}const ke="#3bb2d0",Fe="#fbb03b",Ne="#fff";var Ve=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Fe,ke],"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"],Fe,ke],"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":Ne}},{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"],Fe,ke]}},{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":Ne}},{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":Fe}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Fe}}];function De(e,t){this.x=e,this.y=t}function je(e,t){const r=t.getBoundingClientRect();return new De(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function Re(e,t,r,n){return{type:x.FEATURE,properties:{meta:_.VERTEX,parent:e,coord_path:r,active:n?M.ACTIVE:M.INACTIVE},geometry:{type:x.POINT,coordinates:t}}}De.prototype={clone(){return new De(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:De},De.convert=function(e){if(e instanceof De)return e;if(Array.isArray(e))return new De(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new De(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var Ue=6371008.8,Be={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*Ue,kilometers:6371.0088,kilometres:6371.0088,meters:Ue,metres:Ue,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:Ue/1852,radians:1,yards:6967335.223679999};function Ge(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 Ye(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(!Ze(e[0])||!Ze(e[1]))throw new Error("coordinates must contain numbers");return Ge({type:"Point",coordinates:e},t,r)}function Xe(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 Ge({type:"Polygon",coordinates:e},t,r)}function He(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return Ge({type:"LineString",coordinates:e},t,r)}function Je(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function qe(e,t,r={}){return Ge({type:"MultiLineString",coordinates:e},t,r)}function $e(e,t="kilometers"){const r=Be[t];if(!r)throw new Error(t+" units is invalid");return e*r}function Ke(e,t="kilometers"){const r=Be[t];if(!r)throw new Error(t+" units is invalid");return e/r}function We(e){return 180*(e%(2*Math.PI))/Math.PI}function ze(e){return e%360*Math.PI/180}function Ze(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function Qe(e,t,r){if(null!==e)for(var n,o,i,a,s,c,l,u,d=0,p=0,h=e.type,f="FeatureCollection"===h,g="Feature"===h,y=f?e.features.length:1,m=0;m<y;m++){s=(u=!!(l=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===l.type)?l.geometries.length:1;for(var v=0;v<s;v++){var E=0,b=0;if(null!==(a=u?l.geometries[v]:l)){c=a.coordinates;var x=a.type;switch(d=0,x){case null:break;case"Point":if(!1===t(c,p,m,E,b))return!1;p++,E++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===t(c[n],p,m,E,b))return!1;p++,"MultiPoint"===x&&E++}"LineString"===x&&E++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(o=0;o<c[n].length-d;o++){if(!1===t(c[n][o],p,m,E,b))return!1;p++}"MultiLineString"===x&&E++,"Polygon"===x&&b++}"Polygon"===x&&E++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(b=0,o=0;o<c[n].length;o++){for(i=0;i<c[n][o].length-d;i++){if(!1===t(c[n][o][i],p,m,E,b))return!1;p++}b++}E++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===Qe(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function et(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 tt(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 rt(e,t){tt(e,function(e,r,n,o,i){var a,s=null===e?null:e.type;switch(s){case null:case"Point":case"LineString":case"Polygon":return!1!==t(Ge(e,n,{bbox:o,id:i}),r,0)&&void 0}switch(s){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var c=0;c<e.coordinates.length;c++){var l=e.coordinates[c];if(!1===t(Ge({type:a,coordinates:l},n),r,c))return!1}})}function nt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return ot(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=>ot(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return at(e);default:throw new Error("unknown GeoJSON type")}}function ot(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=it(e.properties),null==e.geometry?t.geometry=null:t.geometry=at(e.geometry),t}function it(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]=it(n):t[r]=n}),t):t}function at(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>at(e)),t):(t.coordinates=st(e.coordinates),t)}function st(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>st(e))}function ct(e,t={}){return lt(e,"mercator",t)}function lt(e,t,r={}){var n=(r=r||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&Ze(e[0])?e="mercator"===t?ut(e):dt(e):(!0!==n&&(e=nt(e)),Qe(e,function(e){var r="mercator"===t?ut(e):dt(e);e[0]=r[0],e[1]=r[1]})),e}function ut(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 dt(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 pt(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=ct(n),a=ct(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return lt(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:x.FEATURE,properties:{meta:_.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:x.POINT,coordinates:u}}}function ht(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=Re(i,e,l,c(l));if(t.midpoints&&o){const e=pt(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===x.POINT?a.push(Re(i,o,r,c(r))):n===x.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===x.LINE_STRING?s(o,r):0===n.indexOf(x.MULTI_PREFIX)&&function(){const r=n.replace(x.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:x.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(ht(i,t,o))})}(),a}var ft={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:gt,LAT_MAX:yt,LAT_RENDERED_MIN:mt,LAT_RENDERED_MAX:vt,LNG_MIN:Et,LNG_MAX:bt}=I;function xt(e,t){let r=gt,n=yt,o=gt,i=yt,a=bt,s=Et;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],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>vt&&(c.lat=vt-r),o+c.lat>yt&&(c.lat=yt-o),n+c.lat<mt&&(c.lat=mt-n),i+c.lat<gt&&(c.lat=gt-i),a+c.lng<=Et&&(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 St(e,t){const r=xt(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===x.POINT?a=n(t):e.type===x.LINE_STRING||e.type===x.MULTI_POINT?a=t.map(n):e.type===x.POLYGON||e.type===x.MULTI_LINE_STRING?a=t.map(o):e.type===x.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Pt={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(P.UPDATE,{action:w.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 ie).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(){ft.enable(this)},onMouseMove:function(e,t){return F(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Pt.onTap=Pt.onClick=function(e,t){return k(t)?this.clickAnywhere(e,t):C(_.VERTEX)(t)?this.clickOnVertex(e,t):F(t)?this.clickOnFeature(e,t):void 0},Pt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),ft.enable(this),this.stopExtendedInteractions(e)},Pt.clickOnVertex=function(e,t){this.changeMode(S.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:E.MOVE})},Pt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Pt.clickOnFeature=function(e,t){ft.disable(this),this.stopExtendedInteractions(e);const r=V(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==x.POINT)return this.changeMode(S.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:E.POINTER}),1===n.length&&ft.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:E.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:E.MOVE})),this.doRender(o)},Pt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),L(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&T(t)?this.startBoxSelect(e,t):void 0},Pt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=je(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Pt.onTouchStart=function(e,t){if(L(t))return this.startOnActiveFeature(e,t)},Pt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Pt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:E.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(m.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=je(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"},Pt.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};St(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Pt.onTouchEnd=Pt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,je(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:E.MOVE}))}this.stopExtendedInteractions(e)},Pt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?M.ACTIVE:M.INACTIVE,r(t),this.fireActionable(),t.properties.active===M.ACTIVE&&t.geometry.type!==x.POINT&&ht(t).forEach(r)},Pt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Pt.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:x.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(P.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Pt.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(P.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const wt=C(_.VERTEX),_t=C(_.MIDPOINT),Mt={fireUpdate:function(){this.fire(P.UPDATE,{action:w.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);V(t)||-1!==n?V(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){St(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=xt(n.map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.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(S.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(S.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===x.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),ft.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){ft.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=M.ACTIVE,r(t),ht(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=M.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(S.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=L(t),n=wt(t),o=_t(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:E.MOVE}):this.updateUIClasses({mouse:E.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Mt.onTouchStart=Mt.onMouseDown=function(e,t){return wt(t)?this.onVertex(e,t):L(t)?this.onFeature(e,t):_t(t)?this.onMidpoint(e,t):void 0},Mt.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},Mt.onClick=function(e,t){return k(t)?this.clickNoTarget(e,t):L(t)?this.clickActiveFeature(e,t):A(t)?this.clickInactive(e,t):void this.stopDragging(e)},Mt.onTap=function(e,t){return k(t)?this.clickNoTarget(e,t):L(t)?this.clickActiveFeature(e,t):A(t)?this.clickInactive(e,t):void 0},Mt.onTouchEnd=Mt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Ot={};function It(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Ot.onSetup=function(){const e=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.POINT),this.setActionableState({trash:!0}),{point:e}},Ot.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)},Ot.onTap=Ot.onClick=function(e,t){this.updateUIClasses({mouse:E.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(P.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.point.id]})},Ot.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Ot.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t)},Ot.onTrash=Ot.stopDrawingAndRemove,Ot.onKeyUp=function(e,t){if(D(t)||j(t))return this.stopDrawingAndRemove(e,t)};const Ct={onSetup:function(){const e=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),ft.disable(this),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.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(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:E.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(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),N(t)&&this.updateUIClasses({mouse:E.POINTER})}};Ct.onTap=Ct.onClick=function(e,t){return N(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ct.onKeyUp=function(e,t){D(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)):j(t)&&this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ct.onStop=function(e){this.updateUIClasses({mouse:E.NONE}),ft.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(P.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT,{},{silent:!0})))},Ct.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?M.ACTIVE:M.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=_.FEATURE,r(Re(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(Re(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:x.FEATURE,properties:t.properties,geometry:{coordinates:e,type:x.LINE_STRING}}),3===o)return}return r(t)}},Ct.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)};const Tt={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:x.FEATURE,properties:{},geometry:{type:x.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),ft.disable(this),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.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(S.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:E.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(S.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),N(t)&&this.updateUIClasses({mouse:E.POINTER})}};Tt.onTap=Tt.onClick=function(e,t){if(N(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Tt.onKeyUp=function(e,t){j(t)?this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.line.id]}):D(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT))},Tt.onStop=function(e){ft.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(P.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT,{},{silent:!0})))},Tt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)},Tt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=_.FEATURE,r(Re(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 Lt={simple_select:Pt,direct_select:Mt,draw_point:Ot,draw_polygon:Ct,draw_line_string:Tt};const At={defaultMode:S.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:Ve,modes:Lt,controls:{},userProperties:!1,suppressAPIEvents:!0},kt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ft={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Nt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?v.HOT:v.COLD}))}var Vt,Dt;var jt,Rt,Ut=(Dt||(Dt=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}),Vt),Bt=J(Ut);var Gt=function(){if(Rt)return jt;Rt=1,jt=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 jt}(),Yt=J(Gt);function Xt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Ht={Polygon:Ee,LineString:ve,Point:me,MultiPolygon:Se,MultiLineString:Se,MultiPoint:Se};var Jt=Object.freeze({__proto__:null,CommonSelectors:H,ModeHandler:he,StringSet:ie,constrainFeatureMovement:xt,createMidPoint:pt,createSupplementaryPoints:ht,createVertex:Re,doubleClickZoom:ft,euclideanDistance:ue,featuresAt:se,getFeatureAtAndSetCursors:le,isClick:de,isEventAtCoordinates:It,isTap:pe,mapEventToBoundingBox:oe,moveFeatures:St,sortFeatures:ne,stringSetsAreEqual:Xt,theme:Ve,toDenseArray:Oe});const qt=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({},Ft,e.controls):t.controls=Object.assign({},kt,e.controls),t=Object.assign({},At,t),t.styles=Nt(t.styles,"cold").concat(Nt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=S;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:x.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:x.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==x.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 ie(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(Yt(t))).features.map(t=>{if(t.id=t.id||ge(),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,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:x.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==S.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(S.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===S.DIRECT_SELECT?e.events.changeMode(S.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===S.SIMPLE_SELECT&&t.getMode()===S.SIMPLE_SELECT?(Xt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===S.DIRECT_SELECT&&t.getMode()===S.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=Ae(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=b,t.options=e,t};function $t(e){qt(e,this)}$t.modes=Lt,$t.constants=I,$t.lib=Jt;var Kt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},Wt=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[]}},zt=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},Zt=(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},Qt=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},er=(e,t)=>{var r=t.split(".").map(Number),n=zt(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]},tr=(e,t)=>({x:e.x*t,y:e.y*t}),rr=e=>e instanceof window.SVGElement||e.ownerSVGElement,nr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},pushUndo(e){var t=this.map._undoStack;t&&t.push(e)},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)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=zt(i),c=Zt(s,r);if(c){Qt(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,tr(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=zt(o),s=Zt(a,r);if(s)Qt(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=zt(i),c=Zt(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c){Qt(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o);var u=e.vertecies[r];u&&this.updateTouchVertexTarget(e,tr(this.map.project(u),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)}};function or(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 ir(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?or(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):or(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ar=(e,t)=>{if(e){var r="dark"===(null==t?void 0:t.mapColorScheme);e.style.setProperty("--touch-fill",r?"#ffffff":"#000000"),e.style.setProperty("--touch-gfx",r?"#000000":"#ffffff")}},sr={addTouchVertexTarget(e){var t=e.container.querySelector("[data-touch-vertex-target]");t||(e.container.insertAdjacentHTML("beforeend","\n <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd' style='display:none;position:absolute;top:50%;left:50%;margin:24px 0 0 -24px' class='touch-vertex-target' data-touch-vertex-target>\n <circle cx='24' cy='24' r='24' fill='var(--touch-fill, #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(--touch-gfx, #fff)'/>\n </svg>\n"),t=e.container.querySelector("[data-touch-vertex-target]")),e.touchVertexTarget=t,ar(t,this.map._drawCurrentMapStyle)},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":"pointer",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||rr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){g(u(this.map)),null!=e&&e.featureId&&(this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=void 0,e._touchMoved=!1)},onTap(e,t){var r,n,o=u(this.map);o&&f(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=er(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(ir(ir({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){var r;g(u(this.map));var n=null===(r=e.vertecies)||void 0===r?void 0:r[e.selectedVertexIndex];if(n&&rr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=t.touches[0].clientX,i=t.touches[0].clientY,a=window.getComputedStyle(e.touchVertexTarget);e.deltaTarget={x:o-Number.parseFloat(a.left),y:i-Number.parseFloat(a.top)};var s=this.map.project(n);e.deltaVertex={x:o/e.scale-s.x,y:i/e.scale-s.y}}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&rr(t.target.parentNode)){e._touchMoved=!0;var r=t.touches[0].clientX,n=t.touches[0].clientY,o={x:r/e.scale-e.deltaVertex.x,y:n/e.scale-e.deltaVertex.y},i=this.map.unproject(o);if(y(e)){var a=u(this.map);h(a,this.map,o),i=p(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function cr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var lr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},ur={updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(t,r){var[n,o]=this.getVertexOrMidpoint(t,r);n<0||!o||this.changeMode(t,function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?cr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({selectedVertexIndex:n,selectedVertexType:o},"vertex"===o&&{coordPath:this.getCoordPath(t,n)}))},getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?1:5,[o,i]=t?lr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getNewCoord(e,t){return this.getOffset(Wt(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},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=zt(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&&(Qt(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=zt(o),s=Zt(a,e.selectedVertexIndex);s&&(Qt(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=zt(t),n=Zt(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?3:2;if(!(o.length<=i)){var a=[...e.vertecies[e.selectedVertexIndex]],s=e.selectedVertexIndex;this._ctx.api.trash(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:s,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}};function dr(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return pr(e);case"FeatureCollection":return function(e){var t={type:"FeatureCollection"};return Object.keys(e).forEach(function(r){switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(function(e){return pr(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return fr(e);default:throw new Error("unknown GeoJSON type")}}function pr(e){var t={type:"Feature"};return Object.keys(e).forEach(function(r){switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=hr(e.properties),t.geometry=fr(e.geometry),t}function hr(e){var t={};return e?(Object.keys(e).forEach(function(r){var n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(function(e){return e}):t[r]=hr(n):t[r]=n}),t):t}function fr(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return fr(e)}),t):(t.coordinates=gr(e.coordinates),t)}function gr(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return gr(e)})}function yr(e){for(var t,r,n=function(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")}(e),o=0,i=1;i<n.length;)t=r||n[0],o+=((r=n[i])[0]-t[0])*(r[1]+t[1]),i++;return o>0}function mr(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 vr(e,t){if(null===(r=t=t||{})||"object"!=typeof r||Array.isArray(r))throw new Error("options is invalid");var r,n=t.reverse||!1,o=t.mutate||!1;if(!e)throw new Error("<geojson> is required");if("boolean"!=typeof n)throw new Error("<reverse> must be a boolean");if("boolean"!=typeof o)throw new Error("<mutate> must be a boolean");!1===o&&(e=dr(e));var i=[];switch(e.type){case"GeometryCollection":return tt(e,function(e){Er(e,n)}),e;case"FeatureCollection":return et(e,function(e){et(Er(e,n),function(e){i.push(e)})}),Je(i)}return Er(e,n)}function Er(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return tt(e,function(e){Er(e,t)}),e;case"LineString":return br(mr(e),t),e;case"Polygon":return xr(mr(e),t),e;case"MultiLineString":return mr(e).forEach(function(e){br(e,t)}),e;case"MultiPolygon":return mr(e).forEach(function(e){xr(e,t)}),e;case"Point":case"MultiPoint":return e}}function br(e,t){yr(e)===t&&e.reverse()}function xr(e,t){yr(e[0])!==t&&e[0].reverse();for(var r=1;r<e.length;r++)yr(e[r])===t&&e[r].reverse()}const Sr=11102230246251565e-32,Pr=134217729,wr=(3+8*Sr)*Sr;function _r(e,t,r,n,o){let i,a,s,c,l=t[0],u=n[0],d=0,p=0;u>l==u>-l?(i=l,l=t[++d]):(i=u,u=n[++p]);let h=0;if(d<e&&p<r)for(u>l==u>-l?(a=l+i,s=i-(a-l),l=t[++d]):(a=u+i,s=i-(a-u),u=n[++p]),i=a,0!==s&&(o[h++]=s);d<e&&p<r;)u>l==u>-l?(a=i+l,c=a-i,s=i-(a-c)+(l-c),l=t[++d]):(a=i+u,c=a-i,s=i-(a-c)+(u-c),u=n[++p]),i=a,0!==s&&(o[h++]=s);for(;d<e;)a=i+l,c=a-i,s=i-(a-c)+(l-c),l=t[++d],i=a,0!==s&&(o[h++]=s);for(;p<r;)a=i+u,c=a-i,s=i-(a-c)+(u-c),u=n[++p],i=a,0!==s&&(o[h++]=s);return 0===i&&0!==h||(o[h++]=i),h}function Mr(e){return new Float64Array(e)}const Or=Mr(4),Ir=Mr(8),Cr=Mr(12),Tr=Mr(16),Lr=Mr(4);function Ar(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),c=a-s,l=Math.abs(a+s);return Math.abs(c)>=33306690738754716e-32*l?c:-function(e,t,r,n,o,i,a){let s,c,l,u,d,p,h,f,g,y,m,v,E,b,x,S,P,w;const _=e-o,M=r-o,O=t-i,I=n-i;b=_*I,p=Pr*_,h=p-(p-_),f=_-h,p=Pr*I,g=p-(p-I),y=I-g,x=f*y-(b-h*g-f*g-h*y),S=O*M,p=Pr*O,h=p-(p-O),f=O-h,p=Pr*M,g=p-(p-M),y=M-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Or[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Or[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Or[2]=v-(w-d)+(m-d),Or[3]=w;let C=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,Or),T=22204460492503146e-32*a;if(C>=T||-C>=T)return C;if(d=e-_,s=e-(_+d)+(d-o),d=r-M,l=r-(M+d)+(d-o),d=t-O,c=t-(O+d)+(d-i),d=n-I,u=n-(I+d)+(d-i),0===s&&0===c&&0===l&&0===u)return C;if(T=11093356479670487e-47*a+wr*Math.abs(C),C+=_*u+I*s-(O*l+M*c),C>=T||-C>=T)return C;b=s*I,p=Pr*s,h=p-(p-s),f=s-h,p=Pr*I,g=p-(p-I),y=I-g,x=f*y-(b-h*g-f*g-h*y),S=c*M,p=Pr*c,h=p-(p-c),f=c-h,p=Pr*M,g=p-(p-M),y=M-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Lr[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Lr[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Lr[2]=v-(w-d)+(m-d),Lr[3]=w;const L=_r(4,Or,4,Lr,Ir);b=_*u,p=Pr*_,h=p-(p-_),f=_-h,p=Pr*u,g=p-(p-u),y=u-g,x=f*y-(b-h*g-f*g-h*y),S=O*l,p=Pr*O,h=p-(p-O),f=O-h,p=Pr*l,g=p-(p-l),y=l-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Lr[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Lr[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Lr[2]=v-(w-d)+(m-d),Lr[3]=w;const A=_r(L,Ir,4,Lr,Cr);b=s*u,p=Pr*s,h=p-(p-s),f=s-h,p=Pr*u,g=p-(p-u),y=u-g,x=f*y-(b-h*g-f*g-h*y),S=c*l,p=Pr*c,h=p-(p-c),f=c-h,p=Pr*l,g=p-(p-l),y=l-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Lr[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Lr[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Lr[2]=v-(w-d)+(m-d),Lr[3]=w;const k=_r(A,Cr,4,Lr,Tr);return Tr[k-1]}(e,t,r,n,o,i,l)}function kr(e,t){var r,n,o,i,a,s,c,l,u,d=0,p=e[0],h=e[1],f=t.length;for(r=0;r<f;r++){n=0;var g=t[r],y=g.length-1;if((l=g[0])[0]!==g[y][0]&&l[1]!==g[y][1])throw new Error("First and last coordinates in a ring must be the same");for(i=l[0]-p,a=l[1]-h;n<y;n++){if(s=(u=g[n+1])[0]-p,c=u[1]-h,0===a&&0===c){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(c>=0&&a<=0||c<=0&&a>=0){if(0===(o=Ar(i,s,a,c,0,0)))return 0;(o>0&&c>0&&a<=0||o<0&&c<=0&&a>0)&&d++}l=u,a=c,i=s}}return d%2!=0}var Fr=function(e,t,r,n,o){this.p1=e,this.p2=t,this.edgeType=r,this.originalIndex=n,this.polygonContourId=o,this.interiorRing=!1,this.minX=Math.min(e.p[0],t.p[0]),this.minY=Math.min(e.p[1],t.p[1]),this.maxX=Math.max(e.p[0],t.p[0]),this.maxY=Math.max(e.p[1],t.p[1]),this.intersectionPoints=[],this.nextEdge=null},Nr=function(e){this.p=e},Vr=function(e,t){this.id=e,this.rawCoords=t};function Dr(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var jr=function(e,t,r,n){this.p=e,this.polylineEdge=t,this.polygonEdge=r,this.isHeadingIn=n,this.distanceFromPolylineEdgeStart=Rr(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Rr(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Rr(e,t){var r=t[0]-e[0],n=t[1]-e[1];return r*=r,n*=n,Math.sqrt(r+n)}jr.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var Ur=1e-9;function Br(e,t){return e[0]*t[1]-e[1]*t[0]}function Gr(e,t){return e[0]*t[0]+e[1]*t[1]}function Yr(e,t,r){return[e[0]+t*r[0],e[1]+t*r[1]]}function Xr(e,t,r){var n=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],o=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],i=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],a=Br(n,o),s=a*a,c=Gr(n,n);if(s>0){var l=Br(i,o)/a;if(l<0||l>1)return null;var u=Br(i,n)/a;return u<0||u>1?null:0===l||1===l?[Yr(e.p1.p,l,n)]:0===u||1===u?[Yr(t.p1.p,u,o)]:[Yr(e.p1.p,l,n)]}var d=Gr(i,i);if((s=(a=Br(i,n))*a)>Ur*c*d)return null;var p=Gr(n,i)/c,h=p+Gr(n,o)/c,f=Math.min(p,h),g=Math.max(p,h);return f<=1&&g>=0?1===f?[Yr(e.p1.p,f>0?f:0,n)]:0===g?[Yr(e.p1.p,g<1?g:1,n)]:[Yr(e.p1.p,f>0?f:0,n),Yr(e.p1.p,g<1?g:1,n)]:null}function Hr(e,t){var r=[],n=[],o=[],i=function(e,t,r,n,o){for(var i=0,a=[],s="Feature"===t.type?t.geometry:t,c="LineString"===s.type?[s.coordinates]:s.coordinates,l=0,u=0;u<c.length;u++){for(var d=c[u].length-1,p=new Nr(c[u][0]),h=null,f={nextEdge:null},g=0;g<d;g++){h=new Nr(c[u][g+1]),p.nextPoint=h,h.prevPoint=p;var y=new Fr(p,h,"polyline",l,null);n.push(y),f.nextEdge=y,y.prevEdge=f,o[0]=Math.min(o[0],p.p[0]),o[1]=Math.min(o[1],p.p[1]),o[2]=Math.max(o[2],p.p[0]),o[3]=Math.max(o[3],p.p[1]),p=h,l+=1,f=y}o[0]=Math.min(o[0],c[u][d][0]),o[1]=Math.min(o[1],c[u][d][1]),o[2]=Math.max(o[2],c[u][d][0]),o[3]=Math.max(o[3],c[u][d][1])}for(var m="Feature"===e.type?e.geometry:e,v="Polygon"===m.type?[m.coordinates]:m.coordinates,E=v.length,b=0;b<E;b++)for(var x=v[b].length,S=0;S<x;S++){i+=1;var P=v[b][S],w=P.length;a.push(new Vr(i,P));for(var _=new Nr(P[0]),M=_,O=void 0,I=null,C={nextEdge:null,prevEdge:null},T=null,L=1;L<w;L++)O=new Nr(P[L]),M.nextPoint=O,O.prevPoint=M,I=new Fr(M,O,"polygon",l,i),C.nextEdge=I,I.prevEdge=C,1===L&&(T=I),S>0&&(I.interiorRing=!0),I.intersectPolylineBbox=Dr(I,o),r.push(I),M=O,l+=1,C=I;I.nextEdge=T,T.prevEdge=I,O.nextPoint=_.nextPoint,_.prevPoint=O.prevPoint}return a}(vr(e),t,n,o,[1/0,1/0,1/0,1/0]);if(function(e,t,r){var n,o,i,a=t.length,s=e.length;for(n=0;n<a;n++){var c=t[n];for(o=0;o<s;o++){var l=e[o];if(l.intersectPolylineBbox&&!(l.maxX<c.minX||l.minX>c.maxX||l.maxY<c.minY||l.minY>c.maxY)){var u=Xr(c,l);if(null!==u)for(i=0;i<u.length;i++){var d=Ar(l.p1.p[0],l.p1.p[1],l.p2.p[0],l.p2.p[1],c.p1.p[0],c.p1.p[1]),p=new jr(u[i],c,l,d>0);r.push(p)}}}}t.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolylineEdgeStart-t.distanceFromPolylineEdgeStart})}),e.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolygonEdgeStart-t.distanceFromPolygonEdgeStart})})}(n,o,r),0===r.length)return e;var a={};i.forEach(function(e){return a[e.id]=0}),r.forEach(function(e){var t=e.polygonEdge.polygonContourId;a[t]=a[t]+1});for(var s=0,c=[],l=null,u=0;u<o.length;u++){var d=o[u];if(d.intersectionPoints.length>0){l=d.intersectionPoints[0];break}}for(var p=l,h={visitCount:1};l!==h&&!(s>2*r.length);){if(s=s++,h.visitCount>=2){for(var f=!1,g=0;g<r.length;g++){var y=r[g];if(y.visitCount<2){p=y,f=!0;break}}if(!f)break}p.visitCount=p.visitCount+1;var m=[];c.push(m),m.push(p.p),p.visitCount=p.visitCount+1;var v=Kr(p,m),E=!1;if(v===(h=v)&&2===r.length)for(var b=0;b<r.length;b++){r[b].visitCount<2&&(E=!0)}for(;v!==p||E;){(v=(v.isHeadingIn?Zr:zr)(v,m))!==p&&(v=Kr(v,m)),E=!1}if(h.visitCount>=2){for(var x=!1,S=0;S<r.length;S++){var P=r[S];if(P.visitCount<2){p=P,x=!0;break}}x&&(h=p)}p=h}for(var w=c.map(function(e){return[e]}),_=Object.keys(a),M=0;M<_.length;M++){var O=_[M];if(0===a[O])$r(qr(Jr(n,parseInt(O)),i),w)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:w}}}function Jr(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.polygonContourId===t)return n}}function qr(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function $r(e,t){for(var r=0;r<t.length;r++){var n=t[r];if(kr(e[0],[n[0]]))return void n.push(e)}t.push([e])}function Kr(e,t){var r=e.polygonEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=Wr(e,r.intersectionPoints),o=r.intersectionPoints[n+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(r.p2.p),null===(r=r.nextEdge))return e;r.intersectionPoints.length>0&&(i=!1)}return r.intersectionPoints[0].incrementVisitCount(),t.push(r.intersectionPoints[0].p),r.intersectionPoints[0]}function Wr(e,t){for(var r=0;r<t.length;r++){if(t[r]===e)return r}return null}function zr(e,t){var r=e.polylineEdge;if(2===r.intersectionPoints.length){var n=r.intersectionPoints[r.intersectionPoints.length-1];if(n===e){var o=r.intersectionPoints[0];return t.push(o.p),o.incrementVisitCount(),o}return t.push(n.p),n.incrementVisitCount(),n}if(r.intersectionPoints.length>2&&r.intersectionPoints[0]!==e){var i=Wr(e,r.intersectionPoints),a=r.intersectionPoints[i-1];return t.push(a.p),a.incrementVisitCount(),a}for(var s=!0;s;){if(t.push(r.p1.p),void 0===(r=r.prevEdge).originalIndex)return e;r.intersectionPoints.length>0&&(s=!1)}if(void 0===r.originalIndex)return e;var c=r.intersectionPoints[r.intersectionPoints.length-1];return c.incrementVisitCount(),t.push(c.p),c}function Zr(e,t){var r=e.polylineEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=Wr(e,r.intersectionPoints),o=r.intersectionPoints[n+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(r.p2.p),null===(r=r.nextEdge))return e;r.intersectionPoints.length>0&&(i=!1)}if(void 0===r)return e;var a=r.intersectionPoints[0];return a.incrementVisitCount(),t.push(a.p),a}function Qr(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 en(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 tn(e){return"Feature"===e.type?e.geometry:e}function rn(e,t,r={}){if(!0===r.final)return function(e,t){let r=rn(t,e);return r=(r+180)%360,r}(e,t);const n=Qr(e),o=Qr(t),i=ze(n[0]),a=ze(o[0]),s=ze(n[1]),c=ze(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 We(Math.atan2(l,u))}var nn=rn;function on(e,t,r,n={}){const o=Qr(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),d=We(l);return void 0!==o[2]?Ye([u,d,o[2]],n.properties):Ye([u,d],n.properties)}var an=on;function sn(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=Qr(e),o=tn(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let c=!1;for(var l=0;l<s.length;++l){const e=kr(n,s[l]);if(0===e)return!r.ignoreBoundary;e&&(c=!0)}return c}class cn{constructor(e=[],t=ln){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function ln(e,t){return e<t?-1:e>t?1:0}function un(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function dn(e,t){return e.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:e.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:e.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?e.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}class pn{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let hn=0,fn=0,gn=0;function yn(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;fn+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new pn(o,hn,fn,gn),c=new pn(i,hn,fn,gn+1);s.otherEvent=c,c.otherEvent=s,un(s,c)>0?(c.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,c.isLeftEndpoint=!1),t.push(s),t.push(c),o=i,gn+=1}}hn+=1}class mn{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function vn(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,c=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,u=(l-s)*(o-r)-(c-a)*(i-n),d=(c-a)*(n-s)-(l-s)*(r-a),p=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const h=d/u,f=p/u;if(h>=0&&h<=1&&f>=0&&f<=1){return[r+h*(o-r),n+h*(i-n)]}return!1}var En=function(e,t){const r=new cn([],un);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)yn(r[e],t)}else yn(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new cn([],dn);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new mn(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=vn(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function bn(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let i=[];"FeatureCollection"===e.type?i=i.concat(e.features):"Feature"===e.type?i.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||i.push(Ge(e)),"FeatureCollection"===t.type?i=i.concat(t.features):"Feature"===t.type?i.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||i.push(Ge(t));const a=En(Je(i),o);let s=[];if(n){const e={};a.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,s.push(t))})}else s=a;return Je(s.map(e=>Ye(e)))}function xn(e,t={}){const r=tn(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=tn(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return Sn(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=tn(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(Sn(e,o))}),Je(i)}(r,t);default:throw new Error("invalid poly")}}function Sn(e,t){return e.length>1?qe(e,t):He(e[0],t)}function Pn(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return rt(e,e=>{rt(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!wn(t,e);case"Polygon":return!sn(e,t)}break;case"LineString":switch(t.type){case"Point":return!wn(e,t);case"LineString":return!function(e,t,r){const n=bn(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!_n(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!sn(t,e);case"LineString":return!_n(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(sn(r,t))return!0;for(const r of t.coordinates[0])if(sn(r,e))return!0;const n=bn(xn(e),xn(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n}function wn(e,t){for(let r=0;r<e.coordinates.length-1;r++)if(Mn(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function _n(e,t,r){for(const r of t.coordinates)if(sn(r,e))return!0;return bn(t,xn(e),{ignoreSelfIntersections:r}).features.length>0}function Mn(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var On=Object.defineProperty,In=(e,t)=>On(e,"name",{value:t,configurable:!0}),Cn=class{constructor(e){var t,r,n;this.direction=!1,this.compareProperties=!0,this.precision=10**-(null!=(t=null==e?void 0:e.precision)?t:17),this.direction=null!=(r=null==e?void 0:e.direction)&&r,this.compareProperties=null==(n=null==e?void 0:e.compareProperties)||n}compare(e,t){if(e.type!==t.type)return!1;if(!Ln(e,t))return!1;switch(e.type){case"Point":return this.compareCoord(e.coordinates,t.coordinates);case"LineString":return this.compareLine(e.coordinates,t.coordinates);case"Polygon":return this.comparePolygon(e,t);case"GeometryCollection":return this.compareGeometryCollection(e,t);case"Feature":return this.compareFeature(e,t);case"FeatureCollection":return this.compareFeatureCollection(e,t);default:if(e.type.startsWith("Multi")){const r=An(e),n=An(t);return r.every(e=>n.some(t=>this.compare(e,t)))}}return!1}compareCoord(e,t){return e.length===t.length&&e.every((e,r)=>Math.abs(e-t[r])<this.precision)}compareLine(e,t,r=0,n=!1){if(!Ln(e,t))return!1;const o=e;let i=t;if(n&&!this.compareCoord(o[0],i[0])){const e=this.fixStartIndex(i,o);if(!e)return!1;i=e}const a=this.compareCoord(o[r],i[r]);return this.direction||a?this.comparePath(o,i):!!this.compareCoord(o[r],i[i.length-(1+r)])&&this.comparePath(o.slice().reverse(),i)}fixStartIndex(e,t){let r,n=-1;for(let r=0;r<e.length;r++)if(this.compareCoord(e[r],t[0])){n=r;break}return n>=0&&(r=[].concat(e.slice(n,e.length),e.slice(1,n+1))),r}comparePath(e,t){return e.every((e,r)=>this.compareCoord(e,t[r]))}comparePolygon(e,t){if(this.compareLine(e.coordinates[0],t.coordinates[0],1,!0)){const r=e.coordinates.slice(1,e.coordinates.length),n=t.coordinates.slice(1,t.coordinates.length);return r.every(e=>n.some(t=>this.compareLine(e,t,1,!0)))}return!1}compareGeometryCollection(e,t){return Ln(e.geometries,t.geometries)&&this.compareBBox(e,t)&&e.geometries.every((e,r)=>this.compare(e,t.geometries[r]))}compareFeature(e,t){return e.id===t.id&&(!this.compareProperties||Fn(e.properties,t.properties))&&this.compareBBox(e,t)&&this.compare(e.geometry,t.geometry)}compareFeatureCollection(e,t){return Ln(e.features,t.features)&&this.compareBBox(e,t)&&e.features.every((e,r)=>this.compare(e,t.features[r]))}compareBBox(e,t){return Boolean(!e.bbox&&!t.bbox)||!(!e.bbox||!t.bbox)&&this.compareCoord(e.bbox,t.bbox)}};In(Cn,"GeojsonEquality");var Tn=Cn;function Ln(e,t){return e.coordinates?e.coordinates.length===t.coordinates.length:e.length===t.length}function An(e){return e.coordinates.map(t=>({type:e.type.replace("Multi",""),coordinates:t}))}function kn(e,t,r){return new Tn(r).compare(e,t)}function Fn(e,t){if(null===e&&null===t)return!0;if(null===e||null===t)return!1;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o of r){const r=e[o],n=t[o],i=Nn(r)&&Nn(n);if(i&&!Fn(r,n)||!i&&r!==n)return!1}return!0}In(Ln,"sameLength"),In(An,"explode"),In(kn,"geojsonEquality"),In(Fn,"equal");var Nn=In(e=>null!=e&&"object"==typeof e,"isObject");function Vn(e,t,r={}){const n=Qr(e),o=en(t);for(let e=0;e<o.length-1;e++){let t=!1;if(r.ignoreEndVertices&&(0===e&&(t="start"),e===o.length-2&&(t="end"),0===e&&e+1===o.length-1&&(t="both")),Dn(o[e],o[e+1],n,t,void 0===r.epsilon?null:r.epsilon))return!0}return!1}function Dn(e,t,r,n,o){const i=r[0],a=r[1],s=e[0],c=e[1],l=t[0],u=t[1],d=l-s,p=u-c,h=(r[0]-s)*p-(r[1]-c)*d;if(null!==o){if(Math.abs(h)>o)return!1}else if(0!==h)return!1;return Math.abs(d)===Math.abs(p)&&0===Math.abs(d)?!n&&(r[0]===e[0]&&r[1]===e[1]):n?"start"===n?Math.abs(d)>=Math.abs(p)?d>0?s<i&&i<=l:l<=i&&i<s:p>0?c<a&&a<=u:u<=a&&a<c:"end"===n?Math.abs(d)>=Math.abs(p)?d>0?s<=i&&i<l:l<i&&i<=s:p>0?c<=a&&a<u:u<a&&a<=c:"both"===n&&(Math.abs(d)>=Math.abs(p)?d>0?s<i&&i<l:l<i&&i<s:p>0?c<a&&a<u:u<a&&a<c):Math.abs(d)>=Math.abs(p)?d>0?s<=i&&i<=l:l<=i&&i<=s:p>0?c<=a&&a<=u:u<=a&&a<=c}function jn(e,t={}){var r="object"==typeof t?t.mutate:t;if(!e)throw new Error("geojson is required");var n=function(e){return"FeatureCollection"===e.type?"FeatureCollection":"GeometryCollection"===e.type?"GeometryCollection":"Feature"===e.type&&null!==e.geometry?e.geometry.type:e.type}(e),o=[];switch(n){case"LineString":o=Rn(e,n);break;case"MultiLineString":case"Polygon":en(e).forEach(function(e){o.push(Rn(e,n))});break;case"MultiPolygon":en(e).forEach(function(e){var t=[];e.forEach(function(e){t.push(Rn(e,n))}),o.push(t)});break;case"Point":return e;case"MultiPoint":var i={};en(e).forEach(function(e){var t=e.join("-");Object.prototype.hasOwnProperty.call(i,t)||(o.push(e),i[t]=!0)});break;default:throw new Error(n+" geometry not supported")}return e.coordinates?!0===r?(e.coordinates=o,e):{type:n,coordinates:o}:!0===r?(e.geometry.coordinates=o,e):Ge({type:n,coordinates:o},e.properties,{bbox:e.bbox,id:e.id})}function Rn(e,t){const r=en(e);if(2===r.length&&!Un(r[0],r[1]))return r;const n=[];let o=0,i=1,a=2;for(n.push(r[o]);a<r.length;)Vn(r[i],He([r[o],r[a]]))?i=a:(n.push(r[i]),o=i,i++,a=i),a++;if(n.push(r[i]),"Polygon"===t||"MultiPolygon"===t){if(Vn(n[0],He([n[1],n[n.length-2]]))&&(n.shift(),n.pop(),n.push(n[0])),n.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!Un(n[0],n[n.length-1]))throw new Error("invalid polygon, first and last points not equal")}return n}function Un(e,t){return e[0]===t[0]&&e[1]===t[1]}function Bn(e,t,r={}){let n=r.precision;if(n=null==n||isNaN(n)?6:n,"number"!=typeof n||!(n>=0))throw new Error("precision must be a positive number");return tn(e).type===tn(t).type&&kn(jn(e),jn(t),{precision:n})}function Gn(e,t){var r=tn(e),n=tn(t),o=r.type,i=n.type;switch(o){case"MultiPoint":switch(i){case"LineString":return Yn(r,n);case"Polygon":return Hn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"MultiPoint":return Yn(n,r);case"LineString":return function(e,t){const r=bn(e,t);if(0===r.features.length)return!1;for(const n of r.features)if(!(Bn(n.geometry,Ye(e.coordinates[0]))||Bn(n.geometry,Ye(e.coordinates[e.coordinates.length-1]))||Bn(n.geometry,Ye(t.coordinates[0]))||Bn(n.geometry,Ye(t.coordinates[t.coordinates.length-1]))))return!0;return!1}(r,n);case"Polygon":return Xn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"MultiPoint":return Hn(n,r);case"LineString":return Xn(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+o+" geometry not supported")}}function Yn(e,t){for(var r=!1,n=!1,o=e.coordinates.length,i=0;i<o&&!r&&!n;){for(var a=0;a<t.coordinates.length-1;a++){var s=!0;0!==a&&a!==t.coordinates.length-2||(s=!1),Jn(t.coordinates[a],t.coordinates[a+1],e.coordinates[i],s)?r=!0:n=!0}i++}return r&&n}function Xn(e,t){return bn(e,xn(t)).features.length>0}function Hn(e,t){var r=!1,n=!1,o=e.coordinates.length;for(let i=0;i<o&&(!r||!n);i++)sn(Ye(e.coordinates[i]),t)?r=!0:n=!0;return n&&r}function Jn(e,t,r,n){var o=r[0]-e[0],i=r[1]-e[1],a=t[0]-e[0],s=t[1]-e[1];return 0===o*s-i*a&&(n?Math.abs(a)>=Math.abs(s)?a>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:s>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1]:Math.abs(a)>=Math.abs(s)?a>0?e[0]<r[0]&&r[0]<t[0]:t[0]<r[0]&&r[0]<e[0]:s>0?e[1]<r[1]&&r[1]<t[1]:t[1]<r[1]&&r[1]<e[1])}function qn(e){return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]}function $n(e){for(var t=0;t<e.length-1;t++)for(var r=e[t],n=t+1;n<e.length-2;n++){if(Vn(r,He([e[n],e[n+1]])))return!0}return!1}function Kn(e,t,r){for(var n=Xe(e),o=r+1;o<t.length;o++)if(!Pn(n,Xe(t[o]))&&Gn(n,He(t[o][0])))return!1;return!0}var Wn=function(e){if(!e.type)return!1;const t=tn(e),r=t.type,n=t.coordinates;switch(r){case"Point":return n.length>1;case"MultiPoint":for(var o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"LineString":if(n.length<2)return!1;for(o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"MultiLineString":if(n.length<2)return!1;for(o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"Polygon":for(o=0;o<t.coordinates.length;o++){if(n[o].length<4)return!1;if(!qn(n[o]))return!1;if($n(n[o]))return!1;if(o>0&&bn(Xe([n[0]]),Xe([n[o]])).features.length>1)return!1}return!0;case"MultiPolygon":for(o=0;o<t.coordinates.length;o++)for(var i=t.coordinates[o],a=0;a<i.length;a++){if(i[a].length<4)return!1;if(!qn(i[a]))return!1;if($n(i[a]))return!1;if(0===a&&!Kn(i,t.coordinates,o))return!1;if(a>0&&bn(Xe([i[0]]),Xe([i[a]])).features.length>1)return!1}return!0;default:return!1}};function zn(e){let t=0;if(e&&e.length>0){t+=Math.abs(eo(e[0]));for(let r=1;r<e.length;r++)t-=Math.abs(eo(e[r]))}return t}var Zn=20294876564838.72,Qn=Math.PI/180;function eo(e){const t=e.length-1;if(t<=2)return 0;let r=0,n=0;for(;n<t;){const o=e[n],i=e[n+1===t?0:n+1],a=e[n+2>=t?(n+2)%t:n+2],s=o[0]*Qn,c=i[1]*Qn;r+=(a[0]*Qn-s)*Math.sin(c),n++}return r*Zn}var to=function(e){return function(e,t,r){var n=r;return tt(e,function(e,r,o,i,a){n=t(n,e,r,o,i,a)}),n}(e,(e,t)=>e+function(e){let t,r=0;switch(e.type){case"Polygon":return zn(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)r+=zn(e.coordinates[t]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};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 r,n,o,i,a=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"meters",n=e.geometry.coordinates,o=[],i=nn(n[1],n[0]),a=an(n[0],t,i,{units:r});o.push(a.geometry.coordinates);for(var s=0;s<n.length;s++){if(s>0&&s<n.length-1){var c=nn(n[s-1],n[s]),l=an(n[s],t,c,{units:r});o.push(l.geometry.coordinates)}o.push(n[s])}var u=nn(n[n.length-2],n[n.length-1]),d=an(n[n.length-1],t,u,{units:r});return o.push(d.geometry.coordinates),He(o)}(t);try{i=Hr(e,a)}catch(e){return null}var s=[];if("MultiPolygon"!==i.geometry.type)return null;if(2!==i.geometry.coordinates.length)return null;s=i.geometry.coordinates.map(t=>Xe(t,e.properties));var c=null!==(r=null!==(n=e.id)&&void 0!==n?n:null===(o=e.properties)||void 0===o?void 0:o.id)&&void 0!==r?r:"poly";return Je(s.map((t,r)=>Xe(t.geometry.coordinates,no(no({},e.properties),{},{id:c}),{id:"".concat(c,"-").concat(r+1)})))},io=(e,t)=>{var[r,n]=e,[o,i]=t,a=e=>e*Math.PI/180,s=a(i-n),c=a(o-r),l=Math.sin(s/2)**2+Math.cos(a(n))*Math.cos(a(i))*Math.sin(c/2)**2;return 12742e3*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))},ao=e=>e.length<=1||function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01;if(e.length<=1)return!0;if(e.length>=2){var r=e[e.length-1],n=e[e.length-2];if(io(r,n)<t)return!1}return!0}(e),so=e=>{if(e[0].length<=1||function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01;if(e[0].length<=1)return!0;if(e[0].length<=3)for(var r=0;r<e[0].length;r++)for(var n=r+1;n<e[0].length;n++)if(io(e[0][r],e[0][n])<t)return!1;return!0}(e))return!0;if(!Array.isArray(e)||e.length<4)return!1;var t=e[0],r=e[e.length-1];if(!(t[0]===r[0]&&t[1]===r[1]))return!1;var n=Xe([e]);return!!Wn(n)&&!(to(n)<=0)},co=(e,t,r)=>{var n=t.filter((t,n)=>{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)&&JSON.stringify(t)!==JSON.stringify(e)});n.length||n.push(e);var o=n.map(t=>{return r=Math.abs(e[0]-t[0]),n=Math.abs(e[1]-t[1]),Math.sqrt(Math.pow(r,2)+Math.pow(n,2));var r,n}),i=n[o.indexOf(Math.min(...o))];return t.findIndex(e=>JSON.stringify(e)===JSON.stringify(i))},lo={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]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=zt(r),o=Zt(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 Wt(this.getFeature(e))||[]},getMidpoints(e){var t=this.getFeature(e),r=Wt(t),n=zt(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=co(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=zt(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 uo(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 po(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?uo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ho=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),fo={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},go=po(po(po(po(po(po({},Mt),nr),sr),ur),lo),{},{onSetup(e){var t,r,n=Mt.onSetup.call(this,e);Object.assign(n,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:n.featureId||e.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});var o=this.getFeature(n.featureId);n.featureType=null==o?void 0:o.type,n.vertecies=this.getVerticies(n.featureId),n.midpoints=this.getMidpoints(n.featureId),this.setupEventListeners(n),"midpoint"===e.selectedVertexType?(n.selectedCoordPaths=[],this.clearSelectedCoordinates(),n.feature&&n.feature.changed(),this._ctx.store.render(),this.updateMidpoint(n.midpoints[e.selectedVertexIndex-n.vertecies.length])):-1===e.selectedVertexIndex&&(n.selectedCoordPaths=[],this.clearSelectedCoordinates(),n.feature&&n.feature.changed(),this._ctx.store.render()),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(n);var i=u(this.map);if(i&&f(i,this.map),"touch"===n.interfaceType&&n.selectedVertexIndex>=0&&"vertex"===n.selectedVertexType){var a=n.vertecies[n.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(n,tr(this.map.project(a),n.scale))},0)}return n._ignorePointermoveDeselect=!0,setTimeout(()=>{n._ignorePointermoveDeselect=!1},100),n},setupEventListeners(e){var t=t=>r=>t.call(this,e,r),r=this.handlers={keydown:t(this.onKeydown),keyup:t(this.onKeyup),pointerdown:t(this.onPointerevent),pointermove:t(this.onPointerevent),pointerup:t(this.onPointerevent),click:t(this.onButtonClick),touchstart:t(this.onTouchstart),touchmove:t(this.onTouchmove),touchend:t(this.onTouchend),selectionchange:t(this.onSelectionChange),scalechange:t(this.onScaleChange),update:t(this.onUpdate),move:t(this.onMove)};window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),this.map.on("draw.selectionchange",r.selectionchange),this.map.on("draw.scalechange",r.scalechange),this.map.on("draw.update",r.update),this.map.on("move",r.move)},onSelectionChange(e,t){var r,n,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=Wt(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire("draw.vertexselection",{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?tr(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onUpdate(e){var t,r=new Set(e.vertecies.map(e=>JSON.stringify(e)));r.size!==e.vertecies.length&&(e.selectedVertexIndex=e.vertecies.findIndex(e=>!r.has(JSON.stringify(e))),null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null))},onKeydown(e,t){if(e.container.contains(document.activeElement)){if(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "===t.key&&e.selectedVertexIndex<0){var r,n,o=u(this.map);if(o&&f(o,this.map),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;return e.isPanEnabled=!1,this.updateVertex(e)}if(!t.altKey&&ho.has(t.key)&&e.selectedVertexIndex>=0){if(t.preventDefault(),t.stopPropagation(),"midpoint"===e.selectedVertexType)return this.insertVertex(e,t);var i=u(this.map),a=this.getFeature(e.featureId);if(!a)return;var s=Wt(a),c=null==s?void 0:s[e.selectedVertexIndex];if(!c)return;if(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...c],e._keyboardMoveStartIndex=e.selectedVertexIndex),y(e)&&e._isSnapped&&i){var l=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:15}(i)+1,g=this.map.project(c),[m,v]=fo[t.key].map(e=>e*l);return e._isSnapped=!1,f(i,this.map),this.moveVertex(e,this.map.unproject({x:g.x+m,y:g.y+v}))}var E=this.getNewCoord(e,t);return y(e)&&i&&(h(i,this.map,this.map.project(E)),d(i))?(e._isSnapped=!0,this.moveVertex(e,p(i))):(e._isSnapped=!1,this.moveVertex(e,E))}if(t.altKey&&ho.has(t.key)&&e.selectedVertexIndex>=0)return t.preventDefault(),t.stopPropagation(),this.updateVertex(e,t.key);if("Escape"===t.key&&this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}),"z"===t.key&&(t.metaKey||t.ctrlKey)&&!t.shiftKey){var b,x=null===(b=document.activeElement)||void 0===b?void 0:b.tagName;if("INPUT"===x||"TEXTAREA"===x)return;return t.preventDefault(),t.stopPropagation(),this.handleUndo(e)}}},onKeyup(e,t){e.container.contains(document.activeElement)&&(e.interfaceType="keyboard",ho.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&void 0!==e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=void 0)),"Delete"===t.key&&this.deleteVertex(e))},onMouseDown(e,t){var r,n;g(u(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,Mt.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=er(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 d=this.getFeature(e.featureId),p=er(d,i);e._insertedVertexIndex=p,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire("draw.vertexselection",{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onMouseUp(e,t){g(u(this.map));var r=!1;if(e._moveStartPosition&&void 0!==e._moveStartIndex){var n=this.getFeature(e.featureId);if(n){var o,i=null===(o=Wt(n))||void 0===o?void 0:o[e._moveStartIndex];i&&(r=i[0]!==e._moveStartPosition[0]||i[1]!==e._moveStartPosition[1])}}var a=e._isInsertingVertex&&void 0!==e._insertedVertexIndex;if(e.dragMoving||r||a)if(this.syncVertices(e),a){var s=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),e.selectedVertexIndex=s,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=void 0,this.map.fire("draw.vertexselection",{index:s,numVertecies:e.vertecies.length})}else r&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition});e._moveStartPosition=null,e._moveStartIndex=null,Mt.onMouseUp.call(this,e,t)},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=u(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),y(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),h(n,this.map,t.point);var o=p(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Mt.onDrag.call(this,e,t)}},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,tr(this.map.project(t),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",po(po({},e),t))},onStop(e){this.map._drawEditContainer=null;var t=this.handlers;e.container.removeEventListener("pointerdown",t.pointerdown),e.container.removeEventListener("pointermove",t.pointermove),e.container.removeEventListener("pointerup",t.pointerup),e.container.removeEventListener("touchstart",t.touchstart),e.container.removeEventListener("touchmove",t.touchmove),e.container.removeEventListener("touchend",t.touchend),this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.scalechange",t.scalechange),this.map.off("draw.update",t.update),this.map.off("move",t.move),this.map.dragPan.enable(),window.removeEventListener("click",t.click),window.removeEventListener("keydown",t.keydown,{capture:!0}),window.removeEventListener("keyup",t.keyup,{capture:!0}),this.hideTouchVertexIndicator(e)}});function yo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function mo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?yo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):yo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var vo=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,createVertices:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,f=e=>e[r];return mo(mo({},e),{},{onSetup(t){var{map:n}=this,o=s?mo(mo({},t),{},{featureId:void 0}):t,i=mo(mo({},e.onSetup.call(this,o)),t);i[r].properties=t.properties;var{container:a,interfaceType:c,vertexMarkerId:l}=i,u=a.querySelector("#".concat(l));u.style.display=["touch","keyboard"].includes(c)?"block":"none",i.vertexMarker=u;var d=(e,t)=>this[e]=t.bind(this,i),p={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,focusHandler:this.onFocus,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo};return Object.entries(p).forEach(e=>{var[t,r]=e;return d(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[a,"focus",this.focusHandler],[a,"blur",this.blurHandler],[a,"pointermove",this.pointermoveHandler],[a,"pointerup",this.pointerupHandler],[n,"pointerdown",this.pointerdownHandler],[n,"draw.create",this.createHandler],[n,"move",this.moveHandler],[n,"draw.undo",this.undoHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),i},onClick(t,r){if(!(r.originalEvent.button>0||this.map._undoInProgress||r.originalEvent.target!==this.map.getCanvas())){var n=u(this.map);if(y(t)&&d(n))r=function(e,t){var r=p(t);return r?l(l({},e),{},{lngLat:r}):e}(r,n);else{var a=o(f(t));if(a.length>0&&(a[a.length-1]=[r.lngLat.lng,r.lngLat.lat]),!c&&!i(f(t)))return}var s=o(f(t)).length;e.onClick.call(this,t,r),o(f(t)).length>s&&this.pushDrawUndo(t)}},onTap(){},doClick(t){if(!this.map._undoInProgress){var r=f(t),n=o(r);if(this.dispatchVertexChange(n),i(r)){var a=u(this.map),s=y(t)&&function(e,t){var r=p(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,a),l=n.length;s?(e.onClick.call(this,t,s),this._ctx.store.render()):this._simulateMouse("click",e.onClick,t);var d=o(f(t));d.length>l&&(this.pushDrawUndo(t),this.dispatchVertexChange(d))}else c&&n.length>1&&(n.pop(),this.map.fire("draw.create",{features:[r.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[r.id]}))}},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},pushDrawUndo(e){var t=this.map._undoStack;t&&!this.map._undoInProgress&&t.push({type:"draw_vertex",geometryType:n,featureId:f(e).id})},undoVertex(e){var t=f(e),r=o(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_reinitializeFeature(t,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n){var a=this.map._undoStack;return a&&a.clear(),this._ctx.api.changeMode("draw_line",{featureId:i,container:t.container,interfaceType:t.interfaceType,vertexMarkerId:t.vertexMarkerId,addVertexButtonId:t.addVertexButtonId,getSnapEnabled:t.getSnapEnabled,properties:t.properties}),!0}var s=this.map.getCenter(),c=[[s.lng,s.lat],[s.lng,s.lat]],l=this.newFeature({type:"Feature",properties:t.properties||{},geometry:{type:n,coordinates:[c]}});return l.id=i,this._ctx.store.add(l),t[r]=l,t.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render(),this.dispatchVertexChange(c),!0},_removeLastVertex(e,t,r){var i="Polygon"===n?t.coordinates[0]:r;i.splice(i.length-2,1);var a=i[i.length-2];a&&(i[i.length-1]=[...a]),e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,o(t))},_updateRubberBand(t,r){if(["touch","keyboard"].includes(t.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render();else{var o=r["Polygon"===n?r.length-2:r.length-1];if(o){var i={lng:o[0],lat:o[1]},a=this.map.project(i);e.onMouseMove.call(this,t,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render()}}this.dispatchVertexChange(r)},onUndo(e,t){var r;"draw_vertex"===(null===(r=t.operation)||void 0===r?void 0:r.type)&&this.undoVertex(e)},_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)},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&(e.vertexMarker.style.display="block")},onCreate(e,t){var r=this._ctx.api,n=t.features[0];r.delete(n.id),n.id=e.featureId,r.add(n,{userProperties:!0})},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onKeydown(e,t){if("z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey){if(document.activeElement===e.container){if("Escape"===t.key)return t.preventDefault();"Enter"===t.key&&(e.isActive=!0),this._setInterface(e,"keyboard"),this.onMove(e,t)}}else{var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;if("INPUT"===n||"TEXTAREA"===n)return;t.preventDefault(),t.stopPropagation();var o=this.map._undoStack;if(o&&o.length>0){var i=o.pop();"draw_vertex"===(null==i?void 0:i.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e))}}},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&(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(t,r){var n=document.activeElement;if(!n||n===t.container||!t.container.contains(n))if("Escape"!==r.key)n!==t.container&&e.onKeyUp.call(this,t,r);else if("keyboard"===t.interfaceType){var o=this.map._undoStack;o&&o.clear(),this._reinitializeFeature(t,f(t))}},onFocus(e){e.vertexMarker.style.display=["touch","keyboard"].includes(e.interfaceType)?"block":"none"},onBlur(e,t){t.target!==e.container&&(e.vertexMarker.style.display="none")},onMouseMove(t,r){if(y(t)){var n=u(this.map);h(n,this.map,r.point);var o=p(n);o&&(r=mo(mo({},r),{},{lngLat:o}))}this.map.fire("draw.geometrychange",t.polygon||t.line),e.onMouseMove.call(this,t,r)},onMove(t){if(["touch","keyboard"].includes(t.interfaceType)){y(t)&&function(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);e.snapToClosestPoint({point:n,lngLat:r})}(u(this.map),this.map);var r=u(this.map),n=y(t)&&p(r);if(n){var o=this.map.project([n.lng,n.lat]);e.onMouseMove.call(this,t,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render()}else this._simulateMouse("mousemove",e.onMouseMove,t)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"pointer",!1)},onPointermove(e,t){"touch"!==t.pointerType&&(e.vertexMarker.style.display="none")},onPointerup(e){this.dispatchVertexChange(o(f(e)))},toDisplayFeatures(t,r,o){e.toDisplayFeatures.call(this,t,r,o);var i=f(t);r.geometry.type===n&&r.id===i.id&&a(r,o,Re)},onStop(t){e.onStop.call(this,t),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),t.vertexMarker.style.display="none"}})},Eo=vo(Ct,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>so(e.coordinates),createVertices:(e,t,r)=>{for(var n=e.geometry.coordinates[0],o=1;o<n.length-2;o++)t(r(e.id,n[o],"0.".concat(o)))}}),bo=vo(Tt,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>ao(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,createVertices:(e,t,r)=>{for(var n=e.geometry.coordinates,o=1;o<n.length-1;o++)t(r(e.id,n[o],"".concat(o)))}}),xo={editStroke:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editVertex:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editMidpoint:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editHalo:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editActive:{light:"rgba(11,12,12,1)",dark:"#ffffff"},splitInvalid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},shapeStroke:"rgba(212,53,28,1)",shapeFill:"rgba(212,53,28,0.1)",strokeWidth:2,snapVertex:"rgba(212,53,28,1)",snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,1)",snapRadius:10,snapLayers:[]},So=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],xo[r]]},Po=e=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":So(e,"fill","shapeFill")}}),wo=e=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":So(e,"stroke","shapeStroke"),"line-width":So(e,"strokeWidth")}}),_o=e=>({id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":e,"fill-opacity":.1}}),Mo=e=>({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":e,"line-width":2,"line-opacity":1}}),Oo=e=>({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":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),Io=e=>({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":e,"line-width":2,"line-opacity":1}}),Co=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}}),To=e=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"]],paint:{"circle-radius":6,"circle-color":e}}),Lo=(e,t)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":8,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Ao=e=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":6,"circle-color":e}}),ko=e=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":4,"circle-color":e}}),Fo=(e,t)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":6,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),No=e=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":4,"circle-color":e}}),Vo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Do=e=>{var t=(e=>{var t;return null!==(t=e.mapColorScheme)&&void 0!==t?t:"light"})(e),r=xo.editStroke[t],n=xo.editVertex[t],o=xo.editMidpoint[t],i=xo.editHalo[t],a=xo.editActive[t],s=xo.splitInvalid[t],c=xo.splitValid[t];return[Po(e),_o(r),Mo(r),wo(e),Oo(s),Io(c),Co(r),ko(o),Fo(i,a),No(o),To(n),Lo(i,a),Ao(n),Vo(r),{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 jo(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 Ro(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 Uo(e,t,r){void 0===r&&(r={});var n=jo(e),o=jo(t),i=ze(o[1]-n[1]),a=ze(o[0]-n[0]),s=ze(n[1]),c=ze(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return $e(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Bo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return qe(e,t);return He(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Go(e,t,r,n){void 0===n&&(n={});var o=jo(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Ye([We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),We(l)],n.properties)}function Yo(e){if(!e)throw new Error("geojson is required");var t=[];return rt(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=Ro(n);break;case"LineString":r=[Ro(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=He([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)}),Je(t)}var Xo={exports:{}};function Ho(e,t,r,n,o){Jo(e,t,r||0,n||e.length-1,o||$o)}function Jo(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);Jo(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(qo(e,r,t),o(e[n],u)>0&&qo(e,r,n);d<p;){for(qo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?qo(e,r,p):qo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function qo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function $o(e,t){return e<t?-1:e>t?1:0}function Ko(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 Wo(e,t){zo(e,0,e.children.length,t,e)}function zo(e,t,r,n,o){o||(o=si(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];Zo(o,e.leaf?n(t):t)}return o}function Zo(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 Qo(e,t){return e.minX-t.minX}function ei(e,t){return e.minY-t.minY}function ti(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ri(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ni(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 oi(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 ii(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function ai(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function si(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ci(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;Ho(e,a,t,r,o),i.push(t,a,a,r)}}var li,ui=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(!ai(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;ai(e,s)&&(t.leaf?r.push(a):ii(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!ai(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(ai(e,i)){if(t.leaf||ii(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=si([]),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=Ko(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!ii(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=si(e.slice(t,r+1)),Wo(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=si([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));ci(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);ci(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 Wo(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=ti(a),c=ni(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),Zo(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=si(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Wo(r,this.toBBox),Wo(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=si([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Wo(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=zo(e,0,a,this.toBBox),s=zo(e,a,r,this.toBBox),c=oi(t,s),l=ti(t)+ti(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:Qo,o=e.leaf?this.compareMinY:ei;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=zo(e,0,t,o),a=zo(e,r-t,r,o);let s=ri(i)+ri(a);for(let n=t;n<r-t;n++){const t=e.children[n];Zo(i,e.leaf?o(t):t),s+=ri(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Zo(a,e.leaf?o(t):t),s+=ri(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Zo(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():Wo(e[r],this.toBBox)}}}),di=q(ui),pi={};function hi(){if(li)return pi;li=1,Object.defineProperty(pi,"__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 pi.areaFactors=r,pi.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},pi.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},pi.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},pi.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)},pi.degreesToRadians=function(e){return e%360*Math.PI/180},pi.earthRadius=e,pi.factors=t,pi.feature=n,pi.featureCollection=s,pi.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")}},pi.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},pi.isNumber=f,pi.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},pi.lengthToDegrees=function(e,t){return h(p(e,t))},pi.lengthToRadians=p,pi.lineString=a,pi.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},pi.multiLineString=c,pi.multiPoint=l,pi.multiPolygon=u,pi.point=o,pi.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},pi.polygon=i,pi.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},pi.radiansToDegrees=h,pi.radiansToLength=d,pi.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},pi.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")})},pi.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")},pi}var fi,gi={};function yi(){if(fi)return gi;fi=1,Object.defineProperty(gi,"__esModule",{value:!0});var e=hi();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 E=0;E<c;E++){var b=0,x=0;if(null!==(s=d?u.geometries[E]:u)){l=s.coordinates;var S=s.type;switch(p=!n||"Polygon"!==S&&"MultiPolygon"!==S?0:1,S){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"===S&&b++}"LineString"===S&&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"===S&&b++,"Polygon"===S&&x++}"Polygon"===S&&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 gi.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},gi.coordEach=t,gi.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},gi.featureEach=n,gi.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},gi.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")},gi.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")},gi.flattenEach=i,gi.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},gi.geomEach=o,gi.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},gi.lineEach=s,gi.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},gi.propEach=r,gi.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},gi.segmentEach=a,gi.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},gi}var mi,vi,Ei={};function bi(){if(mi)return Ei;mi=1,Object.defineProperty(Ei,"__esModule",{value:!0});var e=yi();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 Ei.bbox=t,Ei.default=r,Ei}var xi=function(){if(vi)return Xo.exports;vi=1;var e=di,t=hi(),r=yi(),n=bi().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 Xo.exports=a,Xo.exports.default=a,Xo.exports}(),Si=J(xi);function Pi(e,t){var r={},n=[];if("LineString"===e.type&&(e=Ge(e)),"LineString"===t.type&&(t=Ge(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=wi(e,t);return o&&n.push(o),Je(n)}var i=Si();return i.load(Yo(t)),et(Yo(e),function(e){et(i.search(e),function(t){var o=wi(e,t);if(o){var i=Ro(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),Je(n)}function wi(e,t){var r=Ro(e),n=Ro(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,y=f/p;return g>=0&&g<=1&&y>=0&&y<=1?Ye([o+g*(a-o),i+g*(s-i)]):null}function _i(e,t,r){void 0===r&&(r={});var n=Ye([1/0,1/0],{dist:1/0}),o=0;return rt(e,function(e){for(var i=Ro(e),a=0;a<i.length-1;a++){var s=Ye(i[a]);s.properties.dist=Uo(t,s,r);var c=Ye(i[a+1]);c.properties.dist=Uo(t,c,r);var l=Uo(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=nn(s,c),p=Go(t,u,d+90,r),h=Go(t,u,d-90,r),f=Pi(He([p.geometry.coordinates,h.geometry.coordinates]),He([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Uo(t,g,r),g.properties.location=o+Uo(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 Mi(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 Oi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=Mi(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Ye([We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),We(l)],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=Mi(e),o=Mi(t),i=ze(o[1]-n[1]),a=ze(o[0]-n[0]),s=ze(n[1]),c=ze(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return $e(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,nn(e,t));return r}var Ii=function(){return Ii=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},Ii.apply(this,arguments)},Ci=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=Ii(Ii({},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 Uo(Ye(e),Ye(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=Uo(Ye([r.lng,r.lat]),Ye([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(on(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),Xe([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=Je(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(Je([])))}),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,o=(n=[],Qe(e,function(e){n.push(e)}),n),i=[];if(o.map(function(e){var n=Uo(Ye(e),Ye([t.lng,t.lat]),{units:"meters"});n<r&&i.push({coords:e,dist:n,color:"#8bc34a"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[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(He(e))});break;case"Polygon":var o=Bo(e.geometry);n.push(o);break;case"MultiPolygon":Bo(e.geometry).coodinates.map(function(e){n.push(He(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(Yo(e).features)});var i=[];if(o.map(function(e){var n=Oi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Uo(n,Ye([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=_i(n[i],Ye([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}();function Ti(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var Li="snap-helper-circle";function Ai(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function ki(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})}}function Fi(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:o=[],radius:i=15,rules:a=["vertex","midpoint","edge"],status:s=!1,onSnapped:c=()=>{},colors:l={}}=n;function u(e){if(t._snapInstance||t._snapCreating)return t._snapInstance;t._snapCreating=!0,t.getLayer(Li)&&t.removeLayer(Li),t.getSource(Li)&&t.removeSource(Li),ki(e);var n=new Ci({map:t,drawing:r,options:{layers:o,radius:i,rules:a},status:s,onSnapped:c}),l=s;return Object.defineProperty(n,"status",{get:()=>l,set(){},configurable:!0}),n.setSnapStatus=e=>{l=e},n._defaultLayers=o,n._activeLayers=null,n.setSnapLayers=e=>{null==e?n._activeLayers=null:Array.isArray(e)&&(n._activeLayers=e)},void 0!==t._pendingSnapLayers&&(n.setSnapLayers(t._pendingSnapLayers),delete t._pendingSnapLayers),t._snapInstance=n,n}!function(e){if(!Ci.prototype.__snapPatched){Ci.prototype.__snapPatched=!0;var t=Ci.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=()=>{},t.setMapData=function(e){var t,n;if(this.status){var o=r.setMapData.call(this,e);return(null==e||null===(t=e.features)||void 0===t?void 0:t.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(Li)&&this.map.setLayoutProperty(Li,"visibility","visible"),o}},t.drawingSnapCheck=function(){if(this.status)return r.drawingSnapCheck.call(this)},t.getLines=function(e,t,n){var o=e.geometry;if(!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=>Xe(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>He(e)):r.getLines.call(this,e,t,n)}catch(e){return console.log(e),[]}},t.getCloseFeatures=function(e,t){if(!this.status)return[];var n=this._activeLayers||this._defaultLayers||[];this.options.layers=n.filter(e=>this.map.getLayer(e));var o=this.options.radius||15,i=e.point;e.point=[[i.x-o,i.y-o],[i.x+o,i.y+o]];var a=r.getCloseFeatures.call(this,e,t);return e.point=i,a},t.searchInVertex=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInVertex.apply(this,n);return i&&(i.color=e.vertex),i},t.searchInMidPoint=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInMidPoint.apply(this,n);return i&&(i.color=e.midpoint),i},t.searchInEdge=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInEdge.apply(this,n);return i&&(i.color=e.edge),i},t.snapToClosestPoint=function(e){var t;if(this.status&&(null===(t=this.map)||void 0===t||!t._isZooming))try{var n,o,i=r.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){console.log(e),this.snapStatus=!1,this.snapCoords=null}}}}(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ti(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ti(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:xo.snapVertex,midpoint:xo.snapMidpoint,edge:xo.snapEdge},l)),t.on("style.load",()=>{Ai(()=>t._removed?null:t.getSource("mapbox-gl-draw-hot"),e=>{var r;(ki(e),t.getSource(Li)||t.addSource(Li,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),t.getLayer(Li))||t.addLayer({id:Li,type:"fill",source:Li,paint:{"fill-color":["get","color"],"fill-opacity":.6},layout:{visibility:null!==(r=t._snapInstance)&&void 0!==r&&r.status?"visible":"none"}});t._snapInstance||u(e)})}),t.on("zoomstart",()=>{t._isZooming=!0}),t.on("zoomend",()=>{if(t._isZooming=!1,t.getLayer(Li)){t.setLayoutProperty(Li,"visibility","none");var e=t._snapInstance;null!=e&&e.status&&t.setLayoutProperty(Li,"visibility","visible")}}),Ai(()=>t._removed?null:t.getSource("mapbox-gl-draw-hot"),u)}function Ni(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 Vi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ni(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ni(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Di=e=>{var{mapStyle:t,mapProvider:r,events:n,eventBus:o,snapLayers:i}=e,{map:a}=r;$t.constants.classes.CONTROL_BASE="maplibregl-ctrl",$t.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",$t.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var s=new $t({modes:Vi(Vi({},$t.modes),{},{disabled:Kt,edit_vertex:go,draw_polygon:Eo,draw_line:bo}),styles:Do(t),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"});a.addControl(s);var c=a.getCanvas(),l=null,u=e=>{1===e.touches.length&&(l={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},d=e=>{if("disabled"===s.getMode()&&l){var t=e.changedTouches[0],r=t.clientX-l.x,n=t.clientY-l.y;Date.now()-l.time<300&&Math.abs(r)<10&&Math.abs(n)<10&&c.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:t.clientX,clientY:t.clientY})),l=null}else l=null};c.addEventListener("touchstart",u,{passive:!0}),c.addEventListener("touchend",d,{passive:!0}),r.draw=s,a._drawCurrentMapStyle=t,r.snapEnabled=!1;var p=(e=>{var t=[],r=()=>{e.fire("draw.undochange",{length:t.length})};return{push(e){t.push(e),r()},pop(){var e=t.pop();return r(),e},clear(){t.length=0,r()},get length(){return t.length}}})(a);r.undoStack=p,a._undoStack=p,Fi(a,s,{layers:i,radius:10,rules:["vertex","edge"]});var h=e=>{a._drawCurrentMapStyle=e,a.once("idle",()=>{var t;((e,t)=>{Do(t).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)})})})(a,e);var r=null===(t=a._drawEditContainer)||void 0===t?void 0:t.querySelector("[data-touch-vertex-target]");ar(r,e)})};o.on(n.MAP_SET_STYLE,h);return o.on(n.MAP_SET_SIZE,e=>{a.fire("draw.scalechange",{scale:{small:1,medium:1.5,large:2}[e]})}),{draw:s,remove(){c.removeEventListener("touchstart",u),c.removeEventListener("touchend",d),o.off(n.MAP_SET_STYLE,h),s.deleteAll(),s.changeMode("disabled"),a.removeControl(s)}}},ji=["stroke","fill","strokeWidth"],Ri=e=>{if(!e)return{};var t={};for(var[r,n]of Object.entries(e))if(ji.includes(r)&&"object"==typeof n&&null!==n){var o=Object.entries(n);for(var[i,a]of(o.length>0&&(t[r]=o[0][1]),o))t["".concat(r).concat(i.charAt(0).toUpperCase()+i.slice(1))]=a}else t[r]=n;return t},Ui=["stroke","fill","strokeWidth","properties"];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 Yi=["stroke","fill","strokeWidth","properties"];function Xi(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 Hi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ji=["stroke","fill","strokeWidth","properties"];function qi(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 $i(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ki(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){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ki(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ki(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zi=e=>({mobile:{slot:"actions",showLabel:e},tablet:{slot:"actions",showLabel:e},desktop:{slot:"actions",showLabel:e}}),Zi={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertecies:null,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:a},InitComponent:e=>{var{appState:r,appConfig:n,mapState:o,pluginConfig:i,pluginState:a,services:c,mapProvider:l,buttonConfig:d}=e,{eventBus:p}=c,{crossHair:h}=o,y=["touch","keyboard"].includes(r.interfaceType);t(()=>{var e,t,n,c,u,d=null===(e=null===(t=i.includeModes)||void 0===t?void 0:t.includes(r.mode))||void 0===e||e,h=null!==(n=null===(c=i.excludeModes)||void 0===c?void 0:c.includes(r.mode))&&void 0!==n&&n;if(o.isMapReady&&d&&!h){var{remove:f}=Di({mapStyle:o.mapStyle,snapLayers:i.snapLayers,mapProvider:l,events:s,eventBus:p});return a.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:(null===(u=i.snapLayers)||void 0===u?void 0:u.length)>0}),p.emit("draw:ready"),()=>f()}},[o.isMapReady,r.mode]),t(()=>{if(["draw_polygon","draw_line"].includes(a.mode)&&y){var e=h.isVisible;return h.fixAtCenter(),()=>{e||h.hide()}}},[a.mode,r.interfaceType]),t(()=>{if(l.draw){var e=function(e){var{pluginState:t,mapProvider:r,buttonConfig:n,eventBus:o}=e,{drawDone:i,drawAddPoint:a,drawUndo:s,drawDeletePoint:c,drawSnap:l,drawCancel:d}=n,{map:p,draw:h}=r,{dispatch:y,feature:m,tempFeature:v}=t,E=()=>{r.snapEnabled=!1,y({type:"SET_SNAP",payload:!1});var e,t=u(p);t&&(null===(e=t.setSnapStatus)||void 0===e||e.call(t,!1),g(t)),p.getLayer("snap-helper-circle")&&p.setLayoutProperty("snap-helper-circle","visibility","none")},b=()=>{var e;null===(e=r.undoStack)||void 0===e||e.clear(),y({type:"SET_MODE",payload:null}),y({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},x=()=>{h.trash(),null!=v&&v.id&&h.delete(v.id),m&&h.add(m),E(),h.changeMode("disabled"),b(),o.emit("draw:cancelled",m)},S=0,P=["draw_polygon","draw_line"],w=e=>{P.includes(e.mode)||f(u(p),p)},_=()=>{var e,t=p.getStyle().layers||[];!t.length||null!==(e=t[t.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||t.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>p.moveLayer(e.id))},M=e=>t=>{var r=t.features[0];E(),b(),setTimeout(()=>h.changeMode("disabled"),0),o.emit(e,r)},O=e=>{var t=e.features[0];o.emit("draw:updated",t)},I=M("draw:created"),C=M("draw:edited"),T=e=>{y({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),o.emit("draw:vertexselection",e)},L=e=>{y({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertecies:e.numVertecies}})},A=e=>{y({type:"SET_UNDO_STACK_LENGTH",payload:e.length})};return i.onClick=()=>{var e,t=h.getMode();E(),null===(e=r.undoStack)||void 0===e||e.clear(),"edit_vertex"!==t?["draw_polygon","draw_line"].includes(t)&&h.changeMode("disabled"):p.fire("draw.editfinish",{features:[h.get(v.id)]})},d.onClick=x,s.onClick=()=>{if("edit_vertex"!==h.getMode()){var e=r.undoStack;if(null!=e&&e.length){var t=e.pop();p._undoInProgress=!0,setTimeout(()=>{p._undoInProgress=!1},100),p.fire("draw.undo",{operation:t})}}},l.onClick=()=>{var e=Date.now();if(!(e-S<300)){S=e;var n=!t.snap;y({type:"TOGGLE_SNAP"}),r.snapEnabled=n;var o=u(p);null!=o&&o.setSnapStatus&&o.setSnapStatus(n),!n&&o&&(g(o),p.getLayer("snap-helper-circle")&&p.setLayoutProperty("snap-helper-circle","visibility","none"))}},p.on("styledata",_),p.on("draw.cancel",x),p.on("draw.create",I),p.on("draw.modechange",w),p.on("draw.editfinish",C),p.on("draw.update",O),p.on("draw.vertexselection",T),p.on("draw.vertexchange",L),p.on("draw.undochange",A),()=>{[i,a,s,c,l,d].forEach(e=>{e&&(e.onClick=null)}),p.off("styledata",_),p.off("draw.cancel",x),p.off("draw.create",I),p.off("draw.editfinish",C),p.off("draw.update",O),p.off("draw.modechange",w),p.off("draw.vertexselection",T),p.off("draw.vertexchange",L),p.off("draw.undochange",A)}}({mapProvider:l,buttonConfig:d,pluginState:a,eventBus:p});return()=>e()}},[l,r,a])},buttons:[Wi({id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode}},zi(!0)),Wi({id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:e=>{var{appState:t,pluginState:r}=e;return!["draw_polygon","draw_line"].includes(r.mode)||"touch"!==t.interfaceType}},zi(!0)),Wi({id:"drawDone",label:"Done",variant:"primary",exclusiveSlot:!0,hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return t.numVertecies>=("draw_polygon"===t.mode?3:2)}},zi(!0)),{id:"drawMenu",label:"Menu",iconId:"menu",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},menuItems:[{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return t.undoStackLength>0}},{id:"drawSnap",label:"Snap to feature",iconId:"magnet",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode||!t.hasSnapLayers},pressedWhen:e=>{var{pluginState:t}=e;return!!t.snap}},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:e=>{var t,{pluginState:r}=e;return r.selectedVertexIndex>=0&&r.numVertecies>("Polygon"===(null===(t=r.tempFeature)||void 0===t||null===(t=t.geometry)||void 0===t?void 0:t.type)?3:2)},hiddenWhen:e=>{var{pluginState:t}=e;return!["simple_select","edit_vertex"].includes(t.mode)}}],mobile:{slot:"bottom-right"},tablet:{slot:"top-middle"},desktop:{slot:"top-middle"}}],keyboardShortcuts:[{id:"drawStart",group:"Drawing",title:"Edit vertex",command:"<kbd>Spacebar</kbd></dd>"}],icons:[{id:"menu",svgContent:'<path d="m6 9 6 6 6-6"/>'},{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"check",svgContent:'<path d="M20 6 9 17l-5-5"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(h){g.emit("draw:started",{mode:"draw_polygon"});var y=null;y=void 0!==d.snapLayers?d.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=u(f);null!=m&&m.setSnapLayers?m.setSnapLayers(y):y&&(f._pendingSnapLayers=y),p({type:"SET_HAS_SNAP_LAYERS",payload:(null===(n=y)||void 0===n?void 0:n.length)>0});var{stroke:v,fill:E,strokeWidth:b,properties:x}=d,S=r(d,Ui),P=Gi(Gi({},x),Ri({stroke:v,fill:E,strokeWidth:b}));h.changeMode("draw_polygon",Gi(Gi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,getSnapEnabled:()=>!0===c.snapEnabled,featureId:t},S),{},{properties:P})),p({type:"SET_MODE",payload:"draw_polygon"})}},newLine:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(h){g.emit("draw:started",{mode:"draw_line"});var y=null;y=void 0!==d.snapLayers?d.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=u(f);null!=m&&m.setSnapLayers?m.setSnapLayers(y):y&&(f._pendingSnapLayers=y),p({type:"SET_HAS_SNAP_LAYERS",payload:(null===(n=y)||void 0===n?void 0:n.length)>0});var{stroke:v,fill:E,strokeWidth:b,properties:x}=d,S=r(d,Yi),P=Hi(Hi({},x),Ri({stroke:v,fill:E,strokeWidth:b}));h.changeMode("draw_line",Hi(Hi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,getSnapEnabled:()=>!0===c.snapEnabled,featureId:t},S),{},{properties:P})),p({type:"SET_MODE",payload:"draw_line"})}},editFeature:function(e,t){var r,{appState:n,appConfig:o,mapState:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(!h)return!1;var y=h.get(t);if(!y)return!1;g.emit("draw:editstart",{mode:{LineString:"edit_line",Polygon:"edit_polygon"}[y.geometry.type]});var m,v=null;void 0===d.snapLayers?v=null!==(m=a.snapLayers)&&void 0!==m?m:null:v=d.snapLayers;var E=u(f);null!=E&&E.setSnapLayers?E.setSnapLayers(v):v&&(f._pendingSnapLayers=v),p({type:"SET_HAS_SNAP_LAYERS",payload:(null===(r=v)||void 0===r?void 0:r.length)>0}),h.changeMode("edit_vertex",{container:n.layoutRefs.viewportRef.current,deleteVertexButtonId:"".concat(o.id,"-draw-delete-point"),undoButtonId:"".concat(o.id,"-draw-undo"),isPanEnabled:"keyboard"!==n.interfaceType,interfaceType:n.interfaceType,scale:{small:1,medium:1.5,large:2}[i.mapSize],featureId:t,getSnapEnabled:()=>!0===c.snapEnabled});var b=h.get(t);return p({type:"SET_FEATURE",payload:{feature:b,tempFeature:b}}),p({type:"SET_MODE",payload:"edit_vertex"}),!0},addFeature:(e,t)=>{var{mapProvider:n,services:o}=e,{draw:i}=n,{eventBus:a}=o;if(i){var{stroke:s,fill:c,strokeWidth:l,properties:u}=t,d=$i($i({},r(t,Ji)),{},{properties:$i($i({},u),Ri({stroke:s,fill:c,strokeWidth:l}))});i.add(d,{userProperties:!0}),a.emit("draw:add",d)}},deleteFeature:(e,t)=>{var{mapProvider:r,services:n}=e,{draw:o}=r,{eventBus:i}=n;o&&(o.delete(t),i.emit("draw:delete",{featureIds:t}))},split:function(e,t){var{appState:r,appConfig:n,pluginState:o,mapProvider:i}=e,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:s}=o,{draw:c,map:l}=i;if(c){var d=c.get(t),p=["stroke-inactive.cold",...a.snapLayers||[]],h=u(l);null!=h&&h.setSnapLayers?h.setSnapLayers(p):a.snapLayers&&(l._pendingSnapLayers=p),s({type:"SET_HAS_SNAP_LAYERS",payload:!0}),c.changeMode("draw_line",{container:r.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(n.id,"-cross-hair"),addVertexButtonId:"".concat(n.id,"-draw-add-point"),interfaceType:r.interfaceType,getSnapEnabled:()=>!0===i.snapEnabled,featureId:"_splitter",properties:{splitter:"invalid"}}),l.on("draw.create",e=>{var t=e.features[0],r=oo(d,t);c.setFeatureProperty("_splitter","splitter",r?"valid":"invalid"),s({type:"SET_ACTION",payload:{name:"split",isValid:!!r}})});var f,g,y,m,v=(f=e=>{if(!(e.coordinates.length<2)){var t={id:"_splitter",geometry:{type:"LineString",coordinates:e.coordinates}},r=!!oo(d,t);e.properties.splitter=r?"valid":"invalid",e.ctx.store.render(),"edit_vertex"===c.getMode()&&s({type:"SET_ACTION",payload:{name:"split",isValid:r}})}},g=50,m=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];clearTimeout(y),y=setTimeout(()=>f(...t),g)},m.cancel=()=>{clearTimeout(y),y=null},m);l.on("draw.geometrychange",v),s({type:"SET_MODE",payload:"draw_line"}),s({type:"SET_ACTION",payload:{name:"split"}})}},merge:(e,t)=>{var{services:r}=e;console.log("merge"),console.log(t)}}};export{Zi as manifest};
1
+ import e from"@babel/runtime/helpers/defineProperty";import{useEffect as t}from"preact/compat";import r from"@babel/runtime/helpers/objectWithoutProperties";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 o(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach(function(r){e(t,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))})}return t}var i=new Set(["draw_polygon","draw_line"]),a={SET_MODE:(e,t)=>o(o({},e),{},{mode:t,numVertecies:i.has(t)?0:e.numVertecies}),SET_ACTION:(e,t)=>o(o({},e),{},{action:t.name,actionValid:t.isValid}),SET_FEATURE:(e,t)=>o(o({},e),{},{feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>o(o({},e),{},{selectedVertexIndex:t.index,numVertecies:t.numVertecies}),TOGGLE_SNAP:e=>o(o({},e),{},{snap:!e.snap}),SET_SNAP:(e,t)=>o(o({},e),{},{snap:!!t}),SET_HAS_SNAP_LAYERS:(e,t)=>o(o({},e),{},{hasSnapLayers:!!t}),SET_UNDO_STACK_LENGTH:(e,t)=>o(o({},e),{},{undoStackLength:t})},s={APP_ADD_MARKER:"app:addmarker",APP_UPDATE_MARKER:"app:updatemarker",APP_REMOVE_MARKER:"app:removemarker",APP_SET_MODE:"app:setmode",APP_REVERT_MODE:"app:revertmode",APP_ADD_BUTTON:"app:addbutton",APP_TOGGLE_BUTTON_STATE:"app:togglebuttonstate",APP_ADD_PANEL:"app:addpanel",APP_REMOVE_PANEL:"app:removepanel",APP_SHOW_PANEL:"app:showpanel",APP_HIDE_PANEL:"app:hidepanel",APP_ADD_CONTROL:"app:addcontrol",APP_READY:"app:ready",APP_OPENED:"app:opened",APP_CLOSED:"app:closed",APP_FULLSCREEN_CHANGE:"app:fullscreenchange",APP_PANEL_OPENED:"app:panelopened",APP_PANEL_CLOSED:"app:panelclosed",MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize",MAP_SET_FEATURES:"map:setfeatures",MAP_SET_ACTIVE_FEATURE:"map:setactivefeature",MAP_SELECT_FEATURE:"map:selectfeature",MAP_SET_PIXEL_RATIO:"map:setpixelratio",MAP_FIT_TO_BOUNDS:"map:fittobounds",MAP_SET_VIEW:"map:setview",MAP_INIT_MAP_STYLES:"map:initmapstyles",MAP_STYLE_CHANGE:"map:stylechange",MAP_LOADED:"map:loaded",MAP_READY:"map:ready",MAP_SIZE_CHANGE:"map:sizechange",MAP_FIRST_IDLE:"map:firstidle",MAP_MOVE_START:"map:movestart",MAP_MOVE:"map:move",MAP_MOVE_END:"map:moveend",MAP_STATE_UPDATED:"map:stateupdated",MAP_DATA_CHANGE:"map:datachange",MAP_RENDER:"map:render",MAP_CLICK:"map:click",MAP_DESTROY:"map:destroy"};function c(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 l(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?c(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function u(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function d(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 p(e){return d(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function h(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function f(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 g(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 y(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}const m={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"},v={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},E={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},b={POLYGON:"polygon",LINE:"line_string",POINT:"point"},x={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"},S={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},P={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"},w={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},_={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},M={ACTIVE:"true",INACTIVE:"false"},O=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var I=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:M,classes:m,cursors:E,events:P,geojsonTypes:x,interactions:O,meta:_,modes:S,sources:v,types:b,updateActions:w});function C(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function T(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function L(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===M.ACTIVE&&e.featureTarget.properties.meta===_.FEATURE))}function A(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===M.INACTIVE&&e.featureTarget.properties.meta===_.FEATURE))}function k(e){return void 0===e.featureTarget}function F(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===_.FEATURE)}function N(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===_.VERTEX)}function V(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function D(e){return"Escape"===e.key||27===e.keyCode}function j(e){return"Enter"===e.key||13===e.keyCode}function R(e){return"Backspace"===e.key||8===e.keyCode}function U(e){return"Delete"===e.key||46===e.keyCode}function B(e){return"1"===e.key||49===e.keyCode}function G(e){return"2"===e.key||50===e.keyCode}function Y(e){return"3"===e.key||51===e.keyCode}function X(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var H=Object.freeze({__proto__:null,isActiveFeature:L,isBackspaceKey:R,isDeleteKey:U,isDigit1Key:B,isDigit2Key:G,isDigit3Key:Y,isDigitKey:X,isEnterKey:j,isEscapeKey:D,isFeature:F,isInactiveFeature:A,isOfMetaType:C,isShiftDown:V,isShiftMousedown:T,isTrue:function(){return!0},isVertex:N,noTarget:k});function J(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function q(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 $,K,W={},z={};function Z(){return $||($=1,z.RADIUS=6378137,z.FLATTENING=1/298.257223563,z.POLAR_RADIUS=6356752.3142),z}var Q=function(){if(K)return W;K=1;var e=Z();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 W.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}},W.ring=r,W}(),ee=J(Q);const te={Point:0,LineString:1,MultiLineString:1,Polygon:2};function re(e,t){const r=te[e.geometry.type]-te[t.geometry.type];return 0===r&&e.geometry.type===x.POLYGON?e.area-t.area:r}function ne(e){return e.map(e=>(e.geometry.type===x.POLYGON&&(e.area=ee.geometry({type:x.FEATURE,property:{},geometry:e.geometry})),e)).sort(re).map(e=>(delete e.area,e))}function oe(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function ie(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)}ie.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},ie.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},ie.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},ie.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)},ie.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const ae=[_.FEATURE,_.MIDPOINT,_.VERTEX];var se={click:function(e,t,r){return ce(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return ce(e,t,r,r.options.touchBuffer)}};function ce(e,t,r,n){if(null===r.map)return[];const o=e?oe(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!==ae.indexOf(e.properties.meta)),s=new ie,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),ne(c)}function le(e,t){const r=se.click(e,null,t),n={mouse:E.NONE};return r[0]&&(n.mouse=r[0].properties.active===M.ACTIVE?E.MOVE:E.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=E.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function ue(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function de(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=ue(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function pe(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 ue(e.point,t.point)<n&&t.time-e.time<o}const he=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 fe=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function ge(){return fe()}const ye=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||ge(),this.type=t.geometry.type};ye.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ye.prototype.incomingCoords=function(e){this.setCoordinates(e)},ye.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ye.prototype.setProperty=function(e,t){this.properties[e]=t},ye.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:x.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ye.prototype.internal=function(e){const t={id:this.id,meta:_.FEATURE,"meta:type":this.type,active:M.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:x.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const me=function(e,t){ye.call(this,e,t)};(me.prototype=Object.create(ye.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},me.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},me.prototype.getCoordinate=function(){return this.getCoordinates()};const ve=function(e,t){ye.call(this,e,t)};(ve.prototype=Object.create(ye.prototype)).isValid=function(){return this.coordinates.length>1},ve.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},ve.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},ve.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},ve.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ee=function(e,t){ye.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ee.prototype=Object.create(ye.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ee.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ee.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ee.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])},Ee.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))},Ee.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]]))},Ee.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ee.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 be={MultiPoint:me,MultiLineString:ve,MultiPolygon:Ee},xe=(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)},Se=function(e,t){if(ye.call(this,e,t),delete this.coordinates,this.model=be[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 Pe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Se.prototype=Object.create(ye.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:ge(),type:x.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Se.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Se.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Se.prototype.getCoordinate=function(e){return xe(this.features,"getCoordinate",e)},Se.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===x.POLYGON?e.getCoordinates():e.coordinates)))},Se.prototype.updateCoordinate=function(e,t,r){xe(this.features,"updateCoordinate",e,t,r),this.changed()},Se.prototype.addCoordinate=function(e,t,r){xe(this.features,"addCoordinate",e,t,r),this.changed()},Se.prototype.removeCoordinate=function(e){xe(this.features,"removeCoordinate",e),this.changed()},Se.prototype.getFeatures=function(){return this.features},Pe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Pe.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),{})},Pe.prototype.getSelected=function(){return this._ctx.store.getSelected()},Pe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Pe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Pe.prototype.getFeature=function(e){return this._ctx.store.get(e)},Pe.prototype.select=function(e){return this._ctx.store.select(e)},Pe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Pe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Pe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Pe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Pe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Pe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Pe.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Pe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Pe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Pe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Pe.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)},Pe.prototype.newFeature=function(e){const t=e.geometry.type;return t===x.POINT?new me(this._ctx,e):t===x.LINE_STRING?new ve(this._ctx,e):t===x.POLYGON?new Ee(this._ctx,e):new Se(this._ctx,e)},Pe.prototype.isInstanceOf=function(e,t){if(e===x.POINT)return t instanceof me;if(e===x.LINE_STRING)return t instanceof ve;if(e===x.POLYGON)return t instanceof Ee;if("MultiFeature"===e)return t instanceof Se;throw new Error(`Unknown feature class: ${e}`)},Pe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Pe.prototype.onSetup=function(){},Pe.prototype.onDrag=function(){},Pe.prototype.onClick=function(){},Pe.prototype.onMouseMove=function(){},Pe.prototype.onMouseDown=function(){},Pe.prototype.onMouseUp=function(){},Pe.prototype.onMouseOut=function(){},Pe.prototype.onKeyUp=function(){},Pe.prototype.onKeyDown=function(){},Pe.prototype.onTouchStart=function(){},Pe.prototype.onTouchMove=function(){},Pe.prototype.onTouchEnd=function(){},Pe.prototype.onTap=function(){},Pe.prototype.onStop=function(){},Pe.prototype.onTrash=function(){},Pe.prototype.onCombineFeature=function(){},Pe.prototype.onUncombineFeature=function(){},Pe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const we={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},_e=Object.keys(we);function Me(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Pe(r));return{start(){o=i.onSetup(n),_e.forEach(t=>{const r=we[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 Oe(e){return[].concat(e).filter(e=>void 0!==e)}function Ie(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(v.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(v.COLD).setData({type:x.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(v.HOT).setData({type:x.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Ce(e){let t;this._features={},this._featureIds=new ie,this._selectedFeatureIds=new ie,this._selectedCoordinates=[],this._changedFeatureIds=new ie,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ie.call(this),this._emitSelectionChange&&(this.ctx.events.fire(P.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(P.RENDER,{})}))},this.isDirty=!1}function Te(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}Ce.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ce.prototype.setDirty=function(){return this.isDirty=!0,this},Ce.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(P.CREATE,{features:[t.toGeoJSON()]})}return this},Ce.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(P.UPDATE,{action:t.action?t.action:w.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ce.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ce.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ce.prototype.getAllIds=function(){return this._featureIds.values()},Ce.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ce.prototype.delete=function(e,t={}){const r=[];return Oe(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(P.DELETE,{features:r}),Te(this,t),this},Ce.prototype.get=function(e){return this._features[e]},Ce.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Ce.prototype.select=function(e,t={}){return Oe(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Ce.prototype.deselect=function(e,t={}){return Oe(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Te(this,t),this},Ce.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ce.prototype.setSelected=function(e,t={}){return e=Oe(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},Ce.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ce.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ce.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ce.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Ce.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Ce.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ce.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:w.CHANGE_PROPERTIES})},Ce.prototype.storeMapConfig=function(){O.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Ce.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Ce.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Le=["mode","feature","mouse"];function Ae(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]=Me(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:E.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!de(r,e))},o.touchdrag=function(e){o.drag(e,e=>!pe(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=le(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=le(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=le(t,e);t.featureTarget=n,de(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,pe(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=R(e),r=U(e),n=X(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=he(c,e),o.silent||e.map.fire(P.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(m.CANVAS)&&((R(t)||U(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):B(t)&&e.options.controls.point?c(S.DRAW_POINT):G(t)&&e.options.controls.line_string?c(S.DRAW_LINE_STRING):Y(t)&&e.options.controls.polygon&&c(S.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},u={start(){i=e.options.defaultMode,a=he(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(P.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};return u}(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=[];Le.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=`${m.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(m.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(m.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=`${m.CONTROL_GROUP} ${m.CONTROL_BASE}`,r?(r[b.POINT]&&(t[b.POINT]=s(b.POINT,{container:n,className:m.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(S.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[b.LINE]&&(t[b.LINE]=s(b.LINE,{container:n,className:m.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(S.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[b.POLYGON]&&(t[b.POLYGON]=s(b.POLYGON,{container:n,className:m.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(S.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:m.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:m.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:m.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 Ce(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(v.COLD,{data:{type:x.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(v.HOT,{data:{type:x.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(v.COLD)&&e.map.removeSource(v.COLD),e.map.getSource(v.HOT)&&e.map.removeSource(v.HOT)}};return e.setup=n,n}const ke="#3bb2d0",Fe="#fbb03b",Ne="#fff";var Ve=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Fe,ke],"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"],Fe,ke],"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":Ne}},{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"],Fe,ke]}},{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":Ne}},{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":Fe}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Fe}}];function De(e,t){this.x=e,this.y=t}function je(e,t){const r=t.getBoundingClientRect();return new De(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function Re(e,t,r,n){return{type:x.FEATURE,properties:{meta:_.VERTEX,parent:e,coord_path:r,active:n?M.ACTIVE:M.INACTIVE},geometry:{type:x.POINT,coordinates:t}}}De.prototype={clone(){return new De(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:De},De.convert=function(e){if(e instanceof De)return e;if(Array.isArray(e))return new De(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new De(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var Ue=6371008.8,Be={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*Ue,kilometers:6371.0088,kilometres:6371.0088,meters:Ue,metres:Ue,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:Ue/1852,radians:1,yards:6967335.223679999};function Ge(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 Ye(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(!Ze(e[0])||!Ze(e[1]))throw new Error("coordinates must contain numbers");return Ge({type:"Point",coordinates:e},t,r)}function Xe(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 Ge({type:"Polygon",coordinates:e},t,r)}function He(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return Ge({type:"LineString",coordinates:e},t,r)}function Je(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function qe(e,t,r={}){return Ge({type:"MultiLineString",coordinates:e},t,r)}function $e(e,t="kilometers"){const r=Be[t];if(!r)throw new Error(t+" units is invalid");return e*r}function Ke(e,t="kilometers"){const r=Be[t];if(!r)throw new Error(t+" units is invalid");return e/r}function We(e){return 180*(e%(2*Math.PI))/Math.PI}function ze(e){return e%360*Math.PI/180}function Ze(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function Qe(e,t,r){if(null!==e)for(var n,o,i,a,s,c,l,u,d=0,p=0,h=e.type,f="FeatureCollection"===h,g="Feature"===h,y=f?e.features.length:1,m=0;m<y;m++){s=(u=!!(l=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===l.type)?l.geometries.length:1;for(var v=0;v<s;v++){var E=0,b=0;if(null!==(a=u?l.geometries[v]:l)){c=a.coordinates;var x=a.type;switch(d=0,x){case null:break;case"Point":if(!1===t(c,p,m,E,b))return!1;p++,E++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===t(c[n],p,m,E,b))return!1;p++,"MultiPoint"===x&&E++}"LineString"===x&&E++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(o=0;o<c[n].length-d;o++){if(!1===t(c[n][o],p,m,E,b))return!1;p++}"MultiLineString"===x&&E++,"Polygon"===x&&b++}"Polygon"===x&&E++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(b=0,o=0;o<c[n].length;o++){for(i=0;i<c[n][o].length-d;i++){if(!1===t(c[n][o][i],p,m,E,b))return!1;p++}b++}E++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===Qe(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function et(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 tt(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 rt(e,t){tt(e,function(e,r,n,o,i){var a,s=null===e?null:e.type;switch(s){case null:case"Point":case"LineString":case"Polygon":return!1!==t(Ge(e,n,{bbox:o,id:i}),r,0)&&void 0}switch(s){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var c=0;c<e.coordinates.length;c++){var l=e.coordinates[c];if(!1===t(Ge({type:a,coordinates:l},n),r,c))return!1}})}function nt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return ot(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=>ot(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return at(e);default:throw new Error("unknown GeoJSON type")}}function ot(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=it(e.properties),null==e.geometry?t.geometry=null:t.geometry=at(e.geometry),t}function it(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]=it(n):t[r]=n}),t):t}function at(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>at(e)),t):(t.coordinates=st(e.coordinates),t)}function st(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>st(e))}function ct(e,t={}){return lt(e,"mercator",t)}function lt(e,t,r={}){var n=(r=r||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&Ze(e[0])?e="mercator"===t?ut(e):dt(e):(!0!==n&&(e=nt(e)),Qe(e,function(e){var r="mercator"===t?ut(e):dt(e);e[0]=r[0],e[1]=r[1]})),e}function ut(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 dt(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 pt(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=ct(n),a=ct(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return lt(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:x.FEATURE,properties:{meta:_.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:x.POINT,coordinates:u}}}function ht(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=Re(i,e,l,c(l));if(t.midpoints&&o){const e=pt(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===x.POINT?a.push(Re(i,o,r,c(r))):n===x.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===x.LINE_STRING?s(o,r):0===n.indexOf(x.MULTI_PREFIX)&&function(){const r=n.replace(x.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:x.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(ht(i,t,o))})}(),a}var ft={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:gt,LAT_MAX:yt,LAT_RENDERED_MIN:mt,LAT_RENDERED_MAX:vt,LNG_MIN:Et,LNG_MAX:bt}=I;function xt(e,t){let r=gt,n=yt,o=gt,i=yt,a=bt,s=Et;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],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>vt&&(c.lat=vt-r),o+c.lat>yt&&(c.lat=yt-o),n+c.lat<mt&&(c.lat=mt-n),i+c.lat<gt&&(c.lat=gt-i),a+c.lng<=Et&&(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 St(e,t){const r=xt(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===x.POINT?a=n(t):e.type===x.LINE_STRING||e.type===x.MULTI_POINT?a=t.map(n):e.type===x.POLYGON||e.type===x.MULTI_LINE_STRING?a=t.map(o):e.type===x.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Pt={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(P.UPDATE,{action:w.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 ie).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(){ft.enable(this)},onMouseMove:function(e,t){return F(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Pt.onTap=Pt.onClick=function(e,t){return k(t)?this.clickAnywhere(e,t):C(_.VERTEX)(t)?this.clickOnVertex(e,t):F(t)?this.clickOnFeature(e,t):void 0},Pt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),ft.enable(this),this.stopExtendedInteractions(e)},Pt.clickOnVertex=function(e,t){this.changeMode(S.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:E.MOVE})},Pt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Pt.clickOnFeature=function(e,t){ft.disable(this),this.stopExtendedInteractions(e);const r=V(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==x.POINT)return this.changeMode(S.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:E.POINTER}),1===n.length&&ft.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:E.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:E.MOVE})),this.doRender(o)},Pt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),L(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&T(t)?this.startBoxSelect(e,t):void 0},Pt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=je(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Pt.onTouchStart=function(e,t){if(L(t))return this.startOnActiveFeature(e,t)},Pt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Pt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:E.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(m.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=je(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"},Pt.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};St(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Pt.onTouchEnd=Pt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,je(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:E.MOVE}))}this.stopExtendedInteractions(e)},Pt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?M.ACTIVE:M.INACTIVE,r(t),this.fireActionable(),t.properties.active===M.ACTIVE&&t.geometry.type!==x.POINT&&ht(t).forEach(r)},Pt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Pt.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:x.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(P.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Pt.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(P.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const wt=C(_.VERTEX),_t=C(_.MIDPOINT),Mt={fireUpdate:function(){this.fire(P.UPDATE,{action:w.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);V(t)||-1!==n?V(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){St(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=xt(n.map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.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(S.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(S.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===x.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),ft.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){ft.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=M.ACTIVE,r(t),ht(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=M.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(S.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=L(t),n=wt(t),o=_t(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:E.MOVE}):this.updateUIClasses({mouse:E.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Mt.onTouchStart=Mt.onMouseDown=function(e,t){return wt(t)?this.onVertex(e,t):L(t)?this.onFeature(e,t):_t(t)?this.onMidpoint(e,t):void 0},Mt.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},Mt.onClick=function(e,t){return k(t)?this.clickNoTarget(e,t):L(t)?this.clickActiveFeature(e,t):A(t)?this.clickInactive(e,t):void this.stopDragging(e)},Mt.onTap=function(e,t){return k(t)?this.clickNoTarget(e,t):L(t)?this.clickActiveFeature(e,t):A(t)?this.clickInactive(e,t):void 0},Mt.onTouchEnd=Mt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Ot={};function It(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Ot.onSetup=function(){const e=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.POINT),this.setActionableState({trash:!0}),{point:e}},Ot.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)},Ot.onTap=Ot.onClick=function(e,t){this.updateUIClasses({mouse:E.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(P.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.point.id]})},Ot.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Ot.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t)},Ot.onTrash=Ot.stopDrawingAndRemove,Ot.onKeyUp=function(e,t){if(D(t)||j(t))return this.stopDrawingAndRemove(e,t)};const Ct={onSetup:function(){const e=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),ft.disable(this),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.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(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:E.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(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),N(t)&&this.updateUIClasses({mouse:E.POINTER})}};Ct.onTap=Ct.onClick=function(e,t){return N(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ct.onKeyUp=function(e,t){D(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)):j(t)&&this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ct.onStop=function(e){this.updateUIClasses({mouse:E.NONE}),ft.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(P.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT,{},{silent:!0})))},Ct.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?M.ACTIVE:M.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=_.FEATURE,r(Re(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(Re(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:x.FEATURE,properties:t.properties,geometry:{coordinates:e,type:x.LINE_STRING}}),3===o)return}return r(t)}},Ct.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)};const Tt={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:x.FEATURE,properties:{},geometry:{type:x.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),ft.disable(this),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.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(S.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:E.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(S.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),N(t)&&this.updateUIClasses({mouse:E.POINTER})}};Tt.onTap=Tt.onClick=function(e,t){if(N(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Tt.onKeyUp=function(e,t){j(t)?this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.line.id]}):D(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT))},Tt.onStop=function(e){ft.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(P.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT,{},{silent:!0})))},Tt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)},Tt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=_.FEATURE,r(Re(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 Lt={simple_select:Pt,direct_select:Mt,draw_point:Ot,draw_polygon:Ct,draw_line_string:Tt};const At={defaultMode:S.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:Ve,modes:Lt,controls:{},userProperties:!1,suppressAPIEvents:!0},kt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ft={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Nt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?v.HOT:v.COLD}))}var Vt,Dt;var jt,Rt,Ut=(Dt||(Dt=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}),Vt),Bt=J(Ut);var Gt=function(){if(Rt)return jt;Rt=1,jt=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 jt}(),Yt=J(Gt);function Xt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Ht={Polygon:Ee,LineString:ve,Point:me,MultiPolygon:Se,MultiLineString:Se,MultiPoint:Se};var Jt=Object.freeze({__proto__:null,CommonSelectors:H,ModeHandler:he,StringSet:ie,constrainFeatureMovement:xt,createMidPoint:pt,createSupplementaryPoints:ht,createVertex:Re,doubleClickZoom:ft,euclideanDistance:ue,featuresAt:se,getFeatureAtAndSetCursors:le,isClick:de,isEventAtCoordinates:It,isTap:pe,mapEventToBoundingBox:oe,moveFeatures:St,sortFeatures:ne,stringSetsAreEqual:Xt,theme:Ve,toDenseArray:Oe});const qt=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({},Ft,e.controls):t.controls=Object.assign({},kt,e.controls),t=Object.assign({},At,t),t.styles=Nt(t.styles,"cold").concat(Nt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=S;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:x.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:x.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==x.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 ie(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(Yt(t))).features.map(t=>{if(t.id=t.id||ge(),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,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:x.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==S.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(S.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===S.DIRECT_SELECT?e.events.changeMode(S.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===S.SIMPLE_SELECT&&t.getMode()===S.SIMPLE_SELECT?(Xt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===S.DIRECT_SELECT&&t.getMode()===S.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=Ae(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=b,t.options=e,t};function $t(e){qt(e,this)}$t.modes=Lt,$t.constants=I,$t.lib=Jt;var Kt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},Wt=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[]}},zt=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},Zt=(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},Qt=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},er=(e,t)=>{var r=t.split(".").map(Number),n=zt(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]},tr=(e,t)=>({x:e.x*t,y:e.y*t}),rr=e=>e instanceof window.SVGElement||e.ownerSVGElement,nr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},pushUndo(e){var t=this.map._undoStack;t&&t.push(e)},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)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=zt(i),c=Zt(s,r);if(c){Qt(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,tr(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=zt(o),s=Zt(a,r);if(s)Qt(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=zt(i),c=Zt(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c){Qt(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o);var u=e.vertecies[r];u&&this.updateTouchVertexTarget(e,tr(this.map.project(u),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)}};function or(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 ir(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?or(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):or(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ar=(e,t)=>{if(e){var r="dark"===(null==t?void 0:t.mapColorScheme);e.style.setProperty("--touch-fill",r?"#ffffff":"#000000"),e.style.setProperty("--touch-gfx",r?"#000000":"#ffffff")}},sr={addTouchVertexTarget(e){var t=e.container.querySelector("[data-touch-vertex-target]");t||(e.container.insertAdjacentHTML("beforeend","\n <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd' style='display:none;position:absolute;top:50%;left:50%;margin:24px 0 0 -24px' class='touch-vertex-target' data-touch-vertex-target>\n <circle cx='24' cy='24' r='24' fill='var(--touch-fill, #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(--touch-gfx, #fff)'/>\n </svg>\n"),t=e.container.querySelector("[data-touch-vertex-target]")),e.touchVertexTarget=t,ar(t,this.map._drawCurrentMapStyle)},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||rr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){g(u(this.map)),null!=e&&e.featureId&&(this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=void 0,e._touchMoved=!1)},onTap(e,t){var r,n,o=u(this.map);o&&f(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=er(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(ir(ir({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){var r;g(u(this.map));var n=null===(r=e.vertecies)||void 0===r?void 0:r[e.selectedVertexIndex];if(n&&rr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=t.touches[0].clientX,i=t.touches[0].clientY,a=window.getComputedStyle(e.touchVertexTarget);e.deltaTarget={x:o-Number.parseFloat(a.left),y:i-Number.parseFloat(a.top)};var s=this.map.project(n);e.deltaVertex={x:o/e.scale-s.x,y:i/e.scale-s.y}}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&rr(t.target.parentNode)){e._touchMoved=!0;var r=t.touches[0].clientX,n=t.touches[0].clientY,o={x:r/e.scale-e.deltaVertex.x,y:n/e.scale-e.deltaVertex.y},i=this.map.unproject(o);if(y(e)){var a=u(this.map);h(a,this.map,o),i=p(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function cr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var lr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},ur={updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(t,r){var[n,o]=this.getVertexOrMidpoint(t,r);n<0||!o||this.changeMode(t,function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?cr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({selectedVertexIndex:n,selectedVertexType:o},"vertex"===o&&{coordPath:this.getCoordPath(t,n)}))},getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?1:5,[o,i]=t?lr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getNewCoord(e,t){return this.getOffset(Wt(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},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=zt(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&&(Qt(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=zt(o),s=Zt(a,e.selectedVertexIndex);s&&(Qt(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=zt(t),n=Zt(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?3:2;if(!(o.length<=i)){var a=[...e.vertecies[e.selectedVertexIndex]],s=e.selectedVertexIndex,c=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(c),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:s,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}};function dr(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return pr(e);case"FeatureCollection":return function(e){var t={type:"FeatureCollection"};return Object.keys(e).forEach(function(r){switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(function(e){return pr(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return fr(e);default:throw new Error("unknown GeoJSON type")}}function pr(e){var t={type:"Feature"};return Object.keys(e).forEach(function(r){switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=hr(e.properties),t.geometry=fr(e.geometry),t}function hr(e){var t={};return e?(Object.keys(e).forEach(function(r){var n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(function(e){return e}):t[r]=hr(n):t[r]=n}),t):t}function fr(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return fr(e)}),t):(t.coordinates=gr(e.coordinates),t)}function gr(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return gr(e)})}function yr(e){for(var t,r,n=function(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")}(e),o=0,i=1;i<n.length;)t=r||n[0],o+=((r=n[i])[0]-t[0])*(r[1]+t[1]),i++;return o>0}function mr(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 vr(e,t){if(null===(r=t=t||{})||"object"!=typeof r||Array.isArray(r))throw new Error("options is invalid");var r,n=t.reverse||!1,o=t.mutate||!1;if(!e)throw new Error("<geojson> is required");if("boolean"!=typeof n)throw new Error("<reverse> must be a boolean");if("boolean"!=typeof o)throw new Error("<mutate> must be a boolean");!1===o&&(e=dr(e));var i=[];switch(e.type){case"GeometryCollection":return tt(e,function(e){Er(e,n)}),e;case"FeatureCollection":return et(e,function(e){et(Er(e,n),function(e){i.push(e)})}),Je(i)}return Er(e,n)}function Er(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return tt(e,function(e){Er(e,t)}),e;case"LineString":return br(mr(e),t),e;case"Polygon":return xr(mr(e),t),e;case"MultiLineString":return mr(e).forEach(function(e){br(e,t)}),e;case"MultiPolygon":return mr(e).forEach(function(e){xr(e,t)}),e;case"Point":case"MultiPoint":return e}}function br(e,t){yr(e)===t&&e.reverse()}function xr(e,t){yr(e[0])!==t&&e[0].reverse();for(var r=1;r<e.length;r++)yr(e[r])===t&&e[r].reverse()}const Sr=11102230246251565e-32,Pr=134217729,wr=(3+8*Sr)*Sr;function _r(e,t,r,n,o){let i,a,s,c,l=t[0],u=n[0],d=0,p=0;u>l==u>-l?(i=l,l=t[++d]):(i=u,u=n[++p]);let h=0;if(d<e&&p<r)for(u>l==u>-l?(a=l+i,s=i-(a-l),l=t[++d]):(a=u+i,s=i-(a-u),u=n[++p]),i=a,0!==s&&(o[h++]=s);d<e&&p<r;)u>l==u>-l?(a=i+l,c=a-i,s=i-(a-c)+(l-c),l=t[++d]):(a=i+u,c=a-i,s=i-(a-c)+(u-c),u=n[++p]),i=a,0!==s&&(o[h++]=s);for(;d<e;)a=i+l,c=a-i,s=i-(a-c)+(l-c),l=t[++d],i=a,0!==s&&(o[h++]=s);for(;p<r;)a=i+u,c=a-i,s=i-(a-c)+(u-c),u=n[++p],i=a,0!==s&&(o[h++]=s);return 0===i&&0!==h||(o[h++]=i),h}function Mr(e){return new Float64Array(e)}const Or=Mr(4),Ir=Mr(8),Cr=Mr(12),Tr=Mr(16),Lr=Mr(4);function Ar(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),c=a-s,l=Math.abs(a+s);return Math.abs(c)>=33306690738754716e-32*l?c:-function(e,t,r,n,o,i,a){let s,c,l,u,d,p,h,f,g,y,m,v,E,b,x,S,P,w;const _=e-o,M=r-o,O=t-i,I=n-i;b=_*I,p=Pr*_,h=p-(p-_),f=_-h,p=Pr*I,g=p-(p-I),y=I-g,x=f*y-(b-h*g-f*g-h*y),S=O*M,p=Pr*O,h=p-(p-O),f=O-h,p=Pr*M,g=p-(p-M),y=M-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Or[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Or[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Or[2]=v-(w-d)+(m-d),Or[3]=w;let C=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,Or),T=22204460492503146e-32*a;if(C>=T||-C>=T)return C;if(d=e-_,s=e-(_+d)+(d-o),d=r-M,l=r-(M+d)+(d-o),d=t-O,c=t-(O+d)+(d-i),d=n-I,u=n-(I+d)+(d-i),0===s&&0===c&&0===l&&0===u)return C;if(T=11093356479670487e-47*a+wr*Math.abs(C),C+=_*u+I*s-(O*l+M*c),C>=T||-C>=T)return C;b=s*I,p=Pr*s,h=p-(p-s),f=s-h,p=Pr*I,g=p-(p-I),y=I-g,x=f*y-(b-h*g-f*g-h*y),S=c*M,p=Pr*c,h=p-(p-c),f=c-h,p=Pr*M,g=p-(p-M),y=M-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Lr[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Lr[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Lr[2]=v-(w-d)+(m-d),Lr[3]=w;const L=_r(4,Or,4,Lr,Ir);b=_*u,p=Pr*_,h=p-(p-_),f=_-h,p=Pr*u,g=p-(p-u),y=u-g,x=f*y-(b-h*g-f*g-h*y),S=O*l,p=Pr*O,h=p-(p-O),f=O-h,p=Pr*l,g=p-(p-l),y=l-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Lr[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Lr[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Lr[2]=v-(w-d)+(m-d),Lr[3]=w;const A=_r(L,Ir,4,Lr,Cr);b=s*u,p=Pr*s,h=p-(p-s),f=s-h,p=Pr*u,g=p-(p-u),y=u-g,x=f*y-(b-h*g-f*g-h*y),S=c*l,p=Pr*c,h=p-(p-c),f=c-h,p=Pr*l,g=p-(p-l),y=l-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,d=x-m,Lr[0]=x-(m+d)+(d-P),v=b+m,d=v-b,E=b-(v-d)+(m-d),m=E-S,d=E-m,Lr[1]=E-(m+d)+(d-S),w=v+m,d=w-v,Lr[2]=v-(w-d)+(m-d),Lr[3]=w;const k=_r(A,Cr,4,Lr,Tr);return Tr[k-1]}(e,t,r,n,o,i,l)}function kr(e,t){var r,n,o,i,a,s,c,l,u,d=0,p=e[0],h=e[1],f=t.length;for(r=0;r<f;r++){n=0;var g=t[r],y=g.length-1;if((l=g[0])[0]!==g[y][0]&&l[1]!==g[y][1])throw new Error("First and last coordinates in a ring must be the same");for(i=l[0]-p,a=l[1]-h;n<y;n++){if(s=(u=g[n+1])[0]-p,c=u[1]-h,0===a&&0===c){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(c>=0&&a<=0||c<=0&&a>=0){if(0===(o=Ar(i,s,a,c,0,0)))return 0;(o>0&&c>0&&a<=0||o<0&&c<=0&&a>0)&&d++}l=u,a=c,i=s}}return d%2!=0}var Fr=function(e,t,r,n,o){this.p1=e,this.p2=t,this.edgeType=r,this.originalIndex=n,this.polygonContourId=o,this.interiorRing=!1,this.minX=Math.min(e.p[0],t.p[0]),this.minY=Math.min(e.p[1],t.p[1]),this.maxX=Math.max(e.p[0],t.p[0]),this.maxY=Math.max(e.p[1],t.p[1]),this.intersectionPoints=[],this.nextEdge=null},Nr=function(e){this.p=e},Vr=function(e,t){this.id=e,this.rawCoords=t};function Dr(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var jr=function(e,t,r,n){this.p=e,this.polylineEdge=t,this.polygonEdge=r,this.isHeadingIn=n,this.distanceFromPolylineEdgeStart=Rr(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Rr(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Rr(e,t){var r=t[0]-e[0],n=t[1]-e[1];return r*=r,n*=n,Math.sqrt(r+n)}jr.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var Ur=1e-9;function Br(e,t){return e[0]*t[1]-e[1]*t[0]}function Gr(e,t){return e[0]*t[0]+e[1]*t[1]}function Yr(e,t,r){return[e[0]+t*r[0],e[1]+t*r[1]]}function Xr(e,t,r){var n=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],o=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],i=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],a=Br(n,o),s=a*a,c=Gr(n,n);if(s>0){var l=Br(i,o)/a;if(l<0||l>1)return null;var u=Br(i,n)/a;return u<0||u>1?null:0===l||1===l?[Yr(e.p1.p,l,n)]:0===u||1===u?[Yr(t.p1.p,u,o)]:[Yr(e.p1.p,l,n)]}var d=Gr(i,i);if((s=(a=Br(i,n))*a)>Ur*c*d)return null;var p=Gr(n,i)/c,h=p+Gr(n,o)/c,f=Math.min(p,h),g=Math.max(p,h);return f<=1&&g>=0?1===f?[Yr(e.p1.p,f>0?f:0,n)]:0===g?[Yr(e.p1.p,g<1?g:1,n)]:[Yr(e.p1.p,f>0?f:0,n),Yr(e.p1.p,g<1?g:1,n)]:null}function Hr(e,t){var r=[],n=[],o=[],i=function(e,t,r,n,o){for(var i=0,a=[],s="Feature"===t.type?t.geometry:t,c="LineString"===s.type?[s.coordinates]:s.coordinates,l=0,u=0;u<c.length;u++){for(var d=c[u].length-1,p=new Nr(c[u][0]),h=null,f={nextEdge:null},g=0;g<d;g++){h=new Nr(c[u][g+1]),p.nextPoint=h,h.prevPoint=p;var y=new Fr(p,h,"polyline",l,null);n.push(y),f.nextEdge=y,y.prevEdge=f,o[0]=Math.min(o[0],p.p[0]),o[1]=Math.min(o[1],p.p[1]),o[2]=Math.max(o[2],p.p[0]),o[3]=Math.max(o[3],p.p[1]),p=h,l+=1,f=y}o[0]=Math.min(o[0],c[u][d][0]),o[1]=Math.min(o[1],c[u][d][1]),o[2]=Math.max(o[2],c[u][d][0]),o[3]=Math.max(o[3],c[u][d][1])}for(var m="Feature"===e.type?e.geometry:e,v="Polygon"===m.type?[m.coordinates]:m.coordinates,E=v.length,b=0;b<E;b++)for(var x=v[b].length,S=0;S<x;S++){i+=1;var P=v[b][S],w=P.length;a.push(new Vr(i,P));for(var _=new Nr(P[0]),M=_,O=void 0,I=null,C={nextEdge:null,prevEdge:null},T=null,L=1;L<w;L++)O=new Nr(P[L]),M.nextPoint=O,O.prevPoint=M,I=new Fr(M,O,"polygon",l,i),C.nextEdge=I,I.prevEdge=C,1===L&&(T=I),S>0&&(I.interiorRing=!0),I.intersectPolylineBbox=Dr(I,o),r.push(I),M=O,l+=1,C=I;I.nextEdge=T,T.prevEdge=I,O.nextPoint=_.nextPoint,_.prevPoint=O.prevPoint}return a}(vr(e),t,n,o,[1/0,1/0,1/0,1/0]);if(function(e,t,r){var n,o,i,a=t.length,s=e.length;for(n=0;n<a;n++){var c=t[n];for(o=0;o<s;o++){var l=e[o];if(l.intersectPolylineBbox&&!(l.maxX<c.minX||l.minX>c.maxX||l.maxY<c.minY||l.minY>c.maxY)){var u=Xr(c,l);if(null!==u)for(i=0;i<u.length;i++){var d=Ar(l.p1.p[0],l.p1.p[1],l.p2.p[0],l.p2.p[1],c.p1.p[0],c.p1.p[1]),p=new jr(u[i],c,l,d>0);r.push(p)}}}}t.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolylineEdgeStart-t.distanceFromPolylineEdgeStart})}),e.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolygonEdgeStart-t.distanceFromPolygonEdgeStart})})}(n,o,r),0===r.length)return e;var a={};i.forEach(function(e){return a[e.id]=0}),r.forEach(function(e){var t=e.polygonEdge.polygonContourId;a[t]=a[t]+1});for(var s=0,c=[],l=null,u=0;u<o.length;u++){var d=o[u];if(d.intersectionPoints.length>0){l=d.intersectionPoints[0];break}}for(var p=l,h={visitCount:1};l!==h&&!(s>2*r.length);){if(s=s++,h.visitCount>=2){for(var f=!1,g=0;g<r.length;g++){var y=r[g];if(y.visitCount<2){p=y,f=!0;break}}if(!f)break}p.visitCount=p.visitCount+1;var m=[];c.push(m),m.push(p.p),p.visitCount=p.visitCount+1;var v=Kr(p,m),E=!1;if(v===(h=v)&&2===r.length)for(var b=0;b<r.length;b++){r[b].visitCount<2&&(E=!0)}for(;v!==p||E;){(v=(v.isHeadingIn?Zr:zr)(v,m))!==p&&(v=Kr(v,m)),E=!1}if(h.visitCount>=2){for(var x=!1,S=0;S<r.length;S++){var P=r[S];if(P.visitCount<2){p=P,x=!0;break}}x&&(h=p)}p=h}for(var w=c.map(function(e){return[e]}),_=Object.keys(a),M=0;M<_.length;M++){var O=_[M];if(0===a[O])$r(qr(Jr(n,parseInt(O)),i),w)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:w}}}function Jr(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.polygonContourId===t)return n}}function qr(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function $r(e,t){for(var r=0;r<t.length;r++){var n=t[r];if(kr(e[0],[n[0]]))return void n.push(e)}t.push([e])}function Kr(e,t){var r=e.polygonEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=Wr(e,r.intersectionPoints),o=r.intersectionPoints[n+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(r.p2.p),null===(r=r.nextEdge))return e;r.intersectionPoints.length>0&&(i=!1)}return r.intersectionPoints[0].incrementVisitCount(),t.push(r.intersectionPoints[0].p),r.intersectionPoints[0]}function Wr(e,t){for(var r=0;r<t.length;r++){if(t[r]===e)return r}return null}function zr(e,t){var r=e.polylineEdge;if(2===r.intersectionPoints.length){var n=r.intersectionPoints[r.intersectionPoints.length-1];if(n===e){var o=r.intersectionPoints[0];return t.push(o.p),o.incrementVisitCount(),o}return t.push(n.p),n.incrementVisitCount(),n}if(r.intersectionPoints.length>2&&r.intersectionPoints[0]!==e){var i=Wr(e,r.intersectionPoints),a=r.intersectionPoints[i-1];return t.push(a.p),a.incrementVisitCount(),a}for(var s=!0;s;){if(t.push(r.p1.p),void 0===(r=r.prevEdge).originalIndex)return e;r.intersectionPoints.length>0&&(s=!1)}if(void 0===r.originalIndex)return e;var c=r.intersectionPoints[r.intersectionPoints.length-1];return c.incrementVisitCount(),t.push(c.p),c}function Zr(e,t){var r=e.polylineEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=Wr(e,r.intersectionPoints),o=r.intersectionPoints[n+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(r.p2.p),null===(r=r.nextEdge))return e;r.intersectionPoints.length>0&&(i=!1)}if(void 0===r)return e;var a=r.intersectionPoints[0];return a.incrementVisitCount(),t.push(a.p),a}function Qr(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 en(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 tn(e){return"Feature"===e.type?e.geometry:e}function rn(e,t,r={}){if(!0===r.final)return function(e,t){let r=rn(t,e);return r=(r+180)%360,r}(e,t);const n=Qr(e),o=Qr(t),i=ze(n[0]),a=ze(o[0]),s=ze(n[1]),c=ze(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 We(Math.atan2(l,u))}var nn=rn;function on(e,t,r,n={}){const o=Qr(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),d=We(l);return void 0!==o[2]?Ye([u,d,o[2]],n.properties):Ye([u,d],n.properties)}var an=on;function sn(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=Qr(e),o=tn(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let c=!1;for(var l=0;l<s.length;++l){const e=kr(n,s[l]);if(0===e)return!r.ignoreBoundary;e&&(c=!0)}return c}class cn{constructor(e=[],t=ln){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function ln(e,t){return e<t?-1:e>t?1:0}function un(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function dn(e,t){return e.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:e.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:e.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?e.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}class pn{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let hn=0,fn=0,gn=0;function yn(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;fn+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new pn(o,hn,fn,gn),c=new pn(i,hn,fn,gn+1);s.otherEvent=c,c.otherEvent=s,un(s,c)>0?(c.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,c.isLeftEndpoint=!1),t.push(s),t.push(c),o=i,gn+=1}}hn+=1}class mn{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function vn(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,c=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,u=(l-s)*(o-r)-(c-a)*(i-n),d=(c-a)*(n-s)-(l-s)*(r-a),p=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const h=d/u,f=p/u;if(h>=0&&h<=1&&f>=0&&f<=1){return[r+h*(o-r),n+h*(i-n)]}return!1}var En=function(e,t){const r=new cn([],un);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)yn(r[e],t)}else yn(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new cn([],dn);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new mn(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=vn(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function bn(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let i=[];"FeatureCollection"===e.type?i=i.concat(e.features):"Feature"===e.type?i.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||i.push(Ge(e)),"FeatureCollection"===t.type?i=i.concat(t.features):"Feature"===t.type?i.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||i.push(Ge(t));const a=En(Je(i),o);let s=[];if(n){const e={};a.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,s.push(t))})}else s=a;return Je(s.map(e=>Ye(e)))}function xn(e,t={}){const r=tn(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=tn(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return Sn(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=tn(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(Sn(e,o))}),Je(i)}(r,t);default:throw new Error("invalid poly")}}function Sn(e,t){return e.length>1?qe(e,t):He(e[0],t)}function Pn(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return rt(e,e=>{rt(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!wn(t,e);case"Polygon":return!sn(e,t)}break;case"LineString":switch(t.type){case"Point":return!wn(e,t);case"LineString":return!function(e,t,r){const n=bn(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!_n(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!sn(t,e);case"LineString":return!_n(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(sn(r,t))return!0;for(const r of t.coordinates[0])if(sn(r,e))return!0;const n=bn(xn(e),xn(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n}function wn(e,t){for(let r=0;r<e.coordinates.length-1;r++)if(Mn(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function _n(e,t,r){for(const r of t.coordinates)if(sn(r,e))return!0;return bn(t,xn(e),{ignoreSelfIntersections:r}).features.length>0}function Mn(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var On=Object.defineProperty,In=(e,t)=>On(e,"name",{value:t,configurable:!0}),Cn=class{constructor(e){var t,r,n;this.direction=!1,this.compareProperties=!0,this.precision=10**-(null!=(t=null==e?void 0:e.precision)?t:17),this.direction=null!=(r=null==e?void 0:e.direction)&&r,this.compareProperties=null==(n=null==e?void 0:e.compareProperties)||n}compare(e,t){if(e.type!==t.type)return!1;if(!Ln(e,t))return!1;switch(e.type){case"Point":return this.compareCoord(e.coordinates,t.coordinates);case"LineString":return this.compareLine(e.coordinates,t.coordinates);case"Polygon":return this.comparePolygon(e,t);case"GeometryCollection":return this.compareGeometryCollection(e,t);case"Feature":return this.compareFeature(e,t);case"FeatureCollection":return this.compareFeatureCollection(e,t);default:if(e.type.startsWith("Multi")){const r=An(e),n=An(t);return r.every(e=>n.some(t=>this.compare(e,t)))}}return!1}compareCoord(e,t){return e.length===t.length&&e.every((e,r)=>Math.abs(e-t[r])<this.precision)}compareLine(e,t,r=0,n=!1){if(!Ln(e,t))return!1;const o=e;let i=t;if(n&&!this.compareCoord(o[0],i[0])){const e=this.fixStartIndex(i,o);if(!e)return!1;i=e}const a=this.compareCoord(o[r],i[r]);return this.direction||a?this.comparePath(o,i):!!this.compareCoord(o[r],i[i.length-(1+r)])&&this.comparePath(o.slice().reverse(),i)}fixStartIndex(e,t){let r,n=-1;for(let r=0;r<e.length;r++)if(this.compareCoord(e[r],t[0])){n=r;break}return n>=0&&(r=[].concat(e.slice(n,e.length),e.slice(1,n+1))),r}comparePath(e,t){return e.every((e,r)=>this.compareCoord(e,t[r]))}comparePolygon(e,t){if(this.compareLine(e.coordinates[0],t.coordinates[0],1,!0)){const r=e.coordinates.slice(1,e.coordinates.length),n=t.coordinates.slice(1,t.coordinates.length);return r.every(e=>n.some(t=>this.compareLine(e,t,1,!0)))}return!1}compareGeometryCollection(e,t){return Ln(e.geometries,t.geometries)&&this.compareBBox(e,t)&&e.geometries.every((e,r)=>this.compare(e,t.geometries[r]))}compareFeature(e,t){return e.id===t.id&&(!this.compareProperties||Fn(e.properties,t.properties))&&this.compareBBox(e,t)&&this.compare(e.geometry,t.geometry)}compareFeatureCollection(e,t){return Ln(e.features,t.features)&&this.compareBBox(e,t)&&e.features.every((e,r)=>this.compare(e,t.features[r]))}compareBBox(e,t){return Boolean(!e.bbox&&!t.bbox)||!(!e.bbox||!t.bbox)&&this.compareCoord(e.bbox,t.bbox)}};In(Cn,"GeojsonEquality");var Tn=Cn;function Ln(e,t){return e.coordinates?e.coordinates.length===t.coordinates.length:e.length===t.length}function An(e){return e.coordinates.map(t=>({type:e.type.replace("Multi",""),coordinates:t}))}function kn(e,t,r){return new Tn(r).compare(e,t)}function Fn(e,t){if(null===e&&null===t)return!0;if(null===e||null===t)return!1;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o of r){const r=e[o],n=t[o],i=Nn(r)&&Nn(n);if(i&&!Fn(r,n)||!i&&r!==n)return!1}return!0}In(Ln,"sameLength"),In(An,"explode"),In(kn,"geojsonEquality"),In(Fn,"equal");var Nn=In(e=>null!=e&&"object"==typeof e,"isObject");function Vn(e,t,r={}){const n=Qr(e),o=en(t);for(let e=0;e<o.length-1;e++){let t=!1;if(r.ignoreEndVertices&&(0===e&&(t="start"),e===o.length-2&&(t="end"),0===e&&e+1===o.length-1&&(t="both")),Dn(o[e],o[e+1],n,t,void 0===r.epsilon?null:r.epsilon))return!0}return!1}function Dn(e,t,r,n,o){const i=r[0],a=r[1],s=e[0],c=e[1],l=t[0],u=t[1],d=l-s,p=u-c,h=(r[0]-s)*p-(r[1]-c)*d;if(null!==o){if(Math.abs(h)>o)return!1}else if(0!==h)return!1;return Math.abs(d)===Math.abs(p)&&0===Math.abs(d)?!n&&(r[0]===e[0]&&r[1]===e[1]):n?"start"===n?Math.abs(d)>=Math.abs(p)?d>0?s<i&&i<=l:l<=i&&i<s:p>0?c<a&&a<=u:u<=a&&a<c:"end"===n?Math.abs(d)>=Math.abs(p)?d>0?s<=i&&i<l:l<i&&i<=s:p>0?c<=a&&a<u:u<a&&a<=c:"both"===n&&(Math.abs(d)>=Math.abs(p)?d>0?s<i&&i<l:l<i&&i<s:p>0?c<a&&a<u:u<a&&a<c):Math.abs(d)>=Math.abs(p)?d>0?s<=i&&i<=l:l<=i&&i<=s:p>0?c<=a&&a<=u:u<=a&&a<=c}function jn(e,t={}){var r="object"==typeof t?t.mutate:t;if(!e)throw new Error("geojson is required");var n=function(e){return"FeatureCollection"===e.type?"FeatureCollection":"GeometryCollection"===e.type?"GeometryCollection":"Feature"===e.type&&null!==e.geometry?e.geometry.type:e.type}(e),o=[];switch(n){case"LineString":o=Rn(e,n);break;case"MultiLineString":case"Polygon":en(e).forEach(function(e){o.push(Rn(e,n))});break;case"MultiPolygon":en(e).forEach(function(e){var t=[];e.forEach(function(e){t.push(Rn(e,n))}),o.push(t)});break;case"Point":return e;case"MultiPoint":var i={};en(e).forEach(function(e){var t=e.join("-");Object.prototype.hasOwnProperty.call(i,t)||(o.push(e),i[t]=!0)});break;default:throw new Error(n+" geometry not supported")}return e.coordinates?!0===r?(e.coordinates=o,e):{type:n,coordinates:o}:!0===r?(e.geometry.coordinates=o,e):Ge({type:n,coordinates:o},e.properties,{bbox:e.bbox,id:e.id})}function Rn(e,t){const r=en(e);if(2===r.length&&!Un(r[0],r[1]))return r;const n=[];let o=0,i=1,a=2;for(n.push(r[o]);a<r.length;)Vn(r[i],He([r[o],r[a]]))?i=a:(n.push(r[i]),o=i,i++,a=i),a++;if(n.push(r[i]),"Polygon"===t||"MultiPolygon"===t){if(Vn(n[0],He([n[1],n[n.length-2]]))&&(n.shift(),n.pop(),n.push(n[0])),n.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!Un(n[0],n[n.length-1]))throw new Error("invalid polygon, first and last points not equal")}return n}function Un(e,t){return e[0]===t[0]&&e[1]===t[1]}function Bn(e,t,r={}){let n=r.precision;if(n=null==n||isNaN(n)?6:n,"number"!=typeof n||!(n>=0))throw new Error("precision must be a positive number");return tn(e).type===tn(t).type&&kn(jn(e),jn(t),{precision:n})}function Gn(e,t){var r=tn(e),n=tn(t),o=r.type,i=n.type;switch(o){case"MultiPoint":switch(i){case"LineString":return Yn(r,n);case"Polygon":return Hn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"MultiPoint":return Yn(n,r);case"LineString":return function(e,t){const r=bn(e,t);if(0===r.features.length)return!1;for(const n of r.features)if(!(Bn(n.geometry,Ye(e.coordinates[0]))||Bn(n.geometry,Ye(e.coordinates[e.coordinates.length-1]))||Bn(n.geometry,Ye(t.coordinates[0]))||Bn(n.geometry,Ye(t.coordinates[t.coordinates.length-1]))))return!0;return!1}(r,n);case"Polygon":return Xn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"MultiPoint":return Hn(n,r);case"LineString":return Xn(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+o+" geometry not supported")}}function Yn(e,t){for(var r=!1,n=!1,o=e.coordinates.length,i=0;i<o&&!r&&!n;){for(var a=0;a<t.coordinates.length-1;a++){var s=!0;0!==a&&a!==t.coordinates.length-2||(s=!1),Jn(t.coordinates[a],t.coordinates[a+1],e.coordinates[i],s)?r=!0:n=!0}i++}return r&&n}function Xn(e,t){return bn(e,xn(t)).features.length>0}function Hn(e,t){var r=!1,n=!1,o=e.coordinates.length;for(let i=0;i<o&&(!r||!n);i++)sn(Ye(e.coordinates[i]),t)?r=!0:n=!0;return n&&r}function Jn(e,t,r,n){var o=r[0]-e[0],i=r[1]-e[1],a=t[0]-e[0],s=t[1]-e[1];return 0===o*s-i*a&&(n?Math.abs(a)>=Math.abs(s)?a>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:s>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1]:Math.abs(a)>=Math.abs(s)?a>0?e[0]<r[0]&&r[0]<t[0]:t[0]<r[0]&&r[0]<e[0]:s>0?e[1]<r[1]&&r[1]<t[1]:t[1]<r[1]&&r[1]<e[1])}function qn(e){return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]}function $n(e){for(var t=0;t<e.length-1;t++)for(var r=e[t],n=t+1;n<e.length-2;n++){if(Vn(r,He([e[n],e[n+1]])))return!0}return!1}function Kn(e,t,r){for(var n=Xe(e),o=r+1;o<t.length;o++)if(!Pn(n,Xe(t[o]))&&Gn(n,He(t[o][0])))return!1;return!0}var Wn=function(e){if(!e.type)return!1;const t=tn(e),r=t.type,n=t.coordinates;switch(r){case"Point":return n.length>1;case"MultiPoint":for(var o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"LineString":if(n.length<2)return!1;for(o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"MultiLineString":if(n.length<2)return!1;for(o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"Polygon":for(o=0;o<t.coordinates.length;o++){if(n[o].length<4)return!1;if(!qn(n[o]))return!1;if($n(n[o]))return!1;if(o>0&&bn(Xe([n[0]]),Xe([n[o]])).features.length>1)return!1}return!0;case"MultiPolygon":for(o=0;o<t.coordinates.length;o++)for(var i=t.coordinates[o],a=0;a<i.length;a++){if(i[a].length<4)return!1;if(!qn(i[a]))return!1;if($n(i[a]))return!1;if(0===a&&!Kn(i,t.coordinates,o))return!1;if(a>0&&bn(Xe([i[0]]),Xe([i[a]])).features.length>1)return!1}return!0;default:return!1}};function zn(e){let t=0;if(e&&e.length>0){t+=Math.abs(eo(e[0]));for(let r=1;r<e.length;r++)t-=Math.abs(eo(e[r]))}return t}var Zn=20294876564838.72,Qn=Math.PI/180;function eo(e){const t=e.length-1;if(t<=2)return 0;let r=0,n=0;for(;n<t;){const o=e[n],i=e[n+1===t?0:n+1],a=e[n+2>=t?(n+2)%t:n+2],s=o[0]*Qn,c=i[1]*Qn;r+=(a[0]*Qn-s)*Math.sin(c),n++}return r*Zn}var to=function(e){return function(e,t,r){var n=r;return tt(e,function(e,r,o,i,a){n=t(n,e,r,o,i,a)}),n}(e,(e,t)=>e+function(e){let t,r=0;switch(e.type){case"Polygon":return zn(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)r+=zn(e.coordinates[t]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};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 r,n,o,i,a=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"meters",n=e.geometry.coordinates,o=[],i=nn(n[1],n[0]),a=an(n[0],t,i,{units:r});o.push(a.geometry.coordinates);for(var s=0;s<n.length;s++){if(s>0&&s<n.length-1){var c=nn(n[s-1],n[s]),l=an(n[s],t,c,{units:r});o.push(l.geometry.coordinates)}o.push(n[s])}var u=nn(n[n.length-2],n[n.length-1]),d=an(n[n.length-1],t,u,{units:r});return o.push(d.geometry.coordinates),He(o)}(t);try{i=Hr(e,a)}catch(e){return null}var s=[];if("MultiPolygon"!==i.geometry.type)return null;if(2!==i.geometry.coordinates.length)return null;s=i.geometry.coordinates.map(t=>Xe(t,e.properties));var c=null!==(r=null!==(n=e.id)&&void 0!==n?n:null===(o=e.properties)||void 0===o?void 0:o.id)&&void 0!==r?r:"poly";return Je(s.map((t,r)=>Xe(t.geometry.coordinates,no(no({},e.properties),{},{id:c}),{id:"".concat(c,"-").concat(r+1)})))},io=(e,t)=>{var[r,n]=e,[o,i]=t,a=e=>e*Math.PI/180,s=a(i-n),c=a(o-r),l=Math.sin(s/2)**2+Math.cos(a(n))*Math.cos(a(i))*Math.sin(c/2)**2;return 12742e3*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))},ao=e=>e.length<=1||function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01;if(e.length<=1)return!0;if(e.length>=2){var r=e[e.length-1],n=e[e.length-2];if(io(r,n)<t)return!1}return!0}(e),so=e=>{if(e[0].length<=1||function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01;if(e[0].length<=1)return!0;if(e[0].length<=3)for(var r=0;r<e[0].length;r++)for(var n=r+1;n<e[0].length;n++)if(io(e[0][r],e[0][n])<t)return!1;return!0}(e))return!0;if(!Array.isArray(e)||e.length<4)return!1;var t=e[0],r=e[e.length-1];if(!(t[0]===r[0]&&t[1]===r[1]))return!1;var n=Xe([e]);return!!Wn(n)&&!(to(n)<=0)},co=(e,t,r)=>{var n=t.filter((t,n)=>{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)&&JSON.stringify(t)!==JSON.stringify(e)});n.length||n.push(e);var o=n.map(t=>{return r=Math.abs(e[0]-t[0]),n=Math.abs(e[1]-t[1]),Math.sqrt(Math.pow(r,2)+Math.pow(n,2));var r,n}),i=n[o.indexOf(Math.min(...o))];return t.findIndex(e=>JSON.stringify(e)===JSON.stringify(i))},lo={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]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=zt(r),o=Zt(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 Wt(this.getFeature(e))||[]},getMidpoints(e){var t=this.getFeature(e),r=Wt(t),n=zt(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=co(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=zt(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 uo(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 po(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?uo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ho=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),fo={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},go=po(po(po(po(po(po({},Mt),nr),sr),ur),lo),{},{onSetup(e){var t,r,n=Mt.onSetup.call(this,e);Object.assign(n,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:n.featureId||e.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});var o=this.getFeature(n.featureId);n.featureType=null==o?void 0:o.type,n.vertecies=this.getVerticies(n.featureId),n.midpoints=this.getMidpoints(n.featureId),this.setupEventListeners(n),this.applyVertexSelection(n,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(n);var i=u(this.map);if(i&&f(i,this.map),"touch"===n.interfaceType&&n.selectedVertexIndex>=0&&"vertex"===n.selectedVertexType){var a=n.vertecies[n.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(n,tr(this.map.project(a),n.scale))},0)}return n._ignorePointermoveDeselect=!0,setTimeout(()=>{n._ignorePointermoveDeselect=!1},100),n},setupEventListeners(e){var t=t=>r=>t.call(this,e,r),r=this.handlers={keydown:t(this.onKeydown),keyup:t(this.onKeyup),pointerdown:t(this.onPointerevent),pointermove:t(this.onPointerevent),pointerup:t(this.onPointerevent),click:t(this.onButtonClick),touchstart:t(this.onTouchstart),touchmove:t(this.onTouchmove),touchend:t(this.onTouchend),selectionchange:t(this.onSelectionChange),scalechange:t(this.onScaleChange),update:t(this.onUpdate),move:t(this.onMove),interfacetypechange:t(this.onInterfaceTypeChange)};window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),this.map.on("draw.selectionchange",r.selectionchange),this.map.on("draw.scalechange",r.scalechange),this.map.on("draw.update",r.update),this.map.on("move",r.move),this.map.on("draw.interfacetypechange",r.interfacetypechange)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature&&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&&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=Wt(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire("draw.vertexselection",{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?tr(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?tr(this.map.project(r),e.scale):null)},onUpdate(e){var t,r=new Set(e.vertecies.map(e=>JSON.stringify(e)));r.size!==e.vertecies.length&&(e.selectedVertexIndex=e.vertecies.findIndex(e=>!r.has(JSON.stringify(e))),null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null))},onKeydown(e,t){if(e.container.contains(document.activeElement)){if(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "===t.key&&t.preventDefault()," "===t.key&&e.selectedVertexIndex<0){var r,n,o=u(this.map);if(o&&f(o,this.map),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;return e.isPanEnabled=!1,this.updateVertex(e)}if(!t.altKey&&ho.has(t.key)&&e.selectedVertexIndex>=0){if(t.preventDefault(),t.stopPropagation(),"midpoint"===e.selectedVertexType)return this.insertVertex(e,t);var i=u(this.map),a=this.getFeature(e.featureId);if(!a)return;var s=Wt(a),c=null==s?void 0:s[e.selectedVertexIndex];if(!c)return;if(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...c],e._keyboardMoveStartIndex=e.selectedVertexIndex),y(e)&&e._isSnapped&&i){var l=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:15}(i)+1,g=this.map.project(c),[m,v]=fo[t.key].map(e=>e*l);return e._isSnapped=!1,f(i,this.map),this.moveVertex(e,this.map.unproject({x:g.x+m,y:g.y+v}))}var E=this.getNewCoord(e,t);return y(e)&&i&&(h(i,this.map,this.map.project(E)),d(i))?(e._isSnapped=!0,this.moveVertex(e,p(i))):(e._isSnapped=!1,this.moveVertex(e,E))}if(t.altKey&&ho.has(t.key)&&e.selectedVertexIndex>=0)return t.preventDefault(),t.stopPropagation(),this.updateVertex(e,t.key);if("Escape"===t.key&&this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}),"z"===t.key&&(t.metaKey||t.ctrlKey)&&!t.shiftKey){var b,x=null===(b=document.activeElement)||void 0===b?void 0:b.tagName;if("INPUT"===x||"TEXTAREA"===x)return;return t.preventDefault(),t.stopPropagation(),this.handleUndo(e)}}},onKeyup(e,t){e.container.contains(document.activeElement)&&(e.interfaceType="keyboard",ho.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&void 0!==e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=void 0)),"Delete"===t.key&&this.deleteVertex(e))},onMouseDown(e,t){var r,n;g(u(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,Mt.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=er(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 d=this.getFeature(e.featureId),p=er(d,i);e._insertedVertexIndex=p,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire("draw.vertexselection",{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&void 0!==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=void 0,void this.map.fire("draw.vertexselection",{index:r,numVertecies:e.vertecies.length})}Mt.onClick.call(this,e,t)},onMouseUp(e,t){g(u(this.map));var r=!1;if(e._moveStartPosition&&void 0!==e._moveStartIndex){var n=this.getFeature(e.featureId);if(n){var o,i=null===(o=Wt(n))||void 0===o?void 0:o[e._moveStartIndex];i&&(r=i[0]!==e._moveStartPosition[0]||i[1]!==e._moveStartPosition[1])}}var a=e._isInsertingVertex&&void 0!==e._insertedVertexIndex;if(e.dragMoving||r||a)if(this.syncVertices(e),a){var s=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),e.selectedVertexIndex=s,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=void 0,this.map.fire("draw.vertexselection",{index:s,numVertecies:e.vertecies.length})}else r&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition});e._moveStartPosition=null,e._moveStartIndex=null,Mt.onMouseUp.call(this,e,t)},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=u(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),y(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),h(n,this.map,t.point);var o=p(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Mt.onDrag.call(this,e,t)}},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,tr(this.map.project(t),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",po(po({},e),t))},onStop(e){this.map._drawEditContainer=null;var t=this.handlers;e.container.removeEventListener("pointerdown",t.pointerdown),e.container.removeEventListener("pointermove",t.pointermove),e.container.removeEventListener("pointerup",t.pointerup),e.container.removeEventListener("touchstart",t.touchstart),e.container.removeEventListener("touchmove",t.touchmove),e.container.removeEventListener("touchend",t.touchend),this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.scalechange",t.scalechange),this.map.off("draw.update",t.update),this.map.off("move",t.move),this.map.off("draw.interfacetypechange",t.interfacetypechange),this.map.dragPan.enable(),window.removeEventListener("click",t.click),window.removeEventListener("keydown",t.keydown,{capture:!0}),window.removeEventListener("keyup",t.keyup,{capture:!0}),this.hideTouchVertexIndicator(e)}});function yo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function mo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?yo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):yo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var vo=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,createVertices:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,f=e=>e[r];return mo(mo({},e),{},{onSetup(t){var{map:n}=this,o=s?mo(mo({},t),{},{featureId:null}):t,i=mo(mo({},e.onSetup.call(this,o)),t);i[r].properties=t.properties;var{container:a,vertexMarkerId:c,getInterfaceType:l}=i,u=l?l():i.interfaceType;i.interfaceType=u;var d=a.querySelector("#".concat(c));i.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(i):this._hideCrossHair(i);var p=(e,t)=>this[e]=t.bind(this,i),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};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],[a,"blur",this.blurHandler],[a,"pointermove",this.pointermoveHandler],[a,"pointerup",this.pointerupHandler],[n,"pointerdown",this.pointerdownHandler],[n,"draw.create",this.createHandler],[n,"move",this.moveHandler],[n,"draw.undo",this.undoHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),i},onClick(t,r){if(!(r.originalEvent.button>0||this.map._undoInProgress||r.originalEvent.target!==this.map.getCanvas())){var n=u(this.map);if(y(t)&&d(n))r=function(e,t){var r=p(t);return r?l(l({},e),{},{lngLat:r}):e}(r,n);else{var a=o(f(t));if(a.length>0&&(a[a.length-1]=[r.lngLat.lng,r.lngLat.lat]),!c&&!i(f(t)))return}var s=o(f(t)).length;e.onClick.call(this,t,r),o(f(t)).length>s&&(this.pushDrawUndo(t),this.dispatchVertexChange(o(f(t))))}},onTap(){},doClick(t){if(!this.map._undoInProgress){var r=f(t),n=o(r);if(this.dispatchVertexChange(n),i(r)){var a=u(this.map),s=y(t)&&function(e,t){var r=p(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,a),l=n.length;s?(e.onClick.call(this,t,s),this._ctx.store.render()):this._simulateMouse("click",e.onClick,t);var d=o(f(t));d.length>l&&(this.pushDrawUndo(t),this.dispatchVertexChange(d))}else c&&n.length>1&&(n.pop(),this.map.fire("draw.create",{features:[r.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[r.id]}))}},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},pushDrawUndo(e){var t=this.map._undoStack;t&&!this.map._undoInProgress&&t.push({type:"draw_vertex",geometryType:n,featureId:f(e).id})},undoVertex(e){var t=f(e),r=o(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_reinitializeFeature(t,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n){var a=this.map._undoStack;return a&&a.clear(),this._ctx.api.changeMode("draw_line",{featureId:i,container:t.container,interfaceType:t.interfaceType,crossHair:t.crossHair,vertexMarkerId:t.vertexMarkerId,addVertexButtonId:t.addVertexButtonId,getSnapEnabled:t.getSnapEnabled,properties:t.properties}),!0}var s=this.map.getCenter(),c=[[s.lng,s.lat],[s.lng,s.lat]],l=this.newFeature({type:"Feature",properties:t.properties||{},geometry:{type:n,coordinates:[c]}});return l.id=i,this._ctx.store.add(l),t[r]=l,t.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render(),this.dispatchVertexChange(c),!0},_removeLastVertex(e,t,r){var i="Polygon"===n?t.coordinates[0]:r;i.splice(-2,1);var a=i[i.length-2];a&&(i[i.length-1]=[...a]),e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,o(t))},_updateRubberBand(t,r){if(["touch","keyboard"].includes(t.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render();else{var o=r["Polygon"===n?r.length-2:r.length-1];if(o){var i={lng:o[0],lat:o[1]},a=this.map.project(i);e.onMouseMove.call(this,t,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render()}}this.dispatchVertexChange(r)},onUndo(e,t){var r;"draw_vertex"===(null===(r=t.operation)||void 0===r?void 0:r.type)&&this.undoVertex(e)},_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)},onCreate(e,t){var r=this._ctx.api,n=t.features[0];r.delete(n.id),n.id=e.featureId,r.add(n,{userProperties:!0})},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;if("INPUT"!==n&&"TEXTAREA"!==n){t.preventDefault(),t.stopPropagation();var o=this.map._undoStack;if(o&&o.length>0){var i=o.pop();"draw_vertex"===(null==i?void 0:i.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e))}}},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),this._setInterface(e,"keyboard"),this.onMove(e,t)):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&(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(t,r){var n=document.activeElement;if(!n||n===t.container||!t.container.contains(n))if("Escape"!==r.key)n!==t.container&&e.onKeyUp.call(this,t,r);else if("keyboard"===t.interfaceType){var o=this.map._undoStack;o&&o.clear(),this._reinitializeFeature(t,f(t))}},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(t,r){if(y(t)){var n=u(this.map);h(n,this.map,r.point);var o=p(n);o&&(r=mo(mo({},r),{},{lngLat:o}))}this.map.fire("draw.geometrychange",t.polygon||t.line),e.onMouseMove.call(this,t,r)},onMove(t){if(["touch","keyboard"].includes(t.interfaceType)){y(t)&&function(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);e.snapToClosestPoint({point:n,lngLat:r})}(u(this.map),this.map);var r=u(this.map),n=y(t)&&p(r);if(n){var o=this.map.project([n.lng,n.lat]);e.onMouseMove.call(this,t,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render()}else this._simulateMouse("mousemove",e.onMouseMove,t)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(o(f(e)))},toDisplayFeatures(t,r,o){e.toDisplayFeatures.call(this,t,r,o);var i=f(t);r.geometry.type===n&&r.id===i.id&&a(r,o,Re)},onStop(t){e.onStop.call(this,t),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),this._hideCrossHair(t)}})},Eo=vo(Ct,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>so(e.coordinates),createVertices:(e,t,r)=>{for(var n=e.geometry.coordinates[0],o=1;o<n.length-2;o++)t(r(e.id,n[o],"0.".concat(o)))}}),bo=vo(Tt,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>ao(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,createVertices:(e,t,r)=>{for(var n=e.geometry.coordinates,o=1;o<n.length-1;o++)t(r(e.id,n[o],"".concat(o)))}}),xo={editStroke:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editVertex:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editMidpoint:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editHalo:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editActive:{light:"rgba(11,12,12,1)",dark:"#ffffff"},splitInvalid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},shapeStroke:"rgba(212,53,28,1)",shapeFill:"rgba(212,53,28,0.1)",strokeWidth:2,snapVertex:"rgba(212,53,28,1)",snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,1)",snapRadius:10,snapLayers:[]},So=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],xo[r]]},Po=e=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":So(e,"fill","shapeFill")}}),wo=e=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":So(e,"stroke","shapeStroke"),"line-width":So(e,"strokeWidth")}}),_o=e=>({id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":e,"fill-opacity":.1}}),Mo=e=>({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":e,"line-width":2,"line-opacity":1}}),Oo=e=>({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":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),Io=e=>({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":e,"line-width":2,"line-opacity":1}}),Co=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}}),To=e=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"]],paint:{"circle-radius":6,"circle-color":e}}),Lo=(e,t)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":8,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Ao=e=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":6,"circle-color":e}}),ko=e=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":4,"circle-color":e}}),Fo=(e,t)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":6,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),No=e=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":4,"circle-color":e}}),Vo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Do=e=>{var t=(e=>{var t;return null!==(t=e.mapColorScheme)&&void 0!==t?t:"light"})(e),r=xo.editStroke[t],n=xo.editVertex[t],o=xo.editMidpoint[t],i=xo.editHalo[t],a=xo.editActive[t],s=xo.splitInvalid[t],c=xo.splitValid[t];return[Po(e),_o(r),Mo(r),wo(e),Oo(s),Io(c),Co(r),ko(o),Fo(i,a),No(o),To(n),Lo(i,a),Ao(n),Vo(r),{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 jo(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 Ro(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 Uo(e,t,r){void 0===r&&(r={});var n=jo(e),o=jo(t),i=ze(o[1]-n[1]),a=ze(o[0]-n[0]),s=ze(n[1]),c=ze(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return $e(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Bo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return qe(e,t);return He(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Go(e,t,r,n){void 0===n&&(n={});var o=jo(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Ye([We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),We(l)],n.properties)}function Yo(e){if(!e)throw new Error("geojson is required");var t=[];return rt(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=Ro(n);break;case"LineString":r=[Ro(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=He([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)}),Je(t)}var Xo={exports:{}};function Ho(e,t,r,n,o){Jo(e,t,r||0,n||e.length-1,o||$o)}function Jo(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);Jo(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(qo(e,r,t),o(e[n],u)>0&&qo(e,r,n);d<p;){for(qo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?qo(e,r,p):qo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function qo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function $o(e,t){return e<t?-1:e>t?1:0}function Ko(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 Wo(e,t){zo(e,0,e.children.length,t,e)}function zo(e,t,r,n,o){o||(o=si(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];Zo(o,e.leaf?n(t):t)}return o}function Zo(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 Qo(e,t){return e.minX-t.minX}function ei(e,t){return e.minY-t.minY}function ti(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ri(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ni(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 oi(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 ii(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function ai(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function si(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ci(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;Ho(e,a,t,r,o),i.push(t,a,a,r)}}var li,ui=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(!ai(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;ai(e,s)&&(t.leaf?r.push(a):ii(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!ai(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(ai(e,i)){if(t.leaf||ii(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=si([]),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=Ko(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!ii(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=si(e.slice(t,r+1)),Wo(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=si([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));ci(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);ci(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 Wo(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=ti(a),c=ni(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),Zo(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=si(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Wo(r,this.toBBox),Wo(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=si([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Wo(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=zo(e,0,a,this.toBBox),s=zo(e,a,r,this.toBBox),c=oi(t,s),l=ti(t)+ti(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:Qo,o=e.leaf?this.compareMinY:ei;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=zo(e,0,t,o),a=zo(e,r-t,r,o);let s=ri(i)+ri(a);for(let n=t;n<r-t;n++){const t=e.children[n];Zo(i,e.leaf?o(t):t),s+=ri(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Zo(a,e.leaf?o(t):t),s+=ri(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Zo(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():Wo(e[r],this.toBBox)}}}),di=q(ui),pi={};function hi(){if(li)return pi;li=1,Object.defineProperty(pi,"__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 pi.areaFactors=r,pi.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},pi.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},pi.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},pi.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)},pi.degreesToRadians=function(e){return e%360*Math.PI/180},pi.earthRadius=e,pi.factors=t,pi.feature=n,pi.featureCollection=s,pi.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")}},pi.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},pi.isNumber=f,pi.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},pi.lengthToDegrees=function(e,t){return h(p(e,t))},pi.lengthToRadians=p,pi.lineString=a,pi.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},pi.multiLineString=c,pi.multiPoint=l,pi.multiPolygon=u,pi.point=o,pi.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},pi.polygon=i,pi.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},pi.radiansToDegrees=h,pi.radiansToLength=d,pi.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},pi.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")})},pi.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")},pi}var fi,gi={};function yi(){if(fi)return gi;fi=1,Object.defineProperty(gi,"__esModule",{value:!0});var e=hi();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 E=0;E<c;E++){var b=0,x=0;if(null!==(s=d?u.geometries[E]:u)){l=s.coordinates;var S=s.type;switch(p=!n||"Polygon"!==S&&"MultiPolygon"!==S?0:1,S){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"===S&&b++}"LineString"===S&&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"===S&&b++,"Polygon"===S&&x++}"Polygon"===S&&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 gi.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},gi.coordEach=t,gi.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},gi.featureEach=n,gi.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},gi.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")},gi.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")},gi.flattenEach=i,gi.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},gi.geomEach=o,gi.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},gi.lineEach=s,gi.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},gi.propEach=r,gi.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},gi.segmentEach=a,gi.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},gi}var mi,vi,Ei={};function bi(){if(mi)return Ei;mi=1,Object.defineProperty(Ei,"__esModule",{value:!0});var e=yi();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 Ei.bbox=t,Ei.default=r,Ei}var xi=function(){if(vi)return Xo.exports;vi=1;var e=di,t=hi(),r=yi(),n=bi().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 Xo.exports=a,Xo.exports.default=a,Xo.exports}(),Si=J(xi);function Pi(e,t){var r={},n=[];if("LineString"===e.type&&(e=Ge(e)),"LineString"===t.type&&(t=Ge(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=wi(e,t);return o&&n.push(o),Je(n)}var i=Si();return i.load(Yo(t)),et(Yo(e),function(e){et(i.search(e),function(t){var o=wi(e,t);if(o){var i=Ro(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),Je(n)}function wi(e,t){var r=Ro(e),n=Ro(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,y=f/p;return g>=0&&g<=1&&y>=0&&y<=1?Ye([o+g*(a-o),i+g*(s-i)]):null}function _i(e,t,r){void 0===r&&(r={});var n=Ye([1/0,1/0],{dist:1/0}),o=0;return rt(e,function(e){for(var i=Ro(e),a=0;a<i.length-1;a++){var s=Ye(i[a]);s.properties.dist=Uo(t,s,r);var c=Ye(i[a+1]);c.properties.dist=Uo(t,c,r);var l=Uo(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=nn(s,c),p=Go(t,u,d+90,r),h=Go(t,u,d-90,r),f=Pi(He([p.geometry.coordinates,h.geometry.coordinates]),He([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Uo(t,g,r),g.properties.location=o+Uo(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 Mi(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 Oi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=Mi(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Ye([We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),We(l)],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=Mi(e),o=Mi(t),i=ze(o[1]-n[1]),a=ze(o[0]-n[0]),s=ze(n[1]),c=ze(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return $e(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,nn(e,t));return r}var Ii=function(){return Ii=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},Ii.apply(this,arguments)},Ci=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=Ii(Ii({},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 Uo(Ye(e),Ye(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=Uo(Ye([r.lng,r.lat]),Ye([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(on(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),Xe([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=Je(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(Je([])))}),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,o=(n=[],Qe(e,function(e){n.push(e)}),n),i=[];if(o.map(function(e){var n=Uo(Ye(e),Ye([t.lng,t.lat]),{units:"meters"});n<r&&i.push({coords:e,dist:n,color:"#8bc34a"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[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(He(e))});break;case"Polygon":var o=Bo(e.geometry);n.push(o);break;case"MultiPolygon":Bo(e.geometry).coodinates.map(function(e){n.push(He(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(Yo(e).features)});var i=[];if(o.map(function(e){var n=Oi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Uo(n,Ye([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=_i(n[i],Ye([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}();function Ti(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var Li="snap-helper-circle";function Ai(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function ki(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})}}function Fi(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:o=[],radius:i=15,rules:a=["vertex","midpoint","edge"],status:s=!1,onSnapped:c=()=>{},colors:l={}}=n;function u(e){if(t._snapInstance||t._snapCreating)return t._snapInstance;t._snapCreating=!0,t.getLayer(Li)&&t.removeLayer(Li),t.getSource(Li)&&t.removeSource(Li),ki(e);var n=new Ci({map:t,drawing:r,options:{layers:o,radius:i,rules:a},status:s,onSnapped:c}),l=s;return Object.defineProperty(n,"status",{get:()=>l,set(){},configurable:!0}),n.setSnapStatus=e=>{l=e},n._defaultLayers=o,n._activeLayers=null,n.setSnapLayers=e=>{null==e?n._activeLayers=null:Array.isArray(e)&&(n._activeLayers=e)},void 0!==t._pendingSnapLayers&&(n.setSnapLayers(t._pendingSnapLayers),delete t._pendingSnapLayers),t._snapInstance=n,n}!function(e){if(!Ci.prototype.__snapPatched){Ci.prototype.__snapPatched=!0;var t=Ci.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=()=>{},t.setMapData=function(e){var t,n;if(this.status){var o=r.setMapData.call(this,e);return(null==e||null===(t=e.features)||void 0===t?void 0:t.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(Li)&&this.map.setLayoutProperty(Li,"visibility","visible"),o}},t.drawingSnapCheck=function(){if(this.status)return r.drawingSnapCheck.call(this)},t.getLines=function(e,t,n){var o=e.geometry;if(!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=>Xe(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>He(e)):r.getLines.call(this,e,t,n)}catch(e){return console.log(e),[]}},t.getCloseFeatures=function(e,t){if(!this.status)return[];var n=this._activeLayers||this._defaultLayers||[];this.options.layers=n.filter(e=>this.map.getLayer(e));var o=this.options.radius||15,i=e.point;e.point=[[i.x-o,i.y-o],[i.x+o,i.y+o]];var a=r.getCloseFeatures.call(this,e,t);return e.point=i,a},t.searchInVertex=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInVertex.apply(this,n);return i&&(i.color=e.vertex),i},t.searchInMidPoint=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInMidPoint.apply(this,n);return i&&(i.color=e.midpoint),i},t.searchInEdge=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInEdge.apply(this,n);return i&&(i.color=e.edge),i},t.snapToClosestPoint=function(e){var t;if(this.status&&(null===(t=this.map)||void 0===t||!t._isZooming))try{var n,o,i=r.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){console.log(e),this.snapStatus=!1,this.snapCoords=null}}}}(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ti(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ti(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:xo.snapVertex,midpoint:xo.snapMidpoint,edge:xo.snapEdge},l)),t.on("style.load",()=>{Ai(()=>t._removed?null:t.getSource("mapbox-gl-draw-hot"),e=>{var r;(ki(e),t.getSource(Li)||t.addSource(Li,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),t.getLayer(Li))||t.addLayer({id:Li,type:"fill",source:Li,paint:{"fill-color":["get","color"],"fill-opacity":.6},layout:{visibility:null!==(r=t._snapInstance)&&void 0!==r&&r.status?"visible":"none"}});t._snapInstance||u(e)})}),t.on("zoomstart",()=>{t._isZooming=!0}),t.on("zoomend",()=>{if(t._isZooming=!1,t.getLayer(Li)){t.setLayoutProperty(Li,"visibility","none");var e=t._snapInstance;null!=e&&e.status&&t.setLayoutProperty(Li,"visibility","visible")}}),Ai(()=>t._removed?null:t.getSource("mapbox-gl-draw-hot"),u)}function Ni(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 Vi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ni(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ni(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Di=e=>{var{mapStyle:t,mapProvider:r,events:n,eventBus:o,snapLayers:i}=e,{map:a}=r;$t.constants.classes.CONTROL_BASE="maplibregl-ctrl",$t.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",$t.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var s=new $t({modes:Vi(Vi({},$t.modes),{},{disabled:Kt,edit_vertex:go,draw_polygon:Eo,draw_line:bo}),styles:Do(t),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"});a.addControl(s);var c=a.getCanvas(),l=null,u=e=>{1===e.touches.length&&(l={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},d=e=>{if("disabled"===s.getMode()&&l){var t=e.changedTouches[0],r=t.clientX-l.x,n=t.clientY-l.y;Date.now()-l.time<300&&Math.abs(r)<10&&Math.abs(n)<10&&c.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:t.clientX,clientY:t.clientY})),l=null}else l=null};c.addEventListener("touchstart",u,{passive:!0}),c.addEventListener("touchend",d,{passive:!0}),r.draw=s,a._drawCurrentMapStyle=t,r.snapEnabled=!1;var p=(e=>{var t=[],r=()=>{e.fire("draw.undochange",{length:t.length})};return{push(e){t.push(e),r()},pop(){var e=t.pop();return r(),e},clear(){t.length=0,r()},get length(){return t.length}}})(a);r.undoStack=p,a._undoStack=p,Fi(a,s,{layers:i,radius:10,rules:["vertex","edge"]});var h=e=>{a._drawCurrentMapStyle=e,a.once("idle",()=>{var t;((e,t)=>{Do(t).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)})})})(a,e);var r=null===(t=a._drawEditContainer)||void 0===t?void 0:t.querySelector("[data-touch-vertex-target]");ar(r,e)})};o.on(n.MAP_SET_STYLE,h);return o.on(n.MAP_SET_SIZE,e=>{a.fire("draw.scalechange",{scale:{small:1,medium:1.5,large:2}[e]})}),{draw:s,remove(){c.removeEventListener("touchstart",u),c.removeEventListener("touchend",d),o.off(n.MAP_SET_STYLE,h),s.deleteAll(),s.changeMode("disabled"),a.removeControl(s)}}},ji=["stroke","fill","strokeWidth"],Ri=e=>{if(!e)return{};var t={};for(var[r,n]of Object.entries(e))if(ji.includes(r)&&"object"==typeof n&&null!==n){var o=Object.entries(n);for(var[i,a]of(o.length>0&&(t[r]=o[0][1]),o))t["".concat(r).concat(i.charAt(0).toUpperCase()+i.slice(1))]=a}else t[r]=n;return t},Ui=["stroke","fill","strokeWidth","properties"];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 Yi=["stroke","fill","strokeWidth","properties"];function Xi(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 Hi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ji=["stroke","fill","strokeWidth","properties"];function qi(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 $i(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ki(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){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ki(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ki(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zi=e=>({mobile:{slot:"actions",showLabel:e},tablet:{slot:"actions",showLabel:e},desktop:{slot:"actions",showLabel:e}}),Zi={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertecies:null,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:a},InitComponent:e=>{var{appState:r,appConfig:n,mapState:o,pluginConfig:i,pluginState:a,services:c,mapProvider:l,buttonConfig:d}=e,{eventBus:p}=c,{crossHair:h}=o,y=["touch","keyboard"].includes(r.interfaceType);t(()=>{var e,t,n,c,u,d=null===(e=null===(t=i.includeModes)||void 0===t?void 0:t.includes(r.mode))||void 0===e||e,h=null!==(n=null===(c=i.excludeModes)||void 0===c?void 0:c.includes(r.mode))&&void 0!==n&&n;if(o.isMapReady&&d&&!h){var{remove:f}=Di({mapStyle:o.mapStyle,snapLayers:i.snapLayers,mapProvider:l,events:s,eventBus:p});return a.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:(null===(u=i.snapLayers)||void 0===u?void 0:u.length)>0}),p.emit("draw:ready"),()=>f()}},[o.isMapReady,r.mode]),t(()=>{l.draw&&(l.draw._crossHair=h)},[l.draw,h]),t(()=>{if(["draw_polygon","draw_line"].includes(a.mode)&&y){var e=h.isVisible;return h.fixAtCenter(),()=>{e||h.hide()}}},[a.mode,r.interfaceType]),t(()=>{"edit_vertex"===a.mode&&l.map&&l.map.fire("draw.interfacetypechange",{interfaceType:r.interfaceType})},[r.interfaceType,a.mode]),t(()=>{if(l.draw){var e=function(e){var{pluginState:t,mapProvider:r,buttonConfig:n,eventBus:o}=e,{drawDone:i,drawAddPoint:a,drawUndo:s,drawDeletePoint:c,drawSnap:l,drawCancel:d}=n,{map:p,draw:h}=r,{dispatch:y,feature:m,tempFeature:v}=t,E=()=>{r.snapEnabled=!1,y({type:"SET_SNAP",payload:!1});var e,t=u(p);t&&(null===(e=t.setSnapStatus)||void 0===e||e.call(t,!1),g(t)),p.getLayer("snap-helper-circle")&&p.setLayoutProperty("snap-helper-circle","visibility","none")},b=()=>{var e;null===(e=r.undoStack)||void 0===e||e.clear(),y({type:"SET_MODE",payload:null}),y({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},x=()=>{h.trash(),null!=v&&v.id&&h.delete(v.id),m&&h.add(m),E(),h.changeMode("disabled"),b(),o.emit("draw:cancelled",m)},S=0,P=["draw_polygon","draw_line"],w=e=>{P.includes(e.mode)||f(u(p),p)},_=()=>{var e,t=p.getStyle().layers||[];!t.length||null!==(e=t[t.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||t.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>p.moveLayer(e.id))},M=e=>t=>{var r=t.features[0];E(),b(),setTimeout(()=>h.changeMode("disabled"),0),o.emit(e,r)},O=e=>{var t=e.features[0];o.emit("draw:updated",t)},I=M("draw:created"),C=M("draw:edited"),T=e=>{y({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),o.emit("draw:vertexselection",e)},L=e=>{y({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertecies:e.numVertecies}})},A=e=>{y({type:"SET_UNDO_STACK_LENGTH",payload:e.length})};return i.onClick=()=>{var e,t=h.getMode();E(),null===(e=r.undoStack)||void 0===e||e.clear(),"edit_vertex"!==t?["draw_polygon","draw_line"].includes(t)&&h.changeMode("disabled"):p.fire("draw.editfinish",{features:[h.get(v.id)]})},d.onClick=x,s.onClick=()=>{if("edit_vertex"!==h.getMode()){var e=r.undoStack;if(null!=e&&e.length){var t=e.pop();p._undoInProgress=!0,setTimeout(()=>{p._undoInProgress=!1},100),p.fire("draw.undo",{operation:t})}}},l.onClick=()=>{var e=Date.now();if(!(e-S<300)){S=e;var n=!t.snap;y({type:"TOGGLE_SNAP"}),r.snapEnabled=n;var o=u(p);null!=o&&o.setSnapStatus&&o.setSnapStatus(n),!n&&o&&(g(o),p.getLayer("snap-helper-circle")&&p.setLayoutProperty("snap-helper-circle","visibility","none"))}},p.on("styledata",_),p.on("draw.cancel",x),p.on("draw.create",I),p.on("draw.modechange",w),p.on("draw.editfinish",C),p.on("draw.update",O),p.on("draw.vertexselection",T),p.on("draw.vertexchange",L),p.on("draw.undochange",A),()=>{[i,a,s,c,l,d].forEach(e=>{e&&(e.onClick=null)}),p.off("styledata",_),p.off("draw.cancel",x),p.off("draw.create",I),p.off("draw.editfinish",C),p.off("draw.update",O),p.off("draw.modechange",w),p.off("draw.vertexselection",T),p.off("draw.vertexchange",L),p.off("draw.undochange",A)}}({mapProvider:l,buttonConfig:d,pluginState:a,eventBus:p});return()=>e()}},[l,r,a])},buttons:[Wi({id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode}},zi(!0)),Wi({id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:e=>{var{appState:t,pluginState:r}=e;return!["draw_polygon","draw_line"].includes(r.mode)||"touch"!==t.interfaceType}},zi(!0)),Wi({id:"drawDone",label:"Done",variant:"primary",exclusiveSlot:!0,hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return t.numVertecies>=("draw_polygon"===t.mode?3:2)}},zi(!0)),{id:"drawMenu",label:"Menu",iconId:"menu",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},menuItems:[{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return t.undoStackLength>0}},{id:"drawSnap",label:"Snap to feature",iconId:"magnet",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode||!t.hasSnapLayers},pressedWhen:e=>{var{pluginState:t}=e;return!!t.snap}},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:e=>{var t,{pluginState:r}=e;return r.selectedVertexIndex>=0&&r.numVertecies>("Polygon"===(null===(t=r.tempFeature)||void 0===t||null===(t=t.geometry)||void 0===t?void 0:t.type)?3:2)},hiddenWhen:e=>{var{pluginState:t}=e;return!["simple_select","edit_vertex"].includes(t.mode)}}],mobile:{slot:"bottom-right"},tablet:{slot:"top-middle"},desktop:{slot:"top-middle"}}],keyboardShortcuts:[{id:"drawStart",group:"Drawing",title:"Edit vertex",command:"<kbd>Spacebar</kbd></dd>"}],icons:[{id:"menu",svgContent:'<path d="m6 9 6 6 6-6"/>'},{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"check",svgContent:'<path d="M20 6 9 17l-5-5"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(h){g.emit("draw:started",{mode:"draw_polygon"});var y=null;y=void 0!==d.snapLayers?d.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=u(f);null!=m&&m.setSnapLayers?m.setSnapLayers(y):y&&(f._pendingSnapLayers=y),p({type:"SET_HAS_SNAP_LAYERS",payload:(null===(n=y)||void 0===n?void 0:n.length)>0});var{stroke:v,fill:E,strokeWidth:b,properties:x}=d,S=r(d,Ui),P=Gi(Gi({},x),Ri({stroke:v,fill:E,strokeWidth:b}));h.changeMode("draw_polygon",Gi(Gi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,crossHair:h._crossHair,getSnapEnabled:()=>!0===c.snapEnabled,featureId:t},S),{},{properties:P})),p({type:"SET_MODE",payload:"draw_polygon"})}},newLine:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(h){g.emit("draw:started",{mode:"draw_line"});var y=null;y=void 0!==d.snapLayers?d.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=u(f);null!=m&&m.setSnapLayers?m.setSnapLayers(y):y&&(f._pendingSnapLayers=y),p({type:"SET_HAS_SNAP_LAYERS",payload:(null===(n=y)||void 0===n?void 0:n.length)>0});var{stroke:v,fill:E,strokeWidth:b,properties:x}=d,S=r(d,Yi),P=Hi(Hi({},x),Ri({stroke:v,fill:E,strokeWidth:b}));h.changeMode("draw_line",Hi(Hi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,crossHair:h._crossHair,getSnapEnabled:()=>!0===c.snapEnabled,featureId:t},S),{},{properties:P})),p({type:"SET_MODE",payload:"draw_line"})}},editFeature:function(e,t){var r,{appState:n,appConfig:o,mapState:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(!h)return!1;var y=h.get(t);if(!y)return!1;g.emit("draw:editstart",{mode:{LineString:"edit_line",Polygon:"edit_polygon"}[y.geometry.type]});var m,v=null;void 0===d.snapLayers?v=null!==(m=a.snapLayers)&&void 0!==m?m:null:v=d.snapLayers;var E=u(f);null!=E&&E.setSnapLayers?E.setSnapLayers(v):v&&(f._pendingSnapLayers=v),p({type:"SET_HAS_SNAP_LAYERS",payload:(null===(r=v)||void 0===r?void 0:r.length)>0}),h.changeMode("edit_vertex",{container:n.layoutRefs.viewportRef.current,deleteVertexButtonId:"".concat(o.id,"-draw-delete-point"),undoButtonId:"".concat(o.id,"-draw-undo"),isPanEnabled:"keyboard"!==n.interfaceType,interfaceType:n.interfaceType,scale:{small:1,medium:1.5,large:2}[i.mapSize],featureId:t,getSnapEnabled:()=>!0===c.snapEnabled});var b=h.get(t);return p({type:"SET_FEATURE",payload:{feature:b,tempFeature:b}}),p({type:"SET_MODE",payload:"edit_vertex"}),!0},addFeature:(e,t)=>{var{mapProvider:n,services:o}=e,{draw:i}=n,{eventBus:a}=o;if(i){var{stroke:s,fill:c,strokeWidth:l,properties:u}=t,d=$i($i({},r(t,Ji)),{},{properties:$i($i({},u),Ri({stroke:s,fill:c,strokeWidth:l}))});i.add(d,{userProperties:!0}),a.emit("draw:add",d)}},deleteFeature:(e,t)=>{var{mapProvider:r,services:n}=e,{draw:o}=r,{eventBus:i}=n;o&&(o.delete(t),i.emit("draw:delete",{featureIds:t}))},split:function(e,t){var{appState:r,appConfig:n,pluginState:o,mapProvider:i}=e,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:s}=o,{draw:c,map:l}=i;if(c){var d=c.get(t),p=["stroke-inactive.cold",...a.snapLayers||[]],h=u(l);null!=h&&h.setSnapLayers?h.setSnapLayers(p):a.snapLayers&&(l._pendingSnapLayers=p),s({type:"SET_HAS_SNAP_LAYERS",payload:!0}),c.changeMode("draw_line",{container:r.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(n.id,"-cross-hair"),addVertexButtonId:"".concat(n.id,"-draw-add-point"),interfaceType:r.interfaceType,getSnapEnabled:()=>!0===i.snapEnabled,featureId:"_splitter",properties:{splitter:"invalid"}}),l.on("draw.create",e=>{var t=e.features[0],r=oo(d,t);c.setFeatureProperty("_splitter","splitter",r?"valid":"invalid"),s({type:"SET_ACTION",payload:{name:"split",isValid:!!r}})});var f,g,y,m,v=(f=e=>{if(!(e.coordinates.length<2)){var t={id:"_splitter",geometry:{type:"LineString",coordinates:e.coordinates}},r=!!oo(d,t);e.properties.splitter=r?"valid":"invalid",e.ctx.store.render(),"edit_vertex"===c.getMode()&&s({type:"SET_ACTION",payload:{name:"split",isValid:r}})}},g=50,m=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];clearTimeout(y),y=setTimeout(()=>f(...t),g)},m.cancel=()=>{clearTimeout(y),y=null},m);l.on("draw.geometrychange",v),s({type:"SET_MODE",payload:"draw_line"}),s({type:"SET_ACTION",payload:{name:"split"}})}},merge:(e,t)=>{var{services:r}=e;console.log("merge"),console.log(t)}}};export{Zi as manifest};