@defra/interactive-map 0.0.54-alpha → 0.0.55-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 (139) hide show
  1. package/assets/templates/add-polygons.njk +1 -1
  2. package/assets/templates/add-symbols.njk +4 -4
  3. package/assets/templates/draw-tools.njk +7 -7
  4. package/assets/templates/marker-panel.njk +5 -5
  5. package/assets/templates/place-marker.njk +8 -8
  6. package/assets/templates/search-control.njk +1 -1
  7. package/assets/templates/select-feature.njk +7 -7
  8. package/assets/templates/style-switcher.njk +4 -4
  9. package/assets/templates/toggle-marker-label.njk +3 -3
  10. package/dist/esm/im-core.js +1 -1
  11. package/dist/esm/im-shell.js +1 -1
  12. package/dist/esm/index.js +1 -1
  13. package/dist/umd/im-core.js +1 -1
  14. package/dist/umd/im-core.js.LICENSE.txt +0 -30
  15. package/dist/umd/index.js +1 -1
  16. package/dist/umd/index.js.LICENSE.txt +0 -20
  17. package/docs/api.md +3 -13
  18. package/docs/building-a-plugin.md +2 -2
  19. package/docs/examples/add-marker-with-panel.mdx +46 -44
  20. package/docs/examples/add-polygons.mdx +100 -98
  21. package/docs/examples/add-symbols.mdx +75 -73
  22. package/docs/examples/basic-map.mdx +16 -14
  23. package/docs/examples/button-map.mdx +16 -14
  24. package/docs/examples/draw-tools.mdx +119 -117
  25. package/docs/examples/place-marker.mdx +51 -49
  26. package/docs/examples/search-control.mdx +22 -20
  27. package/docs/examples/select-feature.mdx +107 -105
  28. package/docs/examples/style-switcher.mdx +47 -45
  29. package/docs/examples/toggle-marker-label.mdx +30 -28
  30. package/docs/getting-started.md +26 -24
  31. package/docs/plugins/draw.md +10 -10
  32. package/docs/plugins/interact.md +9 -9
  33. package/docs/plugins/plugin-descriptor.md +1 -1
  34. package/docs/plugins/search.md +3 -3
  35. package/docusaurus.config.cjs +23 -0
  36. package/package.json +3 -7
  37. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  38. package/plugins/beta/draw-es/dist/esm/index.js +1 -1
  39. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  40. package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
  41. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  42. package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
  43. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  44. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  45. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
  46. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  47. package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
  48. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
  49. package/plugins/beta/frame/dist/esm/index.js +1 -1
  50. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
  51. package/plugins/beta/frame/dist/umd/index.js +1 -1
  52. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  53. package/plugins/beta/map-styles/dist/esm/index.js +1 -1
  54. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  55. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  56. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
  57. package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
  58. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
  59. package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
  60. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  61. package/plugins/beta/use-location/dist/esm/index.js +1 -1
  62. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  63. package/plugins/beta/use-location/dist/umd/index.js +1 -1
  64. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  65. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  66. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  67. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  68. package/plugins/datasets/dist/esm/index.js +1 -1
  69. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  70. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  71. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  72. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  73. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  74. package/plugins/datasets/dist/umd/index.js +1 -1
  75. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  76. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  77. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  78. package/plugins/draw/dist/esm/index.js +1 -1
  79. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  80. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  81. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  82. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  83. package/plugins/draw/dist/umd/index.js +1 -1
  84. package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
  85. package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
  86. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  87. package/plugins/interact/dist/esm/index.js +1 -1
  88. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  89. package/plugins/interact/dist/umd/index.js +1 -1
  90. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  91. package/plugins/map-key/dist/esm/index.js +1 -1
  92. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  93. package/plugins/map-key/dist/umd/index.js +1 -1
  94. package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
  95. package/plugins/menu/dist/esm/index.js +1 -1
  96. package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
  97. package/plugins/menu/dist/umd/index.js +1 -1
  98. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  99. package/plugins/search/dist/esm/index.js +1 -1
  100. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  101. package/plugins/search/dist/umd/index.js +1 -1
  102. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  103. package/providers/beta/esri/dist/esm/index.js +1 -1
  104. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
  105. package/providers/beta/open-names/dist/esm/index.js +1 -1
  106. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
  107. package/providers/beta/open-names/dist/umd/index.js +1 -1
  108. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  109. package/providers/beta/openlayers/dist/esm/index.js +1 -1
  110. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  111. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  112. package/providers/beta/openlayers/src/index.js +27 -4
  113. package/providers/beta/openlayers/src/index.test.js +47 -0
  114. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  115. package/providers/maplibre/dist/esm/index.js +1 -1
  116. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  117. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
  118. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  119. package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
  120. package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
  121. package/providers/maplibre/dist/umd/index.js +1 -1
  122. package/providers/maplibre/src/index.js +41 -12
  123. package/providers/maplibre/src/index.test.js +43 -12
  124. package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
  125. package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
  126. package/providers/maplibre/src/utils/spatial.js +22 -12
  127. package/providers/maplibre/src/utils/spatial.test.js +6 -6
  128. package/providers/maplibre/src/utils/workerUrl.js +15 -0
  129. package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
  130. package/rollup.esm.mjs +38 -1
  131. package/src/InteractiveMap/InteractiveMap.js +2 -1
  132. package/src/InteractiveMap/InteractiveMap.test.js +9 -2
  133. package/src/InteractiveMap/domStateManager.js +21 -1
  134. package/src/InteractiveMap/domStateManager.test.js +48 -1
  135. package/src/InteractiveMap/polyfills.js +4 -3
  136. package/src/InteractiveMap/polyfills.test.js +12 -0
  137. package/src/types.js +3 -5
  138. package/webpack.dev.mjs +2 -0
  139. package/webpack.umd.mjs +28 -7
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import{useEffect as t}from"preact/compat";import r from"@babel/runtime/helpers/objectWithoutProperties";function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function o(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach(function(r){e(t,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))})}return t}var i=new Set(["draw_polygon","draw_line"]),a={SET_MODE:(e,t)=>o(o({},e),{},{mode:t,numVertecies:i.has(t)?0:e.numVertecies}),SET_ACTION:(e,t)=>o(o({},e),{},{action:t.name,actionValid:t.isValid}),SET_FEATURE:(e,t)=>o(o({},e),{},{feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>o(o({},e),{},{selectedVertexIndex:t.index,numVertecies:t.numVertecies}),TOGGLE_SNAP:e=>o(o({},e),{},{snap:!e.snap}),SET_SNAP:(e,t)=>o(o({},e),{},{snap:!!t}),SET_HAS_SNAP_LAYERS:(e,t)=>o(o({},e),{},{hasSnapLayers:!!t}),SET_UNDO_STACK_LENGTH:(e,t)=>o(o({},e),{},{undoStackLength:t})},s={APP_ADD_MARKER:"app:addmarker",APP_UPDATE_MARKER:"app:updatemarker",APP_REMOVE_MARKER:"app:removemarker",APP_ADD_BUTTON:"app:addbutton",APP_TOGGLE_BUTTON_STATE:"app:togglebuttonstate",APP_ADD_PANEL:"app:addpanel",APP_REMOVE_PANEL:"app:removepanel",APP_SHOW_PANEL:"app:showpanel",APP_HIDE_PANEL:"app:hidepanel",APP_ADD_CONTROL:"app:addcontrol",APP_SET_APPLICATION_MODE:"app:setapplicationmode",APP_CLEAR_APPLICATION_MODE:"app:clearapplicationmode",APP_SHOW_HINT:"app:showhint",APP_DISMISS_HINT:"app:dismisshint",APP_READY:"app:ready",APP_OPENED:"app:opened",APP_CLOSED:"app:closed",APP_FULLSCREEN_CHANGE:"app:fullscreenchange",APP_PANEL_OPENED:"app:panelopened",APP_PANEL_CLOSED:"app:panelclosed",MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize",MAP_SET_SPATIAL_LIST:"map:setspatiallist",MAP_SET_SPATIAL_LIST_SUPPRESSED:"map:setspatiallistsuppressed",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_SET_PIXEL_RATIO:"map:setpixelratio",MAP_FIT_TO_BOUNDS:"map:fittobounds",MAP_SET_VIEW:"map:setview",MAP_INIT_MAP_STYLES:"map:initmapstyles",MAP_STYLE_CHANGE:"map:stylechange",MAP_LOADED:"map:loaded",MAP_READY:"map:ready",MAP_SIZE_CHANGE:"map:sizechange",MAP_FIRST_IDLE:"map:firstidle",MAP_MOVE_START:"map:movestart",MAP_MOVE:"map:move",MAP_MOVE_END:"map:moveend",MAP_STATE_UPDATED:"map:stateupdated",MAP_DATA_CHANGE:"map:datachange",MAP_RENDER:"map:render",MAP_CLICK:"map:click",MAP_DESTROY:"map:destroy"};function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function l(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?c(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function u(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function p(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 d(e){return p(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function h(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function f(e,t){var r,n,o;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(r=e.snappedFeatures)&&void 0!==r&&r.length&&(e.snappedFeatures.length=0),null!==(n=e.closeFeatures)&&void 0!==n&&n.length&&(e.closeFeatures.length=0),null!==(o=e.lines)&&void 0!==o&&o.length&&(e.lines.length=0));null!=t&&t.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function g(e){var t,r,n;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(t=e.snappedFeatures)&&void 0!==t&&t.length&&(e.snappedFeatures.length=0),null!==(r=e.closeFeatures)&&void 0!==r&&r.length&&(e.closeFeatures.length=0),null!==(n=e.lines)&&void 0!==n&&n.length&&(e.lines.length=0))}function y(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}const m={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},v={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},E={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},b={POLYGON:"polygon",LINE:"line_string",POINT:"point"},x={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},S={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},P={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},w={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},_={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},M={ACTIVE:"true",INACTIVE:"false"},I=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var O=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:M,classes:m,cursors:E,events:P,geojsonTypes:x,interactions:I,meta:_,modes:S,sources:v,types:b,updateActions:w});function C(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function T(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function L(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===M.ACTIVE&&e.featureTarget.properties.meta===_.FEATURE))}function A(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===M.INACTIVE&&e.featureTarget.properties.meta===_.FEATURE))}function k(e){return void 0===e.featureTarget}function F(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===_.FEATURE)}function N(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===_.VERTEX)}function V(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function D(e){return"Escape"===e.key||27===e.keyCode}function j(e){return"Enter"===e.key||13===e.keyCode}function R(e){return"Backspace"===e.key||8===e.keyCode}function U(e){return"Delete"===e.key||46===e.keyCode}function B(e){return"1"===e.key||49===e.keyCode}function G(e){return"2"===e.key||50===e.keyCode}function Y(e){return"3"===e.key||51===e.keyCode}function X(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var H=Object.freeze({__proto__:null,isActiveFeature:L,isBackspaceKey:R,isDeleteKey:U,isDigit1Key:B,isDigit2Key:G,isDigit3Key:Y,isDigitKey:X,isEnterKey:j,isEscapeKey:D,isFeature:F,isInactiveFeature:A,isOfMetaType:C,isShiftDown:V,isShiftMousedown:T,isTrue:function(){return!0},isVertex:N,noTarget:k});function J(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function q(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var $,K,W={},z={};function Z(){return $||($=1,z.RADIUS=6378137,z.FLATTENING=1/298.257223563,z.POLAR_RADIUS=6356752.3142),z}var Q=function(){if(K)return W;K=1;var e=Z();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(r(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(r(e[n]))}return t}function r(t){var r,o,i,a,s,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,a=u-1,s=0):c===u-1?(i=u-1,a=0,s=1):(i=c,a=c+1,s=c+2),r=t[i],o=t[a],l+=(n(t[s][0])-n(r[0]))*Math.sin(n(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function n(e){return e*Math.PI/180}return W.geometry=function e(r){var n,o=0;switch(r.type){case"Polygon":return t(r.coordinates);case"MultiPolygon":for(n=0;n<r.coordinates.length;n++)o+=t(r.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<r.geometries.length;n++)o+=e(r.geometries[n]);return o}},W.ring=r,W}(),ee=J(Q);const te={Point:0,LineString:1,MultiLineString:1,Polygon:2};function re(e,t){const r=te[e.geometry.type]-te[t.geometry.type];return 0===r&&e.geometry.type===x.POLYGON?e.area-t.area:r}function ne(e){return e.map(e=>(e.geometry.type===x.POLYGON&&(e.area=ee.geometry({type:x.FEATURE,property:{},geometry:e.geometry})),e)).sort(re).map(e=>(delete e.area,e))}function oe(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function ie(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}ie.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},ie.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},ie.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},ie.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((e,t)=>e.v-t.v).map(e=>e.k)},ie.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const ae=[_.FEATURE,_.MIDPOINT,_.VERTEX];var se={click:function(e,t,r){return ce(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return ce(e,t,r,r.options.touchBuffer)}};function ce(e,t,r,n){if(null===r.map)return[];const o=e?oe(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==ae.indexOf(e.properties.meta)),s=new ie,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),ne(c)}function le(e,t){const r=se.click(e,null,t),n={mouse:E.NONE};return r[0]&&(n.mouse=r[0].properties.active===M.ACTIVE?E.MOVE:E.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=E.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function ue(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function pe(e,t,r={}){const n=null!=r.fineTolerance?r.fineTolerance:4,o=null!=r.grossTolerance?r.grossTolerance:12,i=null!=r.interval?r.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const a=ue(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function de(e,t,r={}){const n=null!=r.tolerance?r.tolerance:25,o=null!=r.interval?r.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return ue(e.point,t.point)<n&&t.time-e.time<o}const he=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===r[e])throw new Error(`Invalid event type: ${e}`);r[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=r[e];let a=i.length;for(;a--;){const e=i[a];if(e.selector(o)){e.fn.call(n,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const fe=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function ge(){return fe()}const ye=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||ge(),this.type=t.geometry.type};ye.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ye.prototype.incomingCoords=function(e){this.setCoordinates(e)},ye.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ye.prototype.setProperty=function(e,t){this.properties[e]=t},ye.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:x.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ye.prototype.internal=function(e){const t={id:this.id,meta:_.FEATURE,"meta:type":this.type,active:M.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:x.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const me=function(e,t){ye.call(this,e,t)};(me.prototype=Object.create(ye.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},me.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},me.prototype.getCoordinate=function(){return this.getCoordinates()};const ve=function(e,t){ye.call(this,e,t)};(ve.prototype=Object.create(ye.prototype)).isValid=function(){return this.coordinates.length>1},ve.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},ve.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},ve.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},ve.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ee=function(e,t){ye.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ee.prototype=Object.create(ye.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ee.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ee.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ee.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(e=>parseInt(e,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},Ee.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},Ee.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},Ee.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ee.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const be={MultiPoint:me,MultiLineString:ve,MultiPolygon:Ee},xe=(e,t,r,n,o)=>{const i=r.split("."),a=parseInt(i[0],10),s=i[1]?i.slice(1).join("."):null;return e[a][t](s,n,o)},Se=function(e,t){if(ye.call(this,e,t),delete this.coordinates,this.model=be[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function Pe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Se.prototype=Object.create(ye.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:ge(),type:x.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Se.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Se.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Se.prototype.getCoordinate=function(e){return xe(this.features,"getCoordinate",e)},Se.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===x.POLYGON?e.getCoordinates():e.coordinates)))},Se.prototype.updateCoordinate=function(e,t,r){xe(this.features,"updateCoordinate",e,t,r),this.changed()},Se.prototype.addCoordinate=function(e,t,r){xe(this.features,"addCoordinate",e,t,r),this.changed()},Se.prototype.removeCoordinate=function(e){xe(this.features,"removeCoordinate",e),this.changed()},Se.prototype.getFeatures=function(){return this.features},Pe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Pe.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Pe.prototype.getSelected=function(){return this._ctx.store.getSelected()},Pe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Pe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Pe.prototype.getFeature=function(e){return this._ctx.store.get(e)},Pe.prototype.select=function(e){return this._ctx.store.select(e)},Pe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Pe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Pe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Pe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Pe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Pe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Pe.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Pe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Pe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Pe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Pe.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return se[r](e,t,this._ctx)},Pe.prototype.newFeature=function(e){const t=e.geometry.type;return t===x.POINT?new me(this._ctx,e):t===x.LINE_STRING?new ve(this._ctx,e):t===x.POLYGON?new Ee(this._ctx,e):new Se(this._ctx,e)},Pe.prototype.isInstanceOf=function(e,t){if(e===x.POINT)return t instanceof me;if(e===x.LINE_STRING)return t instanceof ve;if(e===x.POLYGON)return t instanceof Ee;if("MultiFeature"===e)return t instanceof Se;throw new Error(`Unknown feature class: ${e}`)},Pe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Pe.prototype.onSetup=function(){},Pe.prototype.onDrag=function(){},Pe.prototype.onClick=function(){},Pe.prototype.onMouseMove=function(){},Pe.prototype.onMouseDown=function(){},Pe.prototype.onMouseUp=function(){},Pe.prototype.onMouseOut=function(){},Pe.prototype.onKeyUp=function(){},Pe.prototype.onKeyDown=function(){},Pe.prototype.onTouchStart=function(){},Pe.prototype.onTouchMove=function(){},Pe.prototype.onTouchEnd=function(){},Pe.prototype.onTap=function(){},Pe.prototype.onStop=function(){},Pe.prototype.onTrash=function(){},Pe.prototype.onCombineFeature=function(){},Pe.prototype.onUncombineFeature=function(){},Pe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const we={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},_e=Object.keys(we);function Me(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Pe(r));return{start(){o=i.onSetup(n),_e.forEach(t=>{const r=we[t];let n=()=>!1;var a;e[r]&&(n=()=>!0),this.on(t,n,(a=r,e=>i[a](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function Ie(e){return[].concat(e).filter(e=>void 0!==e)}function Oe(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(v.HOT)))return s();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let r=[],n=[];e.isDirty?n=e.getAllIds():(r=e.getChangedIds().filter(t=>void 0!==e.get(t)),n=e.sources.hot.filter(t=>t.properties.id&&-1===r.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===r.indexOf(t)});const i=o!==e.sources.cold.length||n.length>0;function a(r,n){const o=e.get(r).internal(t);e.ctx.events.currentModeRender(o,r=>{r.properties.mode=t,e.sources[n].push(r)})}function s(){e.isDirty=!1,e.clearChangedIds()}r.forEach(e=>a(e,"hot")),n.forEach(e=>a(e,"cold")),i&&e.ctx.map.getSource(v.COLD).setData({type:x.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(v.HOT).setData({type:x.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Ce(e){let t;this._features={},this._featureIds=new ie,this._selectedFeatureIds=new ie,this._selectedCoordinates=[],this._changedFeatureIds=new ie,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Oe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(P.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(P.RENDER,{})}))},this.isDirty=!1}function Te(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}Ce.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ce.prototype.setDirty=function(){return this.isDirty=!0,this},Ce.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(P.CREATE,{features:[t.toGeoJSON()]})}return this},Ce.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(P.UPDATE,{action:t.action?t.action:w.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ce.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ce.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ce.prototype.getAllIds=function(){return this._featureIds.values()},Ce.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ce.prototype.delete=function(e,t={}){const r=[];return Ie(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===r.indexOf(this._features[e])&&r.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),r.length&&this.ctx.events.fire(P.DELETE,{features:r}),Te(this,t),this},Ce.prototype.get=function(e){return this._features[e]},Ce.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Ce.prototype.select=function(e,t={}){return Ie(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Ce.prototype.deselect=function(e,t={}){return Ie(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Te(this,t),this},Ce.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ce.prototype.setSelected=function(e,t={}){return e=Ie(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},Ce.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ce.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ce.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ce.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Ce.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Ce.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ce.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:w.CHANGE_PROPERTIES})},Ce.prototype.storeMapConfig=function(){I.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Ce.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Ce.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Le=["mode","feature","mouse"];function Ae(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,r)=>(t[r]=Me(e.options.modes[r]),t),{});let r={},n={};const o={};let i=null,a=null;o.drag=function(t,r){r({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:E.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!pe(r,e))},o.touchdrag=function(e){o.drag(e,e=>!de(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=le(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=le(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=le(t,e);t.featureTarget=n,pe(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(e){a.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;n={time:(new Date).getTime(),point:t.point};const r=se.touch(t,null,e)[0];t.featureTarget=r,a.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const r=se.touch(t,null,e)[0];t.featureTarget=r,de(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=R(e),r=U(e),n=X(e);return!(t||r||n)};function c(r,n,o={}){a.stop();const s=t[r];if(void 0===s)throw new Error(`${r} is not valid`);i=r;const c=s(e,n);a=he(c,e),o.silent||e.map.fire(P.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(m.CANVAS)&&((R(t)||U(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):B(t)&&e.options.controls.point?c(S.DRAW_POINT):G(t)&&e.options.controls.line_string?c(S.DRAW_LINE_STRING):Y(t)&&e.options.controls.polygon&&c(S.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1},u={start(){i=e.options.defaultMode,a=he(t[i](e),e)},changeMode:c,actionable:function(t){let r=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(r=!0),l[e]=t[e]}),r&&e.map.fire(P.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i};return u}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];Le.forEach(e=>{o[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==o[e]&&r.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),r.length>0&&e.container.classList.add(...r),n=Object.assign(n,o)}function s(e,t={}){const n=document.createElement("button");return n.className=`${m.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),n.target===r)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),n}function c(){r&&(r.classList.remove(m.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(m.ACTIVE_BUTTON),r=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:a,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),a()},addButtons:function(){const r=e.options.controls,n=document.createElement("div");return n.className=`${m.CONTROL_GROUP} ${m.CONTROL_BASE}`,r?(r[b.POINT]&&(t[b.POINT]=s(b.POINT,{container:n,className:m.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(S.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[b.LINE]&&(t[b.LINE]=s(b.LINE,{container:n,className:m.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(S.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[b.POLYGON]&&(t[b.POLYGON]=s(b.POLYGON,{container:n,className:m.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(S.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:m.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:m.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:m.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach(e=>{const r=t[e];r.parentNode&&r.parentNode.removeChild(r),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new Ce(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(v.COLD,{data:{type:x.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(v.HOT,{data:{type:x.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(v.COLD)&&e.map.removeSource(v.COLD),e.map.getSource(v.HOT)&&e.map.removeSource(v.HOT)}};return e.setup=n,n}const ke="#3bb2d0",Fe="#fbb03b",Ne="#fff";var Ve=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Fe,ke],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],Fe,ke],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Ne}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],Fe,ke]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":Ne}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":Fe}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Fe}}];function De(e,t){this.x=e,this.y=t}function je(e,t){const r=t.getBoundingClientRect();return new De(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function Re(e,t,r,n){return{type:x.FEATURE,properties:{meta:_.VERTEX,parent:e,coord_path:r,active:n?M.ACTIVE:M.INACTIVE},geometry:{type:x.POINT,coordinates:t}}}De.prototype={clone(){return new De(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,o=r*this.x+t*this.y;return this.x=n,this.y=o,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),o=t.x+r*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:De},De.convert=function(e){if(e instanceof De)return e;if(Array.isArray(e))return new De(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new De(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var Ue=6371008.8,Be={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*Ue,kilometers:6371.0088,kilometres:6371.0088,meters:Ue,metres:Ue,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:Ue/1852,radians:1,yards:6967335.223679999};function Ge(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function Ye(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Ze(e[0])||!Ze(e[1]))throw new Error("coordinates must contain numbers");return Ge({type:"Point",coordinates:e},t,r)}function Xe(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return Ge({type:"Polygon",coordinates:e},t,r)}function He(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return Ge({type:"LineString",coordinates:e},t,r)}function Je(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function qe(e,t,r={}){return Ge({type:"MultiLineString",coordinates:e},t,r)}function $e(e,t="kilometers"){const r=Be[t];if(!r)throw new Error(t+" units is invalid");return e*r}function Ke(e,t="kilometers"){const r=Be[t];if(!r)throw new Error(t+" units is invalid");return e/r}function We(e){return 180*(e%(2*Math.PI))/Math.PI}function ze(e){return e%360*Math.PI/180}function Ze(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function Qe(e,t,r){if(null!==e)for(var n,o,i,a,s,c,l,u,p=0,d=0,h=e.type,f="FeatureCollection"===h,g="Feature"===h,y=f?e.features.length:1,m=0;m<y;m++){s=(u=!!(l=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===l.type)?l.geometries.length:1;for(var v=0;v<s;v++){var E=0,b=0;if(null!==(a=u?l.geometries[v]:l)){c=a.coordinates;var x=a.type;switch(p=0,x){case null:break;case"Point":if(!1===t(c,d,m,E,b))return!1;d++,E++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===t(c[n],d,m,E,b))return!1;d++,"MultiPoint"===x&&E++}"LineString"===x&&E++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(o=0;o<c[n].length-p;o++){if(!1===t(c[n][o],d,m,E,b))return!1;d++}"MultiLineString"===x&&E++,"Polygon"===x&&b++}"Polygon"===x&&E++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(b=0,o=0;o<c[n].length;o++){for(i=0;i<c[n][o].length-p;i++){if(!1===t(c[n][o][i],d,m,E,b))return!1;d++}b++}E++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===Qe(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function et(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function tt(e,t){var r,n,o,i,a,s,c,l,u,p,d=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,p=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,d,l,u,p))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],d,l,u,p))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,d,l,u,p))return!1;d++}}function rt(e,t){tt(e,function(e,r,n,o,i){var a,s=null===e?null:e.type;switch(s){case null:case"Point":case"LineString":case"Polygon":return!1!==t(Ge(e,n,{bbox:o,id:i}),r,0)&&void 0}switch(s){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var c=0;c<e.coordinates.length;c++){var l=e.coordinates[c];if(!1===t(Ge({type:a,coordinates:l},n),r,c))return!1}})}function nt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return ot(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>ot(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return at(e);default:throw new Error("unknown GeoJSON type")}}function ot(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=it(e.properties),null==e.geometry?t.geometry=null:t.geometry=at(e.geometry),t}function it(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=it(n):t[r]=n}),t):t}function at(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>at(e)),t):(t.coordinates=st(e.coordinates),t)}function st(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>st(e))}function ct(e,t={}){return lt(e,"mercator",t)}function lt(e,t,r={}){var n=(r=r||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&Ze(e[0])?e="mercator"===t?ut(e):pt(e):(!0!==n&&(e=nt(e)),Qe(e,function(e){var r="mercator"===t?ut(e):pt(e);e[0]=r[0],e[1]=r[1]})),e}function ut(e){var t,r=Math.PI/180,n=6378137,o=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*r,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*r))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function pt(e){var t=180/Math.PI,r=6378137;return[e[0]*t/r,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/r)))*t]}function dt(e,t,r){const n=t.geometry.coordinates,o=r.geometry.coordinates;if(n[1]>85||n[1]<-85||o[1]>85||o[1]<-85)return null;const i=ct(n),a=ct(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return lt(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:x.FEATURE,properties:{meta:_.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:x.POINT,coordinates:u}}}function ht(e,t={},r=null){const{type:n,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let a=[];function s(e,r){let n="",o=null;e.forEach((e,s)=>{const l=null!=r?`${r}.${s}`:String(s),u=Re(i,e,l,c(l));if(t.midpoints&&o){const e=dt(i,o,u);e&&a.push(e)}o=u;const p=JSON.stringify(e);n!==p&&a.push(u),0===s&&(n=p)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===x.POINT?a.push(Re(i,o,r,c(r))):n===x.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===x.LINE_STRING?s(o,r):0===n.indexOf(x.MULTI_PREFIX)&&function(){const r=n.replace(x.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:x.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(ht(i,t,o))})}(),a}var ft={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:gt,LAT_MAX:yt,LAT_RENDERED_MIN:mt,LAT_RENDERED_MAX:vt,LNG_MIN:Et,LNG_MAX:bt}=O;function xt(e,t){let r=gt,n=yt,o=gt,i=yt,a=bt,s=Et;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],p=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),p>s&&(s=p)});const c=t;return r+c.lat>vt&&(c.lat=vt-r),o+c.lat>yt&&(c.lat=yt-o),n+c.lat<mt&&(c.lat=mt-n),i+c.lat<gt&&(c.lat=gt-i),a+c.lng<=Et&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=bt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function St(e,t){const r=xt(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+r.lng,lat:e[1]+r.lat};return[t.lng,t.lat]},o=e=>e.map(e=>n(e)),i=e=>e.map(e=>o(e));let a;e.type===x.POINT?a=n(t):e.type===x.LINE_STRING||e.type===x.MULTI_POINT?a=t.map(n):e.type===x.POLYGON||e.type===x.MULTI_LINE_STRING?a=t.map(o):e.type===x.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Pt={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(P.UPDATE,{action:w.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let r=!1;if(e.length>1){r=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(r=!1)})}const n=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new ie).values()},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){ft.enable(this)},onMouseMove:function(e,t){return F(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Pt.onTap=Pt.onClick=function(e,t){return k(t)?this.clickAnywhere(e,t):C(_.VERTEX)(t)?this.clickOnVertex(e,t):F(t)?this.clickOnFeature(e,t):void 0},Pt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),ft.enable(this),this.stopExtendedInteractions(e)},Pt.clickOnVertex=function(e,t){this.changeMode(S.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:E.MOVE})},Pt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Pt.clickOnFeature=function(e,t){ft.disable(this),this.stopExtendedInteractions(e);const r=V(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==x.POINT)return this.changeMode(S.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:E.POINTER}),1===n.length&&ft.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:E.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:E.MOVE})),this.doRender(o)},Pt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),L(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&T(t)?this.startBoxSelect(e,t):void 0},Pt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=je(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Pt.onTouchStart=function(e,t){if(L(t))return this.startOnActiveFeature(e,t)},Pt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Pt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:E.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(m.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=je(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),o=Math.max(e.boxSelectStartLocation.x,r.x),i=Math.min(e.boxSelectStartLocation.y,r.y),a=Math.max(e.boxSelectStartLocation.y,r.y),s=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=s,e.boxSelectElement.style.WebkitTransform=s,e.boxSelectElement.style.width=o-n+"px",e.boxSelectElement.style.height=a-i+"px"},Pt.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};St(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Pt.onTouchEnd=Pt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,je(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),o=this.getUniqueIds(n).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:E.MOVE}))}this.stopExtendedInteractions(e)},Pt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?M.ACTIVE:M.INACTIVE,r(t),this.fireActionable(),t.properties.active===M.ACTIVE&&t.geometry.type!==x.POINT&&ht(t).forEach(r)},Pt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Pt.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),r.push(i.toGeoJSON())}if(r.length>1){const e=this.newFeature({type:x.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(P.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Pt.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],r=[];for(let n=0;n<e.length;n++){const o=e[n];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))}t.length>1&&this.fire(P.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const wt=C(_.VERTEX),_t=C(_.MIDPOINT),Mt={fireUpdate:function(){this.fire(P.UPDATE,{action:w.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);V(t)||-1!==n?V(t)&&-1===n&&e.selectedCoordPaths.push(r.coord_path):e.selectedCoordPaths=[r.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,r){St(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=xt(n.map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e}})),r);for(let t=0;t<n.length;t++){const r=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],r[0]+o.lng,r[1]+o.lat)}},clickNoTarget:function(){this.changeMode(S.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(S.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===x.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),ft.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){ft.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=M.ACTIVE,r(t),ht(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=M.INACTIVE,r(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(S.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=L(t),n=wt(t),o=_t(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:E.MOVE}):this.updateUIClasses({mouse:E.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Mt.onTouchStart=Mt.onMouseDown=function(e,t){return wt(t)?this.onVertex(e,t):L(t)?this.onFeature(e,t):_t(t)?this.onMidpoint(e,t):void 0},Mt.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},Mt.onClick=function(e,t){return k(t)?this.clickNoTarget(e,t):L(t)?this.clickActiveFeature(e,t):A(t)?this.clickInactive(e,t):void this.stopDragging(e)},Mt.onTap=function(e,t){return k(t)?this.clickNoTarget(e,t):L(t)?this.clickActiveFeature(e,t):A(t)?this.clickInactive(e,t):void 0},Mt.onTouchEnd=Mt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const It={};function Ot(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}It.onSetup=function(){const e=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.POINT),this.setActionableState({trash:!0}),{point:e}},It.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)},It.onTap=It.onClick=function(e,t){this.updateUIClasses({mouse:E.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(P.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.point.id]})},It.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},It.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t)},It.onTrash=It.stopDrawingAndRemove,It.onKeyUp=function(e,t){if(D(t)||j(t))return this.stopDrawingAndRemove(e,t)};const Ct={onSetup:function(){const e=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),ft.disable(this),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Ot(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:E.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),N(t)&&this.updateUIClasses({mouse:E.POINTER})}};Ct.onTap=Ct.onClick=function(e,t){return N(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ct.onKeyUp=function(e,t){D(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)):j(t)&&this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ct.onStop=function(e){this.updateUIClasses({mouse:E.NONE}),ft.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(P.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT,{},{silent:!0})))},Ct.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=_.FEATURE,r(Re(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(Re(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:x.FEATURE,properties:t.properties,geometry:{coordinates:e,type:x.LINE_STRING}}),3===o)return}return r(t)}},Ct.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)};const Tt={onSetup:function(e){const t=(e=e||{}).featureId;let r,n,o="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const a=r.coordinates.length-1;if(r.coordinates[a][0]===i[0]&&r.coordinates[a][1]===i[1])n=a+1,r.addCoordinate(n,...r.coordinates[a]);else{if(r.coordinates[0][0]!==i[0]||r.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",n=0,r.addCoordinate(n,...r.coordinates[0])}}else r=this.newFeature({type:x.FEATURE,properties:{},geometry:{type:x.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),ft.disable(this),this.updateUIClasses({mouse:E.ADD}),this.activateUIButton(b.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Ot(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&Ot(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:E.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),N(t)&&this.updateUIClasses({mouse:E.POINTER})}};Tt.onTap=Tt.onClick=function(e,t){if(N(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Tt.onKeyUp=function(e,t){j(t)?this.changeMode(S.SIMPLE_SELECT,{featureIds:[e.line.id]}):D(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT))},Tt.onStop=function(e){ft.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(P.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT,{},{silent:!0})))},Tt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(S.SIMPLE_SELECT)},Tt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?M.ACTIVE:M.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=_.FEATURE,r(Re(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),r(t))};var Lt={simple_select:Pt,direct_select:Mt,draw_point:It,draw_polygon:Ct,draw_line_string:Tt};const At={defaultMode:S.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:Ve,modes:Lt,controls:{},userProperties:!1,suppressAPIEvents:!0},kt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ft={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Nt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?v.HOT:v.COLD}))}var Vt,Dt;var jt,Rt,Ut=(Dt||(Dt=1,Vt=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}),Vt),Bt=J(Ut);var Gt=function(){if(Rt)return jt;Rt=1,jt=function(t){if(!t||!t.type)return null;var r=e[t.type];if(!r)return null;if("geometry"===r)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===r)return{type:"FeatureCollection",features:[t]};if("featurecollection"===r)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return jt}(),Yt=J(Gt);function Xt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Ht={Polygon:Ee,LineString:ve,Point:me,MultiPolygon:Se,MultiLineString:Se,MultiPoint:Se};var Jt=Object.freeze({__proto__:null,CommonSelectors:H,ModeHandler:he,StringSet:ie,constrainFeatureMovement:xt,createMidPoint:dt,createSupplementaryPoints:ht,createVertex:Re,doubleClickZoom:ft,euclideanDistance:ue,featuresAt:se,getFeatureAtAndSetCursors:le,isClick:pe,isEventAtCoordinates:Ot,isTap:de,mapEventToBoundingBox:oe,moveFeatures:St,sortFeatures:ne,stringSetsAreEqual:Xt,theme:Ve,toDenseArray:Ie});const qt=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Ft,e.controls):t.controls=Object.assign({},kt,e.controls),t=Object.assign({},At,t),t.styles=Nt(t.styles,"cold").concat(Nt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=S;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return se.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:x.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:x.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:x.FEATURE,properties:{},geometry:{type:x.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==x.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(r),a=new ie(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Yt(t))).features.map(t=>{if(t.id=t.id||ge(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=Ht[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Bt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Bt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:x.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==S.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(S.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===S.DIRECT_SELECT?e.events.changeMode(S.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===S.SIMPLE_SELECT&&t.getMode()===S.SIMPLE_SELECT?(Xt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===S.DIRECT_SELECT&&t.getMode()===S.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,o,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,o,i){return e.store.setFeatureProperty(n,o,i,{silent:r}),t},t}(r,t),r.api=t;const n=Ae(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=b,t.options=e,t};function $t(e){qt(e,this)}$t.modes=Lt,$t.constants=O,$t.lib=Jt;var Kt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},Wt=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},zt=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!0}),r+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,o)=>{t.push({start:r,length:e.length,path:[n,o],closed:!0}),r+=e.length})})}return t},Zt=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},Qt=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},er=(e,t)=>{var r=t.split(".").map(Number),n=zt(e);for(var o of n){if(o.path.every((e,t)=>e===r[t])&&r.length===o.path.length+1){var i=r[r.length-1];return o.start+i}}return r[r.length-1]},tr=(e,t)=>({x:e.x*t,y:e.y*t}),rr=e=>e instanceof window.SVGElement||e.ownerSVGElement,nr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},pushUndo(e){var t=this.map._undoStack;t&&t.push(e)},handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=zt(i),c=Zt(s,r);if(c){Qt(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,tr(this.map.project(l),e.scale))}}},undoInsertVertex(e,t){var{vertexIndex:r,featureId:n}=t,o=this.getFeature(n);if(o){var i=o.toGeoJSON(),a=zt(o),s=Zt(a,r);if(s)Qt(i,s.segment.path).splice(s.localIdx,1),this._applyUndoAndSync(e,i,n),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},undoDeleteVertex(e,t){var{vertexIndex:r,position:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=zt(i),c=Zt(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c){Qt(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o);var u=e.vertecies[r];u&&this.updateTouchVertexTarget(e,tr(this.map.project(u),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertecies=this.getVerticies(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}};function or(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ir(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?or(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):or(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ar=(e,t)=>{if(e){var r="dark"===(null==t?void 0:t.mapColorScheme);e.style.setProperty("--touch-fill",r?"#ffffff":"#000000"),e.style.setProperty("--touch-gfx",r?"#000000":"#ffffff")}},sr={addTouchVertexTarget(e){var t=e.container.querySelector("[data-touch-vertex-target]");t||(e.container.insertAdjacentHTML("beforeend","\n <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd' style='display:none;position:absolute;top:50%;left:50%;margin:24px 0 0 -24px' class='touch-vertex-target' data-touch-vertex-target>\n <circle cx='24' cy='24' r='24' fill='var(--touch-fill, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--touch-gfx, #fff)'/>\n </svg>\n"),t=e.container.querySelector("[data-touch-vertex-target]")),e.touchVertexTarget=t,ar(t,this.map._drawCurrentMapStyle)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||rr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){g(u(this.map)),null!=e&&e.featureId&&(this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=void 0,e._touchMoved=!1)},onTap(e,t){var r,n,o=u(this.map);o&&f(o,this.map);var i=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,a=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if("vertex"===i){var s=this.getFeature(e.featureId),c=er(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(ir(ir({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){var r;g(u(this.map));var n=null===(r=e.vertecies)||void 0===r?void 0:r[e.selectedVertexIndex];if(n&&rr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=t.touches[0].clientX,i=t.touches[0].clientY,a=window.getComputedStyle(e.touchVertexTarget);e.deltaTarget={x:o-Number.parseFloat(a.left),y:i-Number.parseFloat(a.top)};var s=this.map.project(n);e.deltaVertex={x:o/e.scale-s.x,y:i/e.scale-s.y}}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&rr(t.target.parentNode)){e._touchMoved=!0;var r=t.touches[0].clientX,n=t.touches[0].clientY,o={x:r/e.scale-e.deltaVertex.x,y:n/e.scale-e.deltaVertex.y},i=this.map.unproject(o);if(y(e)){var a=u(this.map);h(a,this.map,o),i=d(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function cr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var lr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},ur={updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(t,r){var[n,o]=this.getVertexOrMidpoint(t,r);n<0||!o||this.changeMode(t,function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?cr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({selectedVertexIndex:n,selectedVertexType:o},"vertex"===o&&{coordPath:this.getCoordPath(t,n)}))},getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?1:5,[o,i]=t?lr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getNewCoord(e,t){return this.getOffset(Wt(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertecies.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=zt(o),s=r+1,c=null,l=0,u=0;for(var p of a){var d=p.closed?p.length:p.length-1;if(r<u+d){c=p,l=r-u+1,s=p.start+l;break}u+=d}c&&(Qt(i,c.path).splice(l,0,[n.lng,n.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),this.changeMode(e,{selectedVertexIndex:s,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,s)}))},moveVertex(e,t){if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).checkSnap&&!1!==e.enableSnap){var r,n=this.map._snapInstance;null!=n&&n.snapStatus&&(null===(r=n.snapCoords)||void 0===r?void 0:r.length)>=2&&(t={lng:n.snapCoords[0],lat:n.snapCoords[1]})}var o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=zt(o),s=Zt(a,e.selectedVertexIndex);s&&(Qt(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertecies=this.getVerticies(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=zt(t),n=Zt(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?3:2;if(!(o.length<=i)){var a=[...e.vertecies[e.selectedVertexIndex]],s=e.selectedVertexIndex,c=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(c),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:s,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}};function pr(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return dr(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 dr(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return fr(e);default:throw new Error("unknown GeoJSON type")}}function dr(e){var t={type:"Feature"};return Object.keys(e).forEach(function(r){switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=hr(e.properties),t.geometry=fr(e.geometry),t}function hr(e){var t={};return e?(Object.keys(e).forEach(function(r){var n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(function(e){return e}):t[r]=hr(n):t[r]=n}),t):t}function fr(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return fr(e)}),t):(t.coordinates=gr(e.coordinates),t)}function gr(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return gr(e)})}function yr(e){for(var t,r,n=function(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(e),o=0,i=1;i<n.length;)t=r||n[0],o+=((r=n[i])[0]-t[0])*(r[1]+t[1]),i++;return o>0}function mr(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function vr(e,t){if(null===(r=t=t||{})||"object"!=typeof r||Array.isArray(r))throw new Error("options is invalid");var r,n=t.reverse||!1,o=t.mutate||!1;if(!e)throw new Error("<geojson> is required");if("boolean"!=typeof n)throw new Error("<reverse> must be a boolean");if("boolean"!=typeof o)throw new Error("<mutate> must be a boolean");!1===o&&(e=pr(e));var i=[];switch(e.type){case"GeometryCollection":return tt(e,function(e){Er(e,n)}),e;case"FeatureCollection":return et(e,function(e){et(Er(e,n),function(e){i.push(e)})}),Je(i)}return Er(e,n)}function Er(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return tt(e,function(e){Er(e,t)}),e;case"LineString":return br(mr(e),t),e;case"Polygon":return xr(mr(e),t),e;case"MultiLineString":return mr(e).forEach(function(e){br(e,t)}),e;case"MultiPolygon":return mr(e).forEach(function(e){xr(e,t)}),e;case"Point":case"MultiPoint":return e}}function br(e,t){yr(e)===t&&e.reverse()}function xr(e,t){yr(e[0])!==t&&e[0].reverse();for(var r=1;r<e.length;r++)yr(e[r])===t&&e[r].reverse()}const Sr=11102230246251565e-32,Pr=134217729,wr=(3+8*Sr)*Sr;function _r(e,t,r,n,o){let i,a,s,c,l=t[0],u=n[0],p=0,d=0;u>l==u>-l?(i=l,l=t[++p]):(i=u,u=n[++d]);let h=0;if(p<e&&d<r)for(u>l==u>-l?(a=l+i,s=i-(a-l),l=t[++p]):(a=u+i,s=i-(a-u),u=n[++d]),i=a,0!==s&&(o[h++]=s);p<e&&d<r;)u>l==u>-l?(a=i+l,c=a-i,s=i-(a-c)+(l-c),l=t[++p]):(a=i+u,c=a-i,s=i-(a-c)+(u-c),u=n[++d]),i=a,0!==s&&(o[h++]=s);for(;p<e;)a=i+l,c=a-i,s=i-(a-c)+(l-c),l=t[++p],i=a,0!==s&&(o[h++]=s);for(;d<r;)a=i+u,c=a-i,s=i-(a-c)+(u-c),u=n[++d],i=a,0!==s&&(o[h++]=s);return 0===i&&0!==h||(o[h++]=i),h}function Mr(e){return new Float64Array(e)}const Ir=Mr(4),Or=Mr(8),Cr=Mr(12),Tr=Mr(16),Lr=Mr(4);function Ar(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),c=a-s,l=Math.abs(a+s);return Math.abs(c)>=33306690738754716e-32*l?c:-function(e,t,r,n,o,i,a){let s,c,l,u,p,d,h,f,g,y,m,v,E,b,x,S,P,w;const _=e-o,M=r-o,I=t-i,O=n-i;b=_*O,d=Pr*_,h=d-(d-_),f=_-h,d=Pr*O,g=d-(d-O),y=O-g,x=f*y-(b-h*g-f*g-h*y),S=I*M,d=Pr*I,h=d-(d-I),f=I-h,d=Pr*M,g=d-(d-M),y=M-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,p=x-m,Ir[0]=x-(m+p)+(p-P),v=b+m,p=v-b,E=b-(v-p)+(m-p),m=E-S,p=E-m,Ir[1]=E-(m+p)+(p-S),w=v+m,p=w-v,Ir[2]=v-(w-p)+(m-p),Ir[3]=w;let C=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,Ir),T=22204460492503146e-32*a;if(C>=T||-C>=T)return C;if(p=e-_,s=e-(_+p)+(p-o),p=r-M,l=r-(M+p)+(p-o),p=t-I,c=t-(I+p)+(p-i),p=n-O,u=n-(O+p)+(p-i),0===s&&0===c&&0===l&&0===u)return C;if(T=11093356479670487e-47*a+wr*Math.abs(C),C+=_*u+O*s-(I*l+M*c),C>=T||-C>=T)return C;b=s*O,d=Pr*s,h=d-(d-s),f=s-h,d=Pr*O,g=d-(d-O),y=O-g,x=f*y-(b-h*g-f*g-h*y),S=c*M,d=Pr*c,h=d-(d-c),f=c-h,d=Pr*M,g=d-(d-M),y=M-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,p=x-m,Lr[0]=x-(m+p)+(p-P),v=b+m,p=v-b,E=b-(v-p)+(m-p),m=E-S,p=E-m,Lr[1]=E-(m+p)+(p-S),w=v+m,p=w-v,Lr[2]=v-(w-p)+(m-p),Lr[3]=w;const L=_r(4,Ir,4,Lr,Or);b=_*u,d=Pr*_,h=d-(d-_),f=_-h,d=Pr*u,g=d-(d-u),y=u-g,x=f*y-(b-h*g-f*g-h*y),S=I*l,d=Pr*I,h=d-(d-I),f=I-h,d=Pr*l,g=d-(d-l),y=l-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,p=x-m,Lr[0]=x-(m+p)+(p-P),v=b+m,p=v-b,E=b-(v-p)+(m-p),m=E-S,p=E-m,Lr[1]=E-(m+p)+(p-S),w=v+m,p=w-v,Lr[2]=v-(w-p)+(m-p),Lr[3]=w;const A=_r(L,Or,4,Lr,Cr);b=s*u,d=Pr*s,h=d-(d-s),f=s-h,d=Pr*u,g=d-(d-u),y=u-g,x=f*y-(b-h*g-f*g-h*y),S=c*l,d=Pr*c,h=d-(d-c),f=c-h,d=Pr*l,g=d-(d-l),y=l-g,P=f*y-(S-h*g-f*g-h*y),m=x-P,p=x-m,Lr[0]=x-(m+p)+(p-P),v=b+m,p=v-b,E=b-(v-p)+(m-p),m=E-S,p=E-m,Lr[1]=E-(m+p)+(p-S),w=v+m,p=w-v,Lr[2]=v-(w-p)+(m-p),Lr[3]=w;const k=_r(A,Cr,4,Lr,Tr);return Tr[k-1]}(e,t,r,n,o,i,l)}function kr(e,t){var r,n,o,i,a,s,c,l,u,p=0,d=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]-d,a=l[1]-h;n<y;n++){if(s=(u=g[n+1])[0]-d,c=u[1]-h,0===a&&0===c){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(c>=0&&a<=0||c<=0&&a>=0){if(0===(o=Ar(i,s,a,c,0,0)))return 0;(o>0&&c>0&&a<=0||o<0&&c<=0&&a>0)&&p++}l=u,a=c,i=s}}return p%2!=0}var Fr=function(e,t,r,n,o){this.p1=e,this.p2=t,this.edgeType=r,this.originalIndex=n,this.polygonContourId=o,this.interiorRing=!1,this.minX=Math.min(e.p[0],t.p[0]),this.minY=Math.min(e.p[1],t.p[1]),this.maxX=Math.max(e.p[0],t.p[0]),this.maxY=Math.max(e.p[1],t.p[1]),this.intersectionPoints=[],this.nextEdge=null},Nr=function(e){this.p=e},Vr=function(e,t){this.id=e,this.rawCoords=t};function Dr(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var jr=function(e,t,r,n){this.p=e,this.polylineEdge=t,this.polygonEdge=r,this.isHeadingIn=n,this.distanceFromPolylineEdgeStart=Rr(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Rr(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Rr(e,t){var r=t[0]-e[0],n=t[1]-e[1];return r*=r,n*=n,Math.sqrt(r+n)}jr.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var Ur=1e-9;function Br(e,t){return e[0]*t[1]-e[1]*t[0]}function Gr(e,t){return e[0]*t[0]+e[1]*t[1]}function Yr(e,t,r){return[e[0]+t*r[0],e[1]+t*r[1]]}function Xr(e,t,r){var n=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],o=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],i=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],a=Br(n,o),s=a*a,c=Gr(n,n);if(s>0){var l=Br(i,o)/a;if(l<0||l>1)return null;var u=Br(i,n)/a;return u<0||u>1?null:0===l||1===l?[Yr(e.p1.p,l,n)]:0===u||1===u?[Yr(t.p1.p,u,o)]:[Yr(e.p1.p,l,n)]}var p=Gr(i,i);if((s=(a=Br(i,n))*a)>Ur*c*p)return null;var d=Gr(n,i)/c,h=d+Gr(n,o)/c,f=Math.min(d,h),g=Math.max(d,h);return f<=1&&g>=0?1===f?[Yr(e.p1.p,f>0?f:0,n)]:0===g?[Yr(e.p1.p,g<1?g:1,n)]:[Yr(e.p1.p,f>0?f:0,n),Yr(e.p1.p,g<1?g:1,n)]:null}function Hr(e,t){var r=[],n=[],o=[],i=function(e,t,r,n,o){for(var i=0,a=[],s="Feature"===t.type?t.geometry:t,c="LineString"===s.type?[s.coordinates]:s.coordinates,l=0,u=0;u<c.length;u++){for(var p=c[u].length-1,d=new Nr(c[u][0]),h=null,f={nextEdge:null},g=0;g<p;g++){h=new Nr(c[u][g+1]),d.nextPoint=h,h.prevPoint=d;var y=new Fr(d,h,"polyline",l,null);n.push(y),f.nextEdge=y,y.prevEdge=f,o[0]=Math.min(o[0],d.p[0]),o[1]=Math.min(o[1],d.p[1]),o[2]=Math.max(o[2],d.p[0]),o[3]=Math.max(o[3],d.p[1]),d=h,l+=1,f=y}o[0]=Math.min(o[0],c[u][p][0]),o[1]=Math.min(o[1],c[u][p][1]),o[2]=Math.max(o[2],c[u][p][0]),o[3]=Math.max(o[3],c[u][p][1])}for(var m="Feature"===e.type?e.geometry:e,v="Polygon"===m.type?[m.coordinates]:m.coordinates,E=v.length,b=0;b<E;b++)for(var x=v[b].length,S=0;S<x;S++){i+=1;var P=v[b][S],w=P.length;a.push(new Vr(i,P));for(var _=new Nr(P[0]),M=_,I=void 0,O=null,C={nextEdge:null,prevEdge:null},T=null,L=1;L<w;L++)I=new Nr(P[L]),M.nextPoint=I,I.prevPoint=M,O=new Fr(M,I,"polygon",l,i),C.nextEdge=O,O.prevEdge=C,1===L&&(T=O),S>0&&(O.interiorRing=!0),O.intersectPolylineBbox=Dr(O,o),r.push(O),M=I,l+=1,C=O;O.nextEdge=T,T.prevEdge=O,I.nextPoint=_.nextPoint,_.prevPoint=I.prevPoint}return a}(vr(e),t,n,o,[1/0,1/0,1/0,1/0]);if(function(e,t,r){var n,o,i,a=t.length,s=e.length;for(n=0;n<a;n++){var c=t[n];for(o=0;o<s;o++){var l=e[o];if(l.intersectPolylineBbox&&!(l.maxX<c.minX||l.minX>c.maxX||l.maxY<c.minY||l.minY>c.maxY)){var u=Xr(c,l);if(null!==u)for(i=0;i<u.length;i++){var p=Ar(l.p1.p[0],l.p1.p[1],l.p2.p[0],l.p2.p[1],c.p1.p[0],c.p1.p[1]),d=new jr(u[i],c,l,p>0);r.push(d)}}}}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 p=o[u];if(p.intersectionPoints.length>0){l=p.intersectionPoints[0];break}}for(var d=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){d=y,f=!0;break}}if(!f)break}d.visitCount=d.visitCount+1;var m=[];c.push(m),m.push(d.p),d.visitCount=d.visitCount+1;var v=Kr(d,m),E=!1;if(v===(h=v)&&2===r.length)for(var b=0;b<r.length;b++){r[b].visitCount<2&&(E=!0)}for(;v!==d||E;){(v=(v.isHeadingIn?Zr:zr)(v,m))!==d&&(v=Kr(v,m)),E=!1}if(h.visitCount>=2){for(var x=!1,S=0;S<r.length;S++){var P=r[S];if(P.visitCount<2){d=P,x=!0;break}}x&&(h=d)}d=h}for(var w=c.map(function(e){return[e]}),_=Object.keys(a),M=0;M<_.length;M++){var I=_[M];if(0===a[I])$r(qr(Jr(n,parseInt(I)),i),w)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:w}}}function Jr(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.polygonContourId===t)return n}}function qr(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function $r(e,t){for(var r=0;r<t.length;r++){var n=t[r];if(kr(e[0],[n[0]]))return void n.push(e)}t.push([e])}function Kr(e,t){var r=e.polygonEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=Wr(e,r.intersectionPoints),o=r.intersectionPoints[n+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(r.p2.p),null===(r=r.nextEdge))return e;r.intersectionPoints.length>0&&(i=!1)}return r.intersectionPoints[0].incrementVisitCount(),t.push(r.intersectionPoints[0].p),r.intersectionPoints[0]}function Wr(e,t){for(var r=0;r<t.length;r++){if(t[r]===e)return r}return null}function zr(e,t){var r=e.polylineEdge;if(2===r.intersectionPoints.length){var n=r.intersectionPoints[r.intersectionPoints.length-1];if(n===e){var o=r.intersectionPoints[0];return t.push(o.p),o.incrementVisitCount(),o}return t.push(n.p),n.incrementVisitCount(),n}if(r.intersectionPoints.length>2&&r.intersectionPoints[0]!==e){var i=Wr(e,r.intersectionPoints),a=r.intersectionPoints[i-1];return t.push(a.p),a.incrementVisitCount(),a}for(var s=!0;s;){if(t.push(r.p1.p),void 0===(r=r.prevEdge).originalIndex)return e;r.intersectionPoints.length>0&&(s=!1)}if(void 0===r.originalIndex)return e;var c=r.intersectionPoints[r.intersectionPoints.length-1];return c.incrementVisitCount(),t.push(c.p),c}function Zr(e,t){var r=e.polylineEdge;if(r.intersectionPoints.length>1&&r.intersectionPoints[r.intersectionPoints.length-1]!==e){var n=Wr(e,r.intersectionPoints),o=r.intersectionPoints[n+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(r.p2.p),null===(r=r.nextEdge))return e;r.intersectionPoints.length>0&&(i=!1)}if(void 0===r)return e;var a=r.intersectionPoints[0];return a.incrementVisitCount(),t.push(a.p),a}function Qr(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function en(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function tn(e){return"Feature"===e.type?e.geometry:e}function rn(e,t,r={}){if(!0===r.final)return function(e,t){let r=rn(t,e);return r=(r+180)%360,r}(e,t);const n=Qr(e),o=Qr(t),i=ze(n[0]),a=ze(o[0]),s=ze(n[1]),c=ze(o[1]),l=Math.sin(a-i)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(a-i);return We(Math.atan2(l,u))}var nn=rn;function on(e,t,r,n={}){const o=Qr(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),p=We(l);return void 0!==o[2]?Ye([u,p,o[2]],n.properties):Ye([u,p],n.properties)}var an=on;function sn(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=Qr(e),o=tn(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let c=!1;for(var l=0;l<s.length;++l){const e=kr(n,s[l]);if(0===e)return!r.ignoreBoundary;e&&(c=!0)}return c}class cn{constructor(e=[],t=ln){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function ln(e,t){return e<t?-1:e>t?1:0}function un(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function pn(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 dn{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let hn=0,fn=0,gn=0;function yn(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;fn+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new dn(o,hn,fn,gn),c=new dn(i,hn,fn,gn+1);s.otherEvent=c,c.otherEvent=s,un(s,c)>0?(c.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,c.isLeftEndpoint=!1),t.push(s),t.push(c),o=i,gn+=1}}hn+=1}class mn{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function vn(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,c=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,u=(l-s)*(o-r)-(c-a)*(i-n),p=(c-a)*(n-s)-(l-s)*(r-a),d=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const h=p/u,f=d/u;if(h>=0&&h<=1&&f>=0&&f<=1){return[r+h*(o-r),n+h*(i-n)]}return!1}var En=function(e,t){const r=new cn([],un);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)yn(r[e],t)}else yn(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new cn([],pn);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new mn(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=vn(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function bn(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let i=[];"FeatureCollection"===e.type?i=i.concat(e.features):"Feature"===e.type?i.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||i.push(Ge(e)),"FeatureCollection"===t.type?i=i.concat(t.features):"Feature"===t.type?i.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||i.push(Ge(t));const a=En(Je(i),o);let s=[];if(n){const e={};a.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,s.push(t))})}else s=a;return Je(s.map(e=>Ye(e)))}function xn(e,t={}){const r=tn(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=tn(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return Sn(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=tn(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(Sn(e,o))}),Je(i)}(r,t);default:throw new Error("invalid poly")}}function Sn(e,t){return e.length>1?qe(e,t):He(e[0],t)}function Pn(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return rt(e,e=>{rt(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!wn(t,e);case"Polygon":return!sn(e,t)}break;case"LineString":switch(t.type){case"Point":return!wn(e,t);case"LineString":return!function(e,t,r){const n=bn(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!_n(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!sn(t,e);case"LineString":return!_n(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(sn(r,t))return!0;for(const r of t.coordinates[0])if(sn(r,e))return!0;const n=bn(xn(e),xn(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n}function wn(e,t){for(let r=0;r<e.coordinates.length-1;r++)if(Mn(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function _n(e,t,r){for(const r of t.coordinates)if(sn(r,e))return!0;return bn(t,xn(e),{ignoreSelfIntersections:r}).features.length>0}function Mn(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var In=Object.defineProperty,On=(e,t)=>In(e,"name",{value:t,configurable:!0}),Cn=class{constructor(e){var t,r,n;this.direction=!1,this.compareProperties=!0,this.precision=10**-(null!=(t=null==e?void 0:e.precision)?t:17),this.direction=null!=(r=null==e?void 0:e.direction)&&r,this.compareProperties=null==(n=null==e?void 0:e.compareProperties)||n}compare(e,t){if(e.type!==t.type)return!1;if(!Ln(e,t))return!1;switch(e.type){case"Point":return this.compareCoord(e.coordinates,t.coordinates);case"LineString":return this.compareLine(e.coordinates,t.coordinates);case"Polygon":return this.comparePolygon(e,t);case"GeometryCollection":return this.compareGeometryCollection(e,t);case"Feature":return this.compareFeature(e,t);case"FeatureCollection":return this.compareFeatureCollection(e,t);default:if(e.type.startsWith("Multi")){const r=An(e),n=An(t);return r.every(e=>n.some(t=>this.compare(e,t)))}}return!1}compareCoord(e,t){return e.length===t.length&&e.every((e,r)=>Math.abs(e-t[r])<this.precision)}compareLine(e,t,r=0,n=!1){if(!Ln(e,t))return!1;const o=e;let i=t;if(n&&!this.compareCoord(o[0],i[0])){const e=this.fixStartIndex(i,o);if(!e)return!1;i=e}const a=this.compareCoord(o[r],i[r]);return this.direction||a?this.comparePath(o,i):!!this.compareCoord(o[r],i[i.length-(1+r)])&&this.comparePath(o.slice().reverse(),i)}fixStartIndex(e,t){let r,n=-1;for(let r=0;r<e.length;r++)if(this.compareCoord(e[r],t[0])){n=r;break}return n>=0&&(r=[].concat(e.slice(n,e.length),e.slice(1,n+1))),r}comparePath(e,t){return e.every((e,r)=>this.compareCoord(e,t[r]))}comparePolygon(e,t){if(this.compareLine(e.coordinates[0],t.coordinates[0],1,!0)){const r=e.coordinates.slice(1,e.coordinates.length),n=t.coordinates.slice(1,t.coordinates.length);return r.every(e=>n.some(t=>this.compareLine(e,t,1,!0)))}return!1}compareGeometryCollection(e,t){return Ln(e.geometries,t.geometries)&&this.compareBBox(e,t)&&e.geometries.every((e,r)=>this.compare(e,t.geometries[r]))}compareFeature(e,t){return e.id===t.id&&(!this.compareProperties||Fn(e.properties,t.properties))&&this.compareBBox(e,t)&&this.compare(e.geometry,t.geometry)}compareFeatureCollection(e,t){return Ln(e.features,t.features)&&this.compareBBox(e,t)&&e.features.every((e,r)=>this.compare(e,t.features[r]))}compareBBox(e,t){return Boolean(!e.bbox&&!t.bbox)||!(!e.bbox||!t.bbox)&&this.compareCoord(e.bbox,t.bbox)}};On(Cn,"GeojsonEquality");var Tn=Cn;function Ln(e,t){return e.coordinates?e.coordinates.length===t.coordinates.length:e.length===t.length}function An(e){return e.coordinates.map(t=>({type:e.type.replace("Multi",""),coordinates:t}))}function kn(e,t,r){return new Tn(r).compare(e,t)}function Fn(e,t){if(null===e&&null===t)return!0;if(null===e||null===t)return!1;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o of r){const r=e[o],n=t[o],i=Nn(r)&&Nn(n);if(i&&!Fn(r,n)||!i&&r!==n)return!1}return!0}On(Ln,"sameLength"),On(An,"explode"),On(kn,"geojsonEquality"),On(Fn,"equal");var Nn=On(e=>null!=e&&"object"==typeof e,"isObject");function Vn(e,t,r={}){const n=Qr(e),o=en(t);for(let e=0;e<o.length-1;e++){let t=!1;if(r.ignoreEndVertices&&(0===e&&(t="start"),e===o.length-2&&(t="end"),0===e&&e+1===o.length-1&&(t="both")),Dn(o[e],o[e+1],n,t,void 0===r.epsilon?null:r.epsilon))return!0}return!1}function Dn(e,t,r,n,o){const i=r[0],a=r[1],s=e[0],c=e[1],l=t[0],u=t[1],p=l-s,d=u-c,h=(r[0]-s)*d-(r[1]-c)*p;if(null!==o){if(Math.abs(h)>o)return!1}else if(0!==h)return!1;return Math.abs(p)===Math.abs(d)&&0===Math.abs(p)?!n&&(r[0]===e[0]&&r[1]===e[1]):n?"start"===n?Math.abs(p)>=Math.abs(d)?p>0?s<i&&i<=l:l<=i&&i<s:d>0?c<a&&a<=u:u<=a&&a<c:"end"===n?Math.abs(p)>=Math.abs(d)?p>0?s<=i&&i<l:l<i&&i<=s:d>0?c<=a&&a<u:u<a&&a<=c:"both"===n&&(Math.abs(p)>=Math.abs(d)?p>0?s<i&&i<l:l<i&&i<s:d>0?c<a&&a<u:u<a&&a<c):Math.abs(p)>=Math.abs(d)?p>0?s<=i&&i<=l:l<=i&&i<=s:d>0?c<=a&&a<=u:u<=a&&a<=c}function jn(e,t={}){var r="object"==typeof t?t.mutate:t;if(!e)throw new Error("geojson is required");var n=function(e){return"FeatureCollection"===e.type?"FeatureCollection":"GeometryCollection"===e.type?"GeometryCollection":"Feature"===e.type&&null!==e.geometry?e.geometry.type:e.type}(e),o=[];switch(n){case"LineString":o=Rn(e,n);break;case"MultiLineString":case"Polygon":en(e).forEach(function(e){o.push(Rn(e,n))});break;case"MultiPolygon":en(e).forEach(function(e){var t=[];e.forEach(function(e){t.push(Rn(e,n))}),o.push(t)});break;case"Point":return e;case"MultiPoint":var i={};en(e).forEach(function(e){var t=e.join("-");Object.prototype.hasOwnProperty.call(i,t)||(o.push(e),i[t]=!0)});break;default:throw new Error(n+" geometry not supported")}return e.coordinates?!0===r?(e.coordinates=o,e):{type:n,coordinates:o}:!0===r?(e.geometry.coordinates=o,e):Ge({type:n,coordinates:o},e.properties,{bbox:e.bbox,id:e.id})}function Rn(e,t){const r=en(e);if(2===r.length&&!Un(r[0],r[1]))return r;const n=[];let o=0,i=1,a=2;for(n.push(r[o]);a<r.length;)Vn(r[i],He([r[o],r[a]]))?i=a:(n.push(r[i]),o=i,i++,a=i),a++;if(n.push(r[i]),"Polygon"===t||"MultiPolygon"===t){if(Vn(n[0],He([n[1],n[n.length-2]]))&&(n.shift(),n.pop(),n.push(n[0])),n.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!Un(n[0],n[n.length-1]))throw new Error("invalid polygon, first and last points not equal")}return n}function Un(e,t){return e[0]===t[0]&&e[1]===t[1]}function Bn(e,t,r={}){let n=r.precision;if(n=null==n||isNaN(n)?6:n,"number"!=typeof n||!(n>=0))throw new Error("precision must be a positive number");return tn(e).type===tn(t).type&&kn(jn(e),jn(t),{precision:n})}function Gn(e,t){var r=tn(e),n=tn(t),o=r.type,i=n.type;switch(o){case"MultiPoint":switch(i){case"LineString":return Yn(r,n);case"Polygon":return Hn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"MultiPoint":return Yn(n,r);case"LineString":return function(e,t){const r=bn(e,t);if(0===r.features.length)return!1;for(const n of r.features)if(!(Bn(n.geometry,Ye(e.coordinates[0]))||Bn(n.geometry,Ye(e.coordinates[e.coordinates.length-1]))||Bn(n.geometry,Ye(t.coordinates[0]))||Bn(n.geometry,Ye(t.coordinates[t.coordinates.length-1]))))return!0;return!1}(r,n);case"Polygon":return Xn(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"MultiPoint":return Hn(n,r);case"LineString":return Xn(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+o+" geometry not supported")}}function Yn(e,t){for(var r=!1,n=!1,o=e.coordinates.length,i=0;i<o&&!r&&!n;){for(var a=0;a<t.coordinates.length-1;a++){var s=!0;0!==a&&a!==t.coordinates.length-2||(s=!1),Jn(t.coordinates[a],t.coordinates[a+1],e.coordinates[i],s)?r=!0:n=!0}i++}return r&&n}function Xn(e,t){return bn(e,xn(t)).features.length>0}function Hn(e,t){var r=!1,n=!1,o=e.coordinates.length;for(let i=0;i<o&&(!r||!n);i++)sn(Ye(e.coordinates[i]),t)?r=!0:n=!0;return n&&r}function Jn(e,t,r,n){var o=r[0]-e[0],i=r[1]-e[1],a=t[0]-e[0],s=t[1]-e[1];return 0===o*s-i*a&&(n?Math.abs(a)>=Math.abs(s)?a>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:s>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1]:Math.abs(a)>=Math.abs(s)?a>0?e[0]<r[0]&&r[0]<t[0]:t[0]<r[0]&&r[0]<e[0]:s>0?e[1]<r[1]&&r[1]<t[1]:t[1]<r[1]&&r[1]<e[1])}function qn(e){return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]}function $n(e){for(var t=0;t<e.length-1;t++)for(var r=e[t],n=t+1;n<e.length-2;n++){if(Vn(r,He([e[n],e[n+1]])))return!0}return!1}function Kn(e,t,r){for(var n=Xe(e),o=r+1;o<t.length;o++)if(!Pn(n,Xe(t[o]))&&Gn(n,He(t[o][0])))return!1;return!0}var Wn=function(e){if(!e.type)return!1;const t=tn(e),r=t.type,n=t.coordinates;switch(r){case"Point":return n.length>1;case"MultiPoint":for(var o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"LineString":if(n.length<2)return!1;for(o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"MultiLineString":if(n.length<2)return!1;for(o=0;o<n.length;o++)if(n[o].length<2)return!1;return!0;case"Polygon":for(o=0;o<t.coordinates.length;o++){if(n[o].length<4)return!1;if(!qn(n[o]))return!1;if($n(n[o]))return!1;if(o>0&&bn(Xe([n[0]]),Xe([n[o]])).features.length>1)return!1}return!0;case"MultiPolygon":for(o=0;o<t.coordinates.length;o++)for(var i=t.coordinates[o],a=0;a<i.length;a++){if(i[a].length<4)return!1;if(!qn(i[a]))return!1;if($n(i[a]))return!1;if(0===a&&!Kn(i,t.coordinates,o))return!1;if(a>0&&bn(Xe([i[0]]),Xe([i[a]])).features.length>1)return!1}return!0;default:return!1}};function zn(e){let t=0;if(e&&e.length>0){t+=Math.abs(eo(e[0]));for(let r=1;r<e.length;r++)t-=Math.abs(eo(e[r]))}return t}var Zn=20294876564838.72,Qn=Math.PI/180;function eo(e){const t=e.length-1;if(t<=2)return 0;let r=0,n=0;for(;n<t;){const o=e[n],i=e[n+1===t?0:n+1],a=e[n+2>=t?(n+2)%t:n+2],s=o[0]*Qn,c=i[1]*Qn;r+=(a[0]*Qn-s)*Math.sin(c),n++}return r*Zn}var to=function(e){return function(e,t,r){var n=r;return tt(e,function(e,r,o,i,a){n=t(n,e,r,o,i,a)}),n}(e,(e,t)=>e+function(e){let t,r=0;switch(e.type){case"Polygon":return zn(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)r+=zn(e.coordinates[t]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};function ro(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function no(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ro(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ro(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var oo=(e,t)=>{var r,n,o,i,a=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"meters",n=e.geometry.coordinates,o=[],i=nn(n[1],n[0]),a=an(n[0],t,i,{units:r});o.push(a.geometry.coordinates);for(var s=0;s<n.length;s++){if(s>0&&s<n.length-1){var c=nn(n[s-1],n[s]),l=an(n[s],t,c,{units:r});o.push(l.geometry.coordinates)}o.push(n[s])}var u=nn(n[n.length-2],n[n.length-1]),p=an(n[n.length-1],t,u,{units:r});return o.push(p.geometry.coordinates),He(o)}(t);try{i=Hr(e,a)}catch(e){return null}var s=[];if("MultiPolygon"!==i.geometry.type)return null;if(2!==i.geometry.coordinates.length)return null;s=i.geometry.coordinates.map(t=>Xe(t,e.properties));var c=null!==(r=null!==(n=e.id)&&void 0!==n?n:null===(o=e.properties)||void 0===o?void 0:o.id)&&void 0!==r?r:"poly";return Je(s.map((t,r)=>Xe(t.geometry.coordinates,no(no({},e.properties),{},{id:c}),{id:"".concat(c,"-").concat(r+1)})))},io=(e,t)=>{var[r,n]=e,[o,i]=t,a=e=>e*Math.PI/180,s=a(i-n),c=a(o-r),l=Math.sin(s/2)**2+Math.cos(a(n))*Math.cos(a(i))*Math.sin(c/2)**2;return 12742e3*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))},ao=e=>e.length<=1||function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01;if(e.length<=1)return!0;if(e.length>=2){var r=e[e.length-1],n=e[e.length-2];if(io(r,n)<t)return!1}return!0}(e),so=e=>{if(e[0].length<=1||function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01;if(e[0].length<=1)return!0;if(e[0].length<=3)for(var r=0;r<e[0].length;r++)for(var n=r+1;n<e[0].length;n++)if(io(e[0][r],e[0][n])<t)return!1;return!0}(e))return!0;if(!Array.isArray(e)||e.length<4)return!1;var t=e[0],r=e[e.length-1];if(!(t[0]===r[0]&&t[1]===r[1]))return!1;var n=Xe([e]);return!!Wn(n)&&!(to(n)<=0)},co=(e,t,r)=>{var n=t.filter((t,n)=>{var o=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);return("ArrowUp"===r?t[1]<=e[1]&&i>=o:"ArrowDown"===r?t[1]>e[1]&&i>=o:"ArrowLeft"===r?t[0]<=e[0]&&i<o:"ArrowRight"!==r||t[0]>e[0]&&i<o)&&JSON.stringify(t)!==JSON.stringify(e)});n.length||n.push(e);var o=n.map(t=>{return r=Math.abs(e[0]-t[0]),n=Math.abs(e[1]-t[1]),Math.sqrt(Math.pow(r,2)+Math.pow(n,2));var r,n}),i=n[o.indexOf(Math.min(...o))];return t.findIndex(e=>JSON.stringify(e)===JSON.stringify(i))},lo={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=zt(r),o=Zt(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVerticies(e){return Wt(this.getFeature(e))||[]},getMidpoints(e){var t=this.getFeature(e),r=Wt(t),n=zt(t);if(null==r||!r.length||!n.length)return[];var o=[];for(var i of n)for(var a=i.closed?i.length:i.length-1,s=0;s<a;s++){var c=i.start+s,l=i.start+(s+1)%i.length,[u,p]=r[c],[d,h]=r[l];o.push([(u+d)/2,(p+h)/2])}return o},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertecies)&&void 0!==r&&r.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertecies)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertecies.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=co(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=zt(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertecies.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertecies.length}};function uo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function po(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?uo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ho=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),fo={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},go=po(po(po(po(po(po({},Mt),nr),sr),ur),lo),{},{onSetup(e){var t,r,n=Mt.onSetup.call(this,e);Object.assign(n,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:n.featureId||e.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1});var o=this.getFeature(n.featureId);n.featureType=null==o?void 0:o.type,n.vertecies=this.getVerticies(n.featureId),n.midpoints=this.getMidpoints(n.featureId),this.setupEventListeners(n),this.applyVertexSelection(n,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(n);var i=u(this.map);if(i&&f(i,this.map),"touch"===n.interfaceType&&n.selectedVertexIndex>=0&&"vertex"===n.selectedVertexType){var a=n.vertecies[n.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(n,tr(this.map.project(a),n.scale))},0)}return n._ignorePointermoveDeselect=!0,setTimeout(()=>{n._ignorePointermoveDeselect=!1},100),n},setupEventListeners(e){var t=t=>r=>t.call(this,e,r),r=this.handlers={keydown:t(this.onKeydown),keyup:t(this.onKeyup),pointerdown:t(this.onPointerevent),pointermove:t(this.onPointerevent),pointerup:t(this.onPointerevent),click:t(this.onButtonClick),touchstart:t(this.onTouchstart),touchmove:t(this.onTouchmove),touchend:t(this.onTouchend),selectionchange:t(this.onSelectionChange),scalechange:t(this.onScaleChange),update:t(this.onUpdate),move:t(this.onMove),interfacetypechange:t(this.onInterfaceTypeChange)};window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),this.map.on("draw.selectionchange",r.selectionchange),this.map.on("draw.scalechange",r.scalechange),this.map.on("draw.update",r.update),this.map.on("move",r.move),this.map.on("draw.interfacetypechange",r.interfacetypechange)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature&&e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertecies.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature&&e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=Wt(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire("draw.vertexselection",{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?tr(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?tr(this.map.project(r),e.scale):null)},onUpdate(e){var t,r=new Set(e.vertecies.map(e=>JSON.stringify(e)));r.size!==e.vertecies.length&&(e.selectedVertexIndex=e.vertecies.findIndex(e=>!r.has(JSON.stringify(e))),null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null))},onKeydown(e,t){if(e.container.contains(document.activeElement)){if(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "===t.key&&t.preventDefault()," "===t.key&&e.selectedVertexIndex<0){var r,n,o=u(this.map);if(o&&f(o,this.map),null!==(r=e.vertecies)&&void 0!==r&&r.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertecies)||void 0===n||!n.length)return;return e.isPanEnabled=!1,this.updateVertex(e)}if(!t.altKey&&ho.has(t.key)&&e.selectedVertexIndex>=0){if(t.preventDefault(),t.stopPropagation(),"midpoint"===e.selectedVertexType)return this.insertVertex(e,t);var i=u(this.map),a=this.getFeature(e.featureId);if(!a)return;var s=Wt(a),c=null==s?void 0:s[e.selectedVertexIndex];if(!c)return;if(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...c],e._keyboardMoveStartIndex=e.selectedVertexIndex),y(e)&&e._isSnapped&&i){var l=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:15}(i)+1,g=this.map.project(c),[m,v]=fo[t.key].map(e=>e*l);return e._isSnapped=!1,f(i,this.map),this.moveVertex(e,this.map.unproject({x:g.x+m,y:g.y+v}))}var E=this.getNewCoord(e,t);return y(e)&&i&&(h(i,this.map,this.map.project(E)),p(i))?(e._isSnapped=!0,this.moveVertex(e,d(i))):(e._isSnapped=!1,this.moveVertex(e,E))}if(t.altKey&&ho.has(t.key)&&e.selectedVertexIndex>=0)return t.preventDefault(),t.stopPropagation(),this.updateVertex(e,t.key);if("Escape"===t.key&&this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}),"z"===t.key&&(t.metaKey||t.ctrlKey)&&!t.shiftKey){var b,x=null===(b=document.activeElement)||void 0===b?void 0:b.tagName;if("INPUT"===x||"TEXTAREA"===x)return;return t.preventDefault(),t.stopPropagation(),this.handleUndo(e)}}},onKeyup(e,t){e.container.contains(document.activeElement)&&(e.interfaceType="keyboard",ho.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&void 0!==e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=void 0)),"Delete"===t.key&&this.deleteVertex(e))},onMouseDown(e,t){var r,n;g(u(this.map));var o=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,i=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if(["vertex","midpoint"].includes(o)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,Mt.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=er(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertecies)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var p=this.getFeature(e.featureId),d=er(p,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire("draw.vertexselection",{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&void 0!==e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=void 0,void this.map.fire("draw.vertexselection",{index:r,numVertecies:e.vertecies.length})}Mt.onClick.call(this,e,t)},onMouseUp(e,t){g(u(this.map));var r=!1;if(e._moveStartPosition&&void 0!==e._moveStartIndex){var n=this.getFeature(e.featureId);if(n){var o,i=null===(o=Wt(n))||void 0===o?void 0:o[e._moveStartIndex];i&&(r=i[0]!==e._moveStartPosition[0]||i[1]!==e._moveStartPosition[1])}}var a=e._isInsertingVertex&&void 0!==e._insertedVertexIndex;if(e.dragMoving||r||a)if(this.syncVertices(e),a){var s=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),e.selectedVertexIndex=s,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=void 0,this.map.fire("draw.vertexselection",{index:s,numVertecies:e.vertecies.length})}else r&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition});e._moveStartPosition=null,e._moveStartIndex=null,Mt.onMouseUp.call(this,e,t)},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=u(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),y(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),h(n,this.map,t.point);var o=d(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Mt.onDrag.call(this,e,t)}},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,tr(this.map.project(t),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",po(po({},e),t))},onStop(e){this.map._drawEditContainer=null;var t=this.handlers;e.container.removeEventListener("pointerdown",t.pointerdown),e.container.removeEventListener("pointermove",t.pointermove),e.container.removeEventListener("pointerup",t.pointerup),e.container.removeEventListener("touchstart",t.touchstart),e.container.removeEventListener("touchmove",t.touchmove),e.container.removeEventListener("touchend",t.touchend),this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.scalechange",t.scalechange),this.map.off("draw.update",t.update),this.map.off("move",t.move),this.map.off("draw.interfacetypechange",t.interfacetypechange),this.map.dragPan.enable(),window.removeEventListener("click",t.click),window.removeEventListener("keydown",t.keydown,{capture:!0}),window.removeEventListener("keyup",t.keyup,{capture:!0}),this.hideTouchVertexIndicator(e)}});function yo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function mo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?yo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):yo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var vo=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,createVertices:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,f=e=>e[r];return mo(mo({},e),{},{onSetup(t){var{map:n}=this,o=s?mo(mo({},t),{},{featureId:null}):t,i=mo(mo({},e.onSetup.call(this,o)),t);i[r].properties=t.properties;var{container:a,vertexMarkerId:c,getInterfaceType:l}=i,u=l?l():i.interfaceType;i.interfaceType=u;var p=a.querySelector("#".concat(c));i.vertexMarker=p,["touch","keyboard"].includes(u)?this._showCrossHair(i):this._hideCrossHair(i);var d=(e,t)=>this[e]=t.bind(this,i),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo};return Object.entries(h).forEach(e=>{var[t,r]=e;return d(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[a,"blur",this.blurHandler],[a,"pointermove",this.pointermoveHandler],[a,"pointerup",this.pointerupHandler],[n,"pointerdown",this.pointerdownHandler],[n,"draw.create",this.createHandler],[n,"move",this.moveHandler],[n,"draw.undo",this.undoHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),i},onClick(t,r){if(!(r.originalEvent.button>0||this.map._undoInProgress||r.originalEvent.target!==this.map.getCanvas())){var n=u(this.map);if(y(t)&&p(n))r=function(e,t){var r=d(t);return r?l(l({},e),{},{lngLat:r}):e}(r,n);else{var a=o(f(t));if(a.length>0&&(a[a.length-1]=[r.lngLat.lng,r.lngLat.lat]),!c&&!i(f(t)))return}var s=o(f(t)).length;e.onClick.call(this,t,r),o(f(t)).length>s&&(this.pushDrawUndo(t),this.dispatchVertexChange(o(f(t))))}},onTap(){},doClick(t){if(!this.map._undoInProgress){var r=f(t),n=o(r);if(this.dispatchVertexChange(n),i(r)){var a=u(this.map),s=y(t)&&function(e,t){var r=d(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,a),l=n.length;s?(e.onClick.call(this,t,s),this._ctx.store.render()):this._simulateMouse("click",e.onClick,t);var p=o(f(t));p.length>l&&(this.pushDrawUndo(t),this.dispatchVertexChange(p))}else c&&n.length>1&&(n.pop(),this.map.fire("draw.create",{features:[r.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[r.id]}))}},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},pushDrawUndo(e){var t=this.map._undoStack;t&&!this.map._undoInProgress&&t.push({type:"draw_vertex",geometryType:n,featureId:f(e).id})},undoVertex(e){var t=f(e),r=o(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_reinitializeFeature(t,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n){var a=this.map._undoStack;return a&&a.clear(),this._ctx.api.changeMode("draw_line",{featureId:i,container:t.container,interfaceType:t.interfaceType,crossHair:t.crossHair,vertexMarkerId:t.vertexMarkerId,addVertexButtonId:t.addVertexButtonId,getSnapEnabled:t.getSnapEnabled,properties:t.properties}),!0}var s=this.map.getCenter(),c=[[s.lng,s.lat],[s.lng,s.lat]],l=this.newFeature({type:"Feature",properties:t.properties||{},geometry:{type:n,coordinates:[c]}});return l.id=i,this._ctx.store.add(l),t[r]=l,t.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render(),this.dispatchVertexChange(c),!0},_removeLastVertex(e,t,r){var i="Polygon"===n?t.coordinates[0]:r;i.splice(-2,1);var a=i[i.length-2];a&&(i[i.length-1]=[...a]),e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,o(t))},_updateRubberBand(t,r){if(["touch","keyboard"].includes(t.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render();else{var o=r["Polygon"===n?r.length-2:r.length-1];if(o){var i={lng:o[0],lat:o[1]},a=this.map.project(i);e.onMouseMove.call(this,t,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render()}}this.dispatchVertexChange(r)},onUndo(e,t){var r;"draw_vertex"===(null===(r=t.operation)||void 0===r?void 0:r.type)&&this.undoVertex(e)},_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},onCreate(e,t){var r=this._ctx.api,n=t.features[0];r.delete(n.id),n.id=e.featureId,r.add(n,{userProperties:!0})},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;if("INPUT"!==n&&"TEXTAREA"!==n){t.preventDefault(),t.stopPropagation();var o=this.map._undoStack;if(o&&o.length>0){var i=o.pop();"draw_vertex"===(null==i?void 0:i.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e))}}},onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),this._setInterface(e,"keyboard"),this.onMove(e,t)):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(t,r){var n=document.activeElement;if(!n||n===t.container||!t.container.contains(n))if("Escape"!==r.key)n!==t.container&&e.onKeyUp.call(this,t,r);else if("keyboard"===t.interfaceType){var o=this.map._undoStack;o&&o.clear(),this._reinitializeFeature(t,f(t))}},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(t,r){if(y(t)){var n=u(this.map);h(n,this.map,r.point);var o=d(n);o&&(r=mo(mo({},r),{},{lngLat:o}))}this.map.fire("draw.geometrychange",t.polygon||t.line),e.onMouseMove.call(this,t,r)},onMove(t){if(["touch","keyboard"].includes(t.interfaceType)){y(t)&&function(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);e.snapToClosestPoint({point:n,lngLat:r})}(u(this.map),this.map);var r=u(this.map),n=y(t)&&d(r);if(n){var o=this.map.project([n.lng,n.lat]);e.onMouseMove.call(this,t,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render()}else this._simulateMouse("mousemove",e.onMouseMove,t)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(o(f(e)))},toDisplayFeatures(t,r,o){e.toDisplayFeatures.call(this,t,r,o);var i=f(t);r.geometry.type===n&&r.id===i.id&&a(r,o,Re)},onStop(t){e.onStop.call(this,t),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),this._hideCrossHair(t)}})},Eo=vo(Ct,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>so(e.coordinates),createVertices:(e,t,r)=>{for(var n=e.geometry.coordinates[0],o=1;o<n.length-2;o++)t(r(e.id,n[o],"0.".concat(o)))}}),bo=vo(Tt,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>ao(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,createVertices:(e,t,r)=>{for(var n=e.geometry.coordinates,o=1;o<n.length-1;o++)t(r(e.id,n[o],"".concat(o)))}}),xo={editStroke:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editVertex:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editMidpoint:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editHalo:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editActive:{light:"rgba(11,12,12,1)",dark:"#ffffff"},splitInvalid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},shapeStroke:"rgba(212,53,28,1)",shapeFill:"rgba(212,53,28,0.1)",strokeWidth:2,snapVertex:"rgba(212,53,28,1)",snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,1)",snapRadius:10,snapLayers:[]},So=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],xo[r]]},Po=e=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":So(e,"fill","shapeFill")}}),wo=e=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":So(e,"stroke","shapeStroke"),"line-width":So(e,"strokeWidth")}}),_o=e=>({id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":e,"fill-opacity":.1}}),Mo=e=>({id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-opacity":1}}),Io=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}}),Oo=e=>({id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-opacity":1}}),Co=e=>({id:"stroke-preview-line",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),To=e=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"]],paint:{"circle-radius":6,"circle-color":e}}),Lo=(e,t)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":8,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Ao=e=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":6,"circle-color":e}}),ko=e=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":4,"circle-color":e}}),Fo=(e,t)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":6,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),No=e=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":4,"circle-color":e}}),Vo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Do=e=>{var t=(e=>{var t;return null!==(t=e.mapColorScheme)&&void 0!==t?t:"light"})(e),r=xo.editStroke[t],n=xo.editVertex[t],o=xo.editMidpoint[t],i=xo.editHalo[t],a=xo.editActive[t],s=xo.splitInvalid[t],c=xo.splitValid[t];return[Po(e),_o(r),Mo(r),wo(e),Io(s),Oo(c),Co(r),ko(o),Fo(i,a),No(o),To(n),Lo(i,a),Ao(n),Vo(r),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function jo(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Ro(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Uo(e,t,r){void 0===r&&(r={});var n=jo(e),o=jo(t),i=ze(o[1]-n[1]),a=ze(o[0]-n[0]),s=ze(n[1]),c=ze(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return $e(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function Bo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return qe(e,t);return He(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Go(e,t,r,n){void 0===n&&(n={});var o=jo(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Ye([We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),We(l)],n.properties)}function Yo(e){if(!e)throw new Error("geojson is required");var t=[];return rt(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=Ro(n);break;case"LineString":r=[Ro(n)]}r.forEach(function(r){var n=function(e,t){var r=[];return e.reduce(function(e,n){var o,i,a,s,c,l,u=He([e,n],t);return u.bbox=(i=n,a=(o=e)[0],s=o[1],c=i[0],l=i[1],[a<c?a:c,s<l?s:l,a>c?a:c,s>l?s:l]),r.push(u),n}),r}(r,e.properties);n.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),Je(t)}var Xo={exports:{}};function Ho(e,t,r,n,o){Jo(e,t,r||0,n||e.length-1,o||$o)}function Jo(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);Jo(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],p=r,d=n;for(qo(e,r,t),o(e[n],u)>0&&qo(e,r,n);p<d;){for(qo(e,p,d),p++,d--;o(e[p],u)<0;)p++;for(;o(e[d],u)>0;)d--}0===o(e[r],u)?qo(e,r,d):qo(e,++d,n),d<=t&&(r=d+1),t<=d&&(n=d-1)}}function qo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function $o(e,t){return e<t?-1:e>t?1:0}function Ko(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Wo(e,t){zo(e,0,e.children.length,t,e)}function zo(e,t,r,n,o){o||(o=si(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<r;i++){const t=e.children[i];Zo(o,e.leaf?n(t):t)}return o}function Zo(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Qo(e,t){return e.minX-t.minX}function ei(e,t){return e.minY-t.minY}function ti(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ri(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ni(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function oi(e,t){const r=Math.max(e.minX,t.minX),n=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-r)*Math.max(0,i-n)}function ii(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function ai(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function si(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ci(e,t,r,n,o){const i=[t,r];for(;i.length;){if((r=i.pop())-(t=i.pop())<=n)continue;const a=t+Math.ceil((r-t)/n/2)*n;Ho(e,a,t,r,o),i.push(t,a,a,r)}}var li,ui=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const r=[];if(!ai(e,t))return r;const n=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const a=t.children[i],s=t.leaf?n(a):a;ai(e,s)&&(t.leaf?r.push(a):ii(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!ai(e,t))return!1;const r=[];for(;t;){for(let n=0;n<t.children.length;n++){const o=t.children[n],i=t.leaf?this.toBBox(o):o;if(ai(e,i)){if(t.leaf||ii(e,i))return!0;r.push(o)}}t=r.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=si([]),this}remove(e,t){if(!e)return this;let r=this.data;const n=this.toBBox(e),o=[],i=[];let a,s,c;for(;r||o.length;){if(r||(r=o.pop(),s=o[o.length-1],a=i.pop(),c=!0),r.leaf){const n=Ko(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!ii(r,n)?s?(a++,r=s.children[a],c=!1):r=null:(o.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const r=[];for(;e;)e.leaf?t.push(...e.children):r.push(...e.children),e=r.pop();return t}_build(e,t,r,n){const o=r-t+1;let i,a=this._maxEntries;if(o<=a)return i=si(e.slice(t,r+1)),Wo(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=si([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));ci(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);ci(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Wo(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=ti(a),c=ni(e,a)-s;c<o?(o=c,n=s<n?s:n,r=a):c===o&&s<n&&(n=s,r=a)}t=r||t.children[0]}return t}_insert(e,t,r){const n=r?e:this.toBBox(e),o=[],i=this._chooseSubtree(n,this.data,t,o);for(i.children.push(e),Zo(i,n);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(n,o,t)}_split(e,t){const r=e[t],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const i=this._chooseSplitIndex(r,o,n),a=si(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Wo(r,this.toBBox),Wo(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=si([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Wo(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=zo(e,0,a,this.toBBox),s=zo(e,a,r,this.toBBox),c=oi(t,s),l=ti(t)+ti(s);c<o?(o=c,n=a,i=l<i?l:i):c===o&&l<i&&(i=l,n=a)}return n||r-t}_chooseSplitAxis(e,t,r){const n=e.leaf?this.compareMinX:Qo,o=e.leaf?this.compareMinY:ei;this._allDistMargin(e,t,r,n)<this._allDistMargin(e,t,r,o)&&e.children.sort(n)}_allDistMargin(e,t,r,n){e.children.sort(n);const o=this.toBBox,i=zo(e,0,t,o),a=zo(e,r-t,r,o);let s=ri(i)+ri(a);for(let n=t;n<r-t;n++){const t=e.children[n];Zo(i,e.leaf?o(t):t),s+=ri(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Zo(a,e.leaf?o(t):t),s+=ri(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Zo(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Wo(e[r],this.toBBox)}}}),pi=q(ui),di={};function hi(){if(li)return di;li=1,Object.defineProperty(di,"__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 p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function d(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 di.areaFactors=r,di.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},di.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},di.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},di.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return p(d(e,t),r)},di.degreesToRadians=function(e){return e%360*Math.PI/180},di.earthRadius=e,di.factors=t,di.feature=n,di.featureCollection=s,di.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")}},di.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},di.isNumber=f,di.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},di.lengthToDegrees=function(e,t){return h(d(e,t))},di.lengthToRadians=d,di.lineString=a,di.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},di.multiLineString=c,di.multiPoint=l,di.multiPolygon=u,di.point=o,di.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},di.polygon=i,di.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},di.radiansToDegrees=h,di.radiansToLength=p,di.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},di.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")})},di.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")},di}var fi,gi={};function yi(){if(fi)return gi;fi=1,Object.defineProperty(gi,"__esModule",{value:!0});var e=hi();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,p,d=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(p=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var E=0;E<c;E++){var b=0,x=0;if(null!==(s=p?u.geometries[E]:u)){l=s.coordinates;var S=s.type;switch(d=!n||"Polygon"!==S&&"MultiPolygon"!==S?0:1,S){case null:break;case"Point":if(!1===r(l,h,v,b,x))return!1;h++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,b,x))return!1;h++,"MultiPoint"===S&&b++}"LineString"===S&&b++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-d;i++){if(!1===r(l[o][i],h,v,b,x))return!1;h++}"MultiLineString"===S&&b++,"Polygon"===S&&x++}"Polygon"===S&&b++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(x=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-d;a++){if(!1===r(l[o][i][a],h,v,b,x))return!1;h++}x++}b++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,p,d=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,p=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,d,l,u,p))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],d,l,u,p))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,d,l,u,p))return!1;d++}}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,p=0;return!1!==t(r,function(t,s,d,h,f){if(void 0===c||o>l||h>u||f>p)return c=t,l=o,u=h,p=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return gi.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},gi.coordEach=t,gi.coordReduce=function(e,r,n,o){var i=n;return t(e,function(e,t,o,a,s){i=0===t&&void 0===n?e:r(i,e,t,o,a,s)},o),i},gi.featureEach=n,gi.featureReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},gi.findPoint=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.coordIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return e.point.call(void 0,l,c,r);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,r);case"LineString":return s<0&&(s=l.length+s),e.point.call(void 0,l[s],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s),e.point.call(void 0,l[a][s],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),e.point.call(void 0,l[i][s],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s),e.point.call(void 0,l[i][a][s],c,r)}throw new Error("geojson is invalid")},gi.findSegment=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.segmentIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=l.length+s-1),e.lineString.call(void 0,[l[s],l[s+1]],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s-1),e.lineString.call(void 0,[l[a][s],l[a][s+1]],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s-1),e.lineString.call(void 0,[l[i][s],l[i][s+1]],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s-1),e.lineString.call(void 0,[l[i][a][s],l[i][a][s+1]],c,r)}throw new Error("geojson is invalid")},gi.flattenEach=i,gi.flattenReduce=function(e,t,r){var n=r;return i(e,function(e,o,i){n=0===o&&0===i&&void 0===r?e:t(n,e,o,i)}),n},gi.geomEach=o,gi.geomReduce=function(e,t,r){var n=r;return o(e,function(e,o,i,a,s){n=0===o&&void 0===r?e:t(n,e,o,i,a,s)}),n},gi.lineEach=s,gi.lineReduce=function(e,t,r){var n=r;return s(e,function(e,o,i,a){n=0===o&&void 0===r?e:t(n,e,o,i,a)}),n},gi.propEach=r,gi.propReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},gi.segmentEach=a,gi.segmentReduce=function(e,t,r){var n=r,o=!1;return a(e,function(e,i,a,s,c){n=!1===o&&void 0===r?e:t(n,e,i,a,s,c),o=!0}),n},gi}var mi,vi,Ei={};function bi(){if(mi)return Ei;mi=1,Object.defineProperty(Ei,"__esModule",{value:!0});var e=yi();function t(t,r={}){if(null!=t.bbox&&!0!==r.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}var r=t;return Ei.bbox=t,Ei.default=r,Ei}var xi=function(){if(vi)return Xo.exports;vi=1;var e=pi,t=hi(),r=yi(),n=bi().default,o=r.featureEach;r.coordEach,t.polygon;var i=t.featureCollection;function a(t){var r=new e(t);return r.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.insert.call(this,t)},r.load=function(t){var r=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}),e.prototype.load.call(this,r)},r.remove=function(t,r){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.remove.call(this,t,r)},r.clear=function(){return e.prototype.clear.call(this)},r.search=function(t){var r=e.prototype.search.call(this,this.toBBox(t));return i(r)},r.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},r.all=function(){var t=e.prototype.all.call(this);return i(t)},r.toJSON=function(){return e.prototype.toJSON.call(this)},r.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},r.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=n(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=n(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},r}return Xo.exports=a,Xo.exports.default=a,Xo.exports}(),Si=J(xi);function Pi(e,t){var r={},n=[];if("LineString"===e.type&&(e=Ge(e)),"LineString"===t.type&&(t=Ge(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=wi(e,t);return o&&n.push(o),Je(n)}var i=Si();return i.load(Yo(t)),et(Yo(e),function(e){et(i.search(e),function(t){var o=wi(e,t);if(o){var i=Ro(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),Je(n)}function wi(e,t){var r=Ro(e),n=Ro(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],p=n[1][1],d=(p-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(p-l)*(o-c),f=(a-o)*(i-l)-(s-i)*(o-c);if(0===d)return null;var g=h/d,y=f/d;return g>=0&&g<=1&&y>=0&&y<=1?Ye([o+g*(a-o),i+g*(s-i)]):null}function _i(e,t,r){void 0===r&&(r={});var n=Ye([1/0,1/0],{dist:1/0}),o=0;return rt(e,function(e){for(var i=Ro(e),a=0;a<i.length-1;a++){var s=Ye(i[a]);s.properties.dist=Uo(t,s,r);var c=Ye(i[a+1]);c.properties.dist=Uo(t,c,r);var l=Uo(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),p=nn(s,c),d=Go(t,u,p+90,r),h=Go(t,u,p-90,r),f=Pi(He([d.geometry.coordinates,h.geometry.coordinates]),He([s.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=Uo(t,g,r),g.properties.location=o+Uo(s,g,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),g&&g.properties.dist<n.properties.dist&&((n=g).properties.index=a),o+=l}}),n}function Mi(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Ii(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=Mi(e),i=ze(o[0]),a=ze(o[1]),s=ze(r),c=Ke(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s));return Ye([We(i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l))),We(l)],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=Mi(e),o=Mi(t),i=ze(o[1]-n[1]),a=ze(o[0]-n[0]),s=ze(n[1]),c=ze(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return $e(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,nn(e,t));return r}var Oi=function(){return Oi=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Oi.apply(this,arguments)},Ci=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],r=0;r<e.features.length;r++){var n=e.features[r],o=n.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var a=this.features.unknow.snapPoints;i=Oi(Oi({},i),a)}var s=this.doSnap(n,i);t.push(s)}else if(void 0!==this.features.unknow){a=this.features.unknow.snapPoints,s=this.doSnap(n,a);t.push(s)}else t.push(n)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Uo(Ye(e),Ye(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],p=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){p=!0,c.push(t[n]);break}0==p&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var d=e.geometry.coordinates;for(c=[],l=0;l<d.length;l++){var h=d[l];p=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){p=!0,c.push(t[n]);break}0==p&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=Uo(Ye([r.lng,r.lat]),Ye([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var a=!1,s=this.getCloseFeatures(e,i);s?(this.snapStatus=!0,this.snapCoords=s.coords,a=function(e,t,r={}){const n=r.steps||64,o=r.properties?r.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<n;o++)i.push(on(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),Xe([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=Je(0==a?[]:[a]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(Je([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n,o=(n=[],Qe(e,function(e){n.push(e)}),n),i=[];if(o.map(function(e){var n=Uo(Ye(e),Ye([t.lng,t.lat]),{units:"meters"});n<r&&i.push({coords:e,dist:n,color:"#8bc34a"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(He(e))});break;case"Polygon":var o=Bo(e.geometry);n.push(o);break;case"MultiPolygon":Bo(e.geometry).coodinates.map(function(e){n.push(He(e))})}return n},e.prototype.searchInMidPoint=function(e,t,r){var n=this.getLines(e,t,r),o=[];n.map(function(e){o=o.concat(Yo(e).features)});var i=[];if(o.map(function(e){var n=Ii(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Uo(n,Ye([t.lng,t.lat]),{units:"meters"});o<r&&i.push({coords:n.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,r){for(var n=this.getLines(e,t,r),o=[],i=0;i<n.length;i++){var a=_i(n[i],Ye([t.lng,t.lat]),{units:"meters"});void 0!==a.properties.dist&&a.properties.dist<r&&o.push({coords:a.geometry.coordinates,dist:a.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var r=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(r.length>0){for(var n,o=!1,i=0;i<r.length;i++){var a=r[i],s=this.options.rules,c=e.lngLat;if(o=!1,-1!==s.indexOf("vertex")&&null==n&&(n=this.searchInVertex(a,c,t))){o=!0;break}if(-1!==s.indexOf("midpoint")&&null==n&&(n=this.searchInMidPoint(a,c,t))){o=!0;break}if(-1!==s.indexOf("edge")&&null==n&&(n=this.searchInEdge(a,c,t))){o=!0;break}}return!!o&&n}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}();function Ti(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var Li="snap-helper-circle";function Ai(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function ki(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}function Fi(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:o=[],radius:i=15,rules:a=["vertex","midpoint","edge"],status:s=!1,onSnapped:c=()=>{},colors:l={}}=n;function u(e){if(t._snapInstance||t._snapCreating)return t._snapInstance;t._snapCreating=!0,t.getLayer(Li)&&t.removeLayer(Li),t.getSource(Li)&&t.removeSource(Li),ki(e);var n=new Ci({map:t,drawing:r,options:{layers:o,radius:i,rules:a},status:s,onSnapped:c}),l=s;return Object.defineProperty(n,"status",{get:()=>l,set(){},configurable:!0}),n.setSnapStatus=e=>{l=e},n._defaultLayers=o,n._activeLayers=null,n.setSnapLayers=e=>{null==e?n._activeLayers=null:Array.isArray(e)&&(n._activeLayers=e)},void 0!==t._pendingSnapLayers&&(n.setSnapLayers(t._pendingSnapLayers),delete t._pendingSnapLayers),t._snapInstance=n,n}!function(e){if(!Ci.prototype.__snapPatched){Ci.prototype.__snapPatched=!0;var t=Ci.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},t.setMapData=function(e){var t,n;if(this.status){var o=r.setMapData.call(this,e);return(null==e||null===(t=e.features)||void 0===t?void 0:t.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(Li)&&this.map.setLayoutProperty(Li,"visibility","visible"),o}},t.drawingSnapCheck=function(){if(this.status)return r.drawingSnapCheck.call(this)},t.getLines=function(e,t,n){var o=e.geometry;if(!o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>Xe(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>He(e)):r.getLines.call(this,e,t,n)}catch(e){return console.log(e),[]}},t.getCloseFeatures=function(e,t){if(!this.status)return[];var n=this._activeLayers||this._defaultLayers||[];this.options.layers=n.filter(e=>this.map.getLayer(e));var o=this.options.radius||15,i=e.point;e.point=[[i.x-o,i.y-o],[i.x+o,i.y+o]];var a=r.getCloseFeatures.call(this,e,t);return e.point=i,a},t.searchInVertex=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInVertex.apply(this,n);return i&&(i.color=e.vertex),i},t.searchInMidPoint=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInMidPoint.apply(this,n);return i&&(i.color=e.midpoint),i},t.searchInEdge=function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=r.searchInEdge.apply(this,n);return i&&(i.color=e.edge),i},t.snapToClosestPoint=function(e){var t;if(this.status&&(null===(t=this.map)||void 0===t||!t._isZooming))try{var n,o,i=r.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){console.log(e),this.snapStatus=!1,this.snapCoords=null}}}}(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ti(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ti(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:xo.snapVertex,midpoint:xo.snapMidpoint,edge:xo.snapEdge},l)),t.on("style.load",()=>{Ai(()=>t._removed?null:t.getSource("mapbox-gl-draw-hot"),e=>{var r;(ki(e),t.getSource(Li)||t.addSource(Li,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),t.getLayer(Li))||t.addLayer({id:Li,type:"fill",source:Li,paint:{"fill-color":["get","color"],"fill-opacity":.6},layout:{visibility:null!==(r=t._snapInstance)&&void 0!==r&&r.status?"visible":"none"}});t._snapInstance||u(e)})}),t.on("zoomstart",()=>{t._isZooming=!0}),t.on("zoomend",()=>{if(t._isZooming=!1,t.getLayer(Li)){t.setLayoutProperty(Li,"visibility","none");var e=t._snapInstance;null!=e&&e.status&&t.setLayoutProperty(Li,"visibility","visible")}}),Ai(()=>t._removed?null:t.getSource("mapbox-gl-draw-hot"),u)}function Ni(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Vi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ni(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ni(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Di=e=>{var{mapStyle:t,mapProvider:r,events:n,eventBus:o,snapLayers:i}=e,{map:a}=r;$t.constants.classes.CONTROL_BASE="maplibregl-ctrl",$t.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",$t.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var s=new $t({modes:Vi(Vi({},$t.modes),{},{disabled:Kt,edit_vertex:go,draw_polygon:Eo,draw_line:bo}),styles:Do(t),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"});a.addControl(s);var c=a.getCanvas(),l=null,u=e=>{1===e.touches.length&&(l={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},p=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",p,{passive:!0}),r.draw=s,a._drawCurrentMapStyle=t,r.snapEnabled=!1;var d=(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=d,a._undoStack=d,Fi(a,s,{layers:i,radius:10,rules:["vertex","edge"]});var h=e=>{a._drawCurrentMapStyle=e,a.once("idle",()=>{var t;((e,t)=>{Do(t).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})})(a,e);var r=null===(t=a._drawEditContainer)||void 0===t?void 0:t.querySelector("[data-touch-vertex-target]");ar(r,e)})};o.on(n.MAP_SET_STYLE,h);return o.on(n.MAP_SET_SIZE,e=>{a.fire("draw.scalechange",{scale:{small:1,medium:1.5,large:2}[e]})}),{draw:s,remove(){c.removeEventListener("touchstart",u),c.removeEventListener("touchend",p),o.off(n.MAP_SET_STYLE,h),s.deleteAll(),s.changeMode("disabled"),a.removeControl(s)}}},ji=["stroke","fill","strokeWidth"],Ri=e=>{if(!e)return{};var t={};for(var[r,n]of Object.entries(e))if(ji.includes(r)&&"object"==typeof n&&null!==n){var o=Object.entries(n);for(var[i,a]of(o.length>0&&(t[r]=o[0][1]),o))t["".concat(r).concat(i.charAt(0).toUpperCase()+i.slice(1))]=a}else t[r]=n;return t},Ui=["stroke","fill","strokeWidth","properties"];function Bi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Gi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Bi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Bi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Yi=["stroke","fill","strokeWidth","properties"];function Xi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Hi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ji=["stroke","fill","strokeWidth","properties"];function qi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function $i(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ki(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Wi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ki(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ki(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zi=e=>({mobile:{slot:"actions",showLabel:e},tablet:{slot:"actions",showLabel:e},desktop:{slot:"actions",showLabel:e}}),Zi={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertecies:null,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:a},InitComponent:e=>{var{appState:r,appConfig:n,mapState:o,pluginConfig:i,pluginState:a,services:c,mapProvider:l,buttonConfig:p}=e,{eventBus:d}=c,{crossHair:h}=o,y=["touch","keyboard"].includes(r.interfaceType);t(()=>{var e;if(o.isMapReady){var{remove:t}=Di({mapStyle:o.mapStyle,snapLayers:i.snapLayers,mapProvider:l,events:s,eventBus:d});return a.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:(null===(e=i.snapLayers)||void 0===e?void 0:e.length)>0}),d.emit("draw:ready"),()=>t()}},[o.isMapReady]),t(()=>{l.draw&&(l.draw._crossHair=h)},[l.draw,h]),t(()=>{if(["draw_polygon","draw_line"].includes(a.mode)&&y){var e=h.isVisible;return h.fixAtCenter(),()=>{e||h.hide()}}},[a.mode,r.interfaceType]),t(()=>{"edit_vertex"===a.mode&&l.map&&l.map.fire("draw.interfacetypechange",{interfaceType:r.interfaceType})},[r.interfaceType,a.mode]),t(()=>{if(l.draw){var e=function(e){var{pluginState:t,mapProvider:r,buttonConfig:n,eventBus:o}=e,{drawDone:i,drawAddPoint:a,drawUndo:s,drawDeletePoint:c,drawSnap:l,drawCancel:p}=n,{map:d,draw:h}=r,{dispatch:y,feature:m,tempFeature:v}=t,E=()=>{r.snapEnabled=!1,y({type:"SET_SNAP",payload:!1});var e,t=u(d);t&&(null===(e=t.setSnapStatus)||void 0===e||e.call(t,!1),g(t)),d.getLayer("snap-helper-circle")&&d.setLayoutProperty("snap-helper-circle","visibility","none")},b=()=>{var e;null===(e=r.undoStack)||void 0===e||e.clear(),y({type:"SET_MODE",payload:null}),y({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},x=()=>{h.trash(),null!=v&&v.id&&h.delete(v.id),m&&h.add(m),E(),h.changeMode("disabled"),b(),o.emit("draw:cancelled",m)},S=0,P=["draw_polygon","draw_line"],w=e=>{P.includes(e.mode)||f(u(d),d)},_=()=>{var e,t=d.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=>d.moveLayer(e.id))},M=e=>t=>{var r=t.features[0];E(),b(),setTimeout(()=>h.changeMode("disabled"),0),o.emit(e,r)},I=e=>{var t=e.features[0];o.emit("draw:updated",t)},O=M("draw:created"),C=M("draw:edited"),T=e=>{y({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),o.emit("draw:vertexselection",e)},L=e=>{y({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertecies:e.numVertecies}})},A=e=>{y({type:"SET_UNDO_STACK_LENGTH",payload:e.length})};return i.onClick=()=>{var e,t=h.getMode();E(),null===(e=r.undoStack)||void 0===e||e.clear(),"edit_vertex"!==t?["draw_polygon","draw_line"].includes(t)&&h.changeMode("disabled"):d.fire("draw.editfinish",{features:[h.get(v.id)]})},p.onClick=x,s.onClick=()=>{if("edit_vertex"!==h.getMode()){var e=r.undoStack;if(null!=e&&e.length){var t=e.pop();d._undoInProgress=!0,setTimeout(()=>{d._undoInProgress=!1},100),d.fire("draw.undo",{operation:t})}}},l.onClick=()=>{var e=Date.now();if(!(e-S<300)){S=e;var n=!t.snap;y({type:"TOGGLE_SNAP"}),r.snapEnabled=n;var o=u(d);null!=o&&o.setSnapStatus&&o.setSnapStatus(n),!n&&o&&(g(o),d.getLayer("snap-helper-circle")&&d.setLayoutProperty("snap-helper-circle","visibility","none"))}},d.on("styledata",_),d.on("draw.cancel",x),d.on("draw.create",O),d.on("draw.modechange",w),d.on("draw.editfinish",C),d.on("draw.update",I),d.on("draw.vertexselection",T),d.on("draw.vertexchange",L),d.on("draw.undochange",A),()=>{[i,a,s,c,l,p].forEach(e=>{e&&(e.onClick=null)}),d.off("styledata",_),d.off("draw.cancel",x),d.off("draw.create",O),d.off("draw.editfinish",C),d.off("draw.update",I),d.off("draw.modechange",w),d.off("draw.vertexselection",T),d.off("draw.vertexchange",L),d.off("draw.undochange",A)}}({mapProvider:l,buttonConfig:p,pluginState:a,eventBus:d});return()=>e()}},[l,r,a])},buttons:[Wi({id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode}},zi(!0)),Wi({id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:e=>{var{appState:t,pluginState:r}=e;return!["draw_polygon","draw_line"].includes(r.mode)||"touch"!==t.interfaceType}},zi(!0)),Wi({id:"drawDone",label:"Done",variant:"primary",exclusiveSlot:!0,hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return t.numVertecies>=("draw_polygon"===t.mode?3:2)}},zi(!0)),{id:"drawMenu",label:"Menu",iconId:"menu",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},menuItems:[{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return t.undoStackLength>0}},{id:"drawSnap",label:"Snap to feature",iconId:"magnet",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode||!t.hasSnapLayers},pressedWhen:e=>{var{pluginState:t}=e;return!!t.snap}},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:e=>{var t,{pluginState:r}=e;return r.selectedVertexIndex>=0&&r.numVertecies>("Polygon"===(null===(t=r.tempFeature)||void 0===t||null===(t=t.geometry)||void 0===t?void 0:t.type)?3:2)},hiddenWhen:e=>{var{pluginState:t}=e;return!["simple_select","edit_vertex"].includes(t.mode)}}],mobile:{slot:"bottom-right"},tablet:{slot:"top-middle"},desktop:{slot:"top-middle"}}],keyboardShortcuts:[{id:"drawStart",group:"Drawing",title:"Edit vertex",command:"<kbd>Spacebar</kbd></dd>"}],icons:[{id:"menu",svgContent:'<path d="m6 9 6 6 6-6"/>'},{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"check",svgContent:'<path d="M20 6 9 17l-5-5"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,p=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:d}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(h){g.emit("draw:started",{mode:"draw_polygon"});var y=null;y=void 0!==p.snapLayers?p.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=u(f);null!=m&&m.setSnapLayers?m.setSnapLayers(y):y&&(f._pendingSnapLayers=y),d({type:"SET_HAS_SNAP_LAYERS",payload:(null===(n=y)||void 0===n?void 0:n.length)>0});var{stroke:v,fill:E,strokeWidth:b,properties:x}=p,S=r(p,Ui),P=Gi(Gi({},x),Ri({stroke:v,fill:E,strokeWidth:b}));h.changeMode("draw_polygon",Gi(Gi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,crossHair:h._crossHair,getSnapEnabled:()=>!0===c.snapEnabled,featureId:t},S),{},{properties:P})),d({type:"SET_MODE",payload:"draw_polygon"})}},newLine:function(e,t){var n,{appState:o,appConfig:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,p=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:d}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(h){g.emit("draw:started",{mode:"draw_line"});var y=null;y=void 0!==p.snapLayers?p.snapLayers:void 0!==a.snapLayers?a.snapLayers:null;var m=u(f);null!=m&&m.setSnapLayers?m.setSnapLayers(y):y&&(f._pendingSnapLayers=y),d({type:"SET_HAS_SNAP_LAYERS",payload:(null===(n=y)||void 0===n?void 0:n.length)>0});var{stroke:v,fill:E,strokeWidth:b,properties:x}=p,S=r(p,Yi),P=Hi(Hi({},x),Ri({stroke:v,fill:E,strokeWidth:b}));h.changeMode("draw_line",Hi(Hi({container:o.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(i.id,"-cross-hair"),addVertexButtonId:"".concat(i.id,"-draw-add-point"),interfaceType:o.interfaceType,crossHair:h._crossHair,getSnapEnabled:()=>!0===c.snapEnabled,featureId:t},S),{},{properties:P})),d({type:"SET_MODE",payload:"draw_line"})}},editFeature:function(e,t){var r,{appState:n,appConfig:o,mapState:i,pluginConfig:a,pluginState:s,mapProvider:c,services:l}=e,p=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:d}=s,{draw:h,map:f}=c,{eventBus:g}=l;if(!h)return!1;var y=h.get(t);if(!y)return!1;g.emit("draw:editstart",{mode:{LineString:"edit_line",Polygon:"edit_polygon"}[y.geometry.type]});var m,v=null;void 0===p.snapLayers?v=null!==(m=a.snapLayers)&&void 0!==m?m:null:v=p.snapLayers;var E=u(f);null!=E&&E.setSnapLayers?E.setSnapLayers(v):v&&(f._pendingSnapLayers=v),d({type:"SET_HAS_SNAP_LAYERS",payload:(null===(r=v)||void 0===r?void 0:r.length)>0}),h.changeMode("edit_vertex",{container:n.layoutRefs.viewportRef.current,deleteVertexButtonId:"".concat(o.id,"-draw-delete-point"),undoButtonId:"".concat(o.id,"-draw-undo"),isPanEnabled:"keyboard"!==n.interfaceType,interfaceType:n.interfaceType,scale:{small:1,medium:1.5,large:2}[i.mapSize],featureId:t,getSnapEnabled:()=>!0===c.snapEnabled});var b=h.get(t);return d({type:"SET_FEATURE",payload:{feature:b,tempFeature:b}}),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,p=$i($i({},r(t,Ji)),{},{properties:$i($i({},u),Ri({stroke:s,fill:c,strokeWidth:l}))});i.add(p,{userProperties:!0}),a.emit("draw:add",p)}},deleteFeature:(e,t)=>{var{mapProvider:r,services:n}=e,{draw:o}=r,{eventBus:i}=n;o&&(o.delete(t),i.emit("draw:delete",{featureIds:t}))},split:function(e,t){var{appState:r,appConfig:n,pluginState:o,mapProvider:i}=e,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:s}=o,{draw:c,map:l}=i;if(c){var p=c.get(t),d=["stroke-inactive.cold",...a.snapLayers||[]],h=u(l);null!=h&&h.setSnapLayers?h.setSnapLayers(d):a.snapLayers&&(l._pendingSnapLayers=d),s({type:"SET_HAS_SNAP_LAYERS",payload:!0}),c.changeMode("draw_line",{container:r.layoutRefs.viewportRef.current,vertexMarkerId:"".concat(n.id,"-cross-hair"),addVertexButtonId:"".concat(n.id,"-draw-add-point"),interfaceType:r.interfaceType,getSnapEnabled:()=>!0===i.snapEnabled,featureId:"_splitter",properties:{splitter:"invalid"}}),l.on("draw.create",e=>{var t=e.features[0],r=oo(p,t);c.setFeatureProperty("_splitter","splitter",r?"valid":"invalid"),s({type:"SET_ACTION",payload:{name:"split",isValid:!!r}})});var f,g,y,m,v=(f=e=>{if(!(e.coordinates.length<2)){var t={id:"_splitter",geometry:{type:"LineString",coordinates:e.coordinates}},r=!!oo(p,t);e.properties.splitter=r?"valid":"invalid",e.ctx.store.render(),"edit_vertex"===c.getMode()&&s({type:"SET_ACTION",payload:{name:"split",isValid:r}})}},g=50,m=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];clearTimeout(y),y=setTimeout(()=>f(...t),g)},m.cancel=()=>{clearTimeout(y),y=null},m);l.on("draw.geometrychange",v),s({type:"SET_MODE",payload:"draw_line"}),s({type:"SET_ACTION",payload:{name:"split"}})}},merge:(e,t)=>{var{services:r}=e;console.log("merge"),console.log(t)}}};export{Zi as manifest};
1
+ import{useEffect as e}from"preact/compat";const t=new Set(["draw_polygon","draw_line"]),n={SET_MODE:(e,n)=>({...e,mode:n,numVertecies:t.has(n)?0:e.numVertecies}),SET_ACTION:(e,t)=>({...e,action:t.name,actionValid:t.isValid}),SET_FEATURE:(e,t)=>({...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)=>({...e,selectedVertexIndex:t.index,numVertecies:t.numVertecies}),TOGGLE_SNAP:e=>({...e,snap:!e.snap}),SET_SNAP:(e,t)=>({...e,snap:!!t}),SET_HAS_SNAP_LAYERS:(e,t)=>({...e,hasSnapLayers:!!t}),SET_UNDO_STACK_LENGTH:(e,t)=>({...e,undoStackLength:t})},r={MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize"};function o(e){return e?._snapInstance??null}function i(e){return!!(e?.status&&e?.snapStatus&&e.snapCoords?.length>=2)}function s(e){return i(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function a(e,t,n){if(!e||!t||!e.status)return!1;const r=t.unproject(n);return e.snapToClosestPoint({point:n,lngLat:r}),!0}function c(e,t){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0)),t?.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function l(e){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0))}function u(e){return"function"==typeof e?.getSnapEnabled&&!0===e.getSnapEnabled()}const d={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"},p={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},h={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},f={POLYGON:"polygon",LINE:"line_string",POINT:"point"},g={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},y={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},m={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"},v={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},x={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},E={ACTIVE:"true",INACTIVE:"false"},S=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var w=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:E,classes:d,cursors:h,events:m,geojsonTypes:g,interactions:S,meta:x,modes:y,sources:p,types:f,updateActions:v});function _(e){return function(t){const n=t.featureTarget;return!!n&&(!!n.properties&&n.properties.meta===e)}}function M(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function b(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===E.ACTIVE&&e.featureTarget.properties.meta===x.FEATURE))}function P(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===E.INACTIVE&&e.featureTarget.properties.meta===x.FEATURE))}function I(e){return void 0===e.featureTarget}function C(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===x.FEATURE)}function T(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===x.VERTEX)}function L(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function O(e){return"Escape"===e.key||27===e.keyCode}function A(e){return"Enter"===e.key||13===e.keyCode}function k(e){return"Backspace"===e.key||8===e.keyCode}function F(e){return"Delete"===e.key||46===e.keyCode}function N(e){return"1"===e.key||49===e.keyCode}function V(e){return"2"===e.key||50===e.keyCode}function D(e){return"3"===e.key||51===e.keyCode}function R(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var U=Object.freeze({__proto__:null,isActiveFeature:b,isBackspaceKey:k,isDeleteKey:F,isDigit1Key:N,isDigit2Key:V,isDigit3Key:D,isDigitKey:R,isEnterKey:A,isEscapeKey:O,isFeature:C,isInactiveFeature:P,isOfMetaType:_,isShiftDown:L,isShiftMousedown:M,isTrue:function(){return!0},isVertex:T,noTarget:I});function B(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 n=function e(){var n=!1;try{n=this instanceof e}catch{}return n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var G,Y,X={},$={};function H(){return G||(G=1,$.RADIUS=6378137,$.FLATTENING=1/298.257223563,$.POLAR_RADIUS=6356752.3142),$}var J=function(){if(Y)return X;Y=1;var e=H();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(n(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(n(e[r]))}return t}function n(t){var n,o,i,s,a,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,s=u-1,a=0):c===u-1?(i=u-1,s=0,a=1):(i=c,s=c+1,a=c+2),n=t[i],o=t[s],l+=(r(t[a][0])-r(n[0]))*Math.sin(r(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function r(e){return e*Math.PI/180}return X.geometry=function e(n){var r,o=0;switch(n.type){case"Polygon":return t(n.coordinates);case"MultiPolygon":for(r=0;r<n.coordinates.length;r++)o+=t(n.coordinates[r]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(r=0;r<n.geometries.length;r++)o+=e(n.geometries[r]);return o}},X.ring=n,X}(),q=B(J);const K={Point:0,LineString:1,MultiLineString:1,Polygon:2};function W(e,t){const n=K[e.geometry.type]-K[t.geometry.type];return 0===n&&e.geometry.type===g.POLYGON?e.area-t.area:n}function z(e){return e.map(e=>(e.geometry.type===g.POLYGON&&(e.area=q.geometry({type:g.FEATURE,property:{},geometry:e.geometry})),e)).sort(W).map(e=>(delete e.area,e))}function Z(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Q(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,n=e.length;t<n;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}Q.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Q.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Q.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Q.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)},Q.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const ee=[x.FEATURE,x.MIDPOINT,x.VERTEX];var te={click:function(e,t,n){return ne(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return ne(e,t,n,n.options.touchBuffer)}};function ne(e,t,n,r){if(null===n.map)return[];const o=e?Z(e,r):t,i={};n.options.styles&&(i.layers=n.options.styles.map(e=>e.id).filter(e=>null!=n.map.getLayer(e)));const s=n.map.queryRenderedFeatures(o,i).filter(e=>-1!==ee.indexOf(e.properties.meta)),a=new Q,c=[];return s.forEach(e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),z(c)}function re(e,t){const n=te.click(e,null,t),r={mouse:h.NONE};return n[0]&&(r.mouse=n[0].properties.active===E.ACTIVE?h.MOVE:h.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=h.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function oe(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function ie(e,t,n={}){const r=null!=n.fineTolerance?n.fineTolerance:4,o=null!=n.grossTolerance?n.grossTolerance:12,i=null!=n.interval?n.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const s=oe(e.point,t.point);return s<r||s<o&&t.time-e.time<i}function se(e,t,n={}){const r=null!=n.tolerance?n.tolerance:25,o=null!=n.interval?n.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return oe(e.point,t.point)<r&&t.time-e.time<o}const ae=function(e,t){const n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on(e,t,r){if(void 0===n[e])throw new Error(`Invalid event type: ${e}`);n[e].push({selector:t,fn:r})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=n[e];let s=i.length;for(;s--;){const e=i[s];if(e.selector(o)){e.fn.call(r,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(r),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const ce=((e,t=21)=>(n=t)=>{let r="",o=0|n;for(;o--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function le(){return ce()}const ue=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||le(),this.type=t.geometry.type};ue.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ue.prototype.incomingCoords=function(e){this.setCoordinates(e)},ue.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ue.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ue.prototype.setProperty=function(e,t){this.properties[e]=t},ue.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:g.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ue.prototype.internal=function(e){const t={id:this.id,meta:x.FEATURE,"meta:type":this.type,active:E.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:g.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const de=function(e,t){ue.call(this,e,t)};(de.prototype=Object.create(ue.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},de.prototype.updateCoordinate=function(e,t,n){this.coordinates=3===arguments.length?[t,n]:[e,t],this.changed()},de.prototype.getCoordinate=function(){return this.getCoordinates()};const pe=function(e,t){ue.call(this,e,t)};(pe.prototype=Object.create(ue.prototype)).isValid=function(){return this.coordinates.length>1},pe.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},pe.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},pe.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},pe.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const he=function(e,t){ue.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(he.prototype=Object.create(ue.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},he.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},he.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},he.prototype.addCoordinate=function(e,t,n){this.changed();const r=e.split(".").map(e=>parseInt(e,10));this.coordinates[r[0]].splice(r[1],0,[t,n])},he.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},he.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},he.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},he.prototype.updateCoordinate=function(e,t,n){this.changed();const r=e.split("."),o=parseInt(r[0],10),i=parseInt(r[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,n]};const fe={MultiPoint:de,MultiLineString:pe,MultiPolygon:he},ge=(e,t,n,r,o)=>{const i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,r,o)},ye=function(e,t){if(ue.call(this,e,t),delete this.coordinates,this.model=fe[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function me(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(ye.prototype=Object.create(ue.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:le(),type:g.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},ye.prototype.isValid=function(){return this.features.every(e=>e.isValid())},ye.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},ye.prototype.getCoordinate=function(e){return ge(this.features,"getCoordinate",e)},ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===g.POLYGON?e.getCoordinates():e.coordinates)))},ye.prototype.updateCoordinate=function(e,t,n){ge(this.features,"updateCoordinate",e,t,n),this.changed()},ye.prototype.addCoordinate=function(e,t,n){ge(this.features,"addCoordinate",e,t,n),this.changed()},ye.prototype.removeCoordinate=function(e){ge(this.features,"removeCoordinate",e),this.changed()},ye.prototype.getFeatures=function(){return this.features},me.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},me.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),{})},me.prototype.getSelected=function(){return this._ctx.store.getSelected()},me.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},me.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},me.prototype.getFeature=function(e){return this._ctx.store.get(e)},me.prototype.select=function(e){return this._ctx.store.select(e)},me.prototype.deselect=function(e){return this._ctx.store.deselect(e)},me.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},me.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},me.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},me.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},me.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},me.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},me.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},me.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},me.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},me.prototype.featuresAt=function(e,t,n="click"){if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return te[n](e,t,this._ctx)},me.prototype.newFeature=function(e){const t=e.geometry.type;return t===g.POINT?new de(this._ctx,e):t===g.LINE_STRING?new pe(this._ctx,e):t===g.POLYGON?new he(this._ctx,e):new ye(this._ctx,e)},me.prototype.isInstanceOf=function(e,t){if(e===g.POINT)return t instanceof de;if(e===g.LINE_STRING)return t instanceof pe;if(e===g.POLYGON)return t instanceof he;if("MultiFeature"===e)return t instanceof ye;throw new Error(`Unknown feature class: ${e}`)},me.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},me.prototype.onSetup=function(){},me.prototype.onDrag=function(){},me.prototype.onClick=function(){},me.prototype.onMouseMove=function(){},me.prototype.onMouseDown=function(){},me.prototype.onMouseUp=function(){},me.prototype.onMouseOut=function(){},me.prototype.onKeyUp=function(){},me.prototype.onKeyDown=function(){},me.prototype.onTouchStart=function(){},me.prototype.onTouchMove=function(){},me.prototype.onTouchEnd=function(){},me.prototype.onTap=function(){},me.prototype.onStop=function(){},me.prototype.onTrash=function(){},me.prototype.onCombineFeature=function(){},me.prototype.onUncombineFeature=function(){},me.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const ve={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},xe=Object.keys(ve);function Ee(e){const t=Object.keys(e);return function(n,r={}){let o={};const i=t.reduce((t,n)=>(t[n]=e[n],t),new me(n));return{start(){o=i.onSetup(r),xe.forEach(t=>{const n=ve[t];let r=()=>!1;var s;e[n]&&(r=()=>!0),this.on(t,r,(s=n,e=>i[s](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function Se(e){return[].concat(e).filter(e=>void 0!==e)}function we(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(p.HOT)))return a();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let n=[],r=[];e.isDirty?r=e.getAllIds():(n=e.getChangedIds().filter(t=>void 0!==e.get(t)),r=e.sources.hot.filter(t=>t.properties.id&&-1===n.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===n.indexOf(t)});const i=o!==e.sources.cold.length||r.length>0;function s(n,r){const o=e.get(n).internal(t);e.ctx.events.currentModeRender(o,n=>{n.properties.mode=t,e.sources[r].push(n)})}function a(){e.isDirty=!1,e.clearChangedIds()}n.forEach(e=>s(e,"hot")),r.forEach(e=>s(e,"cold")),i&&e.ctx.map.getSource(p.COLD).setData({type:g.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(p.HOT).setData({type:g.FEATURE_COLLECTION,features:e.sources.hot}),a()}function _e(e){let t;this._features={},this._featureIds=new Q,this._selectedFeatureIds=new Q,this._selectedCoordinates=[],this._changedFeatureIds=new Q,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,we.call(this),this._emitSelectionChange&&(this.ctx.events.fire(m.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:g.FEATURE,properties:{},geometry:{type:g.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(m.RENDER,{})}))},this.isDirty=!1}function Me(e,t={}){const n=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===n.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=n}_e.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},_e.prototype.setDirty=function(){return this.isDirty=!0,this},_e.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(m.CREATE,{features:[t.toGeoJSON()]})}return this},_e.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(m.UPDATE,{action:t.action?t.action:v.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},_e.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},_e.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},_e.prototype.getAllIds=function(){return this._featureIds.values()},_e.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},_e.prototype.delete=function(e,t={}){const n=[];return Se(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===n.indexOf(this._features[e])&&n.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),n.length&&this.ctx.events.fire(m.DELETE,{features:n}),Me(this,t),this},_e.prototype.get=function(e){return this._features[e]},_e.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},_e.prototype.select=function(e,t={}){return Se(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},_e.prototype.deselect=function(e,t={}){return Se(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Me(this,t),this},_e.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},_e.prototype.setSelected=function(e,t={}){return e=Se(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},_e.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},_e.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},_e.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},_e.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},_e.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},_e.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},_e.prototype.setFeatureProperty=function(e,t,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:v.CHANGE_PROPERTIES})},_e.prototype.storeMapConfig=function(){S.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},_e.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},_e.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const be=["mode","feature","mouse"];function Pe(e){let t=null,n=null;const r={onRemove(){return e.map.off("load",r.connect),clearInterval(n),r.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",r.connect),clearInterval(n),r.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,n)=>(t[n]=Ee(e.options.modes[n]),t),{});let n={},r={};const o={};let i=null,s=null;o.drag=function(t,n){n({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:h.DRAG}),s.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!ie(n,e))},o.touchdrag=function(e){o.drag(e,e=>!se(r,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const n=re(t,e);t.featureTarget=n,s.mousemove(t)},o.mousedown=function(t){n={time:(new Date).getTime(),point:t.point};const r=re(t,e);t.featureTarget=r,s.mousedown(t)},o.mouseup=function(t){const r=re(t,e);t.featureTarget=r,ie(n,{point:t.point,time:(new Date).getTime()})?s.click(t):s.mouseup(t)},o.mouseout=function(e){s.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;r={time:(new Date).getTime(),point:t.point};const n=te.touch(t,null,e)[0];t.featureTarget=n,s.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return s.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const n=te.touch(t,null,e)[0];t.featureTarget=n,se(r,{time:(new Date).getTime(),point:t.point})?s.tap(t):s.touchend(t)};const a=e=>{const t=k(e),n=F(e),r=R(e);return!(t||n||r)};function c(n,r,o={}){s.stop();const a=t[n];if(void 0===a)throw new Error(`${n} is not valid`);i=n;const c=a(e,r);s=ae(c,e),o.silent||e.map.fire(m.MODE_CHANGE,{mode:n}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(d.CANVAS)&&((k(t)||F(t))&&e.options.controls.trash?(t.preventDefault(),s.trash()):a(t)?s.keydown(t):N(t)&&e.options.controls.point?c(y.DRAW_POINT):V(t)&&e.options.controls.line_string?c(y.DRAW_LINE_STRING):D(t)&&e.options.controls.polygon&&c(y.DRAW_POLYGON))},o.keyup=function(e){a(e)&&s.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:n,options:r,store:o}=e;r.styles.some(e=>n.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1},u={start(){i=e.options.defaultMode,s=ae(t[i](e),e)},changeMode:c,actionable:function(t){let n=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(n=!0),l[e]=t[e]}),n&&e.map.fire(m.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>s.render(e,t),fire(t,n){e.map&&e.map.fire(t,n)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){s.trash(e)},combineFeatures(){s.combineFeatures()},uncombineFeatures(){s.uncombineFeatures()},getMode:()=>i};return u}(e),e.ui=function(e){const t={};let n=null,r={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function s(){if(!e.container)return;const t=[],n=[];be.forEach(e=>{o[e]!==r[e]&&(t.push(`${e}-${r[e]}`),null!==o[e]&&n.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),n.length>0&&e.container.classList.add(...n),r=Object.assign(r,o)}function a(e,t={}){const r=document.createElement("button");return r.className=`${d.CONTROL_BUTTON} ${t.className}`,r.setAttribute("title",t.title),t.container.appendChild(r),r.addEventListener("click",r=>{if(r.preventDefault(),r.stopPropagation(),r.target===n)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),r}function c(){n&&(n.classList.remove(d.ACTIVE_BUTTON),n=null)}function l(e){c();const r=t[e];r&&r&&"trash"!==e&&(r.classList.add(d.ACTIVE_BUTTON),n=r)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:s,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),s()},addButtons:function(){const n=e.options.controls,r=document.createElement("div");return r.className=`${d.CONTROL_GROUP} ${d.CONTROL_BASE}`,n?(n[f.POINT]&&(t[f.POINT]=a(f.POINT,{container:r,className:d.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(y.DRAW_POINT),onDeactivate:()=>e.events.trash()})),n[f.LINE]&&(t[f.LINE]=a(f.LINE,{container:r,className:d.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(y.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),n[f.POLYGON]&&(t[f.POLYGON]=a(f.POLYGON,{container:r,className:d.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(y.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),n.trash&&(t.trash=a("trash",{container:r,className:d.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),n.combine_features&&(t.combine_features=a("combineFeatures",{container:r,className:d.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),n.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:r,className:d.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),r):r},removeButtons:function(){Object.keys(t).forEach(e=>{const n=t[e];n.parentNode&&n.parentNode.removeChild(n),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new _e(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?r.connect():(o.on("load",r.connect),n=setInterval(()=>{o.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(p.COLD,{data:{type:g.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(p.HOT,{data:{type:g.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(p.COLD)&&e.map.removeSource(p.COLD),e.map.getSource(p.HOT)&&e.map.removeSource(p.HOT)}};return e.setup=r,r}const Ie="#3bb2d0",Ce="#fbb03b",Te="#fff";var Le=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Ce,Ie],"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"],Ce,Ie],"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":Te}},{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"],Ce,Ie]}},{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":Te}},{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":Ce}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Ce}}];function Oe(e,t){this.x=e,this.y=t}function Ae(e,t){const n=t.getBoundingClientRect();return new Oe(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function ke(e,t,n,r){return{type:g.FEATURE,properties:{meta:x.VERTEX,parent:e,coord_path:n,active:r?E.ACTIVE:E.INACTIVE},geometry:{type:g.POINT,coordinates:t}}}Oe.prototype={clone(){return new Oe(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,n=e.y-this.y;return t*t+n*n},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),n=Math.sin(e),r=t*this.x-n*this.y,o=n*this.x+t*this.y;return this.x=r,this.y=o,this},_rotateAround(e,t){const n=Math.cos(e),r=Math.sin(e),o=t.x+n*(this.x-t.x)-r*(this.y-t.y),i=t.y+r*(this.x-t.x)+n*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Oe},Oe.convert=function(e){if(e instanceof Oe)return e;if(Array.isArray(e))return new Oe(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Oe(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var Fe=6371008.8,Ne={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*Fe,kilometers:6371.0088,kilometres:6371.0088,meters:Fe,metres:Fe,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:Fe/1852,radians:1,yards:6967335.223679999};function Ve(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function De(e,t,n={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!He(e[0])||!He(e[1]))throw new Error("coordinates must contain numbers");return Ve({type:"Point",coordinates:e},t,n)}function Re(e,t,n={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return Ve({type:"Polygon",coordinates:e},t,n)}function Ue(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return Ve({type:"LineString",coordinates:e},t,n)}function Be(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function je(e,t,n={}){return Ve({type:"MultiLineString",coordinates:e},t,n)}function Ge(e,t="kilometers"){const n=Ne[t];if(!n)throw new Error(t+" units is invalid");return e*n}function Ye(e,t="kilometers"){const n=Ne[t];if(!n)throw new Error(t+" units is invalid");return e/n}function Xe(e){return 180*(e%(2*Math.PI))/Math.PI}function $e(e){return e%360*Math.PI/180}function He(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function Je(e,t,n){if(null!==e)for(var r,o,i,s,a,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++){a=(u=!!(l=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===l.type)?l.geometries.length:1;for(var v=0;v<a;v++){var x=0,E=0;if(null!==(s=u?l.geometries[v]:l)){c=s.coordinates;var S=s.type;switch(d=0,S){case null:break;case"Point":if(!1===t(c,p,m,x,E))return!1;p++,x++;break;case"LineString":case"MultiPoint":for(r=0;r<c.length;r++){if(!1===t(c[r],p,m,x,E))return!1;p++,"MultiPoint"===S&&x++}"LineString"===S&&x++;break;case"Polygon":case"MultiLineString":for(r=0;r<c.length;r++){for(o=0;o<c[r].length-d;o++){if(!1===t(c[r][o],p,m,x,E))return!1;p++}"MultiLineString"===S&&x++,"Polygon"===S&&E++}"Polygon"===S&&x++;break;case"MultiPolygon":for(r=0;r<c.length;r++){for(E=0,o=0;o<c[r].length;o++){for(i=0;i<c[r][o].length-d;i++){if(!1===t(c[r][o][i],p,m,x,E))return!1;p++}E++}x++}break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(!1===Je(s.geometries[r],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function qe(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function Ke(e,t){var n,r,o,i,s,a,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(n=0;n<g;n++){for(a=h?e.features[n].geometry:f?e.geometry:e,l=h?e.features[n].properties:f?e.properties:{},u=h?e.features[n].bbox:f?e.bbox:void 0,d=h?e.features[n].id:f?e.id:void 0,s=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,o=0;o<s;o++)if(null!==(i=c?a.geometries[o]:a))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(r=0;r<i.geometries.length;r++)if(!1===t(i.geometries[r],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function We(e,t){Ke(e,function(e,n,r,o,i){var s,a=null===e?null:e.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==t(Ve(e,r,{bbox:o,id:i}),n,0)&&void 0}switch(a){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<e.coordinates.length;c++){var l=e.coordinates[c];if(!1===t(Ve({type:s,coordinates:l},r),n,c))return!1}})}function ze(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return Ze(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(e=>Ze(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return et(e);default:throw new Error("unknown GeoJSON type")}}function Ze(e){const t={type:"Feature"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=Qe(e.properties),null==e.geometry?t.geometry=null:t.geometry=et(e.geometry),t}function Qe(e){const t={};return e?(Object.keys(e).forEach(n=>{const r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(e=>e):t[n]=Qe(r):t[n]=r}),t):t}function et(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>et(e)),t):(t.coordinates=tt(e.coordinates),t)}function tt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>tt(e))}function nt(e,t={}){return rt(e,"mercator",t)}function rt(e,t,n={}){var r=(n=n||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&He(e[0])?e="mercator"===t?ot(e):it(e):(!0!==r&&(e=ze(e)),Je(e,function(e){var n="mercator"===t?ot(e):it(e);e[0]=n[0],e[1]=n[1]})),e}function ot(e){var t,n=Math.PI/180,r=6378137,o=20037508.342789244,i=[r*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*n,r*Math.log(Math.tan(.25*Math.PI+.5*e[1]*n))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function it(e){var t=180/Math.PI,n=6378137;return[e[0]*t/n,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/n)))*t]}function st(e,t,n){const r=t.geometry.coordinates,o=n.geometry.coordinates;if(r[1]>85||r[1]<-85||o[1]>85||o[1]<-85)return null;const i=nt(r),s=nt(o),a=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return rt(e,"wgs84",t)}([c(i[0],s[0]),c(i[1],s[1])]),u=[a(l[0]),a(l[1])];return{type:g.FEATURE,properties:{meta:x.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:n.properties.coord_path},geometry:{type:g.POINT,coordinates:u}}}function at(e,t={},n=null){const{type:r,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let s=[];function a(e,n){let r="",o=null;e.forEach((e,a)=>{const l=null!=n?`${n}.${a}`:String(a),u=ke(i,e,l,c(l));if(t.midpoints&&o){const e=st(i,o,u);e&&s.push(e)}o=u;const d=JSON.stringify(e);r!==d&&s.push(u),0===a&&(r=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return r===g.POINT?s.push(ke(i,o,n,c(n))):r===g.POLYGON?o.forEach((e,t)=>{a(e,null!==n?`${n}.${t}`:String(t))}):r===g.LINE_STRING?a(o,n):0===r.indexOf(g.MULTI_PREFIX)&&function(){const n=r.replace(g.MULTI_PREFIX,"");o.forEach((r,o)=>{const i={type:g.FEATURE,properties:e.properties,geometry:{type:n,coordinates:r}};s=s.concat(at(i,t,o))})}(),s}var ct={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:lt,LAT_MAX:ut,LAT_RENDERED_MIN:dt,LAT_RENDERED_MAX:pt,LNG_MIN:ht,LNG_MAX:ft}=w;function gt(e,t){let n=lt,r=ut,o=lt,i=ut,s=ft,a=ht;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],n=[e.geometry.coordinates].flat(t),r=n.map(e=>e[0]),o=n.map(e=>e[1]),i=e=>Math.min.apply(null,e),s=e=>Math.max.apply(null,e);return[i(r),i(o),s(r),s(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>n&&(n=c),l<r&&(r=l),l>o&&(o=l),c<i&&(i=c),u<s&&(s=u),d>a&&(a=d)});const c=t;return n+c.lat>pt&&(c.lat=pt-n),o+c.lat>ut&&(c.lat=ut-o),r+c.lat<dt&&(c.lat=dt-r),i+c.lat<lt&&(c.lat=lt-i),s+c.lng<=ht&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=ft&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function yt(e,t){const n=gt(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),r=e=>{const t={lng:e[0]+n.lng,lat:e[1]+n.lat};return[t.lng,t.lat]},o=e=>e.map(e=>r(e)),i=e=>e.map(e=>o(e));let s;e.type===g.POINT?s=r(t):e.type===g.LINE_STRING||e.type===g.MULTI_POINT?s=t.map(r):e.type===g.POLYGON||e.type===g.MULTI_LINE_STRING?s=t.map(o):e.type===g.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)})}const mt={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(m.UPDATE,{action:v.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let n=!1;if(e.length>1){n=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(n=!1)})}const r=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:n,uncombineFeatures:r,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new Q).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(){ct.enable(this)},onMouseMove:function(e,t){return C(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};mt.onTap=mt.onClick=function(e,t){return I(t)?this.clickAnywhere(e,t):_(x.VERTEX)(t)?this.clickOnVertex(e,t):C(t)?this.clickOnFeature(e,t):void 0},mt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),ct.enable(this),this.stopExtendedInteractions(e)},mt.clickOnVertex=function(e,t){this.changeMode(y.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:h.MOVE})},mt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},mt.clickOnFeature=function(e,t){ct.disable(this),this.stopExtendedInteractions(e);const n=L(t),r=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!n&&i&&this.getFeature(o).type!==g.POINT)return this.changeMode(y.DIRECT_SELECT,{featureId:o});i&&n?(this.deselect(o),this.updateUIClasses({mouse:h.POINTER}),1===r.length&&ct.enable(this)):!i&&n?(this.select(o),this.updateUIClasses({mouse:h.MOVE})):i||n||(r.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:h.MOVE})),this.doRender(o)},mt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),b(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&M(t)?this.startBoxSelect(e,t):void 0},mt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=Ae(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},mt.onTouchStart=function(e,t){if(b(t))return this.startOnActiveFeature(e,t)},mt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},mt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:h.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(d.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=Ae(t.originalEvent,this.map.getContainer()),r=Math.min(e.boxSelectStartLocation.x,n.x),o=Math.max(e.boxSelectStartLocation.x,n.x),i=Math.min(e.boxSelectStartLocation.y,n.y),s=Math.max(e.boxSelectStartLocation.y,n.y),a=`translate(${r}px, ${i}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=o-r+"px",e.boxSelectElement.style.height=s-i+"px"},mt.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};yt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},mt.onTouchEnd=mt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,Ae(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),o=this.getUniqueIds(r).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:h.MOVE}))}this.stopExtendedInteractions(e)},mt.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?E.ACTIVE:E.INACTIVE,n(t),this.fireActionable(),t.properties.active===E.ACTIVE&&t.geometry.type!==g.POINT&&at(t).forEach(n)},mt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},mt.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],n=[],r=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==r)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),n.push(i.toGeoJSON())}if(n.length>1){const e=this.newFeature({type:g.FEATURE,properties:n[0].properties,geometry:{type:`Multi${r}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(m.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},mt.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],n=[];for(let r=0;r<e.length;r++){const o=e[r];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),n.push(o.toGeoJSON()))}t.length>1&&this.fire(m.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const vt=_(x.VERTEX),xt=_(x.MIDPOINT),Et={fireUpdate:function(){this.fire(m.UPDATE,{action:v.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties,r=e.selectedCoordPaths.indexOf(n.coord_path);L(t)||-1!==r?L(t)&&-1===r&&e.selectedCoordPaths.push(n.coord_path):e.selectedCoordPaths=[n.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,n){yt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,n){const r=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=gt(r.map(e=>({type:g.FEATURE,properties:{},geometry:{type:g.POINT,coordinates:e}})),n);for(let t=0;t<r.length;t++){const n=r[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],n[0]+o.lng,n[1]+o.lat)}},clickNoTarget:function(){this.changeMode(y.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(y.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===g.POINT)throw new TypeError("direct_select mode doesn't handle point features");const r={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,r.selectedCoordPaths)),this.setSelected(t),ct.disable(this),this.setActionableState({trash:!0}),r},onStop:function(){ct.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=E.ACTIVE,n(t),at(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=E.INACTIVE,n(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(y.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=b(t),r=vt(t),o=xt(t),i=0===e.selectedCoordPaths.length;n&&i||r&&!i?this.updateUIClasses({mouse:h.MOVE}):this.updateUIClasses({mouse:h.NONE});return(r||n||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Et.onTouchStart=Et.onMouseDown=function(e,t){return vt(t)?this.onVertex(e,t):b(t)?this.onFeature(e,t):xt(t)?this.onMidpoint(e,t):void 0},Et.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat},Et.onClick=function(e,t){return I(t)?this.clickNoTarget(e,t):b(t)?this.clickActiveFeature(e,t):P(t)?this.clickInactive(e,t):void this.stopDragging(e)},Et.onTap=function(e,t){return I(t)?this.clickNoTarget(e,t):b(t)?this.clickActiveFeature(e,t):P(t)?this.clickInactive(e,t):void 0},Et.onTouchEnd=Et.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const St={};function wt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}St.onSetup=function(){const e=this.newFeature({type:g.FEATURE,properties:{},geometry:{type:g.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:h.ADD}),this.activateUIButton(f.POINT),this.setActionableState({trash:!0}),{point:e}},St.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT)},St.onTap=St.onClick=function(e,t){this.updateUIClasses({mouse:h.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(m.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(y.SIMPLE_SELECT,{featureIds:[e.point.id]})},St.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},St.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?E.ACTIVE:E.INACTIVE,!r)return n(t)},St.onTrash=St.stopDrawingAndRemove,St.onKeyUp=function(e,t){if(O(t)||A(t))return this.stopDrawingAndRemove(e,t)};const _t={onSetup:function(){const e=this.newFeature({type:g.FEATURE,properties:{},geometry:{type:g.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),ct.disable(this),this.updateUIClasses({mouse:h.ADD}),this.activateUIButton(f.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&wt(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(y.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:h.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(y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),T(t)&&this.updateUIClasses({mouse:h.POINTER})}};_t.onTap=_t.onClick=function(e,t){return T(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},_t.onKeyUp=function(e,t){O(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT)):A(t)&&this.changeMode(y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},_t.onStop=function(e){this.updateUIClasses({mouse:h.NONE}),ct.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(m.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT,{},{silent:!0})))},_t.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?E.ACTIVE:E.INACTIVE,!r)return n(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=x.FEATURE,n(ke(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const r=t.geometry.coordinates[0].length-3;n(ke(e.polygon.id,t.geometry.coordinates[0][r],`0.${r}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(n({type:g.FEATURE,properties:t.properties,geometry:{coordinates:e,type:g.LINE_STRING}}),3===o)return}return n(t)}},_t.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT)};const Mt={onSetup:function(e){const t=(e=e||{}).featureId;let n,r,o="forward";if(t){if(n=this.getFeature(t),!n)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const s=n.coordinates.length-1;if(n.coordinates[s][0]===i[0]&&n.coordinates[s][1]===i[1])r=s+1,n.addCoordinate(r,...n.coordinates[s]);else{if(n.coordinates[0][0]!==i[0]||n.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",r=0,n.addCoordinate(r,...n.coordinates[0])}}else n=this.newFeature({type:g.FEATURE,properties:{},geometry:{type:g.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),ct.disable(this),this.updateUIClasses({mouse:h.ADD}),this.activateUIButton(f.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&wt(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&wt(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(y.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:h.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(y.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),T(t)&&this.updateUIClasses({mouse:h.POINTER})}};Mt.onTap=Mt.onClick=function(e,t){if(T(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Mt.onKeyUp=function(e,t){A(t)?this.changeMode(y.SIMPLE_SELECT,{featureIds:[e.line.id]}):O(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT))},Mt.onStop=function(e){ct.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(m.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT,{},{silent:!0})))},Mt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(y.SIMPLE_SELECT)},Mt.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?E.ACTIVE:E.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=x.FEATURE,n(ke(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),n(t))};var bt={simple_select:mt,direct_select:Et,draw_point:St,draw_polygon:_t,draw_line_string:Mt};const Pt={defaultMode:y.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:Le,modes:bt,controls:{},userProperties:!1,suppressAPIEvents:!0},It={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ct={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Tt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?p.HOT:p.COLD}))}var Lt,Ot;var At,kt,Ft=(Ot||(Ot=1,Lt=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,o,i;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(o=r;0!==o--;)if(!e(t[o],n[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(o=r;0!==o--;)if(!Object.prototype.hasOwnProperty.call(n,i[o]))return!1;for(o=r;0!==o--;){var s=i[o];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n}),Lt),Nt=B(Ft);var Vt=function(){if(kt)return At;kt=1,At=function(t){if(!t||!t.type)return null;var n=e[t.type];if(!n)return null;if("geometry"===n)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===n)return{type:"FeatureCollection",features:[t]};if("featurecollection"===n)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return At}(),Dt=B(Vt);function Rt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Ut={Polygon:he,LineString:pe,Point:de,MultiPolygon:ye,MultiLineString:ye,MultiPoint:ye};var Bt=Object.freeze({__proto__:null,CommonSelectors:U,ModeHandler:ae,StringSet:Q,constrainFeatureMovement:gt,createMidPoint:st,createSupplementaryPoints:at,createVertex:ke,doubleClickZoom:ct,euclideanDistance:oe,featuresAt:te,getFeatureAtAndSetCursors:re,isClick:ie,isEventAtCoordinates:wt,isTap:se,mapEventToBoundingBox:Z,moveFeatures:yt,sortFeatures:z,stringSetsAreEqual:Rt,theme:Le,toDenseArray:Se});const jt=function(e,t){const n={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Ct,e.controls):t.controls=Object.assign({},It,e.controls),t=Object.assign({},Pt,t),t.styles=Tt(t.styles,"cold").concat(Tt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=y;const n=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return te.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:g.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:g.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:g.FEATURE,properties:{},geometry:{type:g.POINT,coordinates:e.coordinates}}))}},t.set=function(n){if(void 0===n.type||n.type!==g.FEATURE_COLLECTION||!Array.isArray(n.features))throw new Error("Invalid FeatureCollection");const r=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(n),s=new Q(i);return o=o.filter(e=>!s.has(e)),o.length&&t.delete(o),r(),i},t.add=function(t){const r=JSON.parse(JSON.stringify(Dt(t))).features.map(t=>{if(t.id=t.id||le(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const r=Ut[t.geometry.type];if(void 0===r)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new r(e,t);e.store.add(o,{silent:n})}else{const r=e.store.get(t.id),o=r.properties;r.properties=t.properties,Nt(o,t.properties)||e.store.featureChanged(r.id,{silent:n}),Nt(r.getCoordinates(),t.geometry.coordinates)||r.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),r},t.get=function(t){const n=e.store.get(t);if(n)return n.toGeoJSON()},t.getAll=function(){return{type:g.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()!==y.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(y.SIMPLE_SELECT,void 0,{silent:n}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===y.DIRECT_SELECT?e.events.changeMode(y.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,o={}){return r===y.SIMPLE_SELECT&&t.getMode()===y.SIMPLE_SELECT?(Rt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:n}),e.store.render()),t):(r===y.DIRECT_SELECT&&t.getMode()===y.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,o,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,o,i){return e.store.setFeatureProperty(r,o,i,{silent:n}),t},t}(n,t),n.api=t;const r=Pe(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=f,t.options=e,t};function Gt(e){jt(e,this)}Gt.modes=bt,Gt.constants=w,Gt.lib=Bt;const Yt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,n){t.properties.active="false",n(t)}},Xt=e=>{if(!e?.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},$t=e=>{if(!e?.coordinates)return[];const t=[];let n=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!0}),n+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!1}),n+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,r)=>{e.forEach((e,o)=>{t.push({start:n,length:e.length,path:[r,o],closed:!0}),n+=e.length})})}return t},Ht=(e,t)=>{for(const n of e)if(t>=n.start&&t<n.start+n.length)return{segment:n,localIdx:t-n.start};return null},Jt=(e,t)=>{let n=e.geometry.coordinates;for(const e of t)n=n[e];return n},qt=(e,t)=>{const n=t.split(".").map(Number),r=$t(e);for(const e of r){if(e.path.every((e,t)=>e===n[t])&&n.length===e.path.length+1){const t=n[n.length-1];return e.start+t}}return n[n.length-1]},Kt=(e,t)=>({x:e.x*t,y:e.y*t}),Wt=e=>e instanceof window.SVGElement||e.ownerSVGElement,zt={fireGeometryChange(e){const t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},pushUndo(e){const t=this.map._undoStack;t&&t.push(e)},handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_vertex"===n.type?this.undoMoveVertex(e,n):"insert_vertex"===n.type?this.undoInsertVertex(e,n):"delete_vertex"===n.type&&this.undoDeleteVertex(e,n)},undoMoveVertex(e,t){const{vertexIndex:n,previousPosition:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=$t(i),c=Ht(a,n);if(!c)return;Jt(s,c.segment.path)[c.localIdx]=r,this._applyUndoAndSync(e,s,o);const l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Kt(this.map.project(l),e.scale))},undoInsertVertex(e,t){const{vertexIndex:n,featureId:r}=t,o=this.getFeature(r);if(!o)return;const i=o.toGeoJSON(),s=$t(o),a=Ht(s,n);if(!a)return;Jt(i,a.segment.path).splice(a.localIdx,1),this._applyUndoAndSync(e,i,r),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})},undoDeleteVertex(e,t){const{vertexIndex:n,position:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=$t(i);let c=Ht(a,n);if(!c)for(const e of a)if(n===e.start+e.length){c={segment:e,localIdx:e.length};break}if(!c)return;Jt(s,c.segment.path).splice(c.localIdx,0,r),this._applyUndoAndSync(e,s,o);const l=e.vertecies[n];l&&this.updateTouchVertexTarget(e,Kt(this.map.project(l),e.scale)),this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,n)})},_applyUndoAndSync(e,t,n){this._ctx.api.add(t),e.vertecies=this.getVerticies(n),e.midpoints=this.getMidpoints(n),this._ctx.store.render(),this.fireGeometryChange(e)}},Zt=(e,t)=>{if(!e)return;const n="dark"===t?.mapColorScheme;e.style.setProperty("--touch-fill",n?"#ffffff":"#000000"),e.style.setProperty("--touch-gfx",n?"#000000":"#ffffff")},Qt={addTouchVertexTarget(e){let t=e.container.querySelector("[data-touch-vertex-target]");t||(e.container.insertAdjacentHTML("beforeend","\n <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd' style='display:none;position:absolute;top:50%;left:50%;margin:24px 0 0 -24px' class='touch-vertex-target' data-touch-vertex-target>\n <circle cx='24' cy='24' r='24' fill='var(--touch-fill, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--touch-gfx, #fff)'/>\n </svg>\n"),t=e.container.querySelector("[data-touch-vertex-target]")),e.touchVertexTarget=t,Zt(t,this.map._drawCurrentMapStyle)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:`${t.y}px`,left:`${t.x}px`}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||Wt(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){l(o(this.map)),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){const n=o(this.map);n&&c(n,this.map);const r=t.featureTarget?.properties.meta,i=t.featureTarget?.properties.coord_path;if("vertex"===r){const t=this.getFeature(e.featureId),n=qt(t,i);this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:i})}else"midpoint"===r?this.insertVertex({...e,selectedVertexIndex:this.getVertexIndexFromMidpoint(e,i),selectedVertexType:"midpoint"}):this.clickNoTarget(e)},onTouchstart(e,t){l(o(this.map));const n=e.vertecies?.[e.selectedVertexIndex];if(!n||!Wt(t.target.parentNode))return;e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;const r=t.touches[0].clientX,i=t.touches[0].clientY,s=window.getComputedStyle(e.touchVertexTarget);e.deltaTarget={x:r-Number.parseFloat(s.left),y:i-Number.parseFloat(s.top)};const a=this.map.project(n);e.deltaVertex={x:r/e.scale-a.x,y:i/e.scale-a.y}},onTouchmove(e,t){if(e.selectedVertexIndex<0||!Wt(t.target.parentNode))return;e._touchMoved=!0;const n=t.touches[0].clientX,r=t.touches[0].clientY,i={x:n/e.scale-e.deltaVertex.x,y:r/e.scale-e.deltaVertex.y};let c=this.map.unproject(i);if(u(e)){const e=o(this.map);a(e,this.map,i),c=s(e)||c}this.moveVertex(e,c),this.updateTouchVertexTarget(e,{x:n-e.deltaTarget.x,y:r-e.deltaTarget.y})}},en={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},tn={updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(e,t){const[n,r]=this.getVertexOrMidpoint(e,t);n<0||!r||this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:r,..."vertex"===r&&{coordPath:this.getCoordPath(e,n)}})},getOffset(e,t){const n=this.map.project(e),r=t?.shiftKey?1:5,[o,i]=t?en[t.key].map(e=>e*r):[0,0];return this.map.unproject({x:n.x+o,y:n.y+i})},getNewCoord(e,t){return this.getOffset(Xt(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},insertVertex(e,t){const n=e.selectedVertexIndex-e.vertecies.length,r=this.getOffset(e.midpoints[n],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),s=$t(o);let a=n+1,c=null,l=0,u=0;for(const e of s){const t=e.closed?e.length:e.length-1;if(n<u+t){c=e,l=n-u+1,a=e.start+l;break}u+=t}if(!c)return;Jt(i,c.path).splice(l,0,[r.lng,r.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:a}),this.changeMode(e,{selectedVertexIndex:a,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,a)})},moveVertex(e,t,n={}){if(n.checkSnap&&!1!==e.enableSnap){const e=this.map._snapInstance;e?.snapStatus&&e.snapCoords?.length>=2&&(t={lng:e.snapCoords[0],lat:e.snapCoords[1]})}const r=this.getFeature(e.featureId),o=r.toGeoJSON(),i=$t(r),s=Ht(i,e.selectedVertexIndex);if(!s)return;Jt(o,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(o),e.vertecies=this.getVerticies(e.featureId),this.map.fire("draw.geometrychange",e.feature)},deleteVertex(e){const t=this.getFeature(e.featureId);if(!t)return;const n=$t(t),r=Ht(n,e.selectedVertexIndex);if(!r)return;const{segment:o}=r,i=o.closed?3:2;if(o.length<=i)return;const s=[...e.vertecies[e.selectedVertexIndex]],a=e.selectedVertexIndex,c=[...r.segment.path,r.localIdx].join(".");t.removeCoordinate(c),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:a,position:s}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}};function nn(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return rn(e);case"FeatureCollection":return function(e){var t={type:"FeatureCollection"};return Object.keys(e).forEach(function(n){switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(function(e){return rn(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return sn(e);default:throw new Error("unknown GeoJSON type")}}function rn(e){var t={type:"Feature"};return Object.keys(e).forEach(function(n){switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=on(e.properties),t.geometry=sn(e.geometry),t}function on(e){var t={};return e?(Object.keys(e).forEach(function(n){var r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(function(e){return e}):t[n]=on(r):t[n]=r}),t):t}function sn(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return sn(e)}),t):(t.coordinates=an(e.coordinates),t)}function an(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return an(e)})}function cn(e){for(var t,n,r=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<r.length;)t=n||r[0],o+=((n=r[i])[0]-t[0])*(n[1]+t[1]),i++;return o>0}function ln(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 un(e,t){if(null===(n=t=t||{})||"object"!=typeof n||Array.isArray(n))throw new Error("options is invalid");var n,r=t.reverse||!1,o=t.mutate||!1;if(!e)throw new Error("<geojson> is required");if("boolean"!=typeof r)throw new Error("<reverse> must be a boolean");if("boolean"!=typeof o)throw new Error("<mutate> must be a boolean");!1===o&&(e=nn(e));var i=[];switch(e.type){case"GeometryCollection":return Ke(e,function(e){dn(e,r)}),e;case"FeatureCollection":return qe(e,function(e){qe(dn(e,r),function(e){i.push(e)})}),Be(i)}return dn(e,r)}function dn(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return Ke(e,function(e){dn(e,t)}),e;case"LineString":return pn(ln(e),t),e;case"Polygon":return hn(ln(e),t),e;case"MultiLineString":return ln(e).forEach(function(e){pn(e,t)}),e;case"MultiPolygon":return ln(e).forEach(function(e){hn(e,t)}),e;case"Point":case"MultiPoint":return e}}function pn(e,t){cn(e)===t&&e.reverse()}function hn(e,t){cn(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)cn(e[n])===t&&e[n].reverse()}const fn=11102230246251565e-32,gn=134217729,yn=(3+8*fn)*fn;function mn(e,t,n,r,o){let i,s,a,c,l=t[0],u=r[0],d=0,p=0;u>l==u>-l?(i=l,l=t[++d]):(i=u,u=r[++p]);let h=0;if(d<e&&p<n)for(u>l==u>-l?(s=l+i,a=i-(s-l),l=t[++d]):(s=u+i,a=i-(s-u),u=r[++p]),i=s,0!==a&&(o[h++]=a);d<e&&p<n;)u>l==u>-l?(s=i+l,c=s-i,a=i-(s-c)+(l-c),l=t[++d]):(s=i+u,c=s-i,a=i-(s-c)+(u-c),u=r[++p]),i=s,0!==a&&(o[h++]=a);for(;d<e;)s=i+l,c=s-i,a=i-(s-c)+(l-c),l=t[++d],i=s,0!==a&&(o[h++]=a);for(;p<n;)s=i+u,c=s-i,a=i-(s-c)+(u-c),u=r[++p],i=s,0!==a&&(o[h++]=a);return 0===i&&0!==h||(o[h++]=i),h}function vn(e){return new Float64Array(e)}const xn=vn(4),En=vn(8),Sn=vn(12),wn=vn(16),_n=vn(4);function Mn(e,t,n,r,o,i){const s=(t-i)*(n-o),a=(e-o)*(r-i),c=s-a,l=Math.abs(s+a);return Math.abs(c)>=33306690738754716e-32*l?c:-function(e,t,n,r,o,i,s){let a,c,l,u,d,p,h,f,g,y,m,v,x,E,S,w,_,M;const b=e-o,P=n-o,I=t-i,C=r-i;E=b*C,p=gn*b,h=p-(p-b),f=b-h,p=gn*C,g=p-(p-C),y=C-g,S=f*y-(E-h*g-f*g-h*y),w=I*P,p=gn*I,h=p-(p-I),f=I-h,p=gn*P,g=p-(p-P),y=P-g,_=f*y-(w-h*g-f*g-h*y),m=S-_,d=S-m,xn[0]=S-(m+d)+(d-_),v=E+m,d=v-E,x=E-(v-d)+(m-d),m=x-w,d=x-m,xn[1]=x-(m+d)+(d-w),M=v+m,d=M-v,xn[2]=v-(M-d)+(m-d),xn[3]=M;let T=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,xn),L=22204460492503146e-32*s;if(T>=L||-T>=L)return T;if(d=e-b,a=e-(b+d)+(d-o),d=n-P,l=n-(P+d)+(d-o),d=t-I,c=t-(I+d)+(d-i),d=r-C,u=r-(C+d)+(d-i),0===a&&0===c&&0===l&&0===u)return T;if(L=11093356479670487e-47*s+yn*Math.abs(T),T+=b*u+C*a-(I*l+P*c),T>=L||-T>=L)return T;E=a*C,p=gn*a,h=p-(p-a),f=a-h,p=gn*C,g=p-(p-C),y=C-g,S=f*y-(E-h*g-f*g-h*y),w=c*P,p=gn*c,h=p-(p-c),f=c-h,p=gn*P,g=p-(p-P),y=P-g,_=f*y-(w-h*g-f*g-h*y),m=S-_,d=S-m,_n[0]=S-(m+d)+(d-_),v=E+m,d=v-E,x=E-(v-d)+(m-d),m=x-w,d=x-m,_n[1]=x-(m+d)+(d-w),M=v+m,d=M-v,_n[2]=v-(M-d)+(m-d),_n[3]=M;const O=mn(4,xn,4,_n,En);E=b*u,p=gn*b,h=p-(p-b),f=b-h,p=gn*u,g=p-(p-u),y=u-g,S=f*y-(E-h*g-f*g-h*y),w=I*l,p=gn*I,h=p-(p-I),f=I-h,p=gn*l,g=p-(p-l),y=l-g,_=f*y-(w-h*g-f*g-h*y),m=S-_,d=S-m,_n[0]=S-(m+d)+(d-_),v=E+m,d=v-E,x=E-(v-d)+(m-d),m=x-w,d=x-m,_n[1]=x-(m+d)+(d-w),M=v+m,d=M-v,_n[2]=v-(M-d)+(m-d),_n[3]=M;const A=mn(O,En,4,_n,Sn);E=a*u,p=gn*a,h=p-(p-a),f=a-h,p=gn*u,g=p-(p-u),y=u-g,S=f*y-(E-h*g-f*g-h*y),w=c*l,p=gn*c,h=p-(p-c),f=c-h,p=gn*l,g=p-(p-l),y=l-g,_=f*y-(w-h*g-f*g-h*y),m=S-_,d=S-m,_n[0]=S-(m+d)+(d-_),v=E+m,d=v-E,x=E-(v-d)+(m-d),m=x-w,d=x-m,_n[1]=x-(m+d)+(d-w),M=v+m,d=M-v,_n[2]=v-(M-d)+(m-d),_n[3]=M;const k=mn(A,Sn,4,_n,wn);return wn[k-1]}(e,t,n,r,o,i,l)}function bn(e,t){var n,r,o,i,s,a,c,l,u,d=0,p=e[0],h=e[1],f=t.length;for(n=0;n<f;n++){r=0;var g=t[n],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,s=l[1]-h;r<y;r++){if(a=(u=g[r+1])[0]-p,c=u[1]-h,0===s&&0===c){if(a<=0&&i>=0||i<=0&&a>=0)return 0}else if(c>=0&&s<=0||c<=0&&s>=0){if(0===(o=Mn(i,a,s,c,0,0)))return 0;(o>0&&c>0&&s<=0||o<0&&c<=0&&s>0)&&d++}l=u,s=c,i=a}}return d%2!=0}var Pn=function(e,t,n,r,o){this.p1=e,this.p2=t,this.edgeType=n,this.originalIndex=r,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},In=function(e){this.p=e},Cn=function(e,t){this.id=e,this.rawCoords=t};function Tn(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var Ln=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=On(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=On(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function On(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}Ln.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var An=1e-9;function kn(e,t){return e[0]*t[1]-e[1]*t[0]}function Fn(e,t){return e[0]*t[0]+e[1]*t[1]}function Nn(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function Vn(e,t,n){var r=[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]],s=kn(r,o),a=s*s,c=Fn(r,r);if(a>0){var l=kn(i,o)/s;if(l<0||l>1)return null;var u=kn(i,r)/s;return u<0||u>1?null:0===l||1===l?[Nn(e.p1.p,l,r)]:0===u||1===u?[Nn(t.p1.p,u,o)]:[Nn(e.p1.p,l,r)]}var d=Fn(i,i);if((a=(s=kn(i,r))*s)>An*c*d)return null;var p=Fn(r,i)/c,h=p+Fn(r,o)/c,f=Math.min(p,h),g=Math.max(p,h);return f<=1&&g>=0?1===f?[Nn(e.p1.p,f>0?f:0,r)]:0===g?[Nn(e.p1.p,g<1?g:1,r)]:[Nn(e.p1.p,f>0?f:0,r),Nn(e.p1.p,g<1?g:1,r)]:null}function Dn(e,t){var n=[],r=[],o=[],i=function(e,t,n,r,o){for(var i=0,s=[],a="Feature"===t.type?t.geometry:t,c="LineString"===a.type?[a.coordinates]:a.coordinates,l=0,u=0;u<c.length;u++){for(var d=c[u].length-1,p=new In(c[u][0]),h=null,f={nextEdge:null},g=0;g<d;g++){h=new In(c[u][g+1]),p.nextPoint=h,h.prevPoint=p;var y=new Pn(p,h,"polyline",l,null);r.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,x=v.length,E=0;E<x;E++)for(var S=v[E].length,w=0;w<S;w++){i+=1;var _=v[E][w],M=_.length;s.push(new Cn(i,_));for(var b=new In(_[0]),P=b,I=void 0,C=null,T={nextEdge:null,prevEdge:null},L=null,O=1;O<M;O++)I=new In(_[O]),P.nextPoint=I,I.prevPoint=P,C=new Pn(P,I,"polygon",l,i),T.nextEdge=C,C.prevEdge=T,1===O&&(L=C),w>0&&(C.interiorRing=!0),C.intersectPolylineBbox=Tn(C,o),n.push(C),P=I,l+=1,T=C;C.nextEdge=L,L.prevEdge=C,I.nextPoint=b.nextPoint,b.prevPoint=I.prevPoint}return s}(un(e),t,r,o,[1/0,1/0,1/0,1/0]);if(function(e,t,n){var r,o,i,s=t.length,a=e.length;for(r=0;r<s;r++){var c=t[r];for(o=0;o<a;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=Vn(c,l);if(null!==u)for(i=0;i<u.length;i++){var d=Mn(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 Ln(u[i],c,l,d>0);n.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})})}(r,o,n),0===n.length)return e;var s={};i.forEach(function(e){return s[e.id]=0}),n.forEach(function(e){var t=e.polygonEdge.polygonContourId;s[t]=s[t]+1});for(var a=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&&!(a>2*n.length);){if(a=a++,h.visitCount>=2){for(var f=!1,g=0;g<n.length;g++){var y=n[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=jn(p,m),x=!1;if(v===(h=v)&&2===n.length)for(var E=0;E<n.length;E++){n[E].visitCount<2&&(x=!0)}for(;v!==p||x;){(v=(v.isHeadingIn?Xn:Yn)(v,m))!==p&&(v=jn(v,m)),x=!1}if(h.visitCount>=2){for(var S=!1,w=0;w<n.length;w++){var _=n[w];if(_.visitCount<2){p=_,S=!0;break}}S&&(h=p)}p=h}for(var M=c.map(function(e){return[e]}),b=Object.keys(s),P=0;P<b.length;P++){var I=b[P];if(0===s[I])Bn(Un(Rn(r,parseInt(I)),i),M)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:M}}}function Rn(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function Un(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function Bn(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(bn(e[0],[r[0]]))return void r.push(e)}t.push([e])}function jn(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=Gn(e,n.intersectionPoints),o=n.intersectionPoints[r+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(n.p2.p),null===(n=n.nextEdge))return e;n.intersectionPoints.length>0&&(i=!1)}return n.intersectionPoints[0].incrementVisitCount(),t.push(n.intersectionPoints[0].p),n.intersectionPoints[0]}function Gn(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function Yn(e,t){var n=e.polylineEdge;if(2===n.intersectionPoints.length){var r=n.intersectionPoints[n.intersectionPoints.length-1];if(r===e){var o=n.intersectionPoints[0];return t.push(o.p),o.incrementVisitCount(),o}return t.push(r.p),r.incrementVisitCount(),r}if(n.intersectionPoints.length>2&&n.intersectionPoints[0]!==e){var i=Gn(e,n.intersectionPoints),s=n.intersectionPoints[i-1];return t.push(s.p),s.incrementVisitCount(),s}for(var a=!0;a;){if(t.push(n.p1.p),void 0===(n=n.prevEdge).originalIndex)return e;n.intersectionPoints.length>0&&(a=!1)}if(void 0===n.originalIndex)return e;var c=n.intersectionPoints[n.intersectionPoints.length-1];return c.incrementVisitCount(),t.push(c.p),c}function Xn(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=Gn(e,n.intersectionPoints),o=n.intersectionPoints[r+1];return t.push(o.p),o.incrementVisitCount(),o}for(var i=!0;i;){if(t.push(n.p2.p),null===(n=n.nextEdge))return e;n.intersectionPoints.length>0&&(i=!1)}if(void 0===n)return e;var s=n.intersectionPoints[0];return s.incrementVisitCount(),t.push(s.p),s}function $n(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 Hn(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 Jn(e){return"Feature"===e.type?e.geometry:e}function qn(e,t,n={}){if(!0===n.final)return function(e,t){let n=qn(t,e);return n=(n+180)%360,n}(e,t);const r=$n(e),o=$n(t),i=$e(r[0]),s=$e(o[0]),a=$e(r[1]),c=$e(o[1]),l=Math.sin(s-i)*Math.cos(c),u=Math.cos(a)*Math.sin(c)-Math.sin(a)*Math.cos(c)*Math.cos(s-i);return Xe(Math.atan2(l,u))}var Kn=qn;function Wn(e,t,n,r={}){const o=$n(e),i=$e(o[0]),s=$e(o[1]),a=$e(n),c=Ye(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=Xe(i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l))),d=Xe(l);return void 0!==o[2]?De([u,d,o[2]],r.properties):De([u,d],r.properties)}var zn=Wn;function Zn(e,t,n={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const r=$n(e),o=Jn(t),i=o.type,s=t.bbox;let a=o.coordinates;if(s&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(r,s))return!1;"Polygon"===i&&(a=[a]);let c=!1;for(var l=0;l<a.length;++l){const e=bn(r,a[l]);if(0===e)return!n.ignoreBoundary;e&&(c=!0)}return c}class Qn{constructor(e=[],t=er){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:n}=this,r=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(n(r,i)>=0)break;t[e]=i,e=o}t[e]=r}_down(e){const{data:t,compare:n}=this,r=this.length>>1,o=t[e];for(;e<r;){let r=1+(e<<1),i=t[r];const s=r+1;if(s<this.length&&n(t[s],i)<0&&(r=s,i=t[s]),n(i,o)>=0)break;t[e]=i,e=r}t[e]=o}}function er(e,t){return e<t?-1:e>t?1:0}function tr(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 nr(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 rr{constructor(e,t,n,r){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=n,this.eventId=r,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let or=0,ir=0,sr=0;function ar(e,t){const n="Feature"===e.type?e.geometry:e;let r=n.coordinates;"Polygon"!==n.type&&"MultiLineString"!==n.type||(r=[r]),"LineString"===n.type&&(r=[[r]]);for(let e=0;e<r.length;e++)for(let n=0;n<r[e].length;n++){let o=r[e][n][0],i=null;ir+=1;for(let s=0;s<r[e][n].length-1;s++){i=r[e][n][s+1];const a=new rr(o,or,ir,sr),c=new rr(i,or,ir,sr+1);a.otherEvent=c,c.otherEvent=a,tr(a,c)>0?(c.isLeftEndpoint=!0,a.isLeftEndpoint=!1):(a.isLeftEndpoint=!0,c.isLeftEndpoint=!1),t.push(a),t.push(c),o=i,sr+=1}}or+=1}class cr{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function lr(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 n=e.leftSweepEvent.p.x,r=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,s=t.leftSweepEvent.p.x,a=t.leftSweepEvent.p.y,c=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,u=(l-a)*(o-n)-(c-s)*(i-r),d=(c-s)*(r-a)-(l-a)*(n-s),p=(o-n)*(r-a)-(i-r)*(n-s);if(0===u)return!1;const h=d/u,f=p/u;if(h>=0&&h<=1&&f>=0&&f<=1){return[n+h*(o-n),r+h*(i-r)]}return!1}var ur=function(e,t){const n=new Qn([],tr);return function(e,t){if("FeatureCollection"===e.type){const n=e.features;for(let e=0;e<n.length;e++)ar(n[e],t)}else ar(e,t)}(e,n),function(e,t){t=t||!1;const n=[],r=new Qn([],nr);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new cr(o);for(let i=0;i<r.data.length;i++){const s=r.data[i];if(t&&s.leftSweepEvent.featureId===o.featureId)continue;const a=lr(e,s);!1!==a&&n.push(a)}r.push(e)}else!1===o.isLeftEndpoint&&r.pop()}return n}(n,t)};function dr(e,t,n={}){const{removeDuplicates:r=!0,ignoreSelfIntersections:o=!0}=n;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(Ve(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(Ve(t));const s=ur(Be(i),o);let a=[];if(r){const e={};s.forEach(t=>{const n=t.join(",");e[n]||(e[n]=!0,a.push(t))})}else a=s;return Be(a.map(e=>De(e)))}function pr(e,t={}){const n=Jn(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),n.type){case"Polygon":return function(e,t={}){const n=Jn(e),r=n.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return hr(r,o)}(n,t);case"MultiPolygon":return function(e,t={}){const n=Jn(e),r=n.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return r.forEach(e=>{i.push(hr(e,o))}),Be(i)}(n,t);default:throw new Error("invalid poly")}}function hr(e,t){return e.length>1?je(e,t):Ue(e[0],t)}function fr(e,t,{ignoreSelfIntersections:n=!0}={ignoreSelfIntersections:!0}){let r=!0;return We(e,e=>{We(t,t=>{if(!1===r)return!1;r=function(e,t,n){switch(e.type){case"Point":switch(t.type){case"Point":return r=e.coordinates,o=t.coordinates,!(r[0]===o[0]&&r[1]===o[1]);case"LineString":return!gr(t,e);case"Polygon":return!Zn(e,t)}break;case"LineString":switch(t.type){case"Point":return!gr(e,t);case"LineString":return!function(e,t,n){const r=dr(e,t,{ignoreSelfIntersections:n});if(r.features.length>0)return!0;return!1}(e,t,n);case"Polygon":return!yr(t,e,n)}break;case"Polygon":switch(t.type){case"Point":return!Zn(t,e);case"LineString":return!yr(e,t,n);case"Polygon":return!function(e,t,n){for(const n of e.coordinates[0])if(Zn(n,t))return!0;for(const n of t.coordinates[0])if(Zn(n,e))return!0;const r=dr(pr(e),pr(t),{ignoreSelfIntersections:n});if(r.features.length>0)return!0;return!1}(t,e,n)}}var r,o;return!1}(e.geometry,t.geometry,n)})}),r}function gr(e,t){for(let n=0;n<e.coordinates.length-1;n++)if(mr(e.coordinates[n],e.coordinates[n+1],t.coordinates))return!0;return!1}function yr(e,t,n){for(const n of t.coordinates)if(Zn(n,e))return!0;return dr(t,pr(e),{ignoreSelfIntersections:n}).features.length>0}function mr(e,t,n){const r=n[0]-e[0],o=n[1]-e[1],i=t[0]-e[0],s=t[1]-e[1];return 0===r*s-o*i&&(Math.abs(i)>=Math.abs(s)?i>0?e[0]<=n[0]&&n[0]<=t[0]:t[0]<=n[0]&&n[0]<=e[0]:s>0?e[1]<=n[1]&&n[1]<=t[1]:t[1]<=n[1]&&n[1]<=e[1])}var vr=Object.defineProperty,xr=(e,t)=>vr(e,"name",{value:t,configurable:!0}),Er=class{constructor(e){var t,n,r;this.direction=!1,this.compareProperties=!0,this.precision=10**-(null!=(t=null==e?void 0:e.precision)?t:17),this.direction=null!=(n=null==e?void 0:e.direction)&&n,this.compareProperties=null==(r=null==e?void 0:e.compareProperties)||r}compare(e,t){if(e.type!==t.type)return!1;if(!wr(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 n=_r(e),r=_r(t);return n.every(e=>r.some(t=>this.compare(e,t)))}}return!1}compareCoord(e,t){return e.length===t.length&&e.every((e,n)=>Math.abs(e-t[n])<this.precision)}compareLine(e,t,n=0,r=!1){if(!wr(e,t))return!1;const o=e;let i=t;if(r&&!this.compareCoord(o[0],i[0])){const e=this.fixStartIndex(i,o);if(!e)return!1;i=e}const s=this.compareCoord(o[n],i[n]);return this.direction||s?this.comparePath(o,i):!!this.compareCoord(o[n],i[i.length-(1+n)])&&this.comparePath(o.slice().reverse(),i)}fixStartIndex(e,t){let n,r=-1;for(let n=0;n<e.length;n++)if(this.compareCoord(e[n],t[0])){r=n;break}return r>=0&&(n=[].concat(e.slice(r,e.length),e.slice(1,r+1))),n}comparePath(e,t){return e.every((e,n)=>this.compareCoord(e,t[n]))}comparePolygon(e,t){if(this.compareLine(e.coordinates[0],t.coordinates[0],1,!0)){const n=e.coordinates.slice(1,e.coordinates.length),r=t.coordinates.slice(1,t.coordinates.length);return n.every(e=>r.some(t=>this.compareLine(e,t,1,!0)))}return!1}compareGeometryCollection(e,t){return wr(e.geometries,t.geometries)&&this.compareBBox(e,t)&&e.geometries.every((e,n)=>this.compare(e,t.geometries[n]))}compareFeature(e,t){return e.id===t.id&&(!this.compareProperties||br(e.properties,t.properties))&&this.compareBBox(e,t)&&this.compare(e.geometry,t.geometry)}compareFeatureCollection(e,t){return wr(e.features,t.features)&&this.compareBBox(e,t)&&e.features.every((e,n)=>this.compare(e,t.features[n]))}compareBBox(e,t){return Boolean(!e.bbox&&!t.bbox)||!(!e.bbox||!t.bbox)&&this.compareCoord(e.bbox,t.bbox)}};xr(Er,"GeojsonEquality");var Sr=Er;function wr(e,t){return e.coordinates?e.coordinates.length===t.coordinates.length:e.length===t.length}function _r(e){return e.coordinates.map(t=>({type:e.type.replace("Multi",""),coordinates:t}))}function Mr(e,t,n){return new Sr(n).compare(e,t)}function br(e,t){if(null===e&&null===t)return!0;if(null===e||null===t)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o of n){const n=e[o],r=t[o],i=Pr(n)&&Pr(r);if(i&&!br(n,r)||!i&&n!==r)return!1}return!0}xr(wr,"sameLength"),xr(_r,"explode"),xr(Mr,"geojsonEquality"),xr(br,"equal");var Pr=xr(e=>null!=e&&"object"==typeof e,"isObject");function Ir(e,t,n={}){const r=$n(e),o=Hn(t);for(let e=0;e<o.length-1;e++){let t=!1;if(n.ignoreEndVertices&&(0===e&&(t="start"),e===o.length-2&&(t="end"),0===e&&e+1===o.length-1&&(t="both")),Cr(o[e],o[e+1],r,t,void 0===n.epsilon?null:n.epsilon))return!0}return!1}function Cr(e,t,n,r,o){const i=n[0],s=n[1],a=e[0],c=e[1],l=t[0],u=t[1],d=l-a,p=u-c,h=(n[0]-a)*p-(n[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)?!r&&(n[0]===e[0]&&n[1]===e[1]):r?"start"===r?Math.abs(d)>=Math.abs(p)?d>0?a<i&&i<=l:l<=i&&i<a:p>0?c<s&&s<=u:u<=s&&s<c:"end"===r?Math.abs(d)>=Math.abs(p)?d>0?a<=i&&i<l:l<i&&i<=a:p>0?c<=s&&s<u:u<s&&s<=c:"both"===r&&(Math.abs(d)>=Math.abs(p)?d>0?a<i&&i<l:l<i&&i<a:p>0?c<s&&s<u:u<s&&s<c):Math.abs(d)>=Math.abs(p)?d>0?a<=i&&i<=l:l<=i&&i<=a:p>0?c<=s&&s<=u:u<=s&&s<=c}function Tr(e,t={}){var n="object"==typeof t?t.mutate:t;if(!e)throw new Error("geojson is required");var r=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(r){case"LineString":o=Lr(e,r);break;case"MultiLineString":case"Polygon":Hn(e).forEach(function(e){o.push(Lr(e,r))});break;case"MultiPolygon":Hn(e).forEach(function(e){var t=[];e.forEach(function(e){t.push(Lr(e,r))}),o.push(t)});break;case"Point":return e;case"MultiPoint":var i={};Hn(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(r+" geometry not supported")}return e.coordinates?!0===n?(e.coordinates=o,e):{type:r,coordinates:o}:!0===n?(e.geometry.coordinates=o,e):Ve({type:r,coordinates:o},e.properties,{bbox:e.bbox,id:e.id})}function Lr(e,t){const n=Hn(e);if(2===n.length&&!Or(n[0],n[1]))return n;const r=[];let o=0,i=1,s=2;for(r.push(n[o]);s<n.length;)Ir(n[i],Ue([n[o],n[s]]))?i=s:(r.push(n[i]),o=i,i++,s=i),s++;if(r.push(n[i]),"Polygon"===t||"MultiPolygon"===t){if(Ir(r[0],Ue([r[1],r[r.length-2]]))&&(r.shift(),r.pop(),r.push(r[0])),r.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!Or(r[0],r[r.length-1]))throw new Error("invalid polygon, first and last points not equal")}return r}function Or(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ar(e,t,n={}){let r=n.precision;if(r=null==r||isNaN(r)?6:r,"number"!=typeof r||!(r>=0))throw new Error("precision must be a positive number");return Jn(e).type===Jn(t).type&&Mr(Tr(e),Tr(t),{precision:r})}function kr(e,t){var n=Jn(e),r=Jn(t),o=n.type,i=r.type;switch(o){case"MultiPoint":switch(i){case"LineString":return Fr(n,r);case"Polygon":return Vr(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"MultiPoint":return Fr(r,n);case"LineString":return function(e,t){const n=dr(e,t);if(0===n.features.length)return!1;for(const r of n.features)if(!(Ar(r.geometry,De(e.coordinates[0]))||Ar(r.geometry,De(e.coordinates[e.coordinates.length-1]))||Ar(r.geometry,De(t.coordinates[0]))||Ar(r.geometry,De(t.coordinates[t.coordinates.length-1]))))return!0;return!1}(n,r);case"Polygon":return Nr(n,r);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"MultiPoint":return Vr(r,n);case"LineString":return Nr(r,n);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+o+" geometry not supported")}}function Fr(e,t){for(var n=!1,r=!1,o=e.coordinates.length,i=0;i<o&&!n&&!r;){for(var s=0;s<t.coordinates.length-1;s++){var a=!0;0!==s&&s!==t.coordinates.length-2||(a=!1),Dr(t.coordinates[s],t.coordinates[s+1],e.coordinates[i],a)?n=!0:r=!0}i++}return n&&r}function Nr(e,t){return dr(e,pr(t)).features.length>0}function Vr(e,t){var n=!1,r=!1,o=e.coordinates.length;for(let i=0;i<o&&(!n||!r);i++)Zn(De(e.coordinates[i]),t)?n=!0:r=!0;return r&&n}function Dr(e,t,n,r){var o=n[0]-e[0],i=n[1]-e[1],s=t[0]-e[0],a=t[1]-e[1];return 0===o*a-i*s&&(r?Math.abs(s)>=Math.abs(a)?s>0?e[0]<=n[0]&&n[0]<=t[0]:t[0]<=n[0]&&n[0]<=e[0]:a>0?e[1]<=n[1]&&n[1]<=t[1]:t[1]<=n[1]&&n[1]<=e[1]:Math.abs(s)>=Math.abs(a)?s>0?e[0]<n[0]&&n[0]<t[0]:t[0]<n[0]&&n[0]<e[0]:a>0?e[1]<n[1]&&n[1]<t[1]:t[1]<n[1]&&n[1]<e[1])}function Rr(e){return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]}function Ur(e){for(var t=0;t<e.length-1;t++)for(var n=e[t],r=t+1;r<e.length-2;r++){if(Ir(n,Ue([e[r],e[r+1]])))return!0}return!1}function Br(e,t,n){for(var r=Re(e),o=n+1;o<t.length;o++)if(!fr(r,Re(t[o]))&&kr(r,Ue(t[o][0])))return!1;return!0}var jr=function(e){if(!e.type)return!1;const t=Jn(e),n=t.type,r=t.coordinates;switch(n){case"Point":return r.length>1;case"MultiPoint":for(var o=0;o<r.length;o++)if(r[o].length<2)return!1;return!0;case"LineString":if(r.length<2)return!1;for(o=0;o<r.length;o++)if(r[o].length<2)return!1;return!0;case"MultiLineString":if(r.length<2)return!1;for(o=0;o<r.length;o++)if(r[o].length<2)return!1;return!0;case"Polygon":for(o=0;o<t.coordinates.length;o++){if(r[o].length<4)return!1;if(!Rr(r[o]))return!1;if(Ur(r[o]))return!1;if(o>0&&dr(Re([r[0]]),Re([r[o]])).features.length>1)return!1}return!0;case"MultiPolygon":for(o=0;o<t.coordinates.length;o++)for(var i=t.coordinates[o],s=0;s<i.length;s++){if(i[s].length<4)return!1;if(!Rr(i[s]))return!1;if(Ur(i[s]))return!1;if(0===s&&!Br(i,t.coordinates,o))return!1;if(s>0&&dr(Re([i[0]]),Re([i[s]])).features.length>1)return!1}return!0;default:return!1}};function Gr(e){let t=0;if(e&&e.length>0){t+=Math.abs($r(e[0]));for(let n=1;n<e.length;n++)t-=Math.abs($r(e[n]))}return t}var Yr=20294876564838.72,Xr=Math.PI/180;function $r(e){const t=e.length-1;if(t<=2)return 0;let n=0,r=0;for(;r<t;){const o=e[r],i=e[r+1===t?0:r+1],s=e[r+2>=t?(r+2)%t:r+2],a=o[0]*Xr,c=i[1]*Xr;n+=(s[0]*Xr-a)*Math.sin(c),r++}return n*Yr}var Hr=function(e){return function(e,t,n){var r=n;return Ke(e,function(e,n,o,i,s){r=t(r,e,n,o,i,s)}),r}(e,(e,t)=>e+function(e){let t,n=0;switch(e.type){case"Polygon":return Gr(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)n+=Gr(e.coordinates[t]);return n;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};const Jr=(e,t)=>{const n=function(e,t=1,n="meters"){const r=e.geometry.coordinates,o=[],i=Kn(r[1],r[0]),s=zn(r[0],t,i,{units:n});o.push(s.geometry.coordinates);for(let e=0;e<r.length;e++){if(e>0&&e<r.length-1){const i=Kn(r[e-1],r[e]),s=zn(r[e],t,i,{units:n});o.push(s.geometry.coordinates)}o.push(r[e])}const a=Kn(r[r.length-2],r[r.length-1]),c=zn(r[r.length-1],t,a,{units:n});return o.push(c.geometry.coordinates),Ue(o)}(t);let r;try{r=Dn(e,n)}catch{return null}let o=[];if("MultiPolygon"!==r.geometry.type)return null;if(2!==r.geometry.coordinates.length)return null;o=r.geometry.coordinates.map(t=>Re(t,e.properties));const i=e.id??e.properties?.id??"poly";return Be(o.map((t,n)=>Re(t.geometry.coordinates,{...e.properties,id:i},{id:`${i}-${n+1}`})))},qr=([e,t],[n,r])=>{const o=e=>e*Math.PI/180,i=o(r-t),s=o(n-e),a=Math.sin(i/2)**2+Math.cos(o(t))*Math.cos(o(r))*Math.sin(s/2)**2;return 12742e3*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))},Kr=e=>e.length<=1||((e,t=.01)=>{if(e.length<=1)return!0;if(e.length>=2){const n=e[e.length-1],r=e[e.length-2];if(qr(n,r)<t)return!1}return!0})(e),Wr=e=>{if(e[0].length<=1||((e,t=.01)=>{if(e[0].length<=1)return!0;if(e[0].length<=3)for(let n=0;n<e[0].length;n++)for(let r=n+1;r<e[0].length;r++)if(qr(e[0][n],e[0][r])<t)return!1;return!0})(e))return!0;if(!Array.isArray(e)||e.length<4)return!1;const t=e[0],n=e[e.length-1];if(!(t[0]===n[0]&&t[1]===n[1]))return!1;const r=Re([e]);if(!jr(r))return!1;return!(Hr(r)<=0)},zr=(e,t,n)=>{const r=t.filter((t,r)=>{const o=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);let s=!1;return s="ArrowUp"===n?t[1]<=e[1]&&i>=o:"ArrowDown"===n?t[1]>e[1]&&i>=o:"ArrowLeft"===n?t[0]<=e[0]&&i<o:"ArrowRight"!==n||t[0]>e[0]&&i<o,s&&JSON.stringify(t)!==JSON.stringify(e)});r.length||r.push(e);const o=r.map(t=>{return n=Math.abs(e[0]-t[0]),r=Math.abs(e[1]-t[1]),Math.sqrt(Math.pow(n,2)+Math.pow(r,2));var n,r}),i=r[o.indexOf(Math.min(...o))];return t.findIndex(e=>JSON.stringify(e)===JSON.stringify(i))},Zr={findVertexIndex(e,t,n){const r=[];return e.forEach((e,n)=>{e[0]===t[0]&&e[1]===t[1]&&r.push(n)}),0===r.length?-1:1===r.length?r[0]:n>=0?r.reduce((e,t)=>Math.abs(t-n)<Math.abs(e-n)?t:e):r[0]},getCoordPath(e,t){const n=this.getFeature(e.featureId);if(!n)return"0";const r=$t(n),o=Ht(r,t);if(!o)return"0";const{segment:i,localIdx:s}=o;return[...i.path,s].join(".")},syncVertices(e){e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVerticies(e){return Xt(this.getFeature(e))||[]},getMidpoints(e){const t=this.getFeature(e),n=Xt(t),r=$t(t);if(!n?.length||!r.length)return[];const o=[];for(const e of r){const t=e.closed?e.length:e.length-1;for(let r=0;r<t;r++){const t=e.start+r,i=e.start+(r+1)%e.length,[s,a]=n[t],[c,l]=n[i];o.push([(s+c)/2,(a+l)/2])}}return o},getVertexOrMidpoint(e,t){if(e.vertecies?.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),!e.vertecies?.length)return[-1,null];const n=e=>e?Object.values(this.map.project(e)):null,r=[...e.vertecies.map(n),...e.midpoints.map(n)].filter(Boolean);if(!r.length)return[-1,null];const o=r[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),i=zr(o,r,t);return[i,i<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){const n=this.getFeature(e.featureId),r=$t(n),o=t.split(".").map(Number);let i=0;for(const t of r){if(t.path.every((e,t)=>e===o[t])&&o.length===t.path.length+1){const n=o[o.length-1],r=n>0?n-1:t.length-2;return e.vertecies.length+i+r}i+=t.closed?t.length:t.length-1}return e.vertecies.length}},Qr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),eo={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},to={...Et,...zt,...Qt,...tn,...Zr,onSetup(e){const t=Et.onSetup.call(this,e);Object.assign(t,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:t.featureId||e.featureId,selectedVertexIndex:e.selectedVertexIndex??-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:e.scale??1});const n=this.getFeature(t.featureId);t.featureType=n?.type,t.vertecies=this.getVerticies(t.featureId),t.midpoints=this.getMidpoints(t.featureId),this.setupEventListeners(t),this.applyVertexSelection(t,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(t);const r=o(this.map);if(r&&c(r,this.map),"touch"===t.interfaceType&&t.selectedVertexIndex>=0&&"vertex"===t.selectedVertexType){const e=t.vertecies[t.selectedVertexIndex];e&&setTimeout(()=>{this.updateTouchVertexTarget(t,Kt(this.map.project(e),t.scale))},0)}return t._ignorePointermoveDeselect=!0,setTimeout(()=>{t._ignorePointermoveDeselect=!1},100),t},setupEventListeners(e){const t=t=>n=>t.call(this,e,n),n=this.handlers={keydown:t(this.onKeydown),keyup:t(this.onKeyup),pointerdown:t(this.onPointerevent),pointermove:t(this.onPointerevent),pointerup:t(this.onPointerevent),click:t(this.onButtonClick),touchstart:t(this.onTouchstart),touchmove:t(this.onTouchmove),touchend:t(this.onTouchend),selectionchange:t(this.onSelectionChange),scalechange:t(this.onScaleChange),update:t(this.onUpdate),move:t(this.onMove),interfacetypechange:t(this.onInterfaceTypeChange)};window.addEventListener("keydown",n.keydown,{capture:!0}),window.addEventListener("keyup",n.keyup,{capture:!0}),window.addEventListener("click",n.click),e.container.addEventListener("pointerdown",n.pointerdown),e.container.addEventListener("pointermove",n.pointermove),e.container.addEventListener("pointerup",n.pointerup),e.container.addEventListener("touchstart",n.touchstart,{passive:!1}),e.container.addEventListener("touchmove",n.touchmove,{passive:!1}),e.container.addEventListener("touchend",n.touchend,{passive:!1}),this.map.on("draw.selectionchange",n.selectionchange),this.map.on("draw.scalechange",n.scalechange),this.map.on("draw.update",n.update),this.map.on("move",n.move),this.map.on("draw.interfacetypechange",n.interfacetypechange)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature&&e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertecies.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature&&e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){this.syncVertices(e);const n=t.points[t.points.length-1]?.geometry.coordinates;if("keyboard"!==e.interfaceType&&n&&!e.coordPath){const r=t.features[0]?.geometry,o=Xt(r);e.selectedVertexIndex=this.findVertexIndex(o,n,e.selectedVertexIndex)}e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null,this.map.fire("draw.vertexselection",{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});const r=n||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,r?Kt(this.map.project(r),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;const n=e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,n?Kt(this.map.project(n),e.scale):null)},onUpdate(e){const t=new Set(e.vertecies.map(e=>JSON.stringify(e)));t.size!==e.vertecies.length&&(e.selectedVertexIndex=e.vertecies.findIndex(e=>!t.has(JSON.stringify(e))),e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null)},onKeydown(e,t){if(e.container.contains(document.activeElement)){if(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "===t.key&&t.preventDefault()," "===t.key&&e.selectedVertexIndex<0){const t=o(this.map);if(t&&c(t,this.map),e.vertecies?.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),!e.vertecies?.length)return;return e.isPanEnabled=!1,this.updateVertex(e)}if(!t.altKey&&Qr.has(t.key)&&e.selectedVertexIndex>=0){if(t.preventDefault(),t.stopPropagation(),"midpoint"===e.selectedVertexType)return this.insertVertex(e,t);const n=o(this.map),r=this.getFeature(e.featureId);if(!r)return;const l=Xt(r),d=l?.[e.selectedVertexIndex];if(!d)return;if(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...d],e._keyboardMoveStartIndex=e.selectedVertexIndex),u(e)&&e._isSnapped&&n){const r=function(e){return e?.options?.radius??15}(n)+1,o=this.map.project(d),[i,s]=eo[t.key].map(e=>e*r);return e._isSnapped=!1,c(n,this.map),this.moveVertex(e,this.map.unproject({x:o.x+i,y:o.y+s}))}const p=this.getNewCoord(e,t);return u(e)&&n&&(a(n,this.map,this.map.project(p)),i(n))?(e._isSnapped=!0,this.moveVertex(e,s(n))):(e._isSnapped=!1,this.moveVertex(e,p))}if(t.altKey&&Qr.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){const n=document.activeElement?.tagName;if("INPUT"===n||"TEXTAREA"===n)return;return t.preventDefault(),t.stopPropagation(),this.handleUndo(e)}}},onKeyup(e,t){e.container.contains(document.activeElement)&&(e.interfaceType="keyboard",Qr.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){l(o(this.map));const n=t.featureTarget?.properties.meta,r=t.featureTarget?.properties.coord_path;if(["vertex","midpoint"].includes(n)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,Et.onMouseDown.call(this,e,t),"vertex"===n&&r)){const t=this.getFeature(e.featureId),n=qt(t,r);e.selectedVertexIndex=n,e.selectedVertexType="vertex",e.coordPath=r;const o=e.vertecies?.[n];o&&(e._moveStartPosition=[...o],e._moveStartIndex=n)}if("midpoint"===n){const t=this.getFeature(e.featureId),n=qt(t,r);e._insertedVertexIndex=n,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,r),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire("draw.vertexselection",{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&void 0!==e._insertedVertexIndex){const t=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=void 0,void this.map.fire("draw.vertexselection",{index:t,numVertecies:e.vertecies.length})}Et.onClick.call(this,e,t)},onMouseUp(e,t){l(o(this.map));let n=!1;if(e._moveStartPosition&&void 0!==e._moveStartIndex){const t=this.getFeature(e.featureId);if(t){const r=Xt(t)?.[e._moveStartIndex];r&&(n=r[0]!==e._moveStartPosition[0]||r[1]!==e._moveStartPosition[1])}}const r=e._isInsertingVertex&&void 0!==e._insertedVertexIndex;if(e.dragMoving||n||r)if(this.syncVertices(e),r){const t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=void 0,this.map.fire("draw.vertexselection",{index:t,numVertecies:e.vertecies.length})}else n&&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,Et.onMouseUp.call(this,e,t)},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=o(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!u(e)||!n?.status)return void Et.onDrag.call(this,e,t);if(!e.selectedCoordPaths?.length||!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation(),a(n,this.map,t.point);const r=s(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],r.lng,r.lat),e.dragMoveLocation=t.lngLat},onMove(e){const t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Kt(this.map.project(t),e.scale))},onButtonClick(e,t){t.target.closest(`#${e.deleteVertexButtonId}`)&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",{...e,...t})},onStop(e){this.map._drawEditContainer=null;const t=this.handlers;e.container.removeEventListener("pointerdown",t.pointerdown),e.container.removeEventListener("pointermove",t.pointermove),e.container.removeEventListener("pointerup",t.pointerup),e.container.removeEventListener("touchstart",t.touchstart),e.container.removeEventListener("touchmove",t.touchmove),e.container.removeEventListener("touchend",t.touchend),this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.scalechange",t.scalechange),this.map.off("draw.update",t.update),this.map.off("move",t.move),this.map.off("draw.interfacetypechange",t.interfacetypechange),this.map.dragPan.enable(),window.removeEventListener("click",t.click),window.removeEventListener("keydown",t.keydown,{capture:!0}),window.removeEventListener("keyup",t.keyup,{capture:!0}),this.hideTouchVertexIndicator(e)}},no=(e,t)=>{const{featureProp:n,geometryType:r,getCoords:c,validateClick:l,createVertices:d,excludeFeatureIdFromSetup:p=!1,finishOnInvalidClick:h=!1}=t,f=e=>e[n];return{...e,onSetup(t){const{map:r}=this,o=p?{...t,featureId:null}:t,i={...e.onSetup.call(this,o),...t};i[n].properties=t.properties;const{container:s,vertexMarkerId:a,getInterfaceType:c}=i,l=c?c():i.interfaceType;i.interfaceType=l;const u=s.querySelector(`#${a}`);i.vertexMarker=u,["touch","keyboard"].includes(l)?this._showCrossHair(i):this._hideCrossHair(i);const d=(e,t)=>this[e]=t.bind(this,i),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo};return Object.entries(h).forEach(([e,t])=>d(e,t)),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[r,"pointerdown",this.pointerdownHandler],[r,"draw.create",this.createHandler],[r,"move",this.moveHandler],[r,"draw.undo",this.undoHandler]],this._listeners.forEach(([e,t,n])=>e.addEventListener?e.addEventListener(t,n):e.on(t,n)),i},onClick(t,n){if(n.originalEvent.button>0||this.map._undoInProgress||n.originalEvent.target!==this.map.getCanvas())return;const r=o(this.map);if(u(t)&&i(r))n=function(e,t){const n=s(t);return n?{...e,lngLat:n}:e}(n,r);else{const e=c(f(t));if(e.length>0&&(e[e.length-1]=[n.lngLat.lng,n.lngLat.lat]),!h&&!l(f(t)))return}const a=c(f(t)).length;e.onClick.call(this,t,n),c(f(t)).length>a&&(this.pushDrawUndo(t),this.dispatchVertexChange(c(f(t))))},onTap(){},doClick(t){if(this.map._undoInProgress)return;const n=f(t),r=c(n);if(this.dispatchVertexChange(r),!l(n))return void(h&&r.length>1&&(r.pop(),this.map.fire("draw.create",{features:[n.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[n.id]})));const i=o(this.map),a=u(t)&&function(e,t){const n=s(t);if(!n)return null;const r=e.project([n.lng,n.lat]);return{lngLat:n,point:r,originalEvent:new MouseEvent("click",{clientX:r.x,clientY:r.y,bubbles:!0,cancelable:!0})}}(this.map,i),d=r.length;a?(e.onClick.call(this,t,a),this._ctx.store.render()):this._simulateMouse("click",e.onClick,t);const p=c(f(t));p.length>d&&(this.pushDrawUndo(t),this.dispatchVertexChange(p))},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},pushDrawUndo(e){const t=this.map._undoStack;t&&!this.map._undoInProgress&&t.push({type:"draw_vertex",geometryType:r,featureId:f(e).id})},undoVertex(e){const t=f(e),n=c(t);return!(n.length<2)&&(2===n.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,n),!0))},_reinitializeFeature(t,o){const i=o.id;if(this._ctx.store.delete([i]),"LineString"===r){const e=this.map._undoStack;return e&&e.clear(),this._ctx.api.changeMode("draw_line",{featureId:i,container:t.container,interfaceType:t.interfaceType,crossHair:t.crossHair,vertexMarkerId:t.vertexMarkerId,addVertexButtonId:t.addVertexButtonId,getSnapEnabled:t.getSnapEnabled,properties:t.properties}),!0}const s=this.map.getCenter(),a=[[s.lng,s.lat],[s.lng,s.lat]],c=this.newFeature({type:"Feature",properties:t.properties||{},geometry:{type:r,coordinates:[a]}});return c.id=i,this._ctx.store.add(c),t[n]=c,t.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render(),this.dispatchVertexChange(a),!0},_removeLastVertex(e,t,n){const o="Polygon"===r?t.coordinates[0]:n;o.splice(-2,1);const i=o[o.length-2];i&&(o[o.length-1]=[...i]),e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,c(t))},_updateRubberBand(t,n){if(["touch","keyboard"].includes(t.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,t),this._ctx.store.render();else{const o=n["Polygon"===r?n.length-2:n.length-1];if(o){const n={lng:o[0],lat:o[1]},r=this.map.project(n);e.onMouseMove.call(this,t,{lngLat:n,point:r,originalEvent:new MouseEvent("mousemove",{clientX:r.x,clientY:r.y})}),this._ctx.store.render()}}this.dispatchVertexChange(n)},onUndo(e,t){"draw_vertex"===t.operation?.type&&this.undoVertex(e)},_simulateMouse(e,t,n){const{map:r}=this,o=r.getCenter(),i=r.project(o);t.call(this,n,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",n.polygon||n.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},onCreate(e,t){const n=this._ctx.api,r=t.features[0];n.delete(r.id),r.id=e.featureId,n.add(r,{userProperties:!0})},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this.doClick(e)},onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},_handleUndoKeydown(e,t){const n=document.activeElement?.tagName;if("INPUT"===n||"TEXTAREA"===n)return;t.preventDefault(),t.stopPropagation();const r=this.map._undoStack;if(r&&r.length>0){const t=r.pop();"draw_vertex"===t?.type&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e))}},onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),this._setInterface(e,"keyboard"),this.onMove(e,t)):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(t,n){const r=document.activeElement;if(!r||r===t.container||!t.container.contains(r))if("Escape"!==n.key)r!==t.container&&e.onKeyUp.call(this,t,n);else if("keyboard"===t.interfaceType){const e=this.map._undoStack;e&&e.clear(),this._reinitializeFeature(t,f(t))}},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(t,n){if(u(t)){const e=o(this.map);a(e,this.map,n.point);const t=s(e);t&&(n={...n,lngLat:t})}this.map.fire("draw.geometrychange",t.polygon||t.line),e.onMouseMove.call(this,t,n)},onMove(t){if(["touch","keyboard"].includes(t.interfaceType)){u(t)&&function(e,t){if(!e||!t||!e.status)return!1;const n=t.getCenter(),r=t.project(n);e.snapToClosestPoint({point:r,lngLat:n})}(o(this.map),this.map);const n=o(this.map),r=u(t)&&s(n);if(r){const n=this.map.project([r.lng,r.lat]);e.onMouseMove.call(this,t,{lngLat:r,point:n,originalEvent:new MouseEvent("mousemove",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render()}else this._simulateMouse("mousemove",e.onMouseMove,t)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(c(f(e)))},toDisplayFeatures(t,n,o){e.toDisplayFeatures.call(this,t,n,o);const i=f(t);n.geometry.type===r&&n.id===i.id&&d(n,o,ke)},onStop(t){e.onStop.call(this,t),this._listeners.forEach(([e,t,n])=>e.removeEventListener?e.removeEventListener(t,n):e.off(t,n)),this._hideCrossHair(t)}}},ro=no(_t,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>Wr(e.coordinates),createVertices:(e,t,n)=>{const r=e.geometry.coordinates[0];for(let o=1;o<r.length-2;o++)t(n(e.id,r[o],`0.${o}`))}}),oo=no(Mt,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>Kr(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,createVertices:(e,t,n)=>{const r=e.geometry.coordinates;for(let o=1;o<r.length-1;o++)t(n(e.id,r[o],`${o}`))}}),io={editStroke:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editVertex:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editMidpoint:{light:"rgba(29,112,184,1)",dark:"#ffffff"},editHalo:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editActive:{light:"rgba(11,12,12,1)",dark:"#ffffff"},splitInvalid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},shapeStroke:"rgba(212,53,28,1)",shapeFill:"rgba(212,53,28,0.1)",strokeWidth:2,snapVertex:"rgba(212,53,28,1)",snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,1)",snapRadius:10,snapLayers:[]},so=(e,t,n=t)=>["coalesce",["get",`user_${t}${e.id.charAt(0).toUpperCase()+e.id.slice(1)}`],["get",`user_${t}`],io[n]],ao=e=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":so(e,"fill","shapeFill")}}),co=e=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":so(e,"stroke","shapeStroke"),"line-width":so(e,"strokeWidth")}}),lo=e=>({id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":e,"fill-opacity":.1}}),uo=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}}),po=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}}),ho=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}}),fo=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}}),go=e=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"]],paint:{"circle-radius":6,"circle-color":e}}),yo=(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}}),mo=e=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":6,"circle-color":e}}),vo=e=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":4,"circle-color":e}}),xo=(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}}),Eo=e=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":4,"circle-color":e}}),So=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),wo=e=>{const t=(e=>e.mapColorScheme??"light")(e),n=io.editStroke[t],r=io.editVertex[t],o=io.editMidpoint[t],i=io.editHalo[t],s=io.editActive[t],a=io.splitInvalid[t],c=io.splitValid[t];return[ao(e),lo(n),uo(n),co(e),po(a),ho(c),fo(n),vo(o),xo(i,s),Eo(o),go(r),yo(i,s),mo(r),So(n),{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 _o(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 Mo(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 bo(e,t,n){void 0===n&&(n={});var r=_o(e),o=_o(t),i=$e(o[1]-r[1]),s=$e(o[0]-r[0]),a=$e(r[1]),c=$e(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return Ge(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}function Po(e,t){var n;return void 0===t&&(t={}),function(e,t){if(e.length>1)return je(e,t);return Ue(e[0],t)}(("Feature"===(n=e).type?n.geometry:n).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Io(e,t,n,r){void 0===r&&(r={});var o=_o(e),i=$e(o[0]),s=$e(o[1]),a=$e(n),c=Ye(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a));return De([Xe(i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l))),Xe(l)],r.properties)}function Co(e){if(!e)throw new Error("geojson is required");var t=[];return We(e,function(e){!function(e,t){var n=[],r=e.geometry;if(null!==r){switch(r.type){case"Polygon":n=Mo(r);break;case"LineString":n=[Mo(r)]}n.forEach(function(n){var r=function(e,t){var n=[];return e.reduce(function(e,r){var o,i,s,a,c,l,u=Ue([e,r],t);return u.bbox=(i=r,s=(o=e)[0],a=o[1],c=i[0],l=i[1],[s<c?s:c,a<l?a:l,s>c?s:c,a>l?a:l]),n.push(u),r}),n}(n,e.properties);r.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),Be(t)}var To={exports:{}};function Lo(e,t,n,r,o){Oo(e,t,n||0,r||e.length-1,o||ko)}function Oo(e,t,n,r,o){for(;r>n;){if(r-n>600){var i=r-n+1,s=t-n+1,a=Math.log(i),c=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*c*(i-c)/i)*(s-i/2<0?-1:1);Oo(e,t,Math.max(n,Math.floor(t-s*c/i+l)),Math.min(r,Math.floor(t+(i-s)*c/i+l)),o)}var u=e[t],d=n,p=r;for(Ao(e,n,t),o(e[r],u)>0&&Ao(e,n,r);d<p;){for(Ao(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[n],u)?Ao(e,n,p):Ao(e,++p,r),p<=t&&(n=p+1),t<=p&&(r=p-1)}}function Ao(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function ko(e,t){return e<t?-1:e>t?1:0}function Fo(e,t,n){if(!n)return t.indexOf(e);for(let r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function No(e,t){Vo(e,0,e.children.length,t,e)}function Vo(e,t,n,r,o){o||(o=Ho(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<n;i++){const t=e.children[i];Do(o,e.leaf?r(t):t)}return o}function Do(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 Ro(e,t){return e.minX-t.minX}function Uo(e,t){return e.minY-t.minY}function Bo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function jo(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Go(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 Yo(e,t){const n=Math.max(e.minX,t.minX),r=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,i-r)}function Xo(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function $o(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ho(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Jo(e,t,n,r,o){const i=[t,n];for(;i.length;){if((n=i.pop())-(t=i.pop())<=r)continue;const s=t+Math.ceil((n-t)/r/2)*r;Lo(e,s,t,n,o),i.push(t,s,s,n)}}var qo,Ko=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!$o(e,t))return n;const r=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const s=t.children[i],a=t.leaf?r(s):s;$o(e,a)&&(t.leaf?n.push(s):Xo(e,a)?this._all(s,n):o.push(s))}t=o.pop()}return n}collides(e){let t=this.data;if(!$o(e,t))return!1;const n=[];for(;t;){for(let r=0;r<t.children.length;r++){const o=t.children[r],i=t.leaf?this.toBBox(o):o;if($o(e,i)){if(t.leaf||Xo(e,i))return!0;n.push(o)}}t=n.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=Ho([]),this}remove(e,t){if(!e)return this;let n=this.data;const r=this.toBBox(e),o=[],i=[];let s,a,c;for(;n||o.length;){if(n||(n=o.pop(),a=o[o.length-1],s=i.pop(),c=!0),n.leaf){const r=Fo(e,n.children,t);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}c||n.leaf||!Xo(n,r)?a?(s++,n=a.children[s],c=!1):n=null:(o.push(n),i.push(s),s=0,a=n,n=n.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){const o=n-t+1;let i,s=this._maxEntries;if(o<=s)return i=Ho(e.slice(t,n+1)),No(i,this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,r-1))),i=Ho([]),i.leaf=!1,i.height=r;const a=Math.ceil(o/s),c=a*Math.ceil(Math.sqrt(s));Jo(e,t,n,c,this.compareMinX);for(let o=t;o<=n;o+=c){const t=Math.min(o+c-1,n);Jo(e,o,t,a,this.compareMinY);for(let n=o;n<=t;n+=a){const o=Math.min(n+a-1,t);i.children.push(this._build(e,n,o,r-1))}}return No(i,this.toBBox),i}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const s=t.children[i],a=Bo(s),c=Go(e,s)-a;c<o?(o=c,r=a<r?a:r,n=s):c===o&&a<r&&(r=a,n=s)}t=n||t.children[0]}return t}_insert(e,t,n){const r=n?e:this.toBBox(e),o=[],i=this._chooseSubtree(r,this.data,t,o);for(i.children.push(e),Do(i,r);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(r,o,t)}_split(e,t){const n=e[t],r=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,r);const i=this._chooseSplitIndex(n,o,r),s=Ho(n.children.splice(i,n.children.length-i));s.height=n.height,s.leaf=n.leaf,No(n,this.toBBox),No(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this.data=Ho([e,t]),this.data.height=e.height+1,this.data.leaf=!1,No(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,o=1/0,i=1/0;for(let s=t;s<=n-t;s++){const t=Vo(e,0,s,this.toBBox),a=Vo(e,s,n,this.toBBox),c=Yo(t,a),l=Bo(t)+Bo(a);c<o?(o=c,r=s,i=l<i?l:i):c===o&&l<i&&(i=l,r=s)}return r||n-t}_chooseSplitAxis(e,t,n){const r=e.leaf?this.compareMinX:Ro,o=e.leaf?this.compareMinY:Uo;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,o)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);const o=this.toBBox,i=Vo(e,0,t,o),s=Vo(e,n-t,n,o);let a=jo(i)+jo(s);for(let r=t;r<n-t;r++){const t=e.children[r];Do(i,e.leaf?o(t):t),a+=jo(i)}for(let r=n-t-1;r>=t;r--){const t=e.children[r];Do(s,e.leaf?o(t):t),a+=jo(s)}return a}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)Do(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)0===e[n].children.length?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():No(e[n],this.toBBox)}}}),Wo=j(Ko),zo={};function Zo(){if(qo)return zo;qo=1,Object.defineProperty(zo,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},n={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function r(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function o(e,t,n={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return r({type:"Point",coordinates:e},t,n)}function i(e,t,n={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return r({type:"Polygon",coordinates:e},t,n)}function s(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return r({type:"LineString",coordinates:e},t,n)}function a(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function c(e,t,n={}){return r({type:"MultiLineString",coordinates:e},t,n)}function l(e,t,n={}){return r({type:"MultiPoint",coordinates:e},t,n)}function u(e,t,n={}){return r({type:"MultiPolygon",coordinates:e},t,n)}function d(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e*r}function p(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e/r}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return zo.areaFactors=n,zo.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},zo.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},zo.convertArea=function(e,t="meters",r="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=n[t];if(!o)throw new Error("invalid original units");const i=n[r];if(!i)throw new Error("invalid final units");return e/o*i},zo.convertLength=function(e,t="kilometers",n="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),n)},zo.degreesToRadians=function(e){return e%360*Math.PI/180},zo.earthRadius=e,zo.factors=t,zo.feature=r,zo.featureCollection=a,zo.geometry=function(e,t,n={}){switch(e){case"Point":return o(t).geometry;case"LineString":return s(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},zo.geometryCollection=function(e,t,n={}){return r({type:"GeometryCollection",geometries:e},t,n)},zo.isNumber=f,zo.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},zo.lengthToDegrees=function(e,t){return h(p(e,t))},zo.lengthToRadians=p,zo.lineString=s,zo.lineStrings=function(e,t,n={}){return a(e.map(e=>s(e,t)),n)},zo.multiLineString=c,zo.multiPoint=l,zo.multiPolygon=u,zo.point=o,zo.points=function(e,t,n={}){return a(e.map(e=>o(e,t)),n)},zo.polygon=i,zo.polygons=function(e,t,n={}){return a(e.map(e=>i(e,t)),n)},zo.radiansToDegrees=h,zo.radiansToLength=d,zo.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const n=Math.pow(10,t||0);return Math.round(e*n)/n},zo.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")})},zo.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")},zo}var Qo,ei={};function ti(){if(Qo)return ei;Qo=1,Object.defineProperty(ei,"__esModule",{value:!0});var e=Zo();function t(e,n,r){if(null!==e)for(var o,i,s,a,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var x=0;x<c;x++){var E=0,S=0;if(null!==(a=d?u.geometries[x]:u)){l=a.coordinates;var w=a.type;switch(p=!r||"Polygon"!==w&&"MultiPolygon"!==w?0:1,w){case null:break;case"Point":if(!1===n(l,h,v,E,S))return!1;h++,E++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===n(l[o],h,v,E,S))return!1;h++,"MultiPoint"===w&&E++}"LineString"===w&&E++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===n(l[o][i],h,v,E,S))return!1;h++}"MultiLineString"===w&&E++,"Polygon"===w&&S++}"Polygon"===w&&E++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(S=0,i=0;i<l[o].length;i++){for(s=0;s<l[o][i].length-p;s++){if(!1===n(l[o][i][s],h,v,E,S))return!1;h++}S++}E++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===t(a.geometries[o],n,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function n(e,t){var n;switch(e.type){case"FeatureCollection":for(n=0;n<e.features.length&&!1!==t(e.features[n].properties,n);n++);break;case"Feature":t(e.properties,0)}}function r(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function o(e,t){var n,r,o,i,s,a,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(n=0;n<g;n++){for(a=h?e.features[n].geometry:f?e.geometry:e,l=h?e.features[n].properties:f?e.properties:{},u=h?e.features[n].bbox:f?e.bbox:void 0,d=h?e.features[n].id:f?e.id:void 0,s=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,o=0;o<s;o++)if(null!==(i=c?a.geometries[o]:a))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(r=0;r<i.geometries.length;r++)if(!1===t(i.geometries[r],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,n){o(t,function(t,r,o,i,s){var a,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==n(e.feature.call(void 0,t,o,{bbox:i,id:s}),r,0)&&void 0}switch(c){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:a,coordinates:t.coordinates[l]};if(!1===n(e.feature.call(void 0,u,o),r,l))return!1}})}function s(n,r){i(n,function(n,o,i){var s=0;if(n.geometry){var a=n.geometry.type;if("Point"!==a&&"MultiPoint"!==a){var c,l=0,u=0,d=0;return!1!==t(n,function(t,a,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(s=0);var g=e.lineString.call(void 0,[c,t],n.properties);if(!1===r(g,o,i,f,s))return!1;s++,c=t})&&void 0}}})}function a(t,n){if(!t)throw new Error("geojson is required");i(t,function(t,r,o){if(null!==t.geometry){var i=t.geometry.type,s=t.geometry.coordinates;switch(i){case"LineString":if(!1===n(t,r,o,0,0))return!1;break;case"Polygon":for(var a=0;a<s.length;a++)if(!1===n(e.lineString.call(void 0,s[a],t.properties),r,o,a))return!1}}})}return ei.coordAll=function(e){var n=[];return t(e,function(e){n.push(e)}),n},ei.coordEach=t,ei.coordReduce=function(e,n,r,o){var i=r;return t(e,function(e,t,o,s,a){i=0===t&&void 0===r?e:n(i,e,t,o,s,a)},o),i},ei.featureEach=r,ei.featureReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},ei.findPoint=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.coordIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":return e.point.call(void 0,l,c,n);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,n);case"LineString":return a<0&&(a=l.length+a),e.point.call(void 0,l[a],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a),e.point.call(void 0,l[s][a],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),e.point.call(void 0,l[i][a],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a),e.point.call(void 0,l[i][s][a],c,n)}throw new Error("geojson is invalid")},ei.findSegment=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.segmentIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":case"MultiPoint":return null;case"LineString":return a<0&&(a=l.length+a-1),e.lineString.call(void 0,[l[a],l[a+1]],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a-1),e.lineString.call(void 0,[l[s][a],l[s][a+1]],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a-1),e.lineString.call(void 0,[l[i][a],l[i][a+1]],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a-1),e.lineString.call(void 0,[l[i][s][a],l[i][s][a+1]],c,n)}throw new Error("geojson is invalid")},ei.flattenEach=i,ei.flattenReduce=function(e,t,n){var r=n;return i(e,function(e,o,i){r=0===o&&0===i&&void 0===n?e:t(r,e,o,i)}),r},ei.geomEach=o,ei.geomReduce=function(e,t,n){var r=n;return o(e,function(e,o,i,s,a){r=0===o&&void 0===n?e:t(r,e,o,i,s,a)}),r},ei.lineEach=a,ei.lineReduce=function(e,t,n){var r=n;return a(e,function(e,o,i,s){r=0===o&&void 0===n?e:t(r,e,o,i,s)}),r},ei.propEach=n,ei.propReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},ei.segmentEach=s,ei.segmentReduce=function(e,t,n){var r=n,o=!1;return s(e,function(e,i,s,a,c){r=!1===o&&void 0===n?e:t(r,e,i,s,a,c),o=!0}),r},ei}var ni,ri,oi={};function ii(){if(ni)return oi;ni=1,Object.defineProperty(oi,"__esModule",{value:!0});var e=ti();function t(t,n={}){if(null!=t.bbox&&!0!==n.recompute)return t.bbox;const r=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r}var n=t;return oi.bbox=t,oi.default=n,oi}var si=function(){if(ri)return To.exports;ri=1;var e=Wo,t=Zo(),n=ti(),r=ii().default,o=n.featureEach;n.coordEach,t.polygon;var i=t.featureCollection;function s(t){var n=new e(t);return n.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.insert.call(this,t)},n.load=function(t){var n=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}),e.prototype.load.call(this,n)},n.remove=function(t,n){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.remove.call(this,t,n)},n.clear=function(){return e.prototype.clear.call(this)},n.search=function(t){var n=e.prototype.search.call(this,this.toBBox(t));return i(n)},n.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},n.all=function(){var t=e.prototype.all.call(this);return i(t)},n.toJSON=function(){return e.prototype.toJSON.call(this)},n.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},n.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=r(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=r(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},n}return To.exports=s,To.exports.default=s,To.exports}(),ai=B(si);function ci(e,t){var n={},r=[];if("LineString"===e.type&&(e=Ve(e)),"LineString"===t.type&&(t=Ve(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=li(e,t);return o&&r.push(o),Be(r)}var i=ai();return i.load(Co(t)),qe(Co(e),function(e){qe(i.search(e),function(t){var o=li(e,t);if(o){var i=Mo(o).join(",");n[i]||(n[i]=!0,r.push(o))}})}),Be(r)}function li(e,t){var n=Mo(e),r=Mo(t);if(2!==n.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==r.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=n[0][0],i=n[0][1],s=n[1][0],a=n[1][1],c=r[0][0],l=r[0][1],u=r[1][0],d=r[1][1],p=(d-l)*(s-o)-(u-c)*(a-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(s-o)*(i-l)-(a-i)*(o-c);if(0===p)return null;var g=h/p,y=f/p;return g>=0&&g<=1&&y>=0&&y<=1?De([o+g*(s-o),i+g*(a-i)]):null}function ui(e,t,n){void 0===n&&(n={});var r=De([1/0,1/0],{dist:1/0}),o=0;return We(e,function(e){for(var i=Mo(e),s=0;s<i.length-1;s++){var a=De(i[s]);a.properties.dist=bo(t,a,n);var c=De(i[s+1]);c.properties.dist=bo(t,c,n);var l=bo(a,c,n),u=Math.max(a.properties.dist,c.properties.dist),d=Kn(a,c),p=Io(t,u,d+90,n),h=Io(t,u,d-90,n),f=ci(Ue([p.geometry.coordinates,h.geometry.coordinates]),Ue([a.geometry.coordinates,c.geometry.coordinates])),g=null;f.features.length>0&&((g=f.features[0]).properties.dist=bo(t,g,n),g.properties.location=o+bo(a,g,n)),a.properties.dist<r.properties.dist&&((r=a).properties.index=s,r.properties.location=o),c.properties.dist<r.properties.dist&&((r=c).properties.index=s+1,r.properties.location=o+l),g&&g.properties.dist<r.properties.dist&&((r=g).properties.index=s),o+=l}}),r}function di(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function pi(e,t){var n=function(e,t,n,r){void 0===r&&(r={});var o=di(e),i=$e(o[0]),s=$e(o[1]),a=$e(n),c=Ye(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a));return De([Xe(i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l))),Xe(l)],r.properties)}(e,function(e,t,n){void 0===n&&(n={});var r=di(e),o=di(t),i=$e(o[1]-r[1]),s=$e(o[0]-r[0]),a=$e(r[1]),c=$e(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return Ge(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}(e,t)/2,Kn(e,t));return n}var hi=function(){return hi=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},hi.apply(this,arguments)},fi=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],n=0;n<e.features.length;n++){var r=e.features[n],o=r.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var s=this.features.unknow.snapPoints;i=hi(hi({},i),s)}var a=this.doSnap(r,i);t.push(a)}else if(void 0!==this.features.unknow){s=this.features.unknow.snapPoints,a=this.doSnap(r,s);t.push(a)}else t.push(r)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return bo(De(e),De(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var n=e.geometry.coordinates;for(var r in t)this.isPointSnapped(n,t[r])&&(e.geometry.coordinates=t[r]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],s=0;s<o.length;s++){for(var a=o[s],c=[],l=0;l<a.length;l++){var u=a[l],d=!1;for(var r in t)if(this.isPointSnapped(u,t[r])){d=!0,c.push(t[r]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var r in t)if(this.isPointSnapped(h,t[r])){d=!0,c.push(t[r]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,n=this.map.unproject(t),r=[t.x+this.options.radius,t.y],o=this.map.unproject(r),i=bo(De([n.lng,n.lat]),De([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var s=!1,a=this.getCloseFeatures(e,i);a?(this.snapStatus=!0,this.snapCoords=a.coords,s=function(e,t,n={}){const r=n.steps||64,o=n.properties?n.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<r;o++)i.push(Wn(e,t,-360*o/r,n).geometry.coordinates);return i.push(i[0]),Re([i],o)}(a.coords,i,{steps:64,units:"meters",properties:{color:a.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=Be(0==s?[]:[s]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(Be([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var n=e.map.getSource("mapbox-gl-draw-hot");if(n){var r=n._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];r.features.length>0&&(r.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],n=t[0].toFixed(6),r=t[1].toFixed(6),o={};if(o["".concat(n,"_").concat(r)]=t,e){var i=e._data;if(i.features.length>0){var s=i.features.find(function(e){return"feature"==e.properties.meta});if(s){var a=s.properties.id;this.features[a]?this.features[a].snapPoints["".concat(n,"_").concat(r)]=t:this.features[a]={id:a,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(n,"_").concat(r)]=t:this.features.unknow={id:a,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,n){var r,o=(r=[],Je(e,function(e){r.push(e)}),r),i=[];if(o.map(function(e){var r=bo(De(e),De([t.lng,t.lat]),{units:"meters"});r<n&&i.push({coords:e,dist:r,color:"#8bc34a"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.getLines=function(e,t,n){var r=[];switch(e.geometry.type){case"LineString":r.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){r.push(Ue(e))});break;case"Polygon":var o=Po(e.geometry);r.push(o);break;case"MultiPolygon":Po(e.geometry).coodinates.map(function(e){r.push(Ue(e))})}return r},e.prototype.searchInMidPoint=function(e,t,n){var r=this.getLines(e,t,n),o=[];r.map(function(e){o=o.concat(Co(e).features)});var i=[];if(o.map(function(e){var r=pi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=bo(r,De([t.lng,t.lat]),{units:"meters"});o<n&&i.push({coords:r.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,n){for(var r=this.getLines(e,t,n),o=[],i=0;i<r.length;i++){var s=ui(r[i],De([t.lng,t.lat]),{units:"meters"});void 0!==s.properties.dist&&s.properties.dist<n&&o.push({coords:s.geometry.coordinates,dist:s.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var n=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(n.length>0){for(var r,o=!1,i=0;i<n.length;i++){var s=n[i],a=this.options.rules,c=e.lngLat;if(o=!1,-1!==a.indexOf("vertex")&&null==r&&(r=this.searchInVertex(s,c,t))){o=!0;break}if(-1!==a.indexOf("midpoint")&&null==r&&(r=this.searchInMidPoint(s,c,t))){o=!0;break}if(-1!==a.indexOf("edge")&&null==r&&(r=this.searchInEdge(s,c,t))){o=!0;break}}return!!o&&r}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}();const gi="snap-helper-circle";function yi(e,t){!function n(){const r=e();null!==r&&(r?t(r):requestAnimationFrame(n))}()}function mi(e){if(!e||e._data&&Array.isArray(e._data?.features))return;let t={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>t,set:e=>{t=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}function vi(e,t,n={}){if(e._snapInitialized)return e._snapInstance;e._snapInitialized=!0;const{layers:r=[],radius:o=15,rules:i=["vertex","midpoint","edge"],status:s=!1,onSnapped:a=()=>{},colors:c={}}=n;function l(n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,e.getLayer(gi)&&e.removeLayer(gi),e.getSource(gi)&&e.removeSource(gi),mi(n);const c=new fi({map:e,drawing:t,options:{layers:r,radius:o,rules:i},status:s,onSnapped:a});let l=s;return Object.defineProperty(c,"status",{get:()=>l,set(){},configurable:!0}),c.setSnapStatus=e=>{l=e},c._defaultLayers=r,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(fi.prototype.__snapPatched)return;fi.prototype.__snapPatched=!0;const t=fi.prototype,n={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){if(!this.status)return;const t=n.setMapData.call(this,e);return e?.features?.length>0&&this.map?.getLayer(gi)&&this.map.setLayoutProperty(gi,"visibility","visible"),t},t.drawingSnapCheck=function(){if(this.status)return n.drawingSnapCheck.call(this)},t.getLines=function(e,t,r){const o=e.geometry;if(!o||!o.coordinates)return[];const i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>Re(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>Ue(e)):n.getLines.call(this,e,t,r)}catch(e){return console.log(e),[]}},t.getCloseFeatures=function(e,t){if(!this.status)return[];const r=this._activeLayers||this._defaultLayers||[];this.options.layers=r.filter(e=>this.map.getLayer(e));const o=this.options.radius||15,i=e.point;e.point=[[i.x-o,i.y-o],[i.x+o,i.y+o]];const s=n.getCloseFeatures.call(this,e,t);return e.point=i,s},t.searchInVertex=function(...t){const r=n.searchInVertex.apply(this,t);return r&&(r.color=e.vertex),r},t.searchInMidPoint=function(...t){const r=n.searchInMidPoint.apply(this,t);return r&&(r.color=e.midpoint),r},t.searchInEdge=function(...t){const r=n.searchInEdge.apply(this,t);return r&&(r.color=e.edge),r},t.snapToClosestPoint=function(e){if(this.status&&!this.map?._isZooming)try{const t=n.snapToClosestPoint.call(this,e);return this.closeFeatures?.length>100&&(this.closeFeatures.length=0),this.lines?.length>100&&(this.lines.length=0),t}catch(e){console.log(e),this.snapStatus=!1,this.snapCoords=null}}}({vertex:io.snapVertex,midpoint:io.snapMidpoint,edge:io.snapEdge,...c}),e.on("style.load",()=>{yi(()=>e._removed?null:e.getSource("mapbox-gl-draw-hot"),t=>{mi(t),e.getSource(gi)||e.addSource(gi,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(gi)||e.addLayer({id:gi,type:"fill",source:gi,paint:{"fill-color":["get","color"],"fill-opacity":.6},layout:{visibility:e._snapInstance?.status?"visible":"none"}}),e._snapInstance||l(t)})}),e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(gi)){e.setLayoutProperty(gi,"visibility","none");const t=e._snapInstance;t?.status&&e.setLayoutProperty(gi,"visibility","visible")}}),yi(()=>e._removed?null:e.getSource("mapbox-gl-draw-hot"),l)}const xi=({mapStyle:e,mapProvider:t,events:n,eventBus:r,snapLayers:o})=>{const{map:i}=t;Gt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Gt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Gt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";const s=new Gt({modes:{...Gt.modes,disabled:Yt,edit_vertex:to,draw_polygon:ro,draw_line:oo},styles:wo(e),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"});i.addControl(s);const a=i.getCanvas();let c=null;const l=e=>{1===e.touches.length&&(c={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},u=e=>{if("disabled"!==s.getMode()||!c)return void(c=null);const t=e.changedTouches[0],n=t.clientX-c.x,r=t.clientY-c.y;Date.now()-c.time<300&&Math.abs(n)<10&&Math.abs(r)<10&&a.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:t.clientX,clientY:t.clientY})),c=null};a.addEventListener("touchstart",l,{passive:!0}),a.addEventListener("touchend",u,{passive:!0}),t.draw=s,i._drawCurrentMapStyle=e,t.snapEnabled=!1;const d=(e=>{const t=[],n=()=>{e.fire("draw.undochange",{length:t.length})};return{push(e){t.push(e),n()},pop(){const e=t.pop();return n(),e},clear(){t.length=0,n()},get length(){return t.length}}})(i);t.undoStack=d,i._undoStack=d,vi(i,s,{layers:o,radius:10,rules:["vertex","edge"]});const p=e=>{i._drawCurrentMapStyle=e,i.once("idle",()=>{((e,t)=>{wo(t).forEach(t=>{Object.entries(t.paint).forEach(([n,r])=>{e.getLayer(`${t.id}.cold`)&&e.setPaintProperty(`${t.id}.cold`,n,r),e.getLayer(`${t.id}.hot`)&&e.setPaintProperty(`${t.id}.hot`,n,r)})})})(i,e);const t=i._drawEditContainer?.querySelector("[data-touch-vertex-target]");Zt(t,e)})};r.on(n.MAP_SET_STYLE,p);return r.on(n.MAP_SET_SIZE,e=>{i.fire("draw.scalechange",{scale:{small:1,medium:1.5,large:2}[e]})}),{draw:s,remove(){a.removeEventListener("touchstart",l),a.removeEventListener("touchend",u),r.off(n.MAP_SET_STYLE,p),s.deleteAll(),s.changeMode("disabled"),i.removeControl(s)}}},Ei=["stroke","fill","strokeWidth"],Si=e=>{if(!e)return{};const t={};for(const[n,r]of Object.entries(e))if(Ei.includes(n)&&"object"==typeof r&&null!==r){const e=Object.entries(r);e.length>0&&(t[n]=e[0][1]);for(const[r,o]of e)t[`${n}${r.charAt(0).toUpperCase()+r.slice(1)}`]=o}else t[n]=r;return t},wi=e=>({mobile:{slot:"actions",showLabel:e},tablet:{slot:"actions",showLabel:e},desktop:{slot:"actions",showLabel:e}}),_i={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertecies:null,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:n},InitComponent:({appState:t,appConfig:n,mapState:i,pluginConfig:s,pluginState:a,services:u,mapProvider:d,buttonConfig:p})=>{const{eventBus:h}=u,{crossHair:f}=i,g=["touch","keyboard"].includes(t.interfaceType);e(()=>{if(!i.isMapReady)return;const{remove:e}=xi({mapStyle:i.mapStyle,snapLayers:s.snapLayers,mapProvider:d,events:r,eventBus:h});return a.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:s.snapLayers?.length>0}),h.emit("draw:ready"),()=>e()},[i.isMapReady]),e(()=>{d.draw&&(d.draw._crossHair=f)},[d.draw,f]),e(()=>{if(["draw_polygon","draw_line"].includes(a.mode)&&g){const e=f.isVisible;return f.fixAtCenter(),()=>{e||f.hide()}}},[a.mode,t.interfaceType]),e(()=>{"edit_vertex"===a.mode&&d.map&&d.map.fire("draw.interfacetypechange",{interfaceType:t.interfaceType})},[t.interfaceType,a.mode]),e(()=>{if(!d.draw)return;const e=function({pluginState:e,mapProvider:t,buttonConfig:n,eventBus:r}){const{drawDone:i,drawAddPoint:s,drawUndo:a,drawDeletePoint:u,drawSnap:d,drawCancel:p}=n,{map:h,draw:f}=t,{dispatch:g,feature:y,tempFeature:m}=e,v=()=>{t.snapEnabled=!1,g({type:"SET_SNAP",payload:!1});const e=o(h);e&&(e.setSnapStatus?.(!1),l(e)),h.getLayer("snap-helper-circle")&&h.setLayoutProperty("snap-helper-circle","visibility","none")},x=()=>{t.undoStack?.clear(),g({type:"SET_MODE",payload:null}),g({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},E=()=>{f.trash(),m?.id&&f.delete(m.id),y&&f.add(y),v(),f.changeMode("disabled"),x(),r.emit("draw:cancelled",y)};let S=0;const w=["draw_polygon","draw_line"],_=e=>{w.includes(e.mode)||c(o(h),h)},M=()=>{const e=h.getStyle().layers||[];e.length&&!e[e.length-1].source?.startsWith("mapbox-gl-draw")&&e.filter(e=>e.source?.startsWith("mapbox-gl-draw")).forEach(e=>h.moveLayer(e.id))},b=e=>t=>{const n=t.features[0];v(),x(),setTimeout(()=>f.changeMode("disabled"),0),r.emit(e,n)},P=e=>{const t=e.features[0];r.emit("draw:updated",t)},I=b("draw:created"),C=b("draw:edited"),T=e=>{g({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),r.emit("draw:vertexselection",e)},L=e=>{g({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertecies:e.numVertecies}})},O=e=>{g({type:"SET_UNDO_STACK_LENGTH",payload:e.length})};return i.onClick=()=>{const e=f.getMode();v(),t.undoStack?.clear(),"edit_vertex"!==e?["draw_polygon","draw_line"].includes(e)&&f.changeMode("disabled"):h.fire("draw.editfinish",{features:[f.get(m.id)]})},p.onClick=E,a.onClick=()=>{if("edit_vertex"===f.getMode())return;const e=t.undoStack;if(!e?.length)return;const n=e.pop();h._undoInProgress=!0,setTimeout(()=>{h._undoInProgress=!1},100),h.fire("draw.undo",{operation:n})},d.onClick=()=>{const n=Date.now();if(n-S<300)return;S=n;const r=!e.snap;g({type:"TOGGLE_SNAP"}),t.snapEnabled=r;const i=o(h);i?.setSnapStatus&&i.setSnapStatus(r),!r&&i&&(l(i),h.getLayer("snap-helper-circle")&&h.setLayoutProperty("snap-helper-circle","visibility","none"))},h.on("styledata",M),h.on("draw.cancel",E),h.on("draw.create",I),h.on("draw.modechange",_),h.on("draw.editfinish",C),h.on("draw.update",P),h.on("draw.vertexselection",T),h.on("draw.vertexchange",L),h.on("draw.undochange",O),()=>{[i,s,a,u,d,p].forEach(e=>{e&&(e.onClick=null)}),h.off("styledata",M),h.off("draw.cancel",E),h.off("draw.create",I),h.off("draw.editfinish",C),h.off("draw.update",P),h.off("draw.modechange",_),h.off("draw.vertexselection",T),h.off("draw.vertexchange",L),h.off("draw.undochange",O)}}({mapProvider:d,buttonConfig:p,pluginState:a,eventBus:h});return()=>e()},[d,t,a])},buttons:[{id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!e.mode,...wi(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!["draw_polygon","draw_line"].includes(t.mode)||"touch"!==e.interfaceType,...wi(!0)},{id:"drawDone",label:"Done",variant:"primary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!["draw_polygon","draw_line","edit_vertex"].includes(e.mode),enableWhen:({pluginState:e})=>e.numVertecies>=("draw_polygon"===e.mode?3:2),...wi(!0)},{id:"drawMenu",label:"Menu",iconId:"menu",hiddenWhen:({pluginState:e})=>!["draw_polygon","draw_line","edit_vertex"].includes(e.mode),menuItems:[{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:({pluginState:e})=>!["draw_polygon","draw_line","edit_vertex"].includes(e.mode),enableWhen:({pluginState:e})=>e.undoStackLength>0},{id:"drawSnap",label:"Snap to feature",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,pressedWhen:({pluginState:e})=>!!e.snap},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:({pluginState:e})=>e.selectedVertexIndex>=0&&e.numVertecies>("Polygon"===e.tempFeature?.geometry?.type?3:2),hiddenWhen:({pluginState:e})=>!["simple_select","edit_vertex"].includes(e.mode)}],mobile:{slot:"bottom-right"},tablet:{slot:"top-middle"},desktop:{slot:"top-middle"}}],keyboardShortcuts:[{id:"drawStart",group:"Drawing",title:"Edit vertex",command:"<kbd>Spacebar</kbd></dd>"}],icons:[{id:"menu",svgContent:'<path d="m6 9 6 6 6-6"/>'},{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"check",svgContent:'<path d="M20 6 9 17l-5-5"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:({appState:e,appConfig:t,pluginConfig:n,pluginState:r,mapProvider:i,services:s},a,c={})=>{const{dispatch:l}=r,{draw:u,map:d}=i,{eventBus:p}=s;if(!u)return;p.emit("draw:started",{mode:"draw_polygon"});let h=null;h=void 0!==c.snapLayers?c.snapLayers:void 0!==n.snapLayers?n.snapLayers:null;const f=o(d);f?.setSnapLayers?f.setSnapLayers(h):h&&(d._pendingSnapLayers=h),l({type:"SET_HAS_SNAP_LAYERS",payload:h?.length>0});const{stroke:g,fill:y,strokeWidth:m,properties:v,...x}=c,E={...v,...Si({stroke:g,fill:y,strokeWidth:m})};u.changeMode("draw_polygon",{container:e.layoutRefs.viewportRef.current,vertexMarkerId:`${t.id}-cross-hair`,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:u._crossHair,getSnapEnabled:()=>!0===i.snapEnabled,featureId:a,...x,properties:E}),l({type:"SET_MODE",payload:"draw_polygon"})},newLine:({appState:e,appConfig:t,pluginConfig:n,pluginState:r,mapProvider:i,services:s},a,c={})=>{const{dispatch:l}=r,{draw:u,map:d}=i,{eventBus:p}=s;if(!u)return;p.emit("draw:started",{mode:"draw_line"});let h=null;h=void 0!==c.snapLayers?c.snapLayers:void 0!==n.snapLayers?n.snapLayers:null;const f=o(d);f?.setSnapLayers?f.setSnapLayers(h):h&&(d._pendingSnapLayers=h),l({type:"SET_HAS_SNAP_LAYERS",payload:h?.length>0});const{stroke:g,fill:y,strokeWidth:m,properties:v,...x}=c,E={...v,...Si({stroke:g,fill:y,strokeWidth:m})};u.changeMode("draw_line",{container:e.layoutRefs.viewportRef.current,vertexMarkerId:`${t.id}-cross-hair`,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:u._crossHair,getSnapEnabled:()=>!0===i.snapEnabled,featureId:a,...x,properties:E}),l({type:"SET_MODE",payload:"draw_line"})},editFeature:({appState:e,appConfig:t,mapState:n,pluginConfig:r,pluginState:i,mapProvider:s,services:a},c,l={})=>{const{dispatch:u}=i,{draw:d,map:p}=s,{eventBus:h}=a;if(!d)return!1;const f=d.get(c);if(!f)return!1;h.emit("draw:editstart",{mode:{LineString:"edit_line",Polygon:"edit_polygon"}[f.geometry.type]});let g=null;g=void 0===l.snapLayers?r.snapLayers??null:l.snapLayers;const y=o(p);y?.setSnapLayers?y.setSnapLayers(g):g&&(p._pendingSnapLayers=g),u({type:"SET_HAS_SNAP_LAYERS",payload:g?.length>0}),d.changeMode("edit_vertex",{container:e.layoutRefs.viewportRef.current,deleteVertexButtonId:`${t.id}-draw-delete-point`,undoButtonId:`${t.id}-draw-undo`,isPanEnabled:"keyboard"!==e.interfaceType,interfaceType:e.interfaceType,scale:{small:1,medium:1.5,large:2}[n.mapSize],featureId:c,getSnapEnabled:()=>!0===s.snapEnabled});const m=d.get(c);return u({type:"SET_FEATURE",payload:{feature:m,tempFeature:m}}),u({type:"SET_MODE",payload:"edit_vertex"}),!0},addFeature:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:o}=t;if(!r)return;const{stroke:i,fill:s,strokeWidth:a,properties:c,...l}=n,u={...l,properties:{...c,...Si({stroke:i,fill:s,strokeWidth:a})}};r.add(u,{userProperties:!0}),o.emit("draw:add",u)},deleteFeature:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:o}=t;r&&(r.delete(n),o.emit("draw:delete",{featureIds:n}))},split:({appState:e,appConfig:t,pluginState:n,mapProvider:r},i,s={})=>{const{dispatch:a}=n,{draw:c,map:l}=r;if(!c)return;const u=c.get(i),d=["stroke-inactive.cold",...s.snapLayers||[]],p=o(l);p?.setSnapLayers?p.setSnapLayers(d):s.snapLayers&&(l._pendingSnapLayers=d),a({type:"SET_HAS_SNAP_LAYERS",payload:!0}),c.changeMode("draw_line",{container:e.layoutRefs.viewportRef.current,vertexMarkerId:`${t.id}-cross-hair`,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,getSnapEnabled:()=>!0===r.snapEnabled,featureId:"_splitter",properties:{splitter:"invalid"}}),l.on("draw.create",e=>{const t=e.features[0],n=Jr(u,t);c.setFeatureProperty("_splitter","splitter",n?"valid":"invalid"),a({type:"SET_ACTION",payload:{name:"split",isValid:!!n}})});const h=((e,t)=>{let n;const r=(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)};return r.cancel=()=>{clearTimeout(n),n=null},r})(e=>{if(e.coordinates.length<2)return;const t={geometry:{type:"LineString",coordinates:e.coordinates}},n=!!Jr(u,t);e.properties.splitter=n?"valid":"invalid",e.ctx.store.render(),"edit_vertex"===c.getMode()&&a({type:"SET_ACTION",payload:{name:"split",isValid:n}})},50);l.on("draw.geometrychange",h),a({type:"SET_MODE",payload:"draw_line"}),a({type:"SET_ACTION",payload:{name:"split"}})},merge:({services:e},t)=>{console.log("merge"),console.log(t)}}};export{_i as manifest};