@defra/interactive-map 0.0.9-alpha → 0.0.11-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 (120) hide show
  1. package/DOCS_README.md +39 -0
  2. package/README.md +1 -1
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/button-definition.md +21 -3
  9. package/docs/api/panel-definition.md +10 -12
  10. package/docs/api.md +81 -8
  11. package/docs/architecture/architecture-diagrams.md +1 -3
  12. package/docs/architecture/diagrams-viewer.mdx +12 -0
  13. package/docs/demo.mdx +70 -0
  14. package/docs/govuk-prototype.md +23 -0
  15. package/docs/index.md +19 -0
  16. package/docs/plugins/plugin-context.md +3 -3
  17. package/docs/plugins/plugin-manifest.md +1 -1
  18. package/docusaurus.config.cjs +136 -0
  19. package/mise.toml +2 -0
  20. package/package.json +27 -5
  21. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
  22. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
  23. package/plugins/beta/datasets/src/manifest.js +3 -3
  24. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  25. package/plugins/beta/draw-es/src/api/newPolygon.js +1 -3
  26. package/plugins/beta/draw-es/src/events.js +2 -2
  27. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  28. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  29. package/plugins/beta/draw-ml/src/api/newLine.js +2 -2
  30. package/plugins/beta/draw-ml/src/api/newPolygon.js +2 -2
  31. package/plugins/beta/draw-ml/src/events.js +18 -10
  32. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  33. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  34. package/plugins/beta/map-styles/src/manifest.js +3 -3
  35. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  36. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  37. package/plugins/beta/use-location/src/manifest.js +7 -7
  38. package/plugins/search/dist/css/index.css +1 -1
  39. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  40. package/plugins/search/dist/esm/index.js +1 -1
  41. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  42. package/plugins/search/dist/umd/index.js +1 -1
  43. package/plugins/search/src/Search.jsx +9 -3
  44. package/plugins/search/src/Search.test.jsx +190 -0
  45. package/plugins/search/src/components/CloseButton/CloseButton.test.jsx +67 -0
  46. package/plugins/search/src/components/Form/Form.jsx +35 -7
  47. package/plugins/search/src/components/Form/Form.module.scss +27 -0
  48. package/plugins/search/src/components/Form/Form.test.jsx +255 -0
  49. package/plugins/search/src/components/OpenButton/OpenButton.test.jsx +47 -0
  50. package/plugins/search/src/components/SubmitButton/SubmitButton.jsx +28 -0
  51. package/plugins/search/src/components/SubmitButton/SubmitButton.module.scss +8 -0
  52. package/plugins/search/src/components/SubmitButton/SubmitButton.test.jsx +33 -0
  53. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +79 -0
  54. package/plugins/search/src/datasets.js +15 -11
  55. package/plugins/search/src/datasets.test.js +61 -0
  56. package/plugins/search/src/events/fetchSuggestions.js +1 -1
  57. package/plugins/search/src/events/fetchSuggestions.test.js +212 -0
  58. package/plugins/search/src/events/formHandlers.test.js +232 -0
  59. package/plugins/search/src/events/index.test.js +118 -0
  60. package/plugins/search/src/events/inputHandlers.test.js +104 -0
  61. package/plugins/search/src/events/suggestionHandlers.test.js +166 -0
  62. package/plugins/search/src/index.js +1 -1
  63. package/plugins/search/src/index.test.js +47 -0
  64. package/plugins/search/src/reducer.js +9 -4
  65. package/plugins/search/src/reducer.test.js +85 -0
  66. package/plugins/search/src/search.scss +5 -1
  67. package/plugins/search/src/utils/parseOsNamesResults.js +20 -3
  68. package/plugins/search/src/utils/parseOsNamesResults.test.js +158 -0
  69. package/plugins/search/src/utils/updateMap.test.js +52 -0
  70. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  71. package/providers/beta/esri/src/appEvents.js +8 -2
  72. package/providers/beta/esri/src/esriProvider.js +6 -14
  73. package/providers/beta/esri/src/mapEvents.js +7 -1
  74. package/providers/beta/esri/src/utils/coords.js +33 -1
  75. package/providers/beta/esri/src/utils/coords.test.js +126 -0
  76. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  77. package/providers/maplibre/dist/esm/index.js +1 -1
  78. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  79. package/providers/maplibre/dist/umd/index.js +1 -1
  80. package/providers/maplibre/src/appEvents.js +10 -1
  81. package/providers/maplibre/src/appEvents.test.js +13 -4
  82. package/providers/maplibre/src/index.js +5 -13
  83. package/providers/maplibre/src/index.test.js +34 -15
  84. package/providers/maplibre/src/mapEvents.js +9 -1
  85. package/providers/maplibre/src/maplibreProvider.js +14 -15
  86. package/providers/maplibre/src/maplibreProvider.test.js +14 -1
  87. package/providers/maplibre/src/utils/spatial.js +11 -0
  88. package/providers/maplibre/src/utils/spatial.test.js +12 -0
  89. package/src/App/components/Actions/Actions.module.scss +5 -4
  90. package/src/App/components/MapButton/MapButton.jsx +4 -16
  91. package/src/App/components/MapButton/MapButton.module.scss +12 -12
  92. package/src/App/components/MapButton/MapButton.test.jsx +0 -9
  93. package/src/App/components/Panel/Panel.jsx +6 -6
  94. package/src/App/components/Panel/Panel.test.jsx +14 -15
  95. package/src/App/components/Viewport/MapController.jsx +2 -1
  96. package/src/App/hooks/useLayoutMeasurements.js +1 -1
  97. package/src/App/hooks/useLayoutMeasurements.test.js +1 -1
  98. package/src/App/hooks/useMapProviderOverrides.js +21 -1
  99. package/src/App/hooks/useMapProviderOverrides.test.js +51 -2
  100. package/src/App/layout/Layout.jsx +4 -4
  101. package/src/App/layout/layout.module.scss +1 -0
  102. package/src/App/registry/panelRegistry.js +1 -10
  103. package/src/App/registry/panelRegistry.test.js +6 -11
  104. package/src/App/renderer/HtmlElementHost.jsx +11 -3
  105. package/src/App/renderer/HtmlElementHost.test.jsx +89 -0
  106. package/src/App/renderer/mapButtons.js +128 -28
  107. package/src/App/renderer/mapButtons.test.js +119 -19
  108. package/src/App/store/MapProvider.jsx +18 -5
  109. package/src/App/store/MapProvider.test.jsx +56 -1
  110. package/src/App/store/appActionsMap.js +17 -9
  111. package/src/App/store/appActionsMap.test.js +33 -7
  112. package/src/App/store/mapActionsMap.js +4 -7
  113. package/src/InteractiveMap/InteractiveMap.js +18 -0
  114. package/src/InteractiveMap/InteractiveMap.test.js +12 -0
  115. package/src/config/appConfig.js +17 -15
  116. package/src/config/events.js +41 -4
  117. package/src/config/getInitialOpenPanels.js +2 -2
  118. package/src/config/getInitialOpenPanels.test.js +7 -7
  119. package/src/types.js +13 -11
  120. package/src/utils/getValueForStyle.js +1 -1
@@ -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={SET_MODE:(e,t)=>o(o({},e),{},{mode:t}),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})};function a(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 s(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?a(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function c(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function l(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 u(e){return l(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function d(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function p(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 h(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 f(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}const g={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"},y={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},m={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},v={POLYGON:"polygon",LINE:"line_string",POINT:"point"},b={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},E={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},x={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"},S={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},w={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},P={ACTIVE:"true",INACTIVE:"false"},M=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var _=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:P,classes:g,cursors:m,events:x,geojsonTypes:b,interactions:M,meta:w,modes:E,sources:y,types:v,updateActions:S});function O(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function I(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function C(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===P.ACTIVE&&e.featureTarget.properties.meta===w.FEATURE))}function T(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===P.INACTIVE&&e.featureTarget.properties.meta===w.FEATURE))}function L(e){return void 0===e.featureTarget}function k(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===w.FEATURE)}function A(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===w.VERTEX)}function F(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function N(e){return"Escape"===e.key||27===e.keyCode}function V(e){return"Enter"===e.key||13===e.keyCode}function j(e){return"Backspace"===e.key||8===e.keyCode}function D(e){return"Delete"===e.key||46===e.keyCode}function R(e){return"1"===e.key||49===e.keyCode}function U(e){return"2"===e.key||50===e.keyCode}function B(e){return"3"===e.key||51===e.keyCode}function G(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var Y=Object.freeze({__proto__:null,isActiveFeature:C,isBackspaceKey:j,isDeleteKey:D,isDigit1Key:R,isDigit2Key:U,isDigit3Key:B,isDigitKey:G,isEnterKey:V,isEscapeKey:N,isFeature:k,isInactiveFeature:T,isOfMetaType:O,isShiftDown:F,isShiftMousedown:I,isTrue:function(){return!0},isVertex:A,noTarget:L});function X(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function J(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 H,q,$={},W={};function K(){return H||(H=1,W.RADIUS=6378137,W.FLATTENING=1/298.257223563,W.POLAR_RADIUS=6356752.3142),W}var z=function(){if(q)return $;q=1;var e=K();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 $.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}},$.ring=r,$}(),Z=X(z);const Q={Point:0,LineString:1,MultiLineString:1,Polygon:2};function ee(e,t){const r=Q[e.geometry.type]-Q[t.geometry.type];return 0===r&&e.geometry.type===b.POLYGON?e.area-t.area:r}function te(e){return e.map(e=>(e.geometry.type===b.POLYGON&&(e.area=Z.geometry({type:b.FEATURE,property:{},geometry:e.geometry})),e)).sort(ee).map(e=>(delete e.area,e))}function re(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function ne(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)}ne.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},ne.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},ne.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},ne.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)},ne.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const oe=[w.FEATURE,w.MIDPOINT,w.VERTEX];var ie={click:function(e,t,r){return ae(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return ae(e,t,r,r.options.touchBuffer)}};function ae(e,t,r,n){if(null===r.map)return[];const o=e?re(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==oe.indexOf(e.properties.meta)),s=new ne,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),te(c)}function se(e,t){const r=ie.click(e,null,t),n={mouse:m.NONE};return r[0]&&(n.mouse=r[0].properties.active===P.ACTIVE?m.MOVE:m.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=m.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function ce(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function le(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=ce(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function ue(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 ce(e.point,t.point)<n&&t.time-e.time<o}const de=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 pe=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function he(){return pe()}const fe=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||he(),this.type=t.geometry.type};fe.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},fe.prototype.incomingCoords=function(e){this.setCoordinates(e)},fe.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},fe.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},fe.prototype.setProperty=function(e,t){this.properties[e]=t},fe.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:b.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},fe.prototype.internal=function(e){const t={id:this.id,meta:w.FEATURE,"meta:type":this.type,active:P.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:b.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const ge=function(e,t){fe.call(this,e,t)};(ge.prototype=Object.create(fe.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},ge.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},ge.prototype.getCoordinate=function(){return this.getCoordinates()};const ye=function(e,t){fe.call(this,e,t)};(ye.prototype=Object.create(fe.prototype)).isValid=function(){return this.coordinates.length>1},ye.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},ye.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},ye.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},ye.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const me=function(e,t){fe.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(me.prototype=Object.create(fe.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},me.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},me.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},me.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])},me.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))},me.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]]))},me.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},me.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const ve={MultiPoint:ge,MultiLineString:ye,MultiPolygon:me},be=(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)},Ee=function(e,t){if(fe.call(this,e,t),delete this.coordinates,this.model=ve[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function xe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ee.prototype=Object.create(fe.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:he(),type:b.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ee.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ee.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ee.prototype.getCoordinate=function(e){return be(this.features,"getCoordinate",e)},Ee.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===b.POLYGON?e.getCoordinates():e.coordinates)))},Ee.prototype.updateCoordinate=function(e,t,r){be(this.features,"updateCoordinate",e,t,r),this.changed()},Ee.prototype.addCoordinate=function(e,t,r){be(this.features,"addCoordinate",e,t,r),this.changed()},Ee.prototype.removeCoordinate=function(e){be(this.features,"removeCoordinate",e),this.changed()},Ee.prototype.getFeatures=function(){return this.features},xe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},xe.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),{})},xe.prototype.getSelected=function(){return this._ctx.store.getSelected()},xe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},xe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},xe.prototype.getFeature=function(e){return this._ctx.store.get(e)},xe.prototype.select=function(e){return this._ctx.store.select(e)},xe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},xe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},xe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},xe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},xe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},xe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},xe.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},xe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},xe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},xe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},xe.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return ie[r](e,t,this._ctx)},xe.prototype.newFeature=function(e){const t=e.geometry.type;return t===b.POINT?new ge(this._ctx,e):t===b.LINE_STRING?new ye(this._ctx,e):t===b.POLYGON?new me(this._ctx,e):new Ee(this._ctx,e)},xe.prototype.isInstanceOf=function(e,t){if(e===b.POINT)return t instanceof ge;if(e===b.LINE_STRING)return t instanceof ye;if(e===b.POLYGON)return t instanceof me;if("MultiFeature"===e)return t instanceof Ee;throw new Error(`Unknown feature class: ${e}`)},xe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},xe.prototype.onSetup=function(){},xe.prototype.onDrag=function(){},xe.prototype.onClick=function(){},xe.prototype.onMouseMove=function(){},xe.prototype.onMouseDown=function(){},xe.prototype.onMouseUp=function(){},xe.prototype.onMouseOut=function(){},xe.prototype.onKeyUp=function(){},xe.prototype.onKeyDown=function(){},xe.prototype.onTouchStart=function(){},xe.prototype.onTouchMove=function(){},xe.prototype.onTouchEnd=function(){},xe.prototype.onTap=function(){},xe.prototype.onStop=function(){},xe.prototype.onTrash=function(){},xe.prototype.onCombineFeature=function(){},xe.prototype.onUncombineFeature=function(){},xe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Se={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},we=Object.keys(Se);function Pe(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new xe(r));return{start(){o=i.onSetup(n),we.forEach(t=>{const r=Se[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 Me(e){return[].concat(e).filter(e=>void 0!==e)}function _e(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(y.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(y.COLD).setData({type:b.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(y.HOT).setData({type:b.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Oe(e){let t;this._features={},this._featureIds=new ne,this._selectedFeatureIds=new ne,this._selectedCoordinates=[],this._changedFeatureIds=new ne,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,_e.call(this),this._emitSelectionChange&&(this.ctx.events.fire(x.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:b.FEATURE,properties:{},geometry:{type:b.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(x.RENDER,{})}))},this.isDirty=!1}function Ie(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}Oe.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Oe.prototype.setDirty=function(){return this.isDirty=!0,this},Oe.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(x.CREATE,{features:[t.toGeoJSON()]})}return this},Oe.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(x.UPDATE,{action:t.action?t.action:S.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Oe.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Oe.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Oe.prototype.getAllIds=function(){return this._featureIds.values()},Oe.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Oe.prototype.delete=function(e,t={}){const r=[];return Me(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(x.DELETE,{features:r}),Ie(this,t),this},Oe.prototype.get=function(e){return this._features[e]},Oe.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Oe.prototype.select=function(e,t={}){return Me(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Oe.prototype.deselect=function(e,t={}){return Me(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Ie(this,t),this},Oe.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Oe.prototype.setSelected=function(e,t={}){return e=Me(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},Oe.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Oe.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Oe.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Oe.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Oe.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Oe.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Oe.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:S.CHANGE_PROPERTIES})},Oe.prototype.storeMapConfig=function(){M.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Oe.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Oe.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Ce=["mode","feature","mouse"];function Te(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]=Pe(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:m.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!le(r,e))},o.touchdrag=function(e){o.drag(e,e=>!ue(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=se(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=se(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=se(t,e);t.featureTarget=n,le(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=ie.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=ie.touch(t,null,e)[0];t.featureTarget=r,ue(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=j(e),r=D(e),n=G(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=de(c,e),o.silent||e.map.fire(x.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(g.CANVAS)&&((j(t)||D(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):R(t)&&e.options.controls.point?c(E.DRAW_POINT):U(t)&&e.options.controls.line_string?c(E.DRAW_LINE_STRING):B(t)&&e.options.controls.polygon&&c(E.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=de(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(x.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=[];Ce.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=`${g.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(g.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(g.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=`${g.CONTROL_GROUP} ${g.CONTROL_BASE}`,r?(r[v.POINT]&&(t[v.POINT]=s(v.POINT,{container:n,className:g.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(E.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[v.LINE]&&(t[v.LINE]=s(v.LINE,{container:n,className:g.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(E.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[v.POLYGON]&&(t[v.POLYGON]=s(v.POLYGON,{container:n,className:g.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(E.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:g.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:g.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:g.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 Oe(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(y.COLD,{data:{type:b.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(y.HOT,{data:{type:b.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(y.COLD)&&e.map.removeSource(y.COLD),e.map.getSource(y.HOT)&&e.map.removeSource(y.HOT)}};return e.setup=n,n}const Le="#3bb2d0",ke="#fbb03b",Ae="#fff";var Fe=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],ke,Le],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],ke,Le],"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":Ae}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],ke,Le]}},{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":Ae}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":ke}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":ke}}];function Ne(e,t){this.x=e,this.y=t}function Ve(e,t){const r=t.getBoundingClientRect();return new Ne(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function je(e,t,r,n){return{type:b.FEATURE,properties:{meta:w.VERTEX,parent:e,coord_path:r,active:n?P.ACTIVE:P.INACTIVE},geometry:{type:b.POINT,coordinates:t}}}Ne.prototype={clone(){return new Ne(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:Ne},Ne.convert=function(e){if(e instanceof Ne)return e;if(Array.isArray(e))return new Ne(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Ne(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var De=6371008.8,Re={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*De,kilometers:6371.0088,kilometres:6371.0088,meters:De,metres:De,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:De/1852,radians:1,yards:6967335.223679999};function Ue(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 Be(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(!Ke(e[0])||!Ke(e[1]))throw new Error("coordinates must contain numbers");return Ue({type:"Point",coordinates:e},t,r)}function Ge(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 Ue({type:"Polygon",coordinates:e},t,r)}function Ye(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return Ue({type:"LineString",coordinates:e},t,r)}function Xe(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function Je(e,t,r={}){return Ue({type:"MultiLineString",coordinates:e},t,r)}function He(e,t="kilometers"){const r=Re[t];if(!r)throw new Error(t+" units is invalid");return e*r}function qe(e,t="kilometers"){const r=Re[t];if(!r)throw new Error(t+" units is invalid");return e/r}function $e(e){return 180*(e%(2*Math.PI))/Math.PI}function We(e){return e%360*Math.PI/180}function Ke(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function ze(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 b=0,E=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,b,E))return!1;p++,b++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===t(c[n],p,m,b,E))return!1;p++,"MultiPoint"===x&&b++}"LineString"===x&&b++;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,b,E))return!1;p++}"MultiLineString"===x&&b++,"Polygon"===x&&E++}"Polygon"===x&&b++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(E=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,b,E))return!1;p++}E++}b++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===ze(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ze(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 Qe(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 et(e,t){Qe(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(Ue(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(Ue({type:a,coordinates:l},n),r,c))return!1}})}function tt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return rt(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=>rt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ot(e);default:throw new Error("unknown GeoJSON type")}}function rt(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=nt(e.properties),null==e.geometry?t.geometry=null:t.geometry=ot(e.geometry),t}function nt(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]=nt(n):t[r]=n}),t):t}function ot(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ot(e)),t):(t.coordinates=it(e.coordinates),t)}function it(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>it(e))}function at(e,t={}){return st(e,"mercator",t)}function st(e,t,r={}){var n=(r=r||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&Ke(e[0])?e="mercator"===t?ct(e):lt(e):(!0!==n&&(e=tt(e)),ze(e,function(e){var r="mercator"===t?ct(e):lt(e);e[0]=r[0],e[1]=r[1]})),e}function ct(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 lt(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 ut(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=at(n),a=at(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return st(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:b.FEATURE,properties:{meta:w.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:b.POINT,coordinates:u}}}function dt(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=je(i,e,l,c(l));if(t.midpoints&&o){const e=ut(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===b.POINT?a.push(je(i,o,r,c(r))):n===b.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===b.LINE_STRING?s(o,r):0===n.indexOf(b.MULTI_PREFIX)&&function(){const r=n.replace(b.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:b.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(dt(i,t,o))})}(),a}var pt={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:ht,LAT_MAX:ft,LAT_RENDERED_MIN:gt,LAT_RENDERED_MAX:yt,LNG_MIN:mt,LNG_MAX:vt}=_;function bt(e,t){let r=ht,n=ft,o=ht,i=ft,a=vt,s=mt;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>yt&&(c.lat=yt-r),o+c.lat>ft&&(c.lat=ft-o),n+c.lat<gt&&(c.lat=gt-n),i+c.lat<ht&&(c.lat=ht-i),a+c.lng<=mt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=vt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Et(e,t){const r=bt(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===b.POINT?a=n(t):e.type===b.LINE_STRING||e.type===b.MULTI_POINT?a=t.map(n):e.type===b.POLYGON||e.type===b.MULTI_LINE_STRING?a=t.map(o):e.type===b.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const xt={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(x.UPDATE,{action:S.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 ne).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(){pt.enable(this)},onMouseMove:function(e,t){return k(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};xt.onTap=xt.onClick=function(e,t){return L(t)?this.clickAnywhere(e,t):O(w.VERTEX)(t)?this.clickOnVertex(e,t):k(t)?this.clickOnFeature(e,t):void 0},xt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),pt.enable(this),this.stopExtendedInteractions(e)},xt.clickOnVertex=function(e,t){this.changeMode(E.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:m.MOVE})},xt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},xt.clickOnFeature=function(e,t){pt.disable(this),this.stopExtendedInteractions(e);const r=F(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==b.POINT)return this.changeMode(E.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:m.POINTER}),1===n.length&&pt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:m.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:m.MOVE})),this.doRender(o)},xt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),C(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&I(t)?this.startBoxSelect(e,t):void 0},xt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=Ve(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},xt.onTouchStart=function(e,t){if(C(t))return this.startOnActiveFeature(e,t)},xt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},xt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:m.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(g.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=Ve(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"},xt.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};Et(this.getSelected(),r),e.dragMoveLocation=t.lngLat},xt.onTouchEnd=xt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,Ve(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:m.MOVE}))}this.stopExtendedInteractions(e)},xt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?P.ACTIVE:P.INACTIVE,r(t),this.fireActionable(),t.properties.active===P.ACTIVE&&t.geometry.type!==b.POINT&&dt(t).forEach(r)},xt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},xt.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:b.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(x.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},xt.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(x.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const St=O(w.VERTEX),wt=O(w.MIDPOINT),Pt={fireUpdate:function(){this.fire(x.UPDATE,{action:S.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);F(t)||-1!==n?F(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){Et(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=bt(n.map(e=>({type:b.FEATURE,properties:{},geometry:{type:b.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(E.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(E.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===b.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),pt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){pt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=P.ACTIVE,r(t),dt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=P.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(E.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=C(t),n=St(t),o=wt(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:m.MOVE}):this.updateUIClasses({mouse:m.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Pt.onTouchStart=Pt.onMouseDown=function(e,t){return St(t)?this.onVertex(e,t):C(t)?this.onFeature(e,t):wt(t)?this.onMidpoint(e,t):void 0},Pt.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},Pt.onClick=function(e,t){return L(t)?this.clickNoTarget(e,t):C(t)?this.clickActiveFeature(e,t):T(t)?this.clickInactive(e,t):void this.stopDragging(e)},Pt.onTap=function(e,t){return L(t)?this.clickNoTarget(e,t):C(t)?this.clickActiveFeature(e,t):T(t)?this.clickInactive(e,t):void 0},Pt.onTouchEnd=Pt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Mt={};function _t(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Mt.onSetup=function(){const e=this.newFeature({type:b.FEATURE,properties:{},geometry:{type:b.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:m.ADD}),this.activateUIButton(v.POINT),this.setActionableState({trash:!0}),{point:e}},Mt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)},Mt.onTap=Mt.onClick=function(e,t){this.updateUIClasses({mouse:m.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(x.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.point.id]})},Mt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Mt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?P.ACTIVE:P.INACTIVE,!n)return r(t)},Mt.onTrash=Mt.stopDrawingAndRemove,Mt.onKeyUp=function(e,t){if(N(t)||V(t))return this.stopDrawingAndRemove(e,t)};const Ot={onSetup:function(){const e=this.newFeature({type:b.FEATURE,properties:{},geometry:{type:b.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),pt.disable(this),this.updateUIClasses({mouse:m.ADD}),this.activateUIButton(v.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&_t(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:m.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(E.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),A(t)&&this.updateUIClasses({mouse:m.POINTER})}};Ot.onTap=Ot.onClick=function(e,t){return A(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ot.onKeyUp=function(e,t){N(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)):V(t)&&this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ot.onStop=function(e){this.updateUIClasses({mouse:m.NONE}),pt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(x.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT,{},{silent:!0})))},Ot.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?P.ACTIVE:P.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=w.FEATURE,r(je(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(je(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:b.FEATURE,properties:t.properties,geometry:{coordinates:e,type:b.LINE_STRING}}),3===o)return}return r(t)}},Ot.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)};const It={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:b.FEATURE,properties:{},geometry:{type:b.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),pt.disable(this),this.updateUIClasses({mouse:m.ADD}),this.activateUIButton(v.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&_t(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&_t(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:m.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(E.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),A(t)&&this.updateUIClasses({mouse:m.POINTER})}};It.onTap=It.onClick=function(e,t){if(A(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},It.onKeyUp=function(e,t){V(t)?this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.line.id]}):N(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT))},It.onStop=function(e){pt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(x.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT,{},{silent:!0})))},It.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)},It.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?P.ACTIVE:P.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=w.FEATURE,r(je(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 Ct={simple_select:xt,direct_select:Pt,draw_point:Mt,draw_polygon:Ot,draw_line_string:It};const Tt={defaultMode:E.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:Fe,modes:Ct,controls:{},userProperties:!1,suppressAPIEvents:!0},Lt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},kt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function At(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?y.HOT:y.COLD}))}var Ft,Nt;var Vt,jt,Dt=(Nt||(Nt=1,Ft=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}),Ft),Rt=X(Dt);var Ut=function(){if(jt)return Vt;jt=1,Vt=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 Vt}(),Bt=X(Ut);function Gt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Yt={Polygon:me,LineString:ye,Point:ge,MultiPolygon:Ee,MultiLineString:Ee,MultiPoint:Ee};var Xt=Object.freeze({__proto__:null,CommonSelectors:Y,ModeHandler:de,StringSet:ne,constrainFeatureMovement:bt,createMidPoint:ut,createSupplementaryPoints:dt,createVertex:je,doubleClickZoom:pt,euclideanDistance:ce,featuresAt:ie,getFeatureAtAndSetCursors:se,isClick:le,isEventAtCoordinates:_t,isTap:ue,mapEventToBoundingBox:re,moveFeatures:Et,sortFeatures:te,stringSetsAreEqual:Gt,theme:Fe,toDenseArray:Me});const Jt=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},kt,e.controls):t.controls=Object.assign({},Lt,e.controls),t=Object.assign({},Tt,t),t.styles=At(t.styles,"cold").concat(At(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=E;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return ie.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:b.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:b.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:b.FEATURE,properties:{},geometry:{type:b.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==b.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 ne(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Bt(t))).features.map(t=>{if(t.id=t.id||he(),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=Yt[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Rt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Rt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:b.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==E.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(E.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===E.DIRECT_SELECT?e.events.changeMode(E.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===E.SIMPLE_SELECT&&t.getMode()===E.SIMPLE_SELECT?(Gt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===E.DIRECT_SELECT&&t.getMode()===E.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=Te(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=v,t.options=e,t};function Ht(e){Jt(e,this)}Ht.modes=Ct,Ht.constants=_,Ht.lib=Xt;var qt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},$t=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[]}},Wt=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},Kt=(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},zt=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},Zt=(e,t)=>{var r=t.split(".").map(Number),n=Wt(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]},Qt=(e,t)=>({x:e.x*t,y:e.y*t}),er=e=>e instanceof window.SVGElement||e.ownerSVGElement,tr={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=Wt(i),c=Kt(s,r);if(c){zt(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Qt(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=Wt(o),s=Kt(a,r);if(s)zt(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=Wt(i),c=Kt(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c){zt(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o);var u=e.vertecies[r];u&&this.updateTouchVertexTarget(e,Qt(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 rr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function nr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?rr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var or={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='currentColor'/>\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=\"#fff\"/>\n </svg>\n"),t=e.container.querySelector("[data-touch-vertex-target]")),e.touchVertexTarget=t},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||er(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){h(c(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=c(this.map);o&&p(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),l=Zt(s,a);this.changeMode(e,{selectedVertexIndex:l,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(nr(nr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){var r;h(c(this.map));var n=null===(r=e.vertecies)||void 0===r?void 0:r[e.selectedVertexIndex];if(n&&er(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)&&er(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(f(e)){var a=c(this.map);d(a,this.map,o),i=u(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function ir(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 ar={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},sr={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?ir(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ir(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?ar[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($t(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=Wt(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&&(zt(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=Wt(o),s=Kt(a,e.selectedVertexIndex);s&&(zt(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=Wt(t),n=Kt(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 cr(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lr(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 lr(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return dr(e);default:throw new Error("unknown GeoJSON type")}}function lr(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=ur(e.properties),t.geometry=dr(e.geometry),t}function ur(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]=ur(n):t[r]=n}),t):t}function dr(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return dr(e)}),t):(t.coordinates=pr(e.coordinates),t)}function pr(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return pr(e)})}function hr(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 fr(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 gr(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=cr(e));var i=[];switch(e.type){case"GeometryCollection":return Qe(e,function(e){yr(e,n)}),e;case"FeatureCollection":return Ze(e,function(e){Ze(yr(e,n),function(e){i.push(e)})}),Xe(i)}return yr(e,n)}function yr(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return Qe(e,function(e){yr(e,t)}),e;case"LineString":return mr(fr(e),t),e;case"Polygon":return vr(fr(e),t),e;case"MultiLineString":return fr(e).forEach(function(e){mr(e,t)}),e;case"MultiPolygon":return fr(e).forEach(function(e){vr(e,t)}),e;case"Point":case"MultiPoint":return e}}function mr(e,t){hr(e)===t&&e.reverse()}function vr(e,t){hr(e[0])!==t&&e[0].reverse();for(var r=1;r<e.length;r++)hr(e[r])===t&&e[r].reverse()}const br=11102230246251565e-32,Er=134217729,xr=(3+8*br)*br;function Sr(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 wr(e){return new Float64Array(e)}const Pr=wr(4),Mr=wr(8),_r=wr(12),Or=wr(16),Ir=wr(4);function Cr(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,b,E,x,S,w,P;const M=e-o,_=r-o,O=t-i,I=n-i;E=M*I,p=Er*M,h=p-(p-M),f=M-h,p=Er*I,g=p-(p-I),y=I-g,x=f*y-(E-h*g-f*g-h*y),S=O*_,p=Er*O,h=p-(p-O),f=O-h,p=Er*_,g=p-(p-_),y=_-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Pr[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Pr[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Pr[2]=v-(P-d)+(m-d),Pr[3]=P;let C=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,Pr),T=22204460492503146e-32*a;if(C>=T||-C>=T)return C;if(d=e-M,s=e-(M+d)+(d-o),d=r-_,l=r-(_+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+xr*Math.abs(C),C+=M*u+I*s-(O*l+_*c),C>=T||-C>=T)return C;E=s*I,p=Er*s,h=p-(p-s),f=s-h,p=Er*I,g=p-(p-I),y=I-g,x=f*y-(E-h*g-f*g-h*y),S=c*_,p=Er*c,h=p-(p-c),f=c-h,p=Er*_,g=p-(p-_),y=_-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Ir[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Ir[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Ir[2]=v-(P-d)+(m-d),Ir[3]=P;const L=Sr(4,Pr,4,Ir,Mr);E=M*u,p=Er*M,h=p-(p-M),f=M-h,p=Er*u,g=p-(p-u),y=u-g,x=f*y-(E-h*g-f*g-h*y),S=O*l,p=Er*O,h=p-(p-O),f=O-h,p=Er*l,g=p-(p-l),y=l-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Ir[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Ir[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Ir[2]=v-(P-d)+(m-d),Ir[3]=P;const k=Sr(L,Mr,4,Ir,_r);E=s*u,p=Er*s,h=p-(p-s),f=s-h,p=Er*u,g=p-(p-u),y=u-g,x=f*y-(E-h*g-f*g-h*y),S=c*l,p=Er*c,h=p-(p-c),f=c-h,p=Er*l,g=p-(p-l),y=l-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Ir[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Ir[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Ir[2]=v-(P-d)+(m-d),Ir[3]=P;const A=Sr(k,_r,4,Ir,Or);return Or[A-1]}(e,t,r,n,o,i,l)}function Tr(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=Cr(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 Lr=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},kr=function(e){this.p=e},Ar=function(e,t){this.id=e,this.rawCoords=t};function Fr(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var Nr=function(e,t,r,n){this.p=e,this.polylineEdge=t,this.polygonEdge=r,this.isHeadingIn=n,this.distanceFromPolylineEdgeStart=Vr(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Vr(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Vr(e,t){var r=t[0]-e[0],n=t[1]-e[1];return r*=r,n*=n,Math.sqrt(r+n)}Nr.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var jr=1e-9;function Dr(e,t){return e[0]*t[1]-e[1]*t[0]}function Rr(e,t){return e[0]*t[0]+e[1]*t[1]}function Ur(e,t,r){return[e[0]+t*r[0],e[1]+t*r[1]]}function Br(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=Dr(n,o),s=a*a,c=Rr(n,n);if(s>0){var l=Dr(i,o)/a;if(l<0||l>1)return null;var u=Dr(i,n)/a;return u<0||u>1?null:0===l||1===l?[Ur(e.p1.p,l,n)]:0===u||1===u?[Ur(t.p1.p,u,o)]:[Ur(e.p1.p,l,n)]}var d=Rr(i,i);if((s=(a=Dr(i,n))*a)>jr*c*d)return null;var p=Rr(n,i)/c,h=p+Rr(n,o)/c,f=Math.min(p,h),g=Math.max(p,h);return f<=1&&g>=0?1===f?[Ur(e.p1.p,f>0?f:0,n)]:0===g?[Ur(e.p1.p,g<1?g:1,n)]:[Ur(e.p1.p,f>0?f:0,n),Ur(e.p1.p,g<1?g:1,n)]:null}function Gr(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 kr(c[u][0]),h=null,f={nextEdge:null},g=0;g<d;g++){h=new kr(c[u][g+1]),p.nextPoint=h,h.prevPoint=p;var y=new Lr(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,b=v.length,E=0;E<b;E++)for(var x=v[E].length,S=0;S<x;S++){i+=1;var w=v[E][S],P=w.length;a.push(new Ar(i,w));for(var M=new kr(w[0]),_=M,O=void 0,I=null,C={nextEdge:null,prevEdge:null},T=null,L=1;L<P;L++)O=new kr(w[L]),_.nextPoint=O,O.prevPoint=_,I=new Lr(_,O,"polygon",l,i),C.nextEdge=I,I.prevEdge=C,1===L&&(T=I),S>0&&(I.interiorRing=!0),I.intersectPolylineBbox=Fr(I,o),r.push(I),_=O,l+=1,C=I;I.nextEdge=T,T.prevEdge=I,O.nextPoint=M.nextPoint,M.prevPoint=O.prevPoint}return a}(gr(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=Br(c,l);if(null!==u)for(i=0;i<u.length;i++){var d=Cr(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 Nr(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=Hr(p,m),b=!1;if(v===(h=v)&&2===r.length)for(var E=0;E<r.length;E++){r[E].visitCount<2&&(b=!0)}for(;v!==p||b;){(v=(v.isHeadingIn?Wr:$r)(v,m))!==p&&(v=Hr(v,m)),b=!1}if(h.visitCount>=2){for(var x=!1,S=0;S<r.length;S++){var w=r[S];if(w.visitCount<2){p=w,x=!0;break}}x&&(h=p)}p=h}for(var P=c.map(function(e){return[e]}),M=Object.keys(a),_=0;_<M.length;_++){var O=M[_];if(0===a[O])Jr(Xr(Yr(n,parseInt(O)),i),P)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:P}}}function Yr(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.polygonContourId===t)return n}}function Xr(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function Jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];if(Tr(e[0],[n[0]]))return void n.push(e)}t.push([e])}function Hr(e,t){var r=e.polygonEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=qr(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 qr(e,t){for(var r=0;r<t.length;r++){if(t[r]===e)return r}return null}function $r(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=qr(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 Wr(e,t){var r=e.polylineEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=qr(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 Kr(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 zr(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 Zr(e){return"Feature"===e.type?e.geometry:e}function Qr(e,t,r={}){if(!0===r.final)return function(e,t){let r=Qr(t,e);return r=(r+180)%360,r}(e,t);const n=Kr(e),o=Kr(t),i=We(n[0]),a=We(o[0]),s=We(n[1]),c=We(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 $e(Math.atan2(l,u))}var en=Qr;function tn(e,t,r,n={}){const o=Kr(e),i=We(o[0]),a=We(o[1]),s=We(r),c=qe(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=$e(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),d=$e(l);return void 0!==o[2]?Be([u,d,o[2]],n.properties):Be([u,d],n.properties)}var rn=tn;function nn(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=Kr(e),o=Zr(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=Tr(n,s[l]);if(0===e)return!r.ignoreBoundary;e&&(c=!0)}return c}class on{constructor(e=[],t=an){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 an(e,t){return e<t?-1:e>t?1:0}function sn(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 cn(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 ln{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 un=0,dn=0,pn=0;function hn(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;dn+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new ln(o,un,dn,pn),c=new ln(i,un,dn,pn+1);s.otherEvent=c,c.otherEvent=s,sn(s,c)>0?(c.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,c.isLeftEndpoint=!1),t.push(s),t.push(c),o=i,pn+=1}}un+=1}class fn{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function gn(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 yn=function(e,t){const r=new on([],sn);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)hn(r[e],t)}else hn(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new on([],cn);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new fn(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=gn(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function mn(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(Ue(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(Ue(t));const a=yn(Xe(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 Xe(s.map(e=>Be(e)))}function vn(e,t={}){const r=Zr(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=Zr(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return bn(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=Zr(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(bn(e,o))}),Xe(i)}(r,t);default:throw new Error("invalid poly")}}function bn(e,t){return e.length>1?Je(e,t):Ye(e[0],t)}function En(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return et(e,e=>{et(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!xn(t,e);case"Polygon":return!nn(e,t)}break;case"LineString":switch(t.type){case"Point":return!xn(e,t);case"LineString":return!function(e,t,r){const n=mn(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!Sn(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!nn(t,e);case"LineString":return!Sn(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(nn(r,t))return!0;for(const r of t.coordinates[0])if(nn(r,e))return!0;const n=mn(vn(e),vn(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 xn(e,t){for(let r=0;r<e.coordinates.length-1;r++)if(wn(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function Sn(e,t,r){for(const r of t.coordinates)if(nn(r,e))return!0;return mn(t,vn(e),{ignoreSelfIntersections:r}).features.length>0}function wn(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 Pn=Object.defineProperty,Mn=(e,t)=>Pn(e,"name",{value:t,configurable:!0}),_n=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(!In(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=Cn(e),n=Cn(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(!In(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 In(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||Ln(e.properties,t.properties))&&this.compareBBox(e,t)&&this.compare(e.geometry,t.geometry)}compareFeatureCollection(e,t){return In(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)}};Mn(_n,"GeojsonEquality");var On=_n;function In(e,t){return e.coordinates?e.coordinates.length===t.coordinates.length:e.length===t.length}function Cn(e){return e.coordinates.map(t=>({type:e.type.replace("Multi",""),coordinates:t}))}function Tn(e,t,r){return new On(r).compare(e,t)}function Ln(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=kn(r)&&kn(n);if(i&&!Ln(r,n)||!i&&r!==n)return!1}return!0}Mn(In,"sameLength"),Mn(Cn,"explode"),Mn(Tn,"geojsonEquality"),Mn(Ln,"equal");var kn=Mn(e=>null!=e&&"object"==typeof e,"isObject");function An(e,t,r={}){const n=Kr(e),o=zr(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")),Fn(o[e],o[e+1],n,t,void 0===r.epsilon?null:r.epsilon))return!0}return!1}function Fn(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 Nn(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=Vn(e,n);break;case"MultiLineString":case"Polygon":zr(e).forEach(function(e){o.push(Vn(e,n))});break;case"MultiPolygon":zr(e).forEach(function(e){var t=[];e.forEach(function(e){t.push(Vn(e,n))}),o.push(t)});break;case"Point":return e;case"MultiPoint":var i={};zr(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):Ue({type:n,coordinates:o},e.properties,{bbox:e.bbox,id:e.id})}function Vn(e,t){const r=zr(e);if(2===r.length&&!jn(r[0],r[1]))return r;const n=[];let o=0,i=1,a=2;for(n.push(r[o]);a<r.length;)An(r[i],Ye([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(An(n[0],Ye([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(!jn(n[0],n[n.length-1]))throw new Error("invalid polygon, first and last points not equal")}return n}function jn(e,t){return e[0]===t[0]&&e[1]===t[1]}function Dn(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 Zr(e).type===Zr(t).type&&Tn(Nn(e),Nn(t),{precision:n})}function Rn(e,t){var r=Zr(e),n=Zr(t),o=r.type,i=n.type;switch(o){case"MultiPoint":switch(i){case"LineString":return Un(r,n);case"Polygon":return Gn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"MultiPoint":return Un(n,r);case"LineString":return function(e,t){const r=mn(e,t);if(0===r.features.length)return!1;for(const n of r.features)if(!(Dn(n.geometry,Be(e.coordinates[0]))||Dn(n.geometry,Be(e.coordinates[e.coordinates.length-1]))||Dn(n.geometry,Be(t.coordinates[0]))||Dn(n.geometry,Be(t.coordinates[t.coordinates.length-1]))))return!0;return!1}(r,n);case"Polygon":return Bn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"MultiPoint":return Gn(n,r);case"LineString":return Bn(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+o+" geometry not supported")}}function Un(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),Yn(t.coordinates[a],t.coordinates[a+1],e.coordinates[i],s)?r=!0:n=!0}i++}return r&&n}function Bn(e,t){return mn(e,vn(t)).features.length>0}function Gn(e,t){var r=!1,n=!1,o=e.coordinates.length;for(let i=0;i<o&&(!r||!n);i++)nn(Be(e.coordinates[i]),t)?r=!0:n=!0;return n&&r}function Yn(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 Xn(e){return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]}function Jn(e){for(var t=0;t<e.length-1;t++)for(var r=e[t],n=t+1;n<e.length-2;n++){if(An(r,Ye([e[n],e[n+1]])))return!0}return!1}function Hn(e,t,r){for(var n=Ge(e),o=r+1;o<t.length;o++)if(!En(n,Ge(t[o]))&&Rn(n,Ye(t[o][0])))return!1;return!0}var qn=function(e){if(!e.type)return!1;const t=Zr(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(!Xn(n[o]))return!1;if(Jn(n[o]))return!1;if(o>0&&mn(Ge([n[0]]),Ge([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(!Xn(i[a]))return!1;if(Jn(i[a]))return!1;if(0===a&&!Hn(i,t.coordinates,o))return!1;if(a>0&&mn(Ge([i[0]]),Ge([i[a]])).features.length>1)return!1}return!0;default:return!1}};function $n(e){let t=0;if(e&&e.length>0){t+=Math.abs(zn(e[0]));for(let r=1;r<e.length;r++)t-=Math.abs(zn(e[r]))}return t}var Wn=20294876564838.72,Kn=Math.PI/180;function zn(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]*Kn,c=i[1]*Kn;r+=(a[0]*Kn-s)*Math.sin(c),n++}return r*Wn}var Zn=function(e){return function(e,t,r){var n=r;return Qe(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 $n(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)r+=$n(e.coordinates[t]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};function Qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function eo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Qn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Qn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var to=(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=en(n[1],n[0]),a=rn(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=en(n[s-1],n[s]),l=rn(n[s],t,c,{units:r});o.push(l.geometry.coordinates)}o.push(n[s])}var u=en(n[n.length-2],n[n.length-1]),d=rn(n[n.length-1],t,u,{units:r});return o.push(d.geometry.coordinates),Ye(o)}(t);try{i=Gr(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=>Ge(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 Xe(s.map((t,r)=>Ge(t.geometry.coordinates,eo(eo({},e.properties),{},{id:c}),{id:"".concat(c,"-").concat(r+1)})))},ro=(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))},no=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(ro(r,n)<t)return!1}return!0}(e),oo=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(ro(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=Ge([e]);return!!qn(n)&&!(Zn(n)<=0)},io=(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))},ao={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=Wt(r),o=Kt(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 $t(this.getFeature(e))||[]},getMidpoints(e){var t=this.getFeature(e),r=$t(t),n=Wt(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=io(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=Wt(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 so(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function co(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?so(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):so(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var lo=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),uo={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},po=co(co(co(co(co(co({},Pt),tr),or),sr),ao),{},{onSetup(e){var t,r,n=Pt.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.addTouchVertexTarget(n);var i=c(this.map);if(i&&p(i,this.map),"touch"===n.interfaceType&&n.selectedVertexIndex>=0&&"vertex"===n.selectedVertexType){var a=n.vertecies[n.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(n,Qt(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=$t(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?Qt(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=c(this.map);if(o&&p(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&&lo.has(t.key)&&e.selectedVertexIndex>=0){if(t.preventDefault(),t.stopPropagation(),"midpoint"===e.selectedVertexType)return this.insertVertex(e,t);var i=c(this.map),a=this.getFeature(e.featureId);if(!a)return;var s=$t(a),h=null==s?void 0:s[e.selectedVertexIndex];if(!h)return;if(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...h],e._keyboardMoveStartIndex=e.selectedVertexIndex),f(e)&&e._isSnapped&&i){var g=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,y=this.map.project(h),[m,v]=uo[t.key].map(e=>e*g);return e._isSnapped=!1,p(i,this.map),this.moveVertex(e,this.map.unproject({x:y.x+m,y:y.y+v}))}var b=this.getNewCoord(e,t);return f(e)&&i&&(d(i,this.map,this.map.project(b)),l(i))?(e._isSnapped=!0,this.moveVertex(e,u(i))):(e._isSnapped=!1,this.moveVertex(e,b))}if(t.altKey&&lo.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 E,x=null===(E=document.activeElement)||void 0===E?void 0:E.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",lo.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;h(c(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,Pt.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),l=Zt(s,i);e.selectedVertexIndex=l,e.selectedVertexType="vertex",e.coordPath=i;var u=null===(a=e.vertecies)||void 0===a?void 0:a[l];u&&(e._moveStartPosition=[...u],e._moveStartIndex=l)}if("midpoint"===o){var d=this.getFeature(e.featureId),p=Zt(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){h(c(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=$t(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,Pt.onMouseUp.call(this,e,t)},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=c(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),f(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),d(n,this.map,t.point);var o=u(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Pt.onDrag.call(this,e,t)}},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Qt(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",co(co({},e),t))},onStop(e){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 ho(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 fo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ho(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ho(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var go=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,createVertices:a,excludeFeatureIdFromSetup:p=!1,finishOnInvalidClick:h=!1}=t,g=e=>e[r];return fo(fo({},e),{},{onSetup(t){var{map:n}=this,o=p?fo(fo({},t),{},{featureId:void 0}):t,i=fo(fo({},e.onSetup.call(this,o)),t);i[r].properties=t.properties;var{container:a,interfaceType:s,vertexMarkerId:c}=i,l=a.querySelector("#".concat(c));l.style.display=["touch","keyboard"].includes(s)?"block":"none",i.vertexMarker=l;var u=(e,t)=>this[e]=t.bind(this,i),d={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(d).forEach(e=>{var[t,r]=e;return u(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=c(this.map);if(f(t)&&l(n))r=function(e,t){var r=u(t);return r?s(s({},e),{},{lngLat:r}):e}(r,n);else{var i=o(g(t));i.length>0&&(i[i.length-1]=[r.lngLat.lng,r.lngLat.lat])}var a=o(g(t)).length;e.onClick.call(this,t,r),o(g(t)).length>a&&this.pushDrawUndo(t)}},onTap(){},doClick(t){if(!this.map._undoInProgress){var r=g(t),n=o(r);if(this.dispatchVertexChange(n),i(r)){var a=c(this.map),s=f(t)&&function(e,t){var r=u(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),o(g(t)).length>l&&this.pushDrawUndo(t)}else h&&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:e.length})},pushDrawUndo(e){var t=this.map._undoStack;t&&!this.map._undoInProgress&&t.push({type:"draw_vertex",geometryType:n,featureId:g(e).id})},undoVertex(e){var t=g(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,g(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(f(t)){var n=c(this.map);d(n,this.map,r.point);var o=u(n);o&&(r=fo(fo({},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)){f(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})}(c(this.map),this.map);var r=c(this.map),n=f(t)&&u(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(g(e)))},toDisplayFeatures(t,r,o){e.toDisplayFeatures.call(this,t,r,o);var i=g(t);r.geometry.type===n&&r.id===i.id&&a(r,o,je)},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"}})},yo=go(Ot,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>oo(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)))}}),mo=go(It,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>no(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)))}}),vo={editColorsForeground:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editColorsBackground:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editColorsHalo:{light:"rgba(11,12,12,1)",dark:"#ffffff"},splitInvalidColors:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValidColors:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},stroke:"rgba(212,53,28,1)",strokeWidth:2,fill:"rgba(212,53,28,0.1)",snapLayers:[],snapColors:{vertex:"rgba(212,53,28,1)",midpoint:"rgba(40,161,151,1)",edge:"rgba(29,112,184,1)"},snapRadius:10},bo=e=>{var t;return null!==(t=e.mapColorScheme)&&void 0!==t?t:"light"},Eo=(e,t)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],vo[t]],xo=e=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":Eo(e,"fill")}}),So=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":Eo(e,"stroke"),"line-width":Eo(e,"strokeWidth")}}),wo=e=>({id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":e,"fill-opacity":.1}}),Po=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}}),Mo=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}}),_o=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}}),Oo=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}}),Io=e=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"]],paint:{"circle-radius":6,"circle-color":e}}),Co=(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}}),To=e=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":6,"circle-color":e}}),Lo=e=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":4,"circle-color":e}}),ko=(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}}),Ao=e=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":4,"circle-color":e}}),Fo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),No=e=>{var t=vo.editColorsForeground[bo(e)],r=vo.editColorsBackground[bo(e)],n=vo.editColorsHalo[bo(e)],o=vo.splitInvalidColors[bo(e)],i=vo.splitValidColors[bo(e)];return[xo(e),wo(t),Po(t),So(e),Mo(o),_o(i),Oo(t),Lo(t),ko(r,n),Ao(t),Io(t),Co(r,n),To(t),Fo(t),{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 Vo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function jo(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 Do(e,t,r){void 0===r&&(r={});var n=Vo(e),o=Vo(t),i=We(o[1]-n[1]),a=We(o[0]-n[0]),s=We(n[1]),c=We(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return He(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Ro(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return Je(e,t);return Ye(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Uo(e,t,r,n){void 0===n&&(n={});var o=Vo(e),i=We(o[0]),a=We(o[1]),s=We(r),c=qe(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Be([$e(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),$e(l)],n.properties)}function Bo(e){if(!e)throw new Error("geojson is required");var t=[];return et(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=jo(n);break;case"LineString":r=[jo(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=Ye([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)}),Xe(t)}var Go={exports:{}};function Yo(e,t,r,n,o){Xo(e,t,r||0,n||e.length-1,o||Ho)}function Xo(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);Xo(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(Jo(e,r,t),o(e[n],u)>0&&Jo(e,r,n);d<p;){for(Jo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?Jo(e,r,p):Jo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function Jo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Ho(e,t){return e<t?-1:e>t?1:0}function qo(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 $o(e,t){Wo(e,0,e.children.length,t,e)}function Wo(e,t,r,n,o){o||(o=ii(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];Ko(o,e.leaf?n(t):t)}return o}function Ko(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 zo(e,t){return e.minX-t.minX}function Zo(e,t){return e.minY-t.minY}function Qo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ei(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ti(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 ri(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 ni(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function oi(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function ii(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ai(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;Yo(e,a,t,r,o),i.push(t,a,a,r)}}var si,ci=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(!oi(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;oi(e,s)&&(t.leaf?r.push(a):ni(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!oi(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(oi(e,i)){if(t.leaf||ni(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=ii([]),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=qo(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!ni(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=ii(e.slice(t,r+1)),$o(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=ii([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));ai(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);ai(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 $o(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=Qo(a),c=ti(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),Ko(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=ii(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,$o(r,this.toBBox),$o(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=ii([e,t]),this.data.height=e.height+1,this.data.leaf=!1,$o(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=Wo(e,0,a,this.toBBox),s=Wo(e,a,r,this.toBBox),c=ri(t,s),l=Qo(t)+Qo(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:zo,o=e.leaf?this.compareMinY:Zo;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=Wo(e,0,t,o),a=Wo(e,r-t,r,o);let s=ei(i)+ei(a);for(let n=t;n<r-t;n++){const t=e.children[n];Ko(i,e.leaf?o(t):t),s+=ei(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Ko(a,e.leaf?o(t):t),s+=ei(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Ko(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():$o(e[r],this.toBBox)}}}),li=J(ci),ui={};function di(){if(si)return ui;si=1,Object.defineProperty(ui,"__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 ui.areaFactors=r,ui.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},ui.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},ui.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},ui.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)},ui.degreesToRadians=function(e){return e%360*Math.PI/180},ui.earthRadius=e,ui.factors=t,ui.feature=n,ui.featureCollection=s,ui.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")}},ui.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},ui.isNumber=f,ui.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},ui.lengthToDegrees=function(e,t){return h(p(e,t))},ui.lengthToRadians=p,ui.lineString=a,ui.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},ui.multiLineString=c,ui.multiPoint=l,ui.multiPolygon=u,ui.point=o,ui.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},ui.polygon=i,ui.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},ui.radiansToDegrees=h,ui.radiansToLength=d,ui.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},ui.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")})},ui.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")},ui}var pi,hi={};function fi(){if(pi)return hi;pi=1,Object.defineProperty(hi,"__esModule",{value:!0});var e=di();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var b=0;b<c;b++){var E=0,x=0;if(null!==(s=d?u.geometries[b]: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,E,x))return!1;h++,E++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,E,x))return!1;h++,"MultiPoint"===S&&E++}"LineString"===S&&E++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,E,x))return!1;h++}"MultiLineString"===S&&E++,"Polygon"===S&&x++}"Polygon"===S&&E++;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,E,x))return!1;h++}x++}E++}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 hi.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},hi.coordEach=t,hi.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},hi.featureEach=n,hi.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},hi.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")},hi.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")},hi.flattenEach=i,hi.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},hi.geomEach=o,hi.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},hi.lineEach=s,hi.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},hi.propEach=r,hi.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},hi.segmentEach=a,hi.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},hi}var gi,yi,mi={};function vi(){if(gi)return mi;gi=1,Object.defineProperty(mi,"__esModule",{value:!0});var e=fi();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 mi.bbox=t,mi.default=r,mi}var bi=function(){if(yi)return Go.exports;yi=1;var e=li,t=di(),r=fi(),n=vi().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 Go.exports=a,Go.exports.default=a,Go.exports}(),Ei=X(bi);function xi(e,t){var r={},n=[];if("LineString"===e.type&&(e=Ue(e)),"LineString"===t.type&&(t=Ue(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=Si(e,t);return o&&n.push(o),Xe(n)}var i=Ei();return i.load(Bo(t)),Ze(Bo(e),function(e){Ze(i.search(e),function(t){var o=Si(e,t);if(o){var i=jo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),Xe(n)}function Si(e,t){var r=jo(e),n=jo(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?Be([o+g*(a-o),i+g*(s-i)]):null}function wi(e,t,r){void 0===r&&(r={});var n=Be([1/0,1/0],{dist:1/0}),o=0;return et(e,function(e){for(var i=jo(e),a=0;a<i.length-1;a++){var s=Be(i[a]);s.properties.dist=Do(t,s,r);var c=Be(i[a+1]);c.properties.dist=Do(t,c,r);var l=Do(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=en(s,c),p=Uo(t,u,d+90,r),h=Uo(t,u,d-90,r),f=xi(Ye([p.geometry.coordinates,h.geometry.coordinates]),Ye([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Do(t,g,r),g.properties.location=o+Do(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 Pi(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 Mi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=Pi(e),i=We(o[0]),a=We(o[1]),s=We(r),c=qe(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Be([$e(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),$e(l)],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=Pi(e),o=Pi(t),i=We(o[1]-n[1]),a=We(o[0]-n[0]),s=We(n[1]),c=We(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return He(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,en(e,t));return r}var _i=function(){return _i=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},_i.apply(this,arguments)},Oi=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=_i(_i({},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 Do(Be(e),Be(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=Do(Be([r.lng,r.lat]),Be([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(tn(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),Ge([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=Xe(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(Xe([])))}),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=[],ze(e,function(e){n.push(e)}),n),i=[];if(o.map(function(e){var n=Do(Be(e),Be([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(Ye(e))});break;case"Polygon":var o=Ro(e.geometry);n.push(o);break;case"MultiPolygon":Ro(e.geometry).coodinates.map(function(e){n.push(Ye(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(Bo(e).features)});var i=[];if(o.map(function(e){var n=Mi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Do(n,Be([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=wi(n[i],Be([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 Ii(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 Ci(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ii(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ii(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ti="snap-helper-circle";function Li(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 Ai(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e._snapInitialized)return e._snapInstance;e._snapInitialized=!0;var{layers:n=[],radius:o=15,rules:i=["vertex","midpoint","edge"],status:a=!1,onSnapped:s=()=>{},colors:c={}}=r;function l(r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,e.getLayer(Ti)&&e.removeLayer(Ti),e.getSource(Ti)&&e.removeSource(Ti),ki(r);var c=new Oi({map:e,drawing:t,options:{layers:n,radius:o,rules:i},status:a,onSnapped:s}),l=a;return Object.defineProperty(c,"status",{get:()=>l,set(){},configurable:!0}),c.setSnapStatus=e=>{l=e},c._defaultLayers=n,c._activeLayers=null,c.setSnapLayers=e=>{null==e?c._activeLayers=null:Array.isArray(e)&&(c._activeLayers=e)},void 0!==e._pendingSnapLayers&&(c.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=c,c}!function(e){if(!Oi.prototype.__snapPatched){Oi.prototype.__snapPatched=!0;var t=Oi.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(Ti)&&this.map.setLayoutProperty(Ti,"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=>Ge(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>Ye(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){return console.log(e),this.snapStatus=!1,void(this.snapCoords=null)}}}}(Ci(Ci({},vo.snapColors),c)),e.on("style.load",()=>{Li(()=>e._removed?null:e.getSource("mapbox-gl-draw-hot"),t=>{var r;(ki(t),e.getSource(Ti)||e.addSource(Ti,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Ti))||e.addLayer({id:Ti,type:"fill",source:Ti,paint:{"fill-color":["get","color"],"fill-opacity":.6},layout:{visibility:null!==(r=e._snapInstance)&&void 0!==r&&r.status?"visible":"none"}});e._snapInstance||l(t)})}),e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(Ti)){e.setLayoutProperty(Ti,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(Ti,"visibility","visible")}}),Li(()=>e._removed?null:e.getSource("mapbox-gl-draw-hot"),l)}function Fi(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 Ni(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Fi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Fi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vi=e=>{var{mapStyle:t,mapProvider:r,events:n,eventBus:o,snapLayers:i}=e,{map:a}=r;Ht.constants.classes.CONTROL_BASE="maplibregl-ctrl",Ht.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Ht.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var s=new Ht({modes:Ni(Ni({},Ht.modes),{},{disabled:qt,edit_vertex:po,draw_polygon:yo,draw_line:mo}),styles:No(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,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,Ai(a,s,{layers:i,radius:10,rules:["vertex","edge"]});var h=e=>{a.once("idle",()=>{((e,t)=>{No(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)})};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"],Di=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},Ri=["stroke","fill","strokeWidth","properties"];function Ui(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 Bi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ui(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ui(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Gi=["stroke","fill","strokeWidth","properties"];function Yi(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 Xi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Yi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ji=["stroke","fill","strokeWidth","properties"];function Hi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function qi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Hi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Hi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function $i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Wi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?$i(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):$i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ki=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:i},InitComponent:e=>{var{appState:r,appConfig:n,mapState:o,pluginConfig:i,pluginState:a,services:s,mapProvider:l,buttonConfig:u}=e,{events:d,eventBus:p}=s,{crossHair:f}=o,g=["touch","keyboard"].includes(r.interfaceType);t(()=>{var e,t,n,s,c,u=null===(e=null===(t=i.includeModes)||void 0===t?void 0:t.includes(r.mode))||void 0===e||e,h=null!==(n=null===(s=i.excludeModes)||void 0===s?void 0:s.includes(r.mode))&&void 0!==n&&n;if(o.isMapReady&&u&&!h){var{remove:f}=Vi({mapStyle:o.mapStyle,snapLayers:i.snapLayers,mapProvider:l,events:d,eventBus:p});return a.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:(null===(c=i.snapLayers)||void 0===c?void 0:c.length)>0}),p.emit("draw:ready"),()=>f()}},[o.isMapReady,r.mode]),t(()=>{if(["draw_polygon","draw_line"].includes(a.mode)&&g){var e=f.isVisible;return f.fixAtCenter(),()=>{e||f.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:l,drawSnap:u,drawCancel:d}=n,{map:p,draw:f}=r,{dispatch:g,feature:y,tempFeature:m}=t,v=()=>{r.snapEnabled=!1,g({type:"SET_SNAP",payload:!1});var e,t=c(p);t&&(null===(e=t.setSnapStatus)||void 0===e||e.call(t,!1),h(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(),g({type:"SET_MODE",payload:null}),g({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},E=()=>{null!=m&&m.id&&f.delete(m.id),y&&f.add(y),v(),f.changeMode("disabled"),b(),o.emit("draw:cancel",{originalFeature:y})},x=0,S=()=>{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))},w=e=>t=>{var r=t.features[0];b(),setTimeout(()=>f.changeMode("disabled"),0),o.emit(e,{newFeature:r})},P=w("draw:create"),M=w("draw:edit"),_=e=>o.emit("draw:update",e),O=e=>{g({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),o.emit("draw:vertexselection",e)},I=e=>{g({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertecies:e.numVertecies}})},C=e=>{g({type:"SET_UNDO_STACK_LENGTH",payload:e.length})};return i.onClick=()=>{var e,t=f.getMode(),n=f.getAll().features,o=null==n?void 0:n[0];if(v(),null===(e=r.undoStack)||void 0===e||e.clear(),"edit_vertex"!==t){if(["draw_polygon","draw_line"].includes(t)&&0!==n.length){var i=o.geometry;if("Polygon"===i.type){var a=i.coordinates[0];i.coordinates[0]=[...a.slice(0,-2),a[0]]}else i.coordinates=i.coordinates.slice(0,-1);p.fire("draw.create",{features:[o]})}}else p.fire("draw.editfinish",{features:[o]})},d.onClick=E,s.onClick=()=>{if("edit_vertex"!==f.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})}}},u.onClick=()=>{var e=Date.now();if(!(e-x<300)){x=e;var n=!t.snap;g({type:"TOGGLE_SNAP"}),r.snapEnabled=n;var o=c(p);null!=o&&o.setSnapStatus&&o.setSnapStatus(n),!n&&o&&(h(o),p.getLayer("snap-helper-circle")&&p.setLayoutProperty("snap-helper-circle","visibility","none"))}},p.on("styledata",S),p.on("draw.cancel",E),p.on("draw.create",P),p.on("draw.editfinish",M),p.on("draw.update",_),p.on("draw.vertexselection",O),p.on("draw.vertexchange",I),p.on("draw.undochange",C),()=>{[i,a,s,l,u,d].forEach(e=>{e&&(e.onClick=null)}),p.off("styledata",S),p.off("draw.cancel",E),p.off("draw.create",P),p.off("draw.editfinish",M),p.off("draw.update",_),p.off("draw.vertexselection",O),p.off("draw.vertexchange",I),p.off("draw.undochange",C)}}({mapProvider:l,buttonConfig:u,pluginState:a,eventBus:p});return()=>e()}},[l,r,a])},buttons:[Wi({id:"drawAddPoint",label:"Add point",iconId:"plus",variant:"touch",hiddenWhen:e=>{var{appState:t,pluginState:r}=e;return!["draw_polygon","draw_line"].includes(r.mode)||"touch"!==t.interfaceType}},Ki(!1)),Wi({id:"drawCancel",label:"Cancel",variant:"tertiary",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode}},Ki(!0)),Wi({id:"drawMenu",label:"Menu",iconId:"menu",variant:"tertiary",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)}}]},Ki(!0)),Wi({id:"drawDone",label:"Done",variant:"primary",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)}},Ki(!0))],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:l,services:u}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=l,{eventBus:g}=u;if(h){g.emit("draw:start",{mode:"draw_polygon"});var y=null;y=void 0!==d.snapLayers?d.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=c(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:b,strokeWidth:E,properties:x}=d,S=r(d,Ri),w=Bi(Bi({},x),Di({stroke:v,fill:b,strokeWidth:E}));h.changeMode("draw_polygon",Bi(Bi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,getSnapEnabled:()=>!0===l.snapEnabled,featureId:t},S),{},{properties:w})),p({type:"SET_MODE",payload:"draw_polygon"})}},newLine:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:l,services:u}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=l,{eventBus:g}=u;if(h){g.emit("draw:start",{mode:"draw_line"});var y=null;y=void 0!==d.snapLayers?d.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=c(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:b,strokeWidth:E,properties:x}=d,S=r(d,Gi),w=Xi(Xi({},x),Di({stroke:v,fill:b,strokeWidth:E}));h.changeMode("draw_line",Xi(Xi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,getSnapEnabled:()=>!0===l.snapEnabled,featureId:t},S),{},{properties:w})),p({type:"SET_MODE",payload:"draw_line"})}},editFeature:function(e,t){var r,{appState:n,appConfig:o,mapState:i,pluginConfig:a,pluginState:s,mapProvider:l}=e,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:d}=s,{draw:p,map:h}=l;if(p&&p.get(t)){var f,g=null;if(void 0===u.snapLayers)g=null!==(f=a.snapLayers)&&void 0!==f?f:null;else g=u.snapLayers;var y=c(h);null!=y&&y.setSnapLayers?y.setSnapLayers(g):g&&(h._pendingSnapLayers=g),d({type:"SET_HAS_SNAP_LAYERS",payload:(null===(r=g)||void 0===r?void 0:r.length)>0}),p.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===l.snapEnabled});var m=p.get(t);return d({type:"SET_FEATURE",payload:{feature:m,tempFeature:m}}),d({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=qi(qi({},r(t,Ji)),{},{properties:qi(qi({},u),Di({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:l,map:u}=i;if(l){var d=l.get(t),p=["stroke-inactive.cold",...a.snapLayers||[]],h=c(u);null!=h&&h.setSnapLayers?h.setSnapLayers(p):a.snapLayers&&(u._pendingSnapLayers=p),s({type:"SET_HAS_SNAP_LAYERS",payload:!0}),l.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"}}),u.on("draw.create",e=>{var t=e.features[0],r=to(d,t);l.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=!!to(d,t);e.properties.splitter=r?"valid":"invalid",e.ctx.store.render(),"edit_vertex"===l.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);u.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={SET_MODE:(e,t)=>o(o({},e),{},{mode:t}),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})};function a(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 s(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?a(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function c(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function l(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 u(e){return l(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function d(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function p(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 h(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 f(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}const g={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"},y={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},m={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},v={POLYGON:"polygon",LINE:"line_string",POINT:"point"},b={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},E={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},x={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"},S={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},w={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},P={ACTIVE:"true",INACTIVE:"false"},M=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var _=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:P,classes:g,cursors:m,events:x,geojsonTypes:b,interactions:M,meta:w,modes:E,sources:y,types:v,updateActions:S});function O(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function I(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function C(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===P.ACTIVE&&e.featureTarget.properties.meta===w.FEATURE))}function T(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===P.INACTIVE&&e.featureTarget.properties.meta===w.FEATURE))}function L(e){return void 0===e.featureTarget}function k(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===w.FEATURE)}function A(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===w.VERTEX)}function F(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function N(e){return"Escape"===e.key||27===e.keyCode}function V(e){return"Enter"===e.key||13===e.keyCode}function j(e){return"Backspace"===e.key||8===e.keyCode}function D(e){return"Delete"===e.key||46===e.keyCode}function R(e){return"1"===e.key||49===e.keyCode}function U(e){return"2"===e.key||50===e.keyCode}function B(e){return"3"===e.key||51===e.keyCode}function G(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var Y=Object.freeze({__proto__:null,isActiveFeature:C,isBackspaceKey:j,isDeleteKey:D,isDigit1Key:R,isDigit2Key:U,isDigit3Key:B,isDigitKey:G,isEnterKey:V,isEscapeKey:N,isFeature:k,isInactiveFeature:T,isOfMetaType:O,isShiftDown:F,isShiftMousedown:I,isTrue:function(){return!0},isVertex:A,noTarget:L});function X(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function J(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 H,q,$={},W={};function K(){return H||(H=1,W.RADIUS=6378137,W.FLATTENING=1/298.257223563,W.POLAR_RADIUS=6356752.3142),W}var z=function(){if(q)return $;q=1;var e=K();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 $.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}},$.ring=r,$}(),Z=X(z);const Q={Point:0,LineString:1,MultiLineString:1,Polygon:2};function ee(e,t){const r=Q[e.geometry.type]-Q[t.geometry.type];return 0===r&&e.geometry.type===b.POLYGON?e.area-t.area:r}function te(e){return e.map(e=>(e.geometry.type===b.POLYGON&&(e.area=Z.geometry({type:b.FEATURE,property:{},geometry:e.geometry})),e)).sort(ee).map(e=>(delete e.area,e))}function re(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function ne(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)}ne.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},ne.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},ne.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},ne.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)},ne.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const oe=[w.FEATURE,w.MIDPOINT,w.VERTEX];var ie={click:function(e,t,r){return ae(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return ae(e,t,r,r.options.touchBuffer)}};function ae(e,t,r,n){if(null===r.map)return[];const o=e?re(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==oe.indexOf(e.properties.meta)),s=new ne,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),te(c)}function se(e,t){const r=ie.click(e,null,t),n={mouse:m.NONE};return r[0]&&(n.mouse=r[0].properties.active===P.ACTIVE?m.MOVE:m.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=m.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function ce(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function le(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=ce(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function ue(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 ce(e.point,t.point)<n&&t.time-e.time<o}const de=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 pe=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function he(){return pe()}const fe=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||he(),this.type=t.geometry.type};fe.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},fe.prototype.incomingCoords=function(e){this.setCoordinates(e)},fe.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},fe.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},fe.prototype.setProperty=function(e,t){this.properties[e]=t},fe.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:b.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},fe.prototype.internal=function(e){const t={id:this.id,meta:w.FEATURE,"meta:type":this.type,active:P.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:b.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const ge=function(e,t){fe.call(this,e,t)};(ge.prototype=Object.create(fe.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},ge.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},ge.prototype.getCoordinate=function(){return this.getCoordinates()};const ye=function(e,t){fe.call(this,e,t)};(ye.prototype=Object.create(fe.prototype)).isValid=function(){return this.coordinates.length>1},ye.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},ye.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},ye.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},ye.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const me=function(e,t){fe.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(me.prototype=Object.create(fe.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},me.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},me.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},me.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])},me.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))},me.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]]))},me.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},me.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const ve={MultiPoint:ge,MultiLineString:ye,MultiPolygon:me},be=(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)},Ee=function(e,t){if(fe.call(this,e,t),delete this.coordinates,this.model=ve[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function xe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ee.prototype=Object.create(fe.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:he(),type:b.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ee.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ee.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ee.prototype.getCoordinate=function(e){return be(this.features,"getCoordinate",e)},Ee.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===b.POLYGON?e.getCoordinates():e.coordinates)))},Ee.prototype.updateCoordinate=function(e,t,r){be(this.features,"updateCoordinate",e,t,r),this.changed()},Ee.prototype.addCoordinate=function(e,t,r){be(this.features,"addCoordinate",e,t,r),this.changed()},Ee.prototype.removeCoordinate=function(e){be(this.features,"removeCoordinate",e),this.changed()},Ee.prototype.getFeatures=function(){return this.features},xe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},xe.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),{})},xe.prototype.getSelected=function(){return this._ctx.store.getSelected()},xe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},xe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},xe.prototype.getFeature=function(e){return this._ctx.store.get(e)},xe.prototype.select=function(e){return this._ctx.store.select(e)},xe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},xe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},xe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},xe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},xe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},xe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},xe.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},xe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},xe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},xe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},xe.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return ie[r](e,t,this._ctx)},xe.prototype.newFeature=function(e){const t=e.geometry.type;return t===b.POINT?new ge(this._ctx,e):t===b.LINE_STRING?new ye(this._ctx,e):t===b.POLYGON?new me(this._ctx,e):new Ee(this._ctx,e)},xe.prototype.isInstanceOf=function(e,t){if(e===b.POINT)return t instanceof ge;if(e===b.LINE_STRING)return t instanceof ye;if(e===b.POLYGON)return t instanceof me;if("MultiFeature"===e)return t instanceof Ee;throw new Error(`Unknown feature class: ${e}`)},xe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},xe.prototype.onSetup=function(){},xe.prototype.onDrag=function(){},xe.prototype.onClick=function(){},xe.prototype.onMouseMove=function(){},xe.prototype.onMouseDown=function(){},xe.prototype.onMouseUp=function(){},xe.prototype.onMouseOut=function(){},xe.prototype.onKeyUp=function(){},xe.prototype.onKeyDown=function(){},xe.prototype.onTouchStart=function(){},xe.prototype.onTouchMove=function(){},xe.prototype.onTouchEnd=function(){},xe.prototype.onTap=function(){},xe.prototype.onStop=function(){},xe.prototype.onTrash=function(){},xe.prototype.onCombineFeature=function(){},xe.prototype.onUncombineFeature=function(){},xe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Se={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},we=Object.keys(Se);function Pe(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new xe(r));return{start(){o=i.onSetup(n),we.forEach(t=>{const r=Se[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 Me(e){return[].concat(e).filter(e=>void 0!==e)}function _e(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(y.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(y.COLD).setData({type:b.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(y.HOT).setData({type:b.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Oe(e){let t;this._features={},this._featureIds=new ne,this._selectedFeatureIds=new ne,this._selectedCoordinates=[],this._changedFeatureIds=new ne,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,_e.call(this),this._emitSelectionChange&&(this.ctx.events.fire(x.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:b.FEATURE,properties:{},geometry:{type:b.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(x.RENDER,{})}))},this.isDirty=!1}function Ie(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}Oe.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Oe.prototype.setDirty=function(){return this.isDirty=!0,this},Oe.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(x.CREATE,{features:[t.toGeoJSON()]})}return this},Oe.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(x.UPDATE,{action:t.action?t.action:S.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Oe.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Oe.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Oe.prototype.getAllIds=function(){return this._featureIds.values()},Oe.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Oe.prototype.delete=function(e,t={}){const r=[];return Me(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(x.DELETE,{features:r}),Ie(this,t),this},Oe.prototype.get=function(e){return this._features[e]},Oe.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Oe.prototype.select=function(e,t={}){return Me(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Oe.prototype.deselect=function(e,t={}){return Me(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Ie(this,t),this},Oe.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Oe.prototype.setSelected=function(e,t={}){return e=Me(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},Oe.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Oe.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Oe.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Oe.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Oe.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Oe.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Oe.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:S.CHANGE_PROPERTIES})},Oe.prototype.storeMapConfig=function(){M.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Oe.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Oe.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Ce=["mode","feature","mouse"];function Te(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]=Pe(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:m.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!le(r,e))},o.touchdrag=function(e){o.drag(e,e=>!ue(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=se(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=se(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=se(t,e);t.featureTarget=n,le(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=ie.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=ie.touch(t,null,e)[0];t.featureTarget=r,ue(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=j(e),r=D(e),n=G(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=de(c,e),o.silent||e.map.fire(x.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(g.CANVAS)&&((j(t)||D(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):R(t)&&e.options.controls.point?c(E.DRAW_POINT):U(t)&&e.options.controls.line_string?c(E.DRAW_LINE_STRING):B(t)&&e.options.controls.polygon&&c(E.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=de(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(x.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=[];Ce.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=`${g.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(g.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(g.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=`${g.CONTROL_GROUP} ${g.CONTROL_BASE}`,r?(r[v.POINT]&&(t[v.POINT]=s(v.POINT,{container:n,className:g.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(E.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[v.LINE]&&(t[v.LINE]=s(v.LINE,{container:n,className:g.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(E.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[v.POLYGON]&&(t[v.POLYGON]=s(v.POLYGON,{container:n,className:g.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(E.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:g.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:g.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:g.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 Oe(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(y.COLD,{data:{type:b.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(y.HOT,{data:{type:b.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(y.COLD)&&e.map.removeSource(y.COLD),e.map.getSource(y.HOT)&&e.map.removeSource(y.HOT)}};return e.setup=n,n}const Le="#3bb2d0",ke="#fbb03b",Ae="#fff";var Fe=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],ke,Le],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],ke,Le],"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":Ae}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],ke,Le]}},{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":Ae}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":ke}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":ke}}];function Ne(e,t){this.x=e,this.y=t}function Ve(e,t){const r=t.getBoundingClientRect();return new Ne(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function je(e,t,r,n){return{type:b.FEATURE,properties:{meta:w.VERTEX,parent:e,coord_path:r,active:n?P.ACTIVE:P.INACTIVE},geometry:{type:b.POINT,coordinates:t}}}Ne.prototype={clone(){return new Ne(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:Ne},Ne.convert=function(e){if(e instanceof Ne)return e;if(Array.isArray(e))return new Ne(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Ne(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var De=6371008.8,Re={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*De,kilometers:6371.0088,kilometres:6371.0088,meters:De,metres:De,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:De/1852,radians:1,yards:6967335.223679999};function Ue(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 Be(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(!Ke(e[0])||!Ke(e[1]))throw new Error("coordinates must contain numbers");return Ue({type:"Point",coordinates:e},t,r)}function Ge(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 Ue({type:"Polygon",coordinates:e},t,r)}function Ye(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return Ue({type:"LineString",coordinates:e},t,r)}function Xe(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function Je(e,t,r={}){return Ue({type:"MultiLineString",coordinates:e},t,r)}function He(e,t="kilometers"){const r=Re[t];if(!r)throw new Error(t+" units is invalid");return e*r}function qe(e,t="kilometers"){const r=Re[t];if(!r)throw new Error(t+" units is invalid");return e/r}function $e(e){return 180*(e%(2*Math.PI))/Math.PI}function We(e){return e%360*Math.PI/180}function Ke(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function ze(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 b=0,E=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,b,E))return!1;p++,b++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===t(c[n],p,m,b,E))return!1;p++,"MultiPoint"===x&&b++}"LineString"===x&&b++;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,b,E))return!1;p++}"MultiLineString"===x&&b++,"Polygon"===x&&E++}"Polygon"===x&&b++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(E=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,b,E))return!1;p++}E++}b++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===ze(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ze(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 Qe(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 et(e,t){Qe(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(Ue(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(Ue({type:a,coordinates:l},n),r,c))return!1}})}function tt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return rt(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=>rt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ot(e);default:throw new Error("unknown GeoJSON type")}}function rt(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=nt(e.properties),null==e.geometry?t.geometry=null:t.geometry=ot(e.geometry),t}function nt(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]=nt(n):t[r]=n}),t):t}function ot(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ot(e)),t):(t.coordinates=it(e.coordinates),t)}function it(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>it(e))}function at(e,t={}){return st(e,"mercator",t)}function st(e,t,r={}){var n=(r=r||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&Ke(e[0])?e="mercator"===t?ct(e):lt(e):(!0!==n&&(e=tt(e)),ze(e,function(e){var r="mercator"===t?ct(e):lt(e);e[0]=r[0],e[1]=r[1]})),e}function ct(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 lt(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 ut(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=at(n),a=at(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return st(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:b.FEATURE,properties:{meta:w.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:b.POINT,coordinates:u}}}function dt(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=je(i,e,l,c(l));if(t.midpoints&&o){const e=ut(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===b.POINT?a.push(je(i,o,r,c(r))):n===b.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===b.LINE_STRING?s(o,r):0===n.indexOf(b.MULTI_PREFIX)&&function(){const r=n.replace(b.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:b.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(dt(i,t,o))})}(),a}var pt={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:ht,LAT_MAX:ft,LAT_RENDERED_MIN:gt,LAT_RENDERED_MAX:yt,LNG_MIN:mt,LNG_MAX:vt}=_;function bt(e,t){let r=ht,n=ft,o=ht,i=ft,a=vt,s=mt;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>yt&&(c.lat=yt-r),o+c.lat>ft&&(c.lat=ft-o),n+c.lat<gt&&(c.lat=gt-n),i+c.lat<ht&&(c.lat=ht-i),a+c.lng<=mt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=vt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Et(e,t){const r=bt(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===b.POINT?a=n(t):e.type===b.LINE_STRING||e.type===b.MULTI_POINT?a=t.map(n):e.type===b.POLYGON||e.type===b.MULTI_LINE_STRING?a=t.map(o):e.type===b.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const xt={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(x.UPDATE,{action:S.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 ne).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(){pt.enable(this)},onMouseMove:function(e,t){return k(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};xt.onTap=xt.onClick=function(e,t){return L(t)?this.clickAnywhere(e,t):O(w.VERTEX)(t)?this.clickOnVertex(e,t):k(t)?this.clickOnFeature(e,t):void 0},xt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),pt.enable(this),this.stopExtendedInteractions(e)},xt.clickOnVertex=function(e,t){this.changeMode(E.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:m.MOVE})},xt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},xt.clickOnFeature=function(e,t){pt.disable(this),this.stopExtendedInteractions(e);const r=F(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==b.POINT)return this.changeMode(E.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:m.POINTER}),1===n.length&&pt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:m.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:m.MOVE})),this.doRender(o)},xt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),C(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&I(t)?this.startBoxSelect(e,t):void 0},xt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=Ve(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},xt.onTouchStart=function(e,t){if(C(t))return this.startOnActiveFeature(e,t)},xt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},xt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:m.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(g.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=Ve(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"},xt.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};Et(this.getSelected(),r),e.dragMoveLocation=t.lngLat},xt.onTouchEnd=xt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,Ve(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:m.MOVE}))}this.stopExtendedInteractions(e)},xt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?P.ACTIVE:P.INACTIVE,r(t),this.fireActionable(),t.properties.active===P.ACTIVE&&t.geometry.type!==b.POINT&&dt(t).forEach(r)},xt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},xt.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:b.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(x.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},xt.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(x.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const St=O(w.VERTEX),wt=O(w.MIDPOINT),Pt={fireUpdate:function(){this.fire(x.UPDATE,{action:S.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);F(t)||-1!==n?F(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){Et(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=bt(n.map(e=>({type:b.FEATURE,properties:{},geometry:{type:b.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(E.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(E.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===b.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),pt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){pt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=P.ACTIVE,r(t),dt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=P.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(E.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=C(t),n=St(t),o=wt(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:m.MOVE}):this.updateUIClasses({mouse:m.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Pt.onTouchStart=Pt.onMouseDown=function(e,t){return St(t)?this.onVertex(e,t):C(t)?this.onFeature(e,t):wt(t)?this.onMidpoint(e,t):void 0},Pt.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},Pt.onClick=function(e,t){return L(t)?this.clickNoTarget(e,t):C(t)?this.clickActiveFeature(e,t):T(t)?this.clickInactive(e,t):void this.stopDragging(e)},Pt.onTap=function(e,t){return L(t)?this.clickNoTarget(e,t):C(t)?this.clickActiveFeature(e,t):T(t)?this.clickInactive(e,t):void 0},Pt.onTouchEnd=Pt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Mt={};function _t(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Mt.onSetup=function(){const e=this.newFeature({type:b.FEATURE,properties:{},geometry:{type:b.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:m.ADD}),this.activateUIButton(v.POINT),this.setActionableState({trash:!0}),{point:e}},Mt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)},Mt.onTap=Mt.onClick=function(e,t){this.updateUIClasses({mouse:m.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(x.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.point.id]})},Mt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Mt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?P.ACTIVE:P.INACTIVE,!n)return r(t)},Mt.onTrash=Mt.stopDrawingAndRemove,Mt.onKeyUp=function(e,t){if(N(t)||V(t))return this.stopDrawingAndRemove(e,t)};const Ot={onSetup:function(){const e=this.newFeature({type:b.FEATURE,properties:{},geometry:{type:b.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),pt.disable(this),this.updateUIClasses({mouse:m.ADD}),this.activateUIButton(v.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&_t(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:m.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(E.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),A(t)&&this.updateUIClasses({mouse:m.POINTER})}};Ot.onTap=Ot.onClick=function(e,t){return A(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ot.onKeyUp=function(e,t){N(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)):V(t)&&this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ot.onStop=function(e){this.updateUIClasses({mouse:m.NONE}),pt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(x.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT,{},{silent:!0})))},Ot.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?P.ACTIVE:P.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=w.FEATURE,r(je(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(je(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:b.FEATURE,properties:t.properties,geometry:{coordinates:e,type:b.LINE_STRING}}),3===o)return}return r(t)}},Ot.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)};const It={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:b.FEATURE,properties:{},geometry:{type:b.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),pt.disable(this),this.updateUIClasses({mouse:m.ADD}),this.activateUIButton(v.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&_t(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&_t(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:m.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(E.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),A(t)&&this.updateUIClasses({mouse:m.POINTER})}};It.onTap=It.onClick=function(e,t){if(A(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},It.onKeyUp=function(e,t){V(t)?this.changeMode(E.SIMPLE_SELECT,{featureIds:[e.line.id]}):N(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT))},It.onStop=function(e){pt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(x.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT,{},{silent:!0})))},It.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(E.SIMPLE_SELECT)},It.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?P.ACTIVE:P.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=w.FEATURE,r(je(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 Ct={simple_select:xt,direct_select:Pt,draw_point:Mt,draw_polygon:Ot,draw_line_string:It};const Tt={defaultMode:E.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:Fe,modes:Ct,controls:{},userProperties:!1,suppressAPIEvents:!0},Lt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},kt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function At(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?y.HOT:y.COLD}))}var Ft,Nt;var Vt,jt,Dt=(Nt||(Nt=1,Ft=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}),Ft),Rt=X(Dt);var Ut=function(){if(jt)return Vt;jt=1,Vt=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 Vt}(),Bt=X(Ut);function Gt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Yt={Polygon:me,LineString:ye,Point:ge,MultiPolygon:Ee,MultiLineString:Ee,MultiPoint:Ee};var Xt=Object.freeze({__proto__:null,CommonSelectors:Y,ModeHandler:de,StringSet:ne,constrainFeatureMovement:bt,createMidPoint:ut,createSupplementaryPoints:dt,createVertex:je,doubleClickZoom:pt,euclideanDistance:ce,featuresAt:ie,getFeatureAtAndSetCursors:se,isClick:le,isEventAtCoordinates:_t,isTap:ue,mapEventToBoundingBox:re,moveFeatures:Et,sortFeatures:te,stringSetsAreEqual:Gt,theme:Fe,toDenseArray:Me});const Jt=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},kt,e.controls):t.controls=Object.assign({},Lt,e.controls),t=Object.assign({},Tt,t),t.styles=At(t.styles,"cold").concat(At(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=E;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return ie.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:b.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:b.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:b.FEATURE,properties:{},geometry:{type:b.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==b.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 ne(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Bt(t))).features.map(t=>{if(t.id=t.id||he(),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=Yt[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Rt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Rt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:b.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==E.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(E.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===E.DIRECT_SELECT?e.events.changeMode(E.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===E.SIMPLE_SELECT&&t.getMode()===E.SIMPLE_SELECT?(Gt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===E.DIRECT_SELECT&&t.getMode()===E.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=Te(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=v,t.options=e,t};function Ht(e){Jt(e,this)}Ht.modes=Ct,Ht.constants=_,Ht.lib=Xt;var qt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},$t=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[]}},Wt=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},Kt=(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},zt=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},Zt=(e,t)=>{var r=t.split(".").map(Number),n=Wt(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]},Qt=(e,t)=>({x:e.x*t,y:e.y*t}),er=e=>e instanceof window.SVGElement||e.ownerSVGElement,tr={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=Wt(i),c=Kt(s,r);if(c){zt(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Qt(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=Wt(o),s=Kt(a,r);if(s)zt(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=Wt(i),c=Kt(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c){zt(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o);var u=e.vertecies[r];u&&this.updateTouchVertexTarget(e,Qt(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 rr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function nr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?rr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var or={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='currentColor'/>\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=\"#fff\"/>\n </svg>\n"),t=e.container.querySelector("[data-touch-vertex-target]")),e.touchVertexTarget=t},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||er(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){h(c(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=c(this.map);o&&p(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),l=Zt(s,a);this.changeMode(e,{selectedVertexIndex:l,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(nr(nr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){var r;h(c(this.map));var n=null===(r=e.vertecies)||void 0===r?void 0:r[e.selectedVertexIndex];if(n&&er(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)&&er(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(f(e)){var a=c(this.map);d(a,this.map,o),i=u(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function ir(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 ar={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},sr={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?ir(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ir(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?ar[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($t(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=Wt(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&&(zt(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=Wt(o),s=Kt(a,e.selectedVertexIndex);s&&(zt(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=Wt(t),n=Kt(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 cr(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lr(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 lr(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return dr(e);default:throw new Error("unknown GeoJSON type")}}function lr(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=ur(e.properties),t.geometry=dr(e.geometry),t}function ur(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]=ur(n):t[r]=n}),t):t}function dr(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return dr(e)}),t):(t.coordinates=pr(e.coordinates),t)}function pr(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return pr(e)})}function hr(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 fr(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 gr(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=cr(e));var i=[];switch(e.type){case"GeometryCollection":return Qe(e,function(e){yr(e,n)}),e;case"FeatureCollection":return Ze(e,function(e){Ze(yr(e,n),function(e){i.push(e)})}),Xe(i)}return yr(e,n)}function yr(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return Qe(e,function(e){yr(e,t)}),e;case"LineString":return mr(fr(e),t),e;case"Polygon":return vr(fr(e),t),e;case"MultiLineString":return fr(e).forEach(function(e){mr(e,t)}),e;case"MultiPolygon":return fr(e).forEach(function(e){vr(e,t)}),e;case"Point":case"MultiPoint":return e}}function mr(e,t){hr(e)===t&&e.reverse()}function vr(e,t){hr(e[0])!==t&&e[0].reverse();for(var r=1;r<e.length;r++)hr(e[r])===t&&e[r].reverse()}const br=11102230246251565e-32,Er=134217729,xr=(3+8*br)*br;function Sr(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 wr(e){return new Float64Array(e)}const Pr=wr(4),Mr=wr(8),_r=wr(12),Or=wr(16),Ir=wr(4);function Cr(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,b,E,x,S,w,P;const M=e-o,_=r-o,O=t-i,I=n-i;E=M*I,p=Er*M,h=p-(p-M),f=M-h,p=Er*I,g=p-(p-I),y=I-g,x=f*y-(E-h*g-f*g-h*y),S=O*_,p=Er*O,h=p-(p-O),f=O-h,p=Er*_,g=p-(p-_),y=_-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Pr[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Pr[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Pr[2]=v-(P-d)+(m-d),Pr[3]=P;let C=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,Pr),T=22204460492503146e-32*a;if(C>=T||-C>=T)return C;if(d=e-M,s=e-(M+d)+(d-o),d=r-_,l=r-(_+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+xr*Math.abs(C),C+=M*u+I*s-(O*l+_*c),C>=T||-C>=T)return C;E=s*I,p=Er*s,h=p-(p-s),f=s-h,p=Er*I,g=p-(p-I),y=I-g,x=f*y-(E-h*g-f*g-h*y),S=c*_,p=Er*c,h=p-(p-c),f=c-h,p=Er*_,g=p-(p-_),y=_-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Ir[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Ir[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Ir[2]=v-(P-d)+(m-d),Ir[3]=P;const L=Sr(4,Pr,4,Ir,Mr);E=M*u,p=Er*M,h=p-(p-M),f=M-h,p=Er*u,g=p-(p-u),y=u-g,x=f*y-(E-h*g-f*g-h*y),S=O*l,p=Er*O,h=p-(p-O),f=O-h,p=Er*l,g=p-(p-l),y=l-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Ir[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Ir[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Ir[2]=v-(P-d)+(m-d),Ir[3]=P;const k=Sr(L,Mr,4,Ir,_r);E=s*u,p=Er*s,h=p-(p-s),f=s-h,p=Er*u,g=p-(p-u),y=u-g,x=f*y-(E-h*g-f*g-h*y),S=c*l,p=Er*c,h=p-(p-c),f=c-h,p=Er*l,g=p-(p-l),y=l-g,w=f*y-(S-h*g-f*g-h*y),m=x-w,d=x-m,Ir[0]=x-(m+d)+(d-w),v=E+m,d=v-E,b=E-(v-d)+(m-d),m=b-S,d=b-m,Ir[1]=b-(m+d)+(d-S),P=v+m,d=P-v,Ir[2]=v-(P-d)+(m-d),Ir[3]=P;const A=Sr(k,_r,4,Ir,Or);return Or[A-1]}(e,t,r,n,o,i,l)}function Tr(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=Cr(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 Lr=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},kr=function(e){this.p=e},Ar=function(e,t){this.id=e,this.rawCoords=t};function Fr(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var Nr=function(e,t,r,n){this.p=e,this.polylineEdge=t,this.polygonEdge=r,this.isHeadingIn=n,this.distanceFromPolylineEdgeStart=Vr(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Vr(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Vr(e,t){var r=t[0]-e[0],n=t[1]-e[1];return r*=r,n*=n,Math.sqrt(r+n)}Nr.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var jr=1e-9;function Dr(e,t){return e[0]*t[1]-e[1]*t[0]}function Rr(e,t){return e[0]*t[0]+e[1]*t[1]}function Ur(e,t,r){return[e[0]+t*r[0],e[1]+t*r[1]]}function Br(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=Dr(n,o),s=a*a,c=Rr(n,n);if(s>0){var l=Dr(i,o)/a;if(l<0||l>1)return null;var u=Dr(i,n)/a;return u<0||u>1?null:0===l||1===l?[Ur(e.p1.p,l,n)]:0===u||1===u?[Ur(t.p1.p,u,o)]:[Ur(e.p1.p,l,n)]}var d=Rr(i,i);if((s=(a=Dr(i,n))*a)>jr*c*d)return null;var p=Rr(n,i)/c,h=p+Rr(n,o)/c,f=Math.min(p,h),g=Math.max(p,h);return f<=1&&g>=0?1===f?[Ur(e.p1.p,f>0?f:0,n)]:0===g?[Ur(e.p1.p,g<1?g:1,n)]:[Ur(e.p1.p,f>0?f:0,n),Ur(e.p1.p,g<1?g:1,n)]:null}function Gr(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 kr(c[u][0]),h=null,f={nextEdge:null},g=0;g<d;g++){h=new kr(c[u][g+1]),p.nextPoint=h,h.prevPoint=p;var y=new Lr(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,b=v.length,E=0;E<b;E++)for(var x=v[E].length,S=0;S<x;S++){i+=1;var w=v[E][S],P=w.length;a.push(new Ar(i,w));for(var M=new kr(w[0]),_=M,O=void 0,I=null,C={nextEdge:null,prevEdge:null},T=null,L=1;L<P;L++)O=new kr(w[L]),_.nextPoint=O,O.prevPoint=_,I=new Lr(_,O,"polygon",l,i),C.nextEdge=I,I.prevEdge=C,1===L&&(T=I),S>0&&(I.interiorRing=!0),I.intersectPolylineBbox=Fr(I,o),r.push(I),_=O,l+=1,C=I;I.nextEdge=T,T.prevEdge=I,O.nextPoint=M.nextPoint,M.prevPoint=O.prevPoint}return a}(gr(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=Br(c,l);if(null!==u)for(i=0;i<u.length;i++){var d=Cr(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 Nr(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=Hr(p,m),b=!1;if(v===(h=v)&&2===r.length)for(var E=0;E<r.length;E++){r[E].visitCount<2&&(b=!0)}for(;v!==p||b;){(v=(v.isHeadingIn?Wr:$r)(v,m))!==p&&(v=Hr(v,m)),b=!1}if(h.visitCount>=2){for(var x=!1,S=0;S<r.length;S++){var w=r[S];if(w.visitCount<2){p=w,x=!0;break}}x&&(h=p)}p=h}for(var P=c.map(function(e){return[e]}),M=Object.keys(a),_=0;_<M.length;_++){var O=M[_];if(0===a[O])Jr(Xr(Yr(n,parseInt(O)),i),P)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:P}}}function Yr(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.polygonContourId===t)return n}}function Xr(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function Jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];if(Tr(e[0],[n[0]]))return void n.push(e)}t.push([e])}function Hr(e,t){var r=e.polygonEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=qr(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 qr(e,t){for(var r=0;r<t.length;r++){if(t[r]===e)return r}return null}function $r(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=qr(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 Wr(e,t){var r=e.polylineEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=qr(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 Kr(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 zr(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 Zr(e){return"Feature"===e.type?e.geometry:e}function Qr(e,t,r={}){if(!0===r.final)return function(e,t){let r=Qr(t,e);return r=(r+180)%360,r}(e,t);const n=Kr(e),o=Kr(t),i=We(n[0]),a=We(o[0]),s=We(n[1]),c=We(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 $e(Math.atan2(l,u))}var en=Qr;function tn(e,t,r,n={}){const o=Kr(e),i=We(o[0]),a=We(o[1]),s=We(r),c=qe(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=$e(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),d=$e(l);return void 0!==o[2]?Be([u,d,o[2]],n.properties):Be([u,d],n.properties)}var rn=tn;function nn(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=Kr(e),o=Zr(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=Tr(n,s[l]);if(0===e)return!r.ignoreBoundary;e&&(c=!0)}return c}class on{constructor(e=[],t=an){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 an(e,t){return e<t?-1:e>t?1:0}function sn(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 cn(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 ln{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 un=0,dn=0,pn=0;function hn(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;dn+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new ln(o,un,dn,pn),c=new ln(i,un,dn,pn+1);s.otherEvent=c,c.otherEvent=s,sn(s,c)>0?(c.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,c.isLeftEndpoint=!1),t.push(s),t.push(c),o=i,pn+=1}}un+=1}class fn{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function gn(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 yn=function(e,t){const r=new on([],sn);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)hn(r[e],t)}else hn(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new on([],cn);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new fn(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=gn(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function mn(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(Ue(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(Ue(t));const a=yn(Xe(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 Xe(s.map(e=>Be(e)))}function vn(e,t={}){const r=Zr(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=Zr(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return bn(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=Zr(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(bn(e,o))}),Xe(i)}(r,t);default:throw new Error("invalid poly")}}function bn(e,t){return e.length>1?Je(e,t):Ye(e[0],t)}function En(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return et(e,e=>{et(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!xn(t,e);case"Polygon":return!nn(e,t)}break;case"LineString":switch(t.type){case"Point":return!xn(e,t);case"LineString":return!function(e,t,r){const n=mn(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!Sn(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!nn(t,e);case"LineString":return!Sn(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(nn(r,t))return!0;for(const r of t.coordinates[0])if(nn(r,e))return!0;const n=mn(vn(e),vn(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 xn(e,t){for(let r=0;r<e.coordinates.length-1;r++)if(wn(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function Sn(e,t,r){for(const r of t.coordinates)if(nn(r,e))return!0;return mn(t,vn(e),{ignoreSelfIntersections:r}).features.length>0}function wn(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 Pn=Object.defineProperty,Mn=(e,t)=>Pn(e,"name",{value:t,configurable:!0}),_n=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(!In(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=Cn(e),n=Cn(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(!In(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 In(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||Ln(e.properties,t.properties))&&this.compareBBox(e,t)&&this.compare(e.geometry,t.geometry)}compareFeatureCollection(e,t){return In(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)}};Mn(_n,"GeojsonEquality");var On=_n;function In(e,t){return e.coordinates?e.coordinates.length===t.coordinates.length:e.length===t.length}function Cn(e){return e.coordinates.map(t=>({type:e.type.replace("Multi",""),coordinates:t}))}function Tn(e,t,r){return new On(r).compare(e,t)}function Ln(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=kn(r)&&kn(n);if(i&&!Ln(r,n)||!i&&r!==n)return!1}return!0}Mn(In,"sameLength"),Mn(Cn,"explode"),Mn(Tn,"geojsonEquality"),Mn(Ln,"equal");var kn=Mn(e=>null!=e&&"object"==typeof e,"isObject");function An(e,t,r={}){const n=Kr(e),o=zr(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")),Fn(o[e],o[e+1],n,t,void 0===r.epsilon?null:r.epsilon))return!0}return!1}function Fn(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 Nn(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=Vn(e,n);break;case"MultiLineString":case"Polygon":zr(e).forEach(function(e){o.push(Vn(e,n))});break;case"MultiPolygon":zr(e).forEach(function(e){var t=[];e.forEach(function(e){t.push(Vn(e,n))}),o.push(t)});break;case"Point":return e;case"MultiPoint":var i={};zr(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):Ue({type:n,coordinates:o},e.properties,{bbox:e.bbox,id:e.id})}function Vn(e,t){const r=zr(e);if(2===r.length&&!jn(r[0],r[1]))return r;const n=[];let o=0,i=1,a=2;for(n.push(r[o]);a<r.length;)An(r[i],Ye([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(An(n[0],Ye([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(!jn(n[0],n[n.length-1]))throw new Error("invalid polygon, first and last points not equal")}return n}function jn(e,t){return e[0]===t[0]&&e[1]===t[1]}function Dn(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 Zr(e).type===Zr(t).type&&Tn(Nn(e),Nn(t),{precision:n})}function Rn(e,t){var r=Zr(e),n=Zr(t),o=r.type,i=n.type;switch(o){case"MultiPoint":switch(i){case"LineString":return Un(r,n);case"Polygon":return Gn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"MultiPoint":return Un(n,r);case"LineString":return function(e,t){const r=mn(e,t);if(0===r.features.length)return!1;for(const n of r.features)if(!(Dn(n.geometry,Be(e.coordinates[0]))||Dn(n.geometry,Be(e.coordinates[e.coordinates.length-1]))||Dn(n.geometry,Be(t.coordinates[0]))||Dn(n.geometry,Be(t.coordinates[t.coordinates.length-1]))))return!0;return!1}(r,n);case"Polygon":return Bn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"MultiPoint":return Gn(n,r);case"LineString":return Bn(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+o+" geometry not supported")}}function Un(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),Yn(t.coordinates[a],t.coordinates[a+1],e.coordinates[i],s)?r=!0:n=!0}i++}return r&&n}function Bn(e,t){return mn(e,vn(t)).features.length>0}function Gn(e,t){var r=!1,n=!1,o=e.coordinates.length;for(let i=0;i<o&&(!r||!n);i++)nn(Be(e.coordinates[i]),t)?r=!0:n=!0;return n&&r}function Yn(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 Xn(e){return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]}function Jn(e){for(var t=0;t<e.length-1;t++)for(var r=e[t],n=t+1;n<e.length-2;n++){if(An(r,Ye([e[n],e[n+1]])))return!0}return!1}function Hn(e,t,r){for(var n=Ge(e),o=r+1;o<t.length;o++)if(!En(n,Ge(t[o]))&&Rn(n,Ye(t[o][0])))return!1;return!0}var qn=function(e){if(!e.type)return!1;const t=Zr(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(!Xn(n[o]))return!1;if(Jn(n[o]))return!1;if(o>0&&mn(Ge([n[0]]),Ge([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(!Xn(i[a]))return!1;if(Jn(i[a]))return!1;if(0===a&&!Hn(i,t.coordinates,o))return!1;if(a>0&&mn(Ge([i[0]]),Ge([i[a]])).features.length>1)return!1}return!0;default:return!1}};function $n(e){let t=0;if(e&&e.length>0){t+=Math.abs(zn(e[0]));for(let r=1;r<e.length;r++)t-=Math.abs(zn(e[r]))}return t}var Wn=20294876564838.72,Kn=Math.PI/180;function zn(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]*Kn,c=i[1]*Kn;r+=(a[0]*Kn-s)*Math.sin(c),n++}return r*Wn}var Zn=function(e){return function(e,t,r){var n=r;return Qe(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 $n(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)r+=$n(e.coordinates[t]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};function Qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function eo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Qn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Qn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var to=(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=en(n[1],n[0]),a=rn(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=en(n[s-1],n[s]),l=rn(n[s],t,c,{units:r});o.push(l.geometry.coordinates)}o.push(n[s])}var u=en(n[n.length-2],n[n.length-1]),d=rn(n[n.length-1],t,u,{units:r});return o.push(d.geometry.coordinates),Ye(o)}(t);try{i=Gr(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=>Ge(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 Xe(s.map((t,r)=>Ge(t.geometry.coordinates,eo(eo({},e.properties),{},{id:c}),{id:"".concat(c,"-").concat(r+1)})))},ro=(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))},no=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(ro(r,n)<t)return!1}return!0}(e),oo=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(ro(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=Ge([e]);return!!qn(n)&&!(Zn(n)<=0)},io=(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))},ao={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=Wt(r),o=Kt(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 $t(this.getFeature(e))||[]},getMidpoints(e){var t=this.getFeature(e),r=$t(t),n=Wt(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=io(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=Wt(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 so(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function co(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?so(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):so(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var lo=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),uo={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},po=co(co(co(co(co(co({},Pt),tr),or),sr),ao),{},{onSetup(e){var t,r,n=Pt.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.addTouchVertexTarget(n);var i=c(this.map);if(i&&p(i,this.map),"touch"===n.interfaceType&&n.selectedVertexIndex>=0&&"vertex"===n.selectedVertexType){var a=n.vertecies[n.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(n,Qt(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=$t(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?Qt(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=c(this.map);if(o&&p(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&&lo.has(t.key)&&e.selectedVertexIndex>=0){if(t.preventDefault(),t.stopPropagation(),"midpoint"===e.selectedVertexType)return this.insertVertex(e,t);var i=c(this.map),a=this.getFeature(e.featureId);if(!a)return;var s=$t(a),h=null==s?void 0:s[e.selectedVertexIndex];if(!h)return;if(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...h],e._keyboardMoveStartIndex=e.selectedVertexIndex),f(e)&&e._isSnapped&&i){var g=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,y=this.map.project(h),[m,v]=uo[t.key].map(e=>e*g);return e._isSnapped=!1,p(i,this.map),this.moveVertex(e,this.map.unproject({x:y.x+m,y:y.y+v}))}var b=this.getNewCoord(e,t);return f(e)&&i&&(d(i,this.map,this.map.project(b)),l(i))?(e._isSnapped=!0,this.moveVertex(e,u(i))):(e._isSnapped=!1,this.moveVertex(e,b))}if(t.altKey&&lo.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 E,x=null===(E=document.activeElement)||void 0===E?void 0:E.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",lo.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;h(c(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,Pt.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),l=Zt(s,i);e.selectedVertexIndex=l,e.selectedVertexType="vertex",e.coordPath=i;var u=null===(a=e.vertecies)||void 0===a?void 0:a[l];u&&(e._moveStartPosition=[...u],e._moveStartIndex=l)}if("midpoint"===o){var d=this.getFeature(e.featureId),p=Zt(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){h(c(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=$t(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,Pt.onMouseUp.call(this,e,t)},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=c(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),f(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),d(n,this.map,t.point);var o=u(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Pt.onDrag.call(this,e,t)}},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Qt(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",co(co({},e),t))},onStop(e){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 ho(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 fo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ho(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ho(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var go=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,createVertices:a,excludeFeatureIdFromSetup:p=!1,finishOnInvalidClick:h=!1}=t,g=e=>e[r];return fo(fo({},e),{},{onSetup(t){var{map:n}=this,o=p?fo(fo({},t),{},{featureId:void 0}):t,i=fo(fo({},e.onSetup.call(this,o)),t);i[r].properties=t.properties;var{container:a,interfaceType:s,vertexMarkerId:c}=i,l=a.querySelector("#".concat(c));l.style.display=["touch","keyboard"].includes(s)?"block":"none",i.vertexMarker=l;var u=(e,t)=>this[e]=t.bind(this,i),d={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(d).forEach(e=>{var[t,r]=e;return u(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=c(this.map);if(f(t)&&l(n))r=function(e,t){var r=u(t);return r?s(s({},e),{},{lngLat:r}):e}(r,n);else{var i=o(g(t));i.length>0&&(i[i.length-1]=[r.lngLat.lng,r.lngLat.lat])}var a=o(g(t)).length;e.onClick.call(this,t,r),o(g(t)).length>a&&this.pushDrawUndo(t)}},onTap(){},doClick(t){if(!this.map._undoInProgress){var r=g(t),n=o(r);if(this.dispatchVertexChange(n),i(r)){var a=c(this.map),s=f(t)&&function(e,t){var r=u(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),o(g(t)).length>l&&this.pushDrawUndo(t)}else h&&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:e.length})},pushDrawUndo(e){var t=this.map._undoStack;t&&!this.map._undoInProgress&&t.push({type:"draw_vertex",geometryType:n,featureId:g(e).id})},undoVertex(e){var t=g(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,g(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(f(t)){var n=c(this.map);d(n,this.map,r.point);var o=u(n);o&&(r=fo(fo({},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)){f(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})}(c(this.map),this.map);var r=c(this.map),n=f(t)&&u(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(g(e)))},toDisplayFeatures(t,r,o){e.toDisplayFeatures.call(this,t,r,o);var i=g(t);r.geometry.type===n&&r.id===i.id&&a(r,o,je)},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"}})},yo=go(Ot,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>oo(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)))}}),mo=go(It,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>no(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)))}}),vo={editColorsForeground:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editColorsBackground:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editColorsHalo:{light:"rgba(11,12,12,1)",dark:"#ffffff"},splitInvalidColors:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValidColors:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},stroke:"rgba(212,53,28,1)",strokeWidth:2,fill:"rgba(212,53,28,0.1)",snapLayers:[],snapColors:{vertex:"rgba(212,53,28,1)",midpoint:"rgba(40,161,151,1)",edge:"rgba(29,112,184,1)"},snapRadius:10},bo=e=>{var t;return null!==(t=e.mapColorScheme)&&void 0!==t?t:"light"},Eo=(e,t)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],vo[t]],xo=e=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":Eo(e,"fill")}}),So=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":Eo(e,"stroke"),"line-width":Eo(e,"strokeWidth")}}),wo=e=>({id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":e,"fill-opacity":.1}}),Po=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}}),Mo=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}}),_o=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}}),Oo=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}}),Io=e=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"]],paint:{"circle-radius":6,"circle-color":e}}),Co=(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}}),To=e=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":6,"circle-color":e}}),Lo=e=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":4,"circle-color":e}}),ko=(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}}),Ao=e=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":4,"circle-color":e}}),Fo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),No=e=>{var t=vo.editColorsForeground[bo(e)],r=vo.editColorsBackground[bo(e)],n=vo.editColorsHalo[bo(e)],o=vo.splitInvalidColors[bo(e)],i=vo.splitValidColors[bo(e)];return[xo(e),wo(t),Po(t),So(e),Mo(o),_o(i),Oo(t),Lo(t),ko(r,n),Ao(t),Io(t),Co(r,n),To(t),Fo(t),{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 Vo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function jo(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 Do(e,t,r){void 0===r&&(r={});var n=Vo(e),o=Vo(t),i=We(o[1]-n[1]),a=We(o[0]-n[0]),s=We(n[1]),c=We(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return He(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Ro(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return Je(e,t);return Ye(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Uo(e,t,r,n){void 0===n&&(n={});var o=Vo(e),i=We(o[0]),a=We(o[1]),s=We(r),c=qe(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Be([$e(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),$e(l)],n.properties)}function Bo(e){if(!e)throw new Error("geojson is required");var t=[];return et(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=jo(n);break;case"LineString":r=[jo(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=Ye([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)}),Xe(t)}var Go={exports:{}};function Yo(e,t,r,n,o){Xo(e,t,r||0,n||e.length-1,o||Ho)}function Xo(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);Xo(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(Jo(e,r,t),o(e[n],u)>0&&Jo(e,r,n);d<p;){for(Jo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?Jo(e,r,p):Jo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function Jo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Ho(e,t){return e<t?-1:e>t?1:0}function qo(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 $o(e,t){Wo(e,0,e.children.length,t,e)}function Wo(e,t,r,n,o){o||(o=ii(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];Ko(o,e.leaf?n(t):t)}return o}function Ko(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 zo(e,t){return e.minX-t.minX}function Zo(e,t){return e.minY-t.minY}function Qo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ei(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ti(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 ri(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 ni(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function oi(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function ii(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ai(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;Yo(e,a,t,r,o),i.push(t,a,a,r)}}var si,ci=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(!oi(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;oi(e,s)&&(t.leaf?r.push(a):ni(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!oi(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(oi(e,i)){if(t.leaf||ni(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=ii([]),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=qo(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!ni(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=ii(e.slice(t,r+1)),$o(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=ii([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));ai(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);ai(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 $o(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=Qo(a),c=ti(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),Ko(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=ii(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,$o(r,this.toBBox),$o(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=ii([e,t]),this.data.height=e.height+1,this.data.leaf=!1,$o(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=Wo(e,0,a,this.toBBox),s=Wo(e,a,r,this.toBBox),c=ri(t,s),l=Qo(t)+Qo(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:zo,o=e.leaf?this.compareMinY:Zo;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=Wo(e,0,t,o),a=Wo(e,r-t,r,o);let s=ei(i)+ei(a);for(let n=t;n<r-t;n++){const t=e.children[n];Ko(i,e.leaf?o(t):t),s+=ei(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Ko(a,e.leaf?o(t):t),s+=ei(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Ko(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():$o(e[r],this.toBBox)}}}),li=J(ci),ui={};function di(){if(si)return ui;si=1,Object.defineProperty(ui,"__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 ui.areaFactors=r,ui.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},ui.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},ui.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},ui.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)},ui.degreesToRadians=function(e){return e%360*Math.PI/180},ui.earthRadius=e,ui.factors=t,ui.feature=n,ui.featureCollection=s,ui.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")}},ui.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},ui.isNumber=f,ui.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},ui.lengthToDegrees=function(e,t){return h(p(e,t))},ui.lengthToRadians=p,ui.lineString=a,ui.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},ui.multiLineString=c,ui.multiPoint=l,ui.multiPolygon=u,ui.point=o,ui.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},ui.polygon=i,ui.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},ui.radiansToDegrees=h,ui.radiansToLength=d,ui.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},ui.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")})},ui.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")},ui}var pi,hi={};function fi(){if(pi)return hi;pi=1,Object.defineProperty(hi,"__esModule",{value:!0});var e=di();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var b=0;b<c;b++){var E=0,x=0;if(null!==(s=d?u.geometries[b]: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,E,x))return!1;h++,E++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,E,x))return!1;h++,"MultiPoint"===S&&E++}"LineString"===S&&E++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,E,x))return!1;h++}"MultiLineString"===S&&E++,"Polygon"===S&&x++}"Polygon"===S&&E++;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,E,x))return!1;h++}x++}E++}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 hi.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},hi.coordEach=t,hi.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},hi.featureEach=n,hi.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},hi.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")},hi.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")},hi.flattenEach=i,hi.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},hi.geomEach=o,hi.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},hi.lineEach=s,hi.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},hi.propEach=r,hi.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},hi.segmentEach=a,hi.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},hi}var gi,yi,mi={};function vi(){if(gi)return mi;gi=1,Object.defineProperty(mi,"__esModule",{value:!0});var e=fi();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 mi.bbox=t,mi.default=r,mi}var bi=function(){if(yi)return Go.exports;yi=1;var e=li,t=di(),r=fi(),n=vi().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 Go.exports=a,Go.exports.default=a,Go.exports}(),Ei=X(bi);function xi(e,t){var r={},n=[];if("LineString"===e.type&&(e=Ue(e)),"LineString"===t.type&&(t=Ue(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=Si(e,t);return o&&n.push(o),Xe(n)}var i=Ei();return i.load(Bo(t)),Ze(Bo(e),function(e){Ze(i.search(e),function(t){var o=Si(e,t);if(o){var i=jo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),Xe(n)}function Si(e,t){var r=jo(e),n=jo(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?Be([o+g*(a-o),i+g*(s-i)]):null}function wi(e,t,r){void 0===r&&(r={});var n=Be([1/0,1/0],{dist:1/0}),o=0;return et(e,function(e){for(var i=jo(e),a=0;a<i.length-1;a++){var s=Be(i[a]);s.properties.dist=Do(t,s,r);var c=Be(i[a+1]);c.properties.dist=Do(t,c,r);var l=Do(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=en(s,c),p=Uo(t,u,d+90,r),h=Uo(t,u,d-90,r),f=xi(Ye([p.geometry.coordinates,h.geometry.coordinates]),Ye([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Do(t,g,r),g.properties.location=o+Do(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 Pi(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 Mi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=Pi(e),i=We(o[0]),a=We(o[1]),s=We(r),c=qe(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Be([$e(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),$e(l)],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=Pi(e),o=Pi(t),i=We(o[1]-n[1]),a=We(o[0]-n[0]),s=We(n[1]),c=We(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return He(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,en(e,t));return r}var _i=function(){return _i=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},_i.apply(this,arguments)},Oi=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=_i(_i({},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 Do(Be(e),Be(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=Do(Be([r.lng,r.lat]),Be([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(tn(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),Ge([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=Xe(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(Xe([])))}),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=[],ze(e,function(e){n.push(e)}),n),i=[];if(o.map(function(e){var n=Do(Be(e),Be([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(Ye(e))});break;case"Polygon":var o=Ro(e.geometry);n.push(o);break;case"MultiPolygon":Ro(e.geometry).coodinates.map(function(e){n.push(Ye(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(Bo(e).features)});var i=[];if(o.map(function(e){var n=Mi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Do(n,Be([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=wi(n[i],Be([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 Ii(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 Ci(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ii(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ii(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ti="snap-helper-circle";function Li(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 Ai(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e._snapInitialized)return e._snapInstance;e._snapInitialized=!0;var{layers:n=[],radius:o=15,rules:i=["vertex","midpoint","edge"],status:a=!1,onSnapped:s=()=>{},colors:c={}}=r;function l(r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,e.getLayer(Ti)&&e.removeLayer(Ti),e.getSource(Ti)&&e.removeSource(Ti),ki(r);var c=new Oi({map:e,drawing:t,options:{layers:n,radius:o,rules:i},status:a,onSnapped:s}),l=a;return Object.defineProperty(c,"status",{get:()=>l,set(){},configurable:!0}),c.setSnapStatus=e=>{l=e},c._defaultLayers=n,c._activeLayers=null,c.setSnapLayers=e=>{null==e?c._activeLayers=null:Array.isArray(e)&&(c._activeLayers=e)},void 0!==e._pendingSnapLayers&&(c.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=c,c}!function(e){if(!Oi.prototype.__snapPatched){Oi.prototype.__snapPatched=!0;var t=Oi.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(Ti)&&this.map.setLayoutProperty(Ti,"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=>Ge(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>Ye(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){return console.log(e),this.snapStatus=!1,void(this.snapCoords=null)}}}}(Ci(Ci({},vo.snapColors),c)),e.on("style.load",()=>{Li(()=>e._removed?null:e.getSource("mapbox-gl-draw-hot"),t=>{var r;(ki(t),e.getSource(Ti)||e.addSource(Ti,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Ti))||e.addLayer({id:Ti,type:"fill",source:Ti,paint:{"fill-color":["get","color"],"fill-opacity":.6},layout:{visibility:null!==(r=e._snapInstance)&&void 0!==r&&r.status?"visible":"none"}});e._snapInstance||l(t)})}),e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(Ti)){e.setLayoutProperty(Ti,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(Ti,"visibility","visible")}}),Li(()=>e._removed?null:e.getSource("mapbox-gl-draw-hot"),l)}function Fi(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 Ni(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Fi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Fi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vi=e=>{var{mapStyle:t,mapProvider:r,events:n,eventBus:o,snapLayers:i}=e,{map:a}=r;Ht.constants.classes.CONTROL_BASE="maplibregl-ctrl",Ht.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Ht.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var s=new Ht({modes:Ni(Ni({},Ht.modes),{},{disabled:qt,edit_vertex:po,draw_polygon:yo,draw_line:mo}),styles:No(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,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,Ai(a,s,{layers:i,radius:10,rules:["vertex","edge"]});var h=e=>{a.once("idle",()=>{((e,t)=>{No(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)})};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"],Di=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},Ri=["stroke","fill","strokeWidth","properties"];function Ui(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 Bi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ui(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ui(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Gi=["stroke","fill","strokeWidth","properties"];function Yi(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 Xi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Yi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ji=["stroke","fill","strokeWidth","properties"];function Hi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function qi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Hi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Hi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function $i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Wi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?$i(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):$i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ki=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:i},InitComponent:e=>{var{appState:r,appConfig:n,mapState:o,pluginConfig:i,pluginState:a,services:s,mapProvider:l,buttonConfig:u}=e,{events:d,eventBus:p}=s,{crossHair:f}=o,g=["touch","keyboard"].includes(r.interfaceType);t(()=>{var e,t,n,s,c,u=null===(e=null===(t=i.includeModes)||void 0===t?void 0:t.includes(r.mode))||void 0===e||e,h=null!==(n=null===(s=i.excludeModes)||void 0===s?void 0:s.includes(r.mode))&&void 0!==n&&n;if(o.isMapReady&&u&&!h){var{remove:f}=Vi({mapStyle:o.mapStyle,snapLayers:i.snapLayers,mapProvider:l,events:d,eventBus:p});return a.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:(null===(c=i.snapLayers)||void 0===c?void 0:c.length)>0}),p.emit("draw:ready"),()=>f()}},[o.isMapReady,r.mode]),t(()=>{if(["draw_polygon","draw_line"].includes(a.mode)&&g){var e=f.isVisible;return f.fixAtCenter(),()=>{e||f.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:l,drawSnap:u,drawCancel:d}=n,{map:p,draw:f}=r,{dispatch:g,feature:y,tempFeature:m}=t,v=()=>{r.snapEnabled=!1,g({type:"SET_SNAP",payload:!1});var e,t=c(p);t&&(null===(e=t.setSnapStatus)||void 0===e||e.call(t,!1),h(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(),g({type:"SET_MODE",payload:null}),g({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},E=()=>{f.trash(),null!=m&&m.id&&f.delete(m.id),y&&f.add(y),v(),f.changeMode("disabled"),b(),o.emit("draw:cancelled",y)},x=0,S=()=>{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))},w=e=>t=>{var r=t.features[0];b(),setTimeout(()=>f.changeMode("disabled"),0),o.emit(e,r)},P=e=>{var t=e.features[0];o.emit("draw:updated",t)},M=w("draw:created"),_=w("draw:edited"),O=e=>{g({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),o.emit("draw:vertexselection",e)},I=e=>{g({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertecies:e.numVertecies}})},C=e=>{g({type:"SET_UNDO_STACK_LENGTH",payload:e.length})};return i.onClick=()=>{var e,t=f.getMode();v(),null===(e=r.undoStack)||void 0===e||e.clear();var n=f.getAll().features;if("edit_vertex"!==t){if(["draw_polygon","draw_line"].includes(t)&&0!==n.length){var o=null==n?void 0:n[0],i=o.geometry;if("Polygon"===i.type){var a=i.coordinates[0];i.coordinates[0]=[...a.slice(0,-2),a[0]]}else i.coordinates=i.coordinates.slice(0,-1);p.fire("draw.create",{features:[o]})}}else p.fire("draw.editfinish",{features:[f.get(m.id)]})},d.onClick=E,s.onClick=()=>{if("edit_vertex"!==f.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})}}},u.onClick=()=>{var e=Date.now();if(!(e-x<300)){x=e;var n=!t.snap;g({type:"TOGGLE_SNAP"}),r.snapEnabled=n;var o=c(p);null!=o&&o.setSnapStatus&&o.setSnapStatus(n),!n&&o&&(h(o),p.getLayer("snap-helper-circle")&&p.setLayoutProperty("snap-helper-circle","visibility","none"))}},p.on("styledata",S),p.on("draw.cancel",E),p.on("draw.create",M),p.on("draw.editfinish",_),p.on("draw.update",P),p.on("draw.vertexselection",O),p.on("draw.vertexchange",I),p.on("draw.undochange",C),()=>{[i,a,s,l,u,d].forEach(e=>{e&&(e.onClick=null)}),p.off("styledata",S),p.off("draw.cancel",E),p.off("draw.create",M),p.off("draw.editfinish",_),p.off("draw.update",P),p.off("draw.vertexselection",O),p.off("draw.vertexchange",I),p.off("draw.undochange",C)}}({mapProvider:l,buttonConfig:u,pluginState:a,eventBus:p});return()=>e()}},[l,r,a])},buttons:[Wi({id:"drawAddPoint",label:"Add point",iconId:"plus",variant:"touch",hiddenWhen:e=>{var{appState:t,pluginState:r}=e;return!["draw_polygon","draw_line"].includes(r.mode)||"touch"!==t.interfaceType}},Ki(!1)),Wi({id:"drawCancel",label:"Cancel",variant:"tertiary",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode}},Ki(!0)),Wi({id:"drawMenu",label:"Menu",iconId:"menu",variant:"tertiary",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)}}]},Ki(!0)),Wi({id:"drawDone",label:"Done",variant:"primary",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)}},Ki(!0))],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:l,services:u}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=l,{eventBus:g}=u;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=c(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:b,strokeWidth:E,properties:x}=d,S=r(d,Ri),w=Bi(Bi({},x),Di({stroke:v,fill:b,strokeWidth:E}));h.changeMode("draw_polygon",Bi(Bi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,getSnapEnabled:()=>!0===l.snapEnabled,featureId:t},S),{},{properties:w})),p({type:"SET_MODE",payload:"draw_polygon"})}},newLine:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:l,services:u}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:p}=s,{draw:h,map:f}=l,{eventBus:g}=u;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=c(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:b,strokeWidth:E,properties:x}=d,S=r(d,Gi),w=Xi(Xi({},x),Di({stroke:v,fill:b,strokeWidth:E}));h.changeMode("draw_line",Xi(Xi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,getSnapEnabled:()=>!0===l.snapEnabled,featureId:t},S),{},{properties:w})),p({type:"SET_MODE",payload:"draw_line"})}},editFeature:function(e,t){var r,{appState:n,appConfig:o,mapState:i,pluginConfig:a,pluginState:s,mapProvider:l}=e,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:d}=s,{draw:p,map:h}=l;if(p&&p.get(t)){var f,g=null;if(void 0===u.snapLayers)g=null!==(f=a.snapLayers)&&void 0!==f?f:null;else g=u.snapLayers;var y=c(h);null!=y&&y.setSnapLayers?y.setSnapLayers(g):g&&(h._pendingSnapLayers=g),d({type:"SET_HAS_SNAP_LAYERS",payload:(null===(r=g)||void 0===r?void 0:r.length)>0}),p.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===l.snapEnabled});var m=p.get(t);return d({type:"SET_FEATURE",payload:{feature:m,tempFeature:m}}),d({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=qi(qi({},r(t,Ji)),{},{properties:qi(qi({},u),Di({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:l,map:u}=i;if(l){var d=l.get(t),p=["stroke-inactive.cold",...a.snapLayers||[]],h=c(u);null!=h&&h.setSnapLayers?h.setSnapLayers(p):a.snapLayers&&(u._pendingSnapLayers=p),s({type:"SET_HAS_SNAP_LAYERS",payload:!0}),l.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"}}),u.on("draw.create",e=>{var t=e.features[0],r=to(d,t);l.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=!!to(d,t);e.properties.splitter=r?"valid":"invalid",e.ctx.store.render(),"edit_vertex"===l.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);u.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};