@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.
- package/assets/templates/add-polygons.njk +1 -1
- package/assets/templates/add-symbols.njk +4 -4
- package/assets/templates/draw-tools.njk +7 -7
- package/assets/templates/marker-panel.njk +5 -5
- package/assets/templates/place-marker.njk +8 -8
- package/assets/templates/search-control.njk +1 -1
- package/assets/templates/select-feature.njk +7 -7
- package/assets/templates/style-switcher.njk +4 -4
- package/assets/templates/toggle-marker-label.njk +3 -3
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/im-core.js.LICENSE.txt +0 -30
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +0 -20
- package/docs/api.md +3 -13
- package/docs/building-a-plugin.md +2 -2
- package/docs/examples/add-marker-with-panel.mdx +46 -44
- package/docs/examples/add-polygons.mdx +100 -98
- package/docs/examples/add-symbols.mdx +75 -73
- package/docs/examples/basic-map.mdx +16 -14
- package/docs/examples/button-map.mdx +16 -14
- package/docs/examples/draw-tools.mdx +119 -117
- package/docs/examples/place-marker.mdx +51 -49
- package/docs/examples/search-control.mdx +22 -20
- package/docs/examples/select-feature.mdx +107 -105
- package/docs/examples/style-switcher.mdx +47 -45
- package/docs/examples/toggle-marker-label.mdx +30 -28
- package/docs/getting-started.md +26 -24
- package/docs/plugins/draw.md +10 -10
- package/docs/plugins/interact.md +9 -9
- package/docs/plugins/plugin-descriptor.md +1 -1
- package/docs/plugins/search.md +3 -3
- package/docusaurus.config.cjs +23 -0
- package/package.json +3 -7
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/esm/index.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
- package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/esm/index.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
- package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/esm/index.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/esm/index.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/esm/index.js +1 -1
- package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/index.js +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/index.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/index.js +27 -4
- package/providers/beta/openlayers/src/index.test.js +47 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
- package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +41 -12
- package/providers/maplibre/src/index.test.js +43 -12
- package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
- package/providers/maplibre/src/utils/spatial.js +22 -12
- package/providers/maplibre/src/utils/spatial.test.js +6 -6
- package/providers/maplibre/src/utils/workerUrl.js +15 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
- package/rollup.esm.mjs +38 -1
- package/src/InteractiveMap/InteractiveMap.js +2 -1
- package/src/InteractiveMap/InteractiveMap.test.js +9 -2
- package/src/InteractiveMap/domStateManager.js +21 -1
- package/src/InteractiveMap/domStateManager.test.js +48 -1
- package/src/InteractiveMap/polyfills.js +4 -3
- package/src/InteractiveMap/polyfills.test.js +12 -0
- package/src/types.js +3 -5
- package/webpack.dev.mjs +2 -0
- package/webpack.umd.mjs +28 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,K as o,M as i,v as a,a as s,b as c,d as l,S as u,e as d,r as p,l as h,p as f,f as g,g as y,m,h as v,j as _,k as b,n as x,o as P,q as E,C as O,s as S,t as I,u as w,A as M}from"./im-draw-plugin.js";import{c as T,r as C,a as L,s as k,b as A,d as j,e as F,f as V}from"./liveDrawChecks.js";import N from"@babel/runtime/helpers/asyncToGenerator";import"preact/compat";import"@babel/runtime/helpers/objectWithoutProperties";import"preact/jsx-runtime";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"},R={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},U={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},B={POLYGON:"polygon",LINE:"line_string",POINT:"point"},G={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},H={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},Y={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},X={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},K={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},J={ACTIVE:"true",INACTIVE:"false"},$=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var q=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:J,classes:D,cursors:U,events:Y,geojsonTypes:G,interactions:$,meta:K,modes:H,sources:R,types:B,updateActions:X});function Z(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function z(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function W(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.ACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.INACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function ee(e){return void 0===e.featureTarget}function te(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===K.FEATURE)}function re(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===K.VERTEX)}function ne(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function oe(e){return"Escape"===e.key||27===e.keyCode}function ie(e){return"Enter"===e.key||13===e.keyCode}function ae(e){return"Backspace"===e.key||8===e.keyCode}function se(e){return"Delete"===e.key||46===e.keyCode}function ce(e){return"1"===e.key||49===e.keyCode}function le(e){return"2"===e.key||50===e.keyCode}function ue(e){return"3"===e.key||51===e.keyCode}function de(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var pe=Object.freeze({__proto__:null,isActiveFeature:W,isBackspaceKey:ae,isDeleteKey:se,isDigit1Key:ce,isDigit2Key:le,isDigit3Key:ue,isDigitKey:de,isEnterKey:ie,isEscapeKey:oe,isFeature:te,isInactiveFeature:Q,isOfMetaType:Z,isShiftDown:ne,isShiftMousedown:z,isTrue:function(){return!0},isVertex:re,noTarget:ee});function he(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function fe(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var 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 ge,ye,me={},ve={};function _e(){return ge||(ge=1,ve.RADIUS=6378137,ve.FLATTENING=1/298.257223563,ve.POLAR_RADIUS=6356752.3142),ve}var be=function(){if(ye)return me;ye=1;var e=_e();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 me.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}},me.ring=r,me}(),xe=he(be);const Pe={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Ee(e,t){const r=Pe[e.geometry.type]-Pe[t.geometry.type];return 0===r&&e.geometry.type===G.POLYGON?e.area-t.area:r}function Oe(e){return e.map(e=>(e.geometry.type===G.POLYGON&&(e.area=xe.geometry({type:G.FEATURE,property:{},geometry:e.geometry})),e)).sort(Ee).map(e=>(delete e.area,e))}function Se(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function 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 we=[K.FEATURE,K.MIDPOINT,K.VERTEX];var Me={click:function(e,t,r){return Te(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Te(e,t,r,r.options.touchBuffer)}};function Te(e,t,r,n){if(null===r.map)return[];const o=e?Se(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!==we.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))}),Oe(c)}function Ce(e,t){const r=Me.click(e,null,t),n={mouse:U.NONE};return r[0]&&(n.mouse=r[0].properties.active===J.ACTIVE?U.MOVE:U.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=U.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function Le(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function ke(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=Le(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Ae(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 Le(e.point,t.point)<n&&t.time-e.time<o}const je=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 Ve(){return Fe()}const Ne=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ve(),this.type=t.geometry.type};Ne.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Ne.prototype.incomingCoords=function(e){this.setCoordinates(e)},Ne.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ne.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Ne.prototype.setProperty=function(e,t){this.properties[e]=t},Ne.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:G.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Ne.prototype.internal=function(e){const t={id:this.id,meta:K.FEATURE,"meta:type":this.type,active:J.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){Ne.call(this,e,t)};(De.prototype=Object.create(Ne.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},De.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},De.prototype.getCoordinate=function(){return this.getCoordinates()};const Re=function(e,t){Ne.call(this,e,t)};(Re.prototype=Object.create(Ne.prototype)).isValid=function(){return this.coordinates.length>1},Re.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},Re.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Re.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Re.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ue=function(e,t){Ne.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ue.prototype=Object.create(Ne.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ue.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ue.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ue.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])},Ue.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))},Ue.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]]))},Ue.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ue.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:De,MultiLineString:Re,MultiPolygon:Ue},Ge=(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)},He=function(e,t){if(Ne.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 Ye(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(He.prototype=Object.create(Ne.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ve(),type:G.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},He.prototype.isValid=function(){return this.features.every(e=>e.isValid())},He.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},He.prototype.getCoordinate=function(e){return Ge(this.features,"getCoordinate",e)},He.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===G.POLYGON?e.getCoordinates():e.coordinates)))},He.prototype.updateCoordinate=function(e,t,r){Ge(this.features,"updateCoordinate",e,t,r),this.changed()},He.prototype.addCoordinate=function(e,t,r){Ge(this.features,"addCoordinate",e,t,r),this.changed()},He.prototype.removeCoordinate=function(e){Ge(this.features,"removeCoordinate",e),this.changed()},He.prototype.getFeatures=function(){return this.features},Ye.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Ye.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Ye.prototype.getSelected=function(){return this._ctx.store.getSelected()},Ye.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Ye.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Ye.prototype.getFeature=function(e){return this._ctx.store.get(e)},Ye.prototype.select=function(e){return this._ctx.store.select(e)},Ye.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Ye.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Ye.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Ye.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Ye.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Ye.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Ye.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Ye.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Ye.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Ye.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Ye.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return Me[r](e,t,this._ctx)},Ye.prototype.newFeature=function(e){const t=e.geometry.type;return t===G.POINT?new De(this._ctx,e):t===G.LINE_STRING?new Re(this._ctx,e):t===G.POLYGON?new Ue(this._ctx,e):new He(this._ctx,e)},Ye.prototype.isInstanceOf=function(e,t){if(e===G.POINT)return t instanceof De;if(e===G.LINE_STRING)return t instanceof Re;if(e===G.POLYGON)return t instanceof Ue;if("MultiFeature"===e)return t instanceof He;throw new Error(`Unknown feature class: ${e}`)},Ye.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Ye.prototype.onSetup=function(){},Ye.prototype.onDrag=function(){},Ye.prototype.onClick=function(){},Ye.prototype.onMouseMove=function(){},Ye.prototype.onMouseDown=function(){},Ye.prototype.onMouseUp=function(){},Ye.prototype.onMouseOut=function(){},Ye.prototype.onKeyUp=function(){},Ye.prototype.onKeyDown=function(){},Ye.prototype.onTouchStart=function(){},Ye.prototype.onTouchMove=function(){},Ye.prototype.onTouchEnd=function(){},Ye.prototype.onTap=function(){},Ye.prototype.onStop=function(){},Ye.prototype.onTrash=function(){},Ye.prototype.onCombineFeature=function(){},Ye.prototype.onUncombineFeature=function(){},Ye.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Xe={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Ke=Object.keys(Xe);function Je(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Ye(r));return{start(){o=i.onSetup(n),Ke.forEach(t=>{const r=Xe[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 $e(e){return[].concat(e).filter(e=>void 0!==e)}function qe(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(R.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(R.COLD).setData({type:G.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(R.HOT).setData({type:G.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Ze(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,qe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(Y.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(Y.RENDER,{})}))},this.isDirty=!1}function ze(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}Ze.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ze.prototype.setDirty=function(){return this.isDirty=!0,this},Ze.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(Y.CREATE,{features:[t.toGeoJSON()]})}return this},Ze.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(Y.UPDATE,{action:t.action?t.action:X.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ze.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ze.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ze.prototype.getAllIds=function(){return this._featureIds.values()},Ze.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ze.prototype.delete=function(e,t={}){const r=[];return $e(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(Y.DELETE,{features:r}),ze(this,t),this},Ze.prototype.get=function(e){return this._features[e]},Ze.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Ze.prototype.select=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Ze.prototype.deselect=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),ze(this,t),this},Ze.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ze.prototype.setSelected=function(e,t={}){return e=$e(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},Ze.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ze.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ze.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ze.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Ze.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Ze.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ze.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:X.CHANGE_PROPERTIES})},Ze.prototype.storeMapConfig=function(){$.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Ze.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Ze.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const We=["mode","feature","mouse"];function Qe(e){let t=null,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]=Je(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:U.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!ke(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Ae(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=Ce(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Ce(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Ce(t,e);t.featureTarget=n,ke(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=Me.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=Me.touch(t,null,e)[0];t.featureTarget=r,Ae(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=ae(e),r=se(e),n=de(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=je(c,e),o.silent||e.map.fire(Y.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(D.CANVAS)&&((ae(t)||se(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):ce(t)&&e.options.controls.point?c(H.DRAW_POINT):le(t)&&e.options.controls.line_string?c(H.DRAW_LINE_STRING):ue(t)&&e.options.controls.polygon&&c(H.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,a=je(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(Y.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];We.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=`${D.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(D.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(D.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=`${D.CONTROL_GROUP} ${D.CONTROL_BASE}`,r?(r[B.POINT]&&(t[B.POINT]=s(B.POINT,{container:n,className:D.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(H.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[B.LINE]&&(t[B.LINE]=s(B.LINE,{container:n,className:D.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(H.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[B.POLYGON]&&(t[B.POLYGON]=s(B.POLYGON,{container:n,className:D.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(H.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:D.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:D.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:D.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 Ze(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(R.COLD,{data:{type:G.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(R.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(R.COLD)&&e.map.removeSource(R.COLD),e.map.getSource(R.HOT)&&e.map.removeSource(R.HOT)}};return e.setup=n,n}const et="#3bb2d0",tt="#fbb03b",rt="#fff";var nt=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],tt,et],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],tt,et],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":rt}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],tt,et]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":rt}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":tt}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":tt}}];function ot(e,t){this.x=e,this.y=t}function it(e,t){const r=t.getBoundingClientRect();return new ot(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function at(e,t,r,n){return{type:G.FEATURE,properties:{meta:K.VERTEX,parent:e,coord_path:r,active:n?J.ACTIVE:J.INACTIVE},geometry:{type:G.POINT,coordinates:t}}}function st(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return ct(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>ct(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ut(e);default:throw new Error("unknown GeoJSON type")}}function ct(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=lt(e.properties),null==e.geometry?t.geometry=null:t.geometry=ut(e.geometry),t}function lt(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=lt(n):t[r]=n}),t):t}function ut(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ut(e)),t):(t.coordinates=dt(e.coordinates),t)}function dt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>dt(e))}function pt(e,t={}){return ht(e,"mercator",t)}function ht(e,n,o={}){var i=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&t(e[0])?e="mercator"===n?ft(e):gt(e):(!0!==i&&(e=st(e)),r(e,function(e){var t="mercator"===n?ft(e):gt(e);e[0]=t[0],e[1]=t[1]})),e}function ft(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 gt(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 yt(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=pt(n),a=pt(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ht(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:G.FEATURE,properties:{meta:K.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:G.POINT,coordinates:u}}}function mt(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=at(i,e,l,c(l));if(t.midpoints&&o){const e=yt(i,o,u);e&&a.push(e)}o=u;const d=JSON.stringify(e);n!==d&&a.push(u),0===s&&(n=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===G.POINT?a.push(at(i,o,r,c(r))):n===G.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===G.LINE_STRING?s(o,r):0===n.indexOf(G.MULTI_PREFIX)&&function(){const r=n.replace(G.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:G.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(mt(i,t,o))})}(),a}ot.prototype={clone(){return new ot(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,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:ot},ot.convert=function(e){if(e instanceof ot)return e;if(Array.isArray(e))return new ot(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new ot(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var vt={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:_t,LAT_MAX:bt,LAT_RENDERED_MIN:xt,LAT_RENDERED_MAX:Pt,LNG_MIN:Et,LNG_MAX:Ot}=q;function St(e,t){let r=_t,n=bt,o=_t,i=bt,a=Ot,s=Et;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),d>s&&(s=d)});const c=t;return r+c.lat>Pt&&(c.lat=Pt-r),o+c.lat>bt&&(c.lat=bt-o),n+c.lat<xt&&(c.lat=xt-n),i+c.lat<_t&&(c.lat=_t-i),a+c.lng<=Et&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=Ot&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function It(e,t){const r=St(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===G.POINT?a=n(t):e.type===G.LINE_STRING||e.type===G.MULTI_POINT?a=t.map(n):e.type===G.POLYGON||e.type===G.MULTI_LINE_STRING?a=t.map(o):e.type===G.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const wt={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(Y.UPDATE,{action:X.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let 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(){vt.enable(this)},onMouseMove:function(e,t){return te(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};wt.onTap=wt.onClick=function(e,t){return ee(t)?this.clickAnywhere(e,t):Z(K.VERTEX)(t)?this.clickOnVertex(e,t):te(t)?this.clickOnFeature(e,t):void 0},wt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),vt.enable(this),this.stopExtendedInteractions(e)},wt.clickOnVertex=function(e,t){this.changeMode(H.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:U.MOVE})},wt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},wt.clickOnFeature=function(e,t){vt.disable(this),this.stopExtendedInteractions(e);const r=ne(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==G.POINT)return this.changeMode(H.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:U.POINTER}),1===n.length&&vt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:U.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:U.MOVE})),this.doRender(o)},wt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),W(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&z(t)?this.startBoxSelect(e,t):void 0},wt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=it(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},wt.onTouchStart=function(e,t){if(W(t))return this.startOnActiveFeature(e,t)},wt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},wt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:U.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(D.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=it(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"},wt.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};It(this.getSelected(),r),e.dragMoveLocation=t.lngLat},wt.onTouchEnd=wt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,it(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:U.MOVE}))}this.stopExtendedInteractions(e)},wt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?J.ACTIVE:J.INACTIVE,r(t),this.fireActionable(),t.properties.active===J.ACTIVE&&t.geometry.type!==G.POINT&&mt(t).forEach(r)},wt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},wt.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:G.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(Y.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},wt.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(Y.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const Mt=Z(K.VERTEX),Tt=Z(K.MIDPOINT),Ct={fireUpdate:function(){this.fire(Y.UPDATE,{action:X.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);ne(t)||-1!==n?ne(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){It(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=St(n.map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.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(H.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(H.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===G.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),vt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){vt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=J.ACTIVE,r(t),mt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=J.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(H.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=W(t),n=Mt(t),o=Tt(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:U.MOVE}):this.updateUIClasses({mouse:U.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ct.onTouchStart=Ct.onMouseDown=function(e,t){return Mt(t)?this.onVertex(e,t):W(t)?this.onFeature(e,t):Tt(t)?this.onMidpoint(e,t):void 0},Ct.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},Ct.onClick=function(e,t){return ee(t)?this.clickNoTarget(e,t):W(t)?this.clickActiveFeature(e,t):Q(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ct.onTap=function(e,t){return ee(t)?this.clickNoTarget(e,t):W(t)?this.clickActiveFeature(e,t):Q(t)?this.clickInactive(e,t):void 0},Ct.onTouchEnd=Ct.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Lt={};function kt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Lt.onSetup=function(){const e=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:U.ADD}),this.activateUIButton(B.POINT),this.setActionableState({trash:!0}),{point:e}},Lt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)},Lt.onTap=Lt.onClick=function(e,t){this.updateUIClasses({mouse:U.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(Y.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.point.id]})},Lt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Lt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?J.ACTIVE:J.INACTIVE,!n)return r(t)},Lt.onTrash=Lt.stopDrawingAndRemove,Lt.onKeyUp=function(e,t){if(oe(t)||ie(t))return this.stopDrawingAndRemove(e,t)};const At={onSetup:function(){const e=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),vt.disable(this),this.updateUIClasses({mouse:U.ADD}),this.activateUIButton(B.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&kt(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:U.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:U.POINTER})}};At.onTap=At.onClick=function(e,t){return re(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},At.onKeyUp=function(e,t){oe(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)):ie(t)&&this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},At.onStop=function(e){this.updateUIClasses({mouse:U.NONE}),vt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(Y.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT,{},{silent:!0})))},At.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?J.ACTIVE:J.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=K.FEATURE,r(at(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(at(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:G.FEATURE,properties:t.properties,geometry:{coordinates:e,type:G.LINE_STRING}}),3===o)return}return r(t)}},At.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)};const jt={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:G.FEATURE,properties:{},geometry:{type:G.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),vt.disable(this),this.updateUIClasses({mouse:U.ADD}),this.activateUIButton(B.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&kt(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&kt(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:U.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:U.POINTER})}};jt.onTap=jt.onClick=function(e,t){if(re(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},jt.onKeyUp=function(e,t){ie(t)?this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]}):oe(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT))},jt.onStop=function(e){vt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(Y.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT,{},{silent:!0})))},jt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)},jt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?J.ACTIVE:J.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=K.FEATURE,r(at(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 Ft={simple_select:wt,direct_select:Ct,draw_point:Lt,draw_polygon:At,draw_line_string:jt};const Vt={defaultMode:H.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:nt,modes:Ft,controls:{},userProperties:!1,suppressAPIEvents:!0},Nt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Dt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Rt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?R.HOT:R.COLD}))}var Ut,Bt;var Gt,Ht,Yt=he(Bt?Ut:(Bt=1,Ut=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}));var Xt=function(){if(Ht)return Gt;Ht=1,Gt=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 Gt}(),Kt=he(Xt);function Jt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const $t={Polygon:Ue,LineString:Re,Point:De,MultiPolygon:He,MultiLineString:He,MultiPoint:He};var qt=Object.freeze({__proto__:null,CommonSelectors:pe,ModeHandler:je,StringSet:Ie,constrainFeatureMovement:St,createMidPoint:yt,createSupplementaryPoints:mt,createVertex:at,doubleClickZoom:vt,euclideanDistance:Le,featuresAt:Me,getFeatureAtAndSetCursors:Ce,isClick:ke,isEventAtCoordinates:kt,isTap:Ae,mapEventToBoundingBox:Se,moveFeatures:It,sortFeatures:Oe,stringSetsAreEqual:Jt,theme:nt,toDenseArray:$e});const Zt=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({},Dt,e.controls):t.controls=Object.assign({},Nt,e.controls),t=Object.assign({},Vt,t),t.styles=Rt(t.styles,"cold").concat(Rt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=H;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Me.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(r){if(void 0===r.type||r.type!==G.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(Kt(t))).features.map(t=>{if(t.id=t.id||Ve(),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=$t[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,Yt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Yt(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:G.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==H.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(H.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===H.DIRECT_SELECT?e.events.changeMode(H.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===H.SIMPLE_SELECT&&t.getMode()===H.SIMPLE_SELECT?(Jt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===H.DIRECT_SELECT&&t.getMode()===H.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=Qe(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=B,t.options=e,t};function zt(e){Zt(e,this)}zt.modes=Ft,zt.constants=q,zt.lib=qt;var Wt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},Qt="draw.create",er="draw.update",tr="draw.modechange",rr="draw.editfinish",nr="draw.cancel",or="draw.vertexselection",ir="draw.vertexchange",ar="draw.undochange",sr="draw.undo",cr="draw.geometrychange",lr="draw.interfacetypechange",ur="draw.placementblocked",dr="draw.nudgevertex",pr="draw.selectvertex",hr="draw.insertvertexatmidpoint",fr="styledata",gr=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[]}},yr=e=>{var t=gr(e),r=mr(e);if(!t.length||!r.length)return[];var n=[];for(var o of r)for(var i=o.closed?o.length:o.length-1,a=0;a<i;a++){var s=o.start+a,c=o.start+(a+1)%o.length,[l,u]=t[s],[d,p]=t[c];n.push([(l+d)/2,(u+p)/2])}return n},mr=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},vr=(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},_r=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},br=(e,t)=>{var r=t.split(".").map(Number),n=mr(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]},xr=(e,t)=>({x:e.x*t,y:e.y*t}),Pr=e=>e instanceof window.SVGElement||e.ownerSVGElement;function Er(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 Or(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Er(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Er(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Sr(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function Ir(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 wr(e){return Ir(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Mr(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function Tr(e,t){e&&(e._autoSnapSuspended=t)}function Cr(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Lr(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 kr(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 Ar(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var jr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r=>n=>r.call(e,t,n),o={keydown:n(e.onKeydown),keyup:n(e.onKeyup),pointerdown:n(e.onPointerevent),pointermove:n(e.onPointerevent),pointerup:n(e.onPointerevent),click:n(e.onButtonClick),touchstart:n(e.onTouchstart),touchmove:n(e.onTouchmove),touchend:n(e.onTouchend),scalechange:n(e.onScaleChange),move:n(e.onMove),interfacetypechange:n(e.onInterfaceTypeChange)};for(var[i,a]of Object.entries(r))o[i]=n(a);return o},Fr=(e,t,r)=>{window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),t.on("draw.scalechange",r.scalechange),t.on("move",r.move),t.on(lr,r.interfacetypechange),t.on(dr,r.nudge)},Vr=(e,t,r)=>{e.container.removeEventListener("pointerdown",r.pointerdown),e.container.removeEventListener("pointermove",r.pointermove),e.container.removeEventListener("pointerup",r.pointerup),e.container.removeEventListener("touchstart",r.touchstart),e.container.removeEventListener("touchmove",r.touchmove),e.container.removeEventListener("touchend",r.touchend),t.off("draw.scalechange",r.scalechange),t.off("move",r.move),t.off(lr,r.interfacetypechange),t.off(dr,r.nudge),t.dragPan.enable(),window.removeEventListener("click",r.click),window.removeEventListener("keydown",r.keydown,{capture:!0}),window.removeEventListener("keyup",r.keyup,{capture:!0})},Nr=e=>{var t=Sr(e);t&&Lr(t,e)},Dr={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,r){e&&setTimeout(()=>{var n=this.getFeature(r);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){var t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}};function Rr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ur(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Rr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Br={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},Gr=Ur(Ur({},Dr),{},{UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Br,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r),this.emitGeometryValidation(Br[r.type],r.vertexIndex,r.featureId)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=mr(i),c=vr(s,r);if(c){_r(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,xr(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=mr(o),s=vr(a,r);if(s)_r(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=mr(i),c=vr(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)_r(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,xr(this.map.project(e.vertices[r]),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertices=this.getVertices(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}}),Hr=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Yr=(e,t,r,n,o)=>{var i=window.getComputedStyle(t),a={x:r.x-Number.parseFloat(i.left),y:r.y-Number.parseFloat(i.top)},s=e.project(n);return{deltaTarget:a,deltaVertex:{x:r.x/o-s.x,y:r.y/o-s.y}}},Xr=(e,t,r)=>{var n={x:r.x/t.scale-t.deltaVertex.x,y:r.y/t.scale-t.deltaVertex.y},o=e.unproject(n);if(Ar(t)){var i=Sr(e);Mr(i,e,n),o=wr(i)||o}return o};function Kr(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 Jr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Kr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Kr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var $r=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=C(t,r);L(e,{editActive:n,editHalo:o,editVertex:i})}},qr={addTouchVertexTarget(e){e.touchVertexTarget=T(e.container),$r(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||Pr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(kr(Sr(this.map)),null!=e&&e.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xr(this.map.project(t),e.scale))}},onTap(e,t){var r,n,o=Sr(this.map);o&&Lr(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=br(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(Jr(Jr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){kr(Sr(this.map));var r=this.getVertices(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&Pr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=Hr(t);Object.assign(e,Yr(this.map,e.touchVertexTarget,o,n,e.scale))}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&Pr(t.target.parentNode)){e._touchMoved=!0;var r=Hr(t);this.moveVertex(e,Xr(this.map,e,r)),this.updateTouchVertexTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}},Zr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),zr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Wr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Qr=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Wr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},en=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,tn={handleUndoShortcut(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},rn={getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?o.nudgeAmount:o.stepAmount,[i,a]=t?zr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+i,y:r.y+a})},getOffsetByDelta(e,t,r,n){var i=this.map.project(e),a=n?o.stepAmount:o.nudgeAmount;return this.map.unproject({x:i.x+t*a,y:i.y+r*a})},resolveSnapTarget(e,t,r,o,i){var a=Sr(this.map);if(Ar(e)&&e._isSnapped&&a){var s=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:n.snapRadius}(a)+1,c=this.map.project(o);return e._isSnapped=!1,Lr(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return Ar(e)&&a&&(Mr(a,this.map,this.map.project(l)),Ir(a))?(e._isSnapped=!0,wr(a)):(e._isSnapped=!1,l)}};function nn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function on(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?nn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):nn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var an=on(on({},rn),{},{updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(e,t){var[r,n]=this.getVertexOrMidpoint(e,t);r<0||!n||this.changeMode(e,on({selectedVertexIndex:r,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,r)}))},getNewCoord(e,t){return this.getOffset(gr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=gr(i))||void 0===o?void 0:o[e.selectedVertexIndex]);if(a){var s=[...a],c=e.selectedVertexIndex,l=this.resolveSnapTarget(e,t,r,a,()=>this.getOffsetByDelta(a,t,r,n));this.moveVertex(e,l),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:c,previousPosition:s})}}},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertices.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=mr(o),s=r+1,c=null,l=0,u=0;for(var d of a){var p=d.closed?d.length:d.length-1;if(r<u+p){c=d,l=r-u+1,s=d.start+l;break}u+=p}c&&(_r(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=mr(o),s=vr(a,e.selectedVertexIndex);s&&(_r(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=mr(t),n=vr(r,e.selectedVertexIndex);if(n){var{segment:o}=n,a=o.closed?i.Polygon:i.LineString;if(!(o.length<=a)){var s=[...e.vertices[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:s}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}}),sn={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e,n[0]):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=mr(r),o=vr(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return gr(this.getFeature(e))},getMidpoints(e){return yr(this.getFeature(e))},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertices)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertices.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=k(a,i,t);return[s,s<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=mr(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertices.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertices.length}};function cn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ln(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?cn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var un=ln(ln({},tn),{},{onKeydown(e,t){Qr(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Zr.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?en(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){var t,r,n=Sr(this.map);n&&Lr(n,this.map),null!==(t=e.vertices)&&void 0!==t&&t.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertices)&&void 0!==r&&r.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){var r;if("midpoint"!==e.selectedVertexType){var n=this.getFeature(e.featureId),o=n&&(null===(r=gr(n))||void 0===r?void 0:r[e.selectedVertexIndex]);o&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...o],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,o)))}else this.insertVertex(e,t)},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Qr(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&A(t),Zr.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&null!=e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=null)),"Delete"===t.key&&this.deleteVertex(e))}}),dn={onMouseDown(e,t){var r,n;kr(Sr(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,Ct.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=br(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertices)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=br(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(or,{index:e.selectedVertexIndex,numVertices:e.vertices.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(or,{index:r,numVertices:e.vertices.length})}Ct.onClick.call(this,e,t)},onMouseUp(e,t){kr(Sr(this.map));var r=e._isInsertingVertex&&null!=e._insertedVertexIndex,n=this._didVertexMove(e);(e.dragMoving||n||r)&&(this.syncVertices(e),r?this._recordInsertionUndo(e):n&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,Ct.onMouseUp.call(this,e,t)},_didVertexMove(e){var t;if(!e._moveStartPosition||null==e._moveStartIndex)return!1;var r=this.getFeature(e.featureId),n=r&&(null===(t=gr(r))||void 0===t?void 0:t[e._moveStartIndex]);return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){var t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(or,{index:t,numVertices:e.vertices.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=Sr(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),Ar(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),Mr(n,this.map,t.point);var o=wr(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Ct.onDrag.call(this,e,t)}}};function pn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function hn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?pn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):pn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var fn=hn(hn(hn(hn(hn(hn(hn(hn({},zt.modes.direct_select),Gr),qr),an),sn),un),dn),{},{onSetup(e){var t,r,n,o=zt.modes.direct_select.onSetup.call(this,e);(Object.assign(o,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:o.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1}),this.map._lastEditFeatureId!==o.featureId)&&(null===(n=this.map._undoStack)||void 0===n||n.clear(),this.map._lastEditFeatureId=o.featureId);var i=this.getFeature(o.featureId);if(o.featureType=null==i?void 0:i.type,o.vertices=this.getVertices(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o),Nr(this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var a=o.vertices[o.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(o,xr(this.map.project(a),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=this.handlers=jr(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint});Fr(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(pr,t.selectvertex),this.map.on(hr,t.insertvertexatmidpoint)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertices.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=gr(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(or,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});var c=o||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?xr(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?xr(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xr(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertices[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,xr(this.map.project(r),e.scale))},onSelectVertex(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));var n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,hn({selectedVertexIndex:t.index,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}))},onInsertVertexAtMidpoint(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex(hn(hn({},e),{},{selectedVertexIndex:t.index,selectedVertexType:"midpoint"}))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",hn(hn({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(pr,t.selectvertex),this.map.off(hr,t.insertvertexatmidpoint),Vr(e,this.map,t),this.hideTouchVertexIndicator(e)}});function gn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function yn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?gn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var mn={move_point:"commit-move"},vn=yn(yn({},Dr),{},{UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:mn,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_point"===r.type&&this.undoMovePoint(e,r),this.emitGeometryValidation(mn[r.type],r.vertexIndex,r.featureId)}},undoMovePoint(e,t){var{previousPosition:r,featureId:n}=t,o=this.getFeature(n);o&&(o.updateCoordinate("",r[0],r[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,xr(this.map.project(r),e.scale)))}}),_n={addTouchPointTarget(e){e.touchPointTarget=T(e.container),$r(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){kr(Sr(this.map)),e._touchMoved&&e._moveStartPosition&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._touchMoved=!1,e.feature&&this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){kr(Sr(this.map));var r=this.getPointCoord(e);if(r&&Pr(t.target.parentNode)){e._moveStartPosition=[...r],e._touchMoved=!1;var n=Hr(t);Object.assign(e,Yr(this.map,e.touchPointTarget,n,r,e.scale))}},onTouchmove(e,t){if(Pr(t.target.parentNode)){e._touchMoved=!0;var r=Hr(t);this.movePoint(e,Xr(this.map,e,r)),this.updateTouchPointTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}};function bn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function xn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?bn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):bn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Pn=xn(xn({},rn),{},{getPointCoord(e){var t;return null===(t=this.getFeature(e.featureId))||void 0===t?void 0:t.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,r,n){var o=this.getPointCoord(e);if(o){var i=[...o],a=this.resolveSnapTarget(e,t,r,o,()=>this.getOffsetByDelta(o,t,r,n));this.movePoint(e,a),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}}});function En(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function On(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?En(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):En(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Sn=On(On({},tn),{},{onKeydown(e,t){Qr(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Zr.has(t.key)?this.handleArrowKey(e,t):en(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){var r=this.getPointCoord(e);r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r]),this.movePoint(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Qr(e)||(e.interfaceType="keyboard",A(t),Zr.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}}),In="edit_point",wn={onFeature(e,t){e.dragMoving||(e._moveStartPosition=[...e.feature.coordinates],e._grabOffset=[e.feature.coordinates[0]-t.lngLat.lng,e.feature.coordinates[1]-t.lngLat.lat],Tr(Sr(this.map),!0)),Ct.onFeature.call(this,e,t)},onClick(e,t){if(!W(t)&&((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=a(r,{mode:In,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:In,vertexIndex:0}),n})(this.map,[t.lngLat.lng,t.lngLat.lat])){var r=[...e.feature.coordinates],n=Sr(this.map),o=t.lngLat;Ar(e)&&n&&(Mr(n,this.map,t.point),o=wr(n)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:r})}},onMouseUp(e,t){var r=Sr(this.map);kr(r),Tr(r,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Ct.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;var t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var r=Sr(this.map);if(r&&(r.snapStatus=!1,r.snapCoords=null),Ar(e)&&null!=r&&r.status){if(e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};Mr(r,this.map,this.map.project([n.lng,n.lat]));var o=wr(r)||n;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Ct.onDrag.call(this,e,t)}},onTrash(){}};function Mn(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 Tn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Mn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Mn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Cn=Tn(Tn(Tn(Tn(Tn(Tn(Tn({},zt.modes.direct_select),vn),_n),Pn),Sn),wn),{},{onSetup(e){var t,r,n=e.featureId,o=this.getFeature(n);if(!o)throw new Error("You must provide a featureId to enter edit_point mode");var i,a={featureId:n,feature:o,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};(this.setSelectedCoordinates([]),this.setSelected(n),vt.disable(this),this.setActionableState({trash:!1}),Object.assign(a,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:null!==(t=e.scale)&&void 0!==t?t:1}),this.map._lastEditFeatureId!==a.featureId)&&(null===(i=this.map._undoStack)||void 0===i||i.clear(),this.map._lastEditFeatureId=a.featureId);return this.setupEventListeners(a),this.map._drawEditContainer=e.container,this.addTouchPointTarget(a),null===(r=a.container)||void 0===r||r.focus({preventScroll:!0}),Nr(this.map),"touch"===a.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(a,xr(this.map.project(a.feature.coordinates),a.scale))},0),this.map.fire(or,{index:0,numVertices:1}),a},setupEventListeners(e){var t=this.handlers=jr(this,e,{nudge:this.onNudgePoint});Fr(e,this.map,t)},toDisplayFeatures(e,t,r){t.properties.active=e.featureId===t.properties.id?"true":"false",r(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Vr(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}});function Ln(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 kn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ln(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ln(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var An=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?kn(kn({},e),{},{featureId:null}):e,a=kn(kn({},t.onSetup.call(this,i)),e);a[r].properties=e.properties;var{container:s,vertexMarkerId:c,getInterfaceType:l}=a,u=l?l():a.interfaceType;a.interfaceType=u;var d=s.querySelector("#".concat(c));a.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(a):this._hideCrossHair(a),a.crossHair&&(a.crossHair.activate=()=>{var e;return null===(e=this._placeAtCrossHair)||void 0===e?void 0:e.call(this,a)});var p=(e,t)=>this[e]=t.bind(this,a),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(e=>{var[t,r]=e;return p(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"keyup",A,{capture:!0}],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(e=>{var[t,r,n,o]=e;return t.addEventListener?t.addEventListener(r,n,o):t.on(r,n)}),a},onStop(e){var r;t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n,o]=e;return t.removeEventListener?t.removeEventListener(r,n,o):t.off(r,n)}),null!==(r=e.crossHair)&&void 0!==r&&r.activate&&(e.crossHair.activate=null),["touch","keyboard"].includes(e.interfaceType)||this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function jn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Fn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?jn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):jn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vn=(e,t,r,n,o)=>{setTimeout(()=>{var i=t(n);i&&e.fire("draw.geometrychange",((e,t,r)=>{var n=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[n]}:{type:"LineString",coordinates:n},properties:{}},phase:r,vertexIndex:Math.max(0,n.length-1)}})(i,r,o))},0)},Nn=e=>{var{geometryType:t,getFeature:r,getCoords:n}=e;return{_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(e,o){var i=r(e);if(!i||!o)return!0;var a=s({placed:n(i).slice(0,-1),point:o,geometryType:t,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Vn(this.map,r,n,e,t)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onCreate(e,t){((e,t,r)=>{e.delete(t.id),t.id=r,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}},Dn=e=>{var{ParentMode:t,getFeature:r,getCoords:n,validateClick:o,finishOnInvalidClick:i}=e;return{onClick(e,a){var s;if(!this._isIgnorableClick(a)&&(!1!==this.map._drawGeometryValid||"vertex"!==(null===(s=a.featureTarget)||void 0===s||null===(s=s.properties)||void 0===s?void 0:s.meta))){var c=Sr(this.map);if(Ar(e)&&Ir(c))a=function(e,t){var r=wr(t);return r?Or(Or({},e),{},{lngLat:r}):e}(a,c);else if(!((e,t)=>{var a=n(r(e));return a.length>0&&(a[a.length-1]=[t.lngLat.lng,t.lngLat.lat]),i||o(r(e))})(e,a))return;if(this._canPlaceVertex(e,[a.lngLat.lng,a.lngLat.lat])){var l=n(r(e)).length;t.onClick.call(this,e,a),n(r(e)).length>l&&(this.pushDrawUndo(e),this.dispatchVertexChange(n(r(e))),this.emitDrawValidation(e))}}},doClick(e){if(!this.map._undoInProgress){var a=r(e),s=n(a);if(this.dispatchVertexChange(s),o(a)){var c=Sr(this.map),l=Ar(e)&&function(e,t){var r=wr(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(this._canPlaceVertex(e,[u.lng,u.lat])){l?(t.onClick.call(this,e,l),this._ctx.store.render()):this._simulateMouse("click",t.onClick,e);var d=n(r(e));this.pushDrawUndo(e),this.dispatchVertexChange(d),this.emitDrawValidation(e)}}else i&&!1!==this.map._drawGeometryValid&&(s.pop(),this.map.fire("draw.create",{features:[a.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[a.id]}))}},_placeAtCrossHair(e){this.doClick(e)}}};function Rn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Un(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Rn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Bn=e=>{var{geometryType:t,getFeature:r}=e;return{pushDrawUndo(e){var n=this.map._undoStack;n&&!this.map._undoInProgress&&n.push({type:"draw_vertex",geometryType:t,featureId:r(e).id})},onUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"draw_vertex"===(null==r?void 0:r.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))}},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}},Gn=e=>{var{ParentMode:t,geometryType:r,getCoords:n,getFeature:o}=e;return{undoVertex(e){var t=o(e),r=n(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_removeLastVertex(e,t,o){var i="Polygon"===r?t.coordinates[0]:o;i.splice(-2,1),i[i.length-1]=[...i[i.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(t))},_updateRubberBand(e,n){if(["touch","keyboard"].includes(e.interfaceType))this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render();else{var o=n["Polygon"===r?n.length-2:n.length-1],i={lng:o[0],lat:o[1]},a=this.map.project(i);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}this.dispatchVertexChange(n)}}},Hn=e=>{var{ParentMode:t,featureProp:r,geometryType:n}=e;return{_reinitializeFeature(e,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(e,i);var a=this.map.getCenter(),s=[[a.lng,a.lat],[a.lng,a.lat]],c=this.newFeature({type:"Feature",properties:e.properties||{},geometry:{type:n,coordinates:[s]}});return c.id=i,this._ctx.store.add(c),e[r]=c,e.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render(),this.dispatchVertexChange(s),!0},_restartLineStringDraw(e,t){var r=this.map._undoStack;return r&&r.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}},Yn=e=>{var{ParentMode:t,getFeature:r,INTERFACE_KEYS:n}=e;return{onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(e,n){var o=document.activeElement;if(!o||o===e.container||!e.container.contains(o))if("Escape"!==n.key)o!==e.container&&t.onKeyUp.call(this,e,n);else if("keyboard"===e.interfaceType){var i=this.map._undoStack;i&&i.clear(),this._reinitializeFeature(e,r(e))}}}};function Xn(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 Kn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Jn=e=>{var{ParentMode:t,getFeature:r,getCoords:n}=e;return{onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(e,r){if(Ar(e)){var n=Sr(this.map);Mr(n,this.map,r.point);var o=wr(n);o&&(r=Kn(Kn({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e,r){var n="move"===(null==r?void 0:r.type)&&!r.originalEvent;if(["touch","keyboard"].includes(e.interfaceType)||n){Ar(e)&&Cr(Sr(this.map),this.map);var o=Sr(this.map),i=Ar(e)&&wr(o);if(i){var a=this.map.project([i.lng,i.lat]);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}else this._simulateMouse("mousemove",t.onMouseMove,e)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(r(e)))}}},$n=e=>{var{ParentMode:t,geometryType:r,getFeature:n,getPlacedCoords:o}=e;return{_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},toDisplayFeatures(e,i,a){t.toDisplayFeatures.call(this,e,i,a);var s=n(e);i.geometry.type===r&&i.properties.id===s.id&&o(i).forEach(e=>a({type:"Feature",properties:{meta:"draw-vertex",parent:s.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}};function qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Zn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zn=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s,finishOnInvalidClick:c,getFeature:e=>e[r],INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return Zn(Zn(Zn(Zn(Zn(Zn(Zn({},e),An(l)),(e=>Fn(Fn({},Nn(e)),Dn(e)))(l)),(e=>Un(Un(Un({},Bn(e)),Gn(e)),Hn(e)))(l)),Yn(l)),Jn(l)),$n(l))},Wn=zn(zt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>c(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Qn=zn(zt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>l(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)});function eo(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 to(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?eo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):eo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ro="draw_point",no=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),oo=zt.modes.draw_point,io=An({ParentMode:oo,featureProp:"point",excludeFeatureIdFromSetup:!1}),ao={onKeyUp(){},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},onCreate(e,t){var r,n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),null===(r=e.resolvePointSymbol)||void 0===r||r.call(e,e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){var r="move"===(null==t?void 0:t.type)&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||r)&&Ar(e)&&Cr(Sr(this.map),this.map)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onTouchStart(e){this._setInterface(e,"touch"),this.onMove(e)},onTouchEnd(e){this._setInterface(e,"touch"),this.onMove(e)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onMouseMove(e,t){Ar(e)&&Mr(Sr(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),no.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&no.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(!(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())){var r=Sr(this.map),n=Ar(e)&&Ir(r)?wr(r):null;this._commit(e,n||t.lngLat)}},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){var t=Sr(this.map);Ar(e)&&Cr(t,this.map);var r=Ar(e)&&Ir(t)?wr(t):null;this._commit(e,r||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=a(r,{mode:ro,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:ro,vertexIndex:0}),n})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},so=to(to(to({},oo),io),ao),co=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],lo=["get","user_sortKey"],uo=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":lo},paint:{"fill-color":co(e,"fill",t.shapeFill)}}),po=(e,t)=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round","line-sort-key":lo},paint:{"line-color":co(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),ho=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}}),fo=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),go=(e,t,r)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),yo=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),mo=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),vo=(e,t,r)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),_o=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),bo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),xo=function(e){var t,r,n,o,i,a=C(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:s,midpointRadius:c,vertexHaloRadius:l,midpointHaloRadius:d}=u;return[uo(e,a),(i=a.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":i}}),(o=a.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":o,"line-width":2,"line-opacity":1}}),(n=a.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":n,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),po(e,a),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":lo},paint:{}},(r=a.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":r,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(t=a.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t,"line-width":2,"line-opacity":1}}),ho(a.editStroke),mo(a.editMidpoint,c),vo(a.editHalo,a.editActive,d),_o(a.editMidpoint,c),fo(a.editVertex,s),go(a.editHalo,a.editActive,l),yo(a.editVertex,s),bo(a.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function Po(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 Eo(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 Oo(e,t,r){void 0===r&&(r={});var n=Po(e),o=Po(t),i=d(o[1]-n[1]),a=d(o[0]-n[0]),s=d(n[1]),c=d(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return p(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function So(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 Io(e,t,r,n={}){const o=So(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),p=g(u),y=g(l);return void 0!==o[2]?f([p,y,o[2]],n.properties):f([p,y],n.properties)}function wo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return m(e,t);return v(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Mo(e,t,r={}){if(!0===r.final)return function(e,t){let r=Mo(t,e);return r=(r+180)%360,r}(e,t);const n=So(e),o=So(t),i=d(n[0]),a=d(o[0]),s=d(n[1]),c=d(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 g(Math.atan2(l,u))}var To=Mo;function Co(e,t,r,n){void 0===n&&(n={});var o=Po(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),p=g(u),y=g(l);return f([p,y],n.properties)}function Lo(e){if(!e)throw new Error("geojson is required");var t=[];return _(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=Eo(n);break;case"LineString":r=[Eo(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=v([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)}),b(t)}var ko={exports:{}};function Ao(e,t,r,n,o){jo(e,t,r||0,n||e.length-1,o||Vo)}function jo(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);jo(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(Fo(e,r,t),o(e[n],u)>0&&Fo(e,r,n);d<p;){for(Fo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?Fo(e,r,p):Fo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function Fo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Vo(e,t){return e<t?-1:e>t?1:0}function No(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Do(e,t){Ro(e,0,e.children.length,t,e)}function Ro(e,t,r,n,o){o||(o=qo(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];Uo(o,e.leaf?n(t):t)}return o}function Uo(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 Bo(e,t){return e.minX-t.minX}function Go(e,t){return e.minY-t.minY}function Ho(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Yo(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Xo(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 Ko(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 Jo(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 qo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Zo(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;Ao(e,a,t,r,o),i.push(t,a,a,r)}}var zo,Wo=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(!$o(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;$o(e,s)&&(t.leaf?r.push(a):Jo(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!$o(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($o(e,i)){if(t.leaf||Jo(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=qo([]),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=No(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!Jo(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=qo(e.slice(t,r+1)),Do(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=qo([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));Zo(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);Zo(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Do(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=Ho(a),c=Xo(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),Uo(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=qo(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Do(r,this.toBBox),Do(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=qo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Do(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=Ro(e,0,a,this.toBBox),s=Ro(e,a,r,this.toBBox),c=Ko(t,s),l=Ho(t)+Ho(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:Bo,o=e.leaf?this.compareMinY:Go;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=Ro(e,0,t,o),a=Ro(e,r-t,r,o);let s=Yo(i)+Yo(a);for(let n=t;n<r-t;n++){const t=e.children[n];Uo(i,e.leaf?o(t):t),s+=Yo(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Uo(a,e.leaf?o(t):t),s+=Yo(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Uo(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Do(e[r],this.toBBox)}}}),Qo=fe(Wo),ei={};function ti(){if(zo)return ei;zo=1,Object.defineProperty(ei,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},r={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function n(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function o(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:e},t,r)}function i(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:e},t,r)}function a(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:e},t,r)}function s(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return n({type:"MultiLineString",coordinates:e},t,r)}function l(e,t,r={}){return n({type:"MultiPoint",coordinates:e},t,r)}function u(e,t,r={}){return n({type:"MultiPolygon",coordinates:e},t,r)}function d(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e/n}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return ei.areaFactors=r,ei.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},ei.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},ei.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},ei.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),r)},ei.degreesToRadians=function(e){return e%360*Math.PI/180},ei.earthRadius=e,ei.factors=t,ei.feature=n,ei.featureCollection=s,ei.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")}},ei.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},ei.isNumber=f,ei.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},ei.lengthToDegrees=function(e,t){return h(p(e,t))},ei.lengthToRadians=p,ei.lineString=a,ei.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},ei.multiLineString=c,ei.multiPoint=l,ei.multiPolygon=u,ei.point=o,ei.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},ei.polygon=i,ei.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},ei.radiansToDegrees=h,ei.radiansToLength=d,ei.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},ei.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")})},ei.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")},ei}var ri,ni={};function oi(){if(ri)return ni;ri=1,Object.defineProperty(ni,"__esModule",{value:!0});var e=ti();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var _=0;_<c;_++){var b=0,x=0;if(null!==(s=d?u.geometries[_]:u)){l=s.coordinates;var P=s.type;switch(p=!n||"Polygon"!==P&&"MultiPolygon"!==P?0:1,P){case null:break;case"Point":if(!1===r(l,h,v,b,x))return!1;h++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,b,x))return!1;h++,"MultiPoint"===P&&b++}"LineString"===P&&b++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,b,x))return!1;h++}"MultiLineString"===P&&b++,"Polygon"===P&&x++}"Polygon"===P&&b++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(x=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-p;a++){if(!1===r(l[o][i][a],h,v,b,x))return!1;h++}x++}b++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(r=0;r<g;r++){for(s=h?e.features[r].geometry:f?e.geometry:e,l=h?e.features[r].properties:f?e.properties:{},u=h?e.features[r].bbox:f?e.bbox:void 0,d=h?e.features[r].id:f?e.id:void 0,a=(c=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=c?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,r){o(t,function(t,n,o,i,a){var s,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==r(e.feature.call(void 0,t,o,{bbox:i,id:a}),n,0)&&void 0}switch(c){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:s,coordinates:t.coordinates[l]};if(!1===r(e.feature.call(void 0,u,o),n,l))return!1}})}function a(r,n){i(r,function(r,o,i){var a=0;if(r.geometry){var s=r.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var c,l=0,u=0,d=0;return!1!==t(r,function(t,s,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return ni.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},ni.coordEach=t,ni.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},ni.featureEach=n,ni.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},ni.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")},ni.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")},ni.flattenEach=i,ni.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},ni.geomEach=o,ni.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},ni.lineEach=s,ni.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},ni.propEach=r,ni.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},ni.segmentEach=a,ni.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},ni}var ii,ai,si={};function ci(){if(ii)return si;ii=1,Object.defineProperty(si,"__esModule",{value:!0});var e=oi();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 si.bbox=t,si.default=r,si}var li=function(){if(ai)return ko.exports;ai=1;var e=Qo,t=ti(),r=oi(),n=ci().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 ko.exports=a,ko.exports.default=a,ko.exports}(),ui=he(li);function di(e,t){var r={},n=[];if("LineString"===e.type&&(e=x(e)),"LineString"===t.type&&(t=x(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=pi(e,t);return o&&n.push(o),b(n)}var i=ui();return i.load(Lo(t)),P(Lo(e),function(e){P(i.search(e),function(t){var o=pi(e,t);if(o){var i=Eo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),b(n)}function pi(e,t){var r=Eo(e),n=Eo(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],d=n[1][1],p=(d-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(d-l)*(o-c),g=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var y=h/p,m=g/p;return y>=0&&y<=1&&m>=0&&m<=1?f([o+y*(a-o),i+y*(s-i)]):null}function hi(e,t,r){void 0===r&&(r={});var n=f([1/0,1/0],{dist:1/0}),o=0;return _(e,function(e){for(var i=Eo(e),a=0;a<i.length-1;a++){var s=f(i[a]);s.properties.dist=Oo(t,s,r);var c=f(i[a+1]);c.properties.dist=Oo(t,c,r);var l=Oo(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=To(s,c),p=Co(t,u,d+90,r),h=Co(t,u,d-90,r),g=di(v([p.geometry.coordinates,h.geometry.coordinates]),v([s.geometry.coordinates,c.geometry.coordinates])),y=null;g.features.length>0&&((y=g.features[0]).properties.dist=Oo(t,y,r),y.properties.location=o+Oo(s,y,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),y&&y.properties.dist<n.properties.dist&&((n=y).properties.index=a),o+=l}}),n}function fi(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 gi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=fi(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),p=g(u),y=g(l);return f([p,y],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=fi(e),o=fi(t),i=d(o[1]-n[1]),a=d(o[0]-n[0]),s=d(n[1]),c=d(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return p(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,To(e,t));return r}var yi=function(){return yi=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},yi.apply(this,arguments)},mi=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=yi(yi({},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 Oo(f(e),f(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],d=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=Oo(f([r.lng,r.lat]),f([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(Io(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),y([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=b(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(b([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n=E(e),o=[];if(n.map(function(e){var n=Oo(f(e),f([t.lng,t.lat]),{units:"meters"});n<r&&o.push({coords:e,dist:n,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(v(e))});break;case"Polygon":var o=wo(e.geometry);n.push(o);break;case"MultiPolygon":wo(e.geometry).coodinates.map(function(e){n.push(v(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(Lo(e).features)});var i=[];if(o.map(function(e){var n=gi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Oo(n,f([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=hi(n[i],f([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}(),vi="snap-helper-circle",_i="mapbox-gl-draw-hot";function bi(e){if(!mi.prototype.__snapPatched){mi.prototype.__snapPatched=!0;var t=mi.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){var r,n;if(this.status){var o=t.setMapData.call(this,e);return(null==e||null===(r=e.features)||void 0===r?void 0:r.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(vi)&&this.map.setLayoutProperty(vi,"visibility","visible"),o}},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,r,n){var o=e.geometry;if(null==o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>y(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>v(e)):t.getLines.call(this,e,r,n)}catch(e){return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];var o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));var i=this.options.radius||n.snapRadius,a=e.point;e.point=[[a.x-i,a.y-i],[a.x+i,a.y+i]];var s=t.getCloseFeatures.call(this,e,r);return e.point=a,s}}(t,r),function(e,t,r){e.searchInVertex=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInVertex.apply(this,n);return i&&(i.color=r.vertex),i},e.searchInMidPoint=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInMidPoint.apply(this,n);return i&&(i.color=r.midpoint),i},e.searchInEdge=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInEdge.apply(this,n);return i&&(i.color=r.edge),i}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){var r;if(this.status&&(null===(r=this.map)||void 0===r||!r._isZooming)&&(!this._autoSnapSuspended||e._explicit))try{var n,o,i=t.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}}function xi(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function Pi(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}var Ei=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Oi(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(vi)&&e.removeLayer(vi),e.getSource(vi)&&e.removeSource(vi)}(e),Pi(r);var o=new mi({map:e,drawing:t,options:{layers:n.layers,radius:n.radius,rules:n.rules},status:n.status,onSnapped:n.onSnapped});return function(e,t,r){var n=t;Object.defineProperty(e,"status",{get:()=>n&&Ei.has(r.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{n=e}}(o,n.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,n.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function Si(e,t,r){e.on("style.load",()=>{xi(()=>e._removed?null:e.getSource(_i),n=>{Pi(n),function(e){var t;e.getSource(vi)||e.addSource(vi,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(vi)||e.addLayer({id:vi,type:"fill",source:vi,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Oi(e,t,n,r)})})}function Ii(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function wi(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:i=[],radius:a=n.snapRadius,rules:s=["vertex","midpoint","edge"],status:c=!1,onSnapped:l=()=>{},colors:u={}}=o,d={layers:i,radius:a,rules:s,status:c,onSnapped:l};return bi(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ii(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ii(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:O.snapVertex,midpoint:O.snapMidpoint,edge:O.snapEdge},u)),Si(t,r,d),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(vi)){e.setLayoutProperty(vi,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(vi,"visibility","visible")}})}(t),xi(()=>t._removed?null:t.getSource(_i),e=>Oi(t,r,e,d)),t._snapInstance}function Mi(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 Ti(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Mi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Mi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ci="point-symbol",Li=new Set(["".concat(Ci,".hot"),"".concat(Ci,".cold")]),ki=(e,t)=>{var r,n=(e=>{var t=["match",["get","user_symbolImageId"]];for(var[r,n]of Object.entries(e))t.push(r,["literal",n]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);null===(r=t.options)||void 0===r||null===(r=r.styles)||void 0===r||r.forEach(e=>{Li.has(e.id)&&(e.layout=Ti(Ti({},e.layout),{},{"icon-offset":n}))}),Li.forEach(t=>{e.getLayer(t)&&e.setLayoutProperty(t,"icon-offset",n)})},Ai=function(){var e=N(function*(e){var{draw:t,mapProvider:r,map:n,symbolRegistry:o,featureId:i,properties:a,pixelRatioOverride:s}=e;if(!S(a))return null;var c=n._drawCurrentMapStyle,l=null!=s?s:(e=>{var t;return(null===(t=e.getPixelRatio)||void 0===t?void 0:t.call(e))||1})(n);yield r.addSymbolsToMap([a],c,o,l);var u=t.get(i);if(!u)return null;var d=o.getSymbolImageId(a,c,"normal",l);if(!d)return null;var p=r.getActiveSymbolImageId(d),h=r.getSelectedSymbolImageId(d),f=r.getSymbolIconLayout(o.getSymbolDef(a));return((e,t,r,n)=>{var o;null!==(o=e._symbolIconOffsetMap)&&void 0!==o||(e._symbolIconOffsetMap={}),e._symbolIconOffsetMap[r]||(e._symbolIconOffsetMap[r]=n,ki(e,t))})(n,t,d,f["icon-offset"]),Ti(Ti({},u),{},{properties:Ti(Ti({},a),{},{symbolImageId:d,symbolIconAnchor:f["icon-anchor"],symbolActiveImageId:p,symbolSelectedImageId:h})})});return function(t){return e.apply(this,arguments)}}(),ji=function(){var e=N(function*(e){var t=yield Ai(e);t&&e.draw.add(t)});return function(t){return e.apply(this,arguments)}}(),Fi=function(){var e=N(function*(e){var t,{draw:r,mapProvider:n,map:o,symbolRegistry:i,pixelRatioOverride:a}=e;o._pointSymbolRefreshId=(null!==(t=o._pointSymbolRefreshId)&&void 0!==t?t:0)+1;var s=o._pointSymbolRefreshId,c=r.getAll().features.filter(e=>"Point"===e.geometry.type&&S(e.properties)),l=yield Promise.allSettled(c.map(e=>Ai({draw:r,mapProvider:n,map:o,symbolRegistry:i,featureId:e.id,properties:e.properties,pixelRatioOverride:a})));if(l.filter(e=>"rejected"===e.status).forEach(e=>{I.error("[draw] failed to resolve point symbol",e.reason)}),o._pointSymbolRefreshId===s){var u=l.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);u.length&&r.add({type:"FeatureCollection",features:u}),((e,t)=>{var r=e._symbolIconOffsetMap;if(r){var n=new Set(t.getAll().features.map(e=>{var t;return null===(t=e.properties)||void 0===t?void 0:t.symbolImageId})),o=Object.keys(r).filter(e=>!n.has(e));o.length&&(o.forEach(e=>delete r[e]),ki(e,t))}})(o,r)}});return function(t){return e.apply(this,arguments)}}();function Vi(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ni(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Vi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Vi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Di="mapbox-gl-draw-cold",Ri="mapbox-gl-draw-hot",Ui=e=>{var{map:t,draw:r,mapProvider:n,symbolRegistry:o,pluginConfig:i,onDone:a}=e,s=t._drawCurrentMapStyle;t.once("idle",()=>{var e,c=((e,t)=>{if(e.getSource(Di))return!1;var r={type:"FeatureCollection",features:[]};return e.addSource(Di,{data:r,type:"geojson"}),e.addSource(Ri,{data:r,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(t,r);!function(e,t){xo(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})}(t,s,i);var l=null===(e=t._drawEditContainer)||void 0===e?void 0:e.querySelector("[data-im-draw-touch-target]");$r(l,s,i),Fi({draw:r,mapProvider:n,map:t,symbolRegistry:o}).then(()=>{c&&r.set(r.getAll()),t.triggerRepaint(),a()}).catch(e=>I.error("[draw] failed to refresh point symbols after a style change",e))})},Bi=e=>{var t,{mapStyle:r,mapProvider:o,symbolRegistry:i,events:a,eventBus:s,snapLayers:c,pluginConfig:l={}}=e,{map:u}=o;zt.constants.classes.CONTROL_BASE="maplibregl-ctrl",zt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",zt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var d=Ni(Ni({},zt.modes),{},{disabled:Wt,edit_vertex:fn,edit_point:Cn,draw_polygon:Wn,draw_line:Qn,draw_point:so}),p=o._mapboxDrawInstance;p?Object.assign(p.modes,d):(p=new zt({modes:d,styles:xo(r,l),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),u.addControl(p),o._mapboxDrawInstance=p);var h=((e,t)=>{var r=e.getCanvas(),n=null,o=e=>{1===e.touches.length&&(n={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"===t.getMode()&&n){var o=e.changedTouches[0],i=o.clientX-n.x,a=o.clientY-n.y;Date.now()-n.time<300&&Math.abs(i)<10&&Math.abs(a)<10&&r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),n=null}else n=null};return r.addEventListener("touchstart",o,{passive:!0}),r.addEventListener("touchend",i,{passive:!0}),{remove(){r.removeEventListener("touchstart",o),r.removeEventListener("touchend",i)}}})(u,p);o.draw=p,u._drawCurrentMapStyle=r,u._drawPluginConfig=l,o.snapEnabled=!1;var f=o.undoStack;f||(f=j(e=>u.fire("draw.undochange",{length:e})),o.undoStack=f),u._undoStack=f;var g=C(r,l);wi(u,p,{layers:c,radius:null!==(t=l.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:g.snapVertex,edge:g.snapEdge}});var y=()=>s.emit(a.MAP_DATA_CHANGE),{handleSetMapStyle:m,handleStyleChanged:v}=(e=>{var{map:t,draw:r,mapProvider:n,symbolRegistry:o,pluginConfig:i,eventBus:a,events:s,notifyPointSymbolsRefreshed:c}=e,l=e=>{t._drawCurrentMapStyle=e};a.on(s.MAP_SET_STYLE,l);var u=!1,d=()=>{u||(u=!0,Ui({map:t,draw:r,mapProvider:n,symbolRegistry:o,pluginConfig:i,onDone:()=>{u=!1,c()}}))};return a.on(s.MAP_STYLE_CHANGE,d),{handleSetMapStyle:l,handleStyleChanged:d}})({map:u,draw:p,mapProvider:o,symbolRegistry:i,pluginConfig:l,eventBus:s,events:a,notifyPointSymbolsRefreshed:y}),_=e=>{u.fire("draw.scalechange",{scale:w[e]})};s.on(a.MAP_SET_SIZE,_);var b=e=>{Fi({draw:p,mapProvider:o,map:u,symbolRegistry:i,pixelRatioOverride:e}).then(()=>{u.triggerRepaint(),y()}).catch(e=>I.error("[draw] failed to refresh point symbols",e))};return s.on(a.MAP_SET_PIXEL_RATIO,b),{draw:p,remove(){h.remove(),s.off(a.MAP_SET_STYLE,m),s.off(a.MAP_STYLE_CHANGE,v),s.off(a.MAP_SET_SIZE,_),s.off(a.MAP_SET_PIXEL_RATIO,b),p.changeMode("disabled"),o.draw=null}}};function Gi(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?Gi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Gi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Yi=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),Xi=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),Ki=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),Ji=(e,t)=>{var r,n,o;if("draw_polygon"===e)return{feature:Yi(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1};if("draw_line"===e)return{feature:Xi(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1};if("edit_vertex"===e){var i,a=t[0];return Array.isArray(null==a?void 0:a[0])?{feature:Yi(t),numVertices:a.length}:{feature:Xi(t),numVertices:null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0}}return"edit_point"===e?{feature:Ki(t),numVertices:1}:null};class $i{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._symbolRegistry=t.symbolRegistry,this._bus=(n=new Map,{on(e,t){n.has(e)||n.set(e,new Set),n.get(e).add(t)},off(e,t){var r;null===(r=n.get(e))||void 0===r||r.delete(t)},emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var i=n.get(e);i&&Array.from(i).forEach(e=>e(...r))}}),this._editingFeatureId=null,this._sortKeyCounter=0;var{draw:o,remove:i}=Bi({mapStyle:t.mapStyle,mapProvider:e,symbolRegistry:t.symbolRegistry,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:null!==(r=t.pluginConfig)&&void 0!==r?r:{}});this._draw=o,this._cleanupDraw=i,this._liveStroke=F({onChange:(e,t)=>{this._applyStrokeInvalid(e);var r=this._draw.getMode();"edit_vertex"!==r&&"edit_point"!==r||this._bus.emit(M.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=V({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(M.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{var t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(M.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(M.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(M.CANCEL),vertexselection:e=>this._bus.emit(M.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(M.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(M.UNDO_CHANGE,e.length),update:e=>this._bus.emit(M.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(M.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(M.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(M.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(Qt,this._mapHandlers.create),this._map.on(rr,this._mapHandlers.editfinish),this._map.on(nr,this._mapHandlers.cancel),this._map.on(or,this._mapHandlers.vertexselection),this._map.on(ir,this._mapHandlers.vertexchange),this._map.on(ar,this._mapHandlers.undochange),this._map.on(er,this._mapHandlers.update),this._map.on(cr,this._mapHandlers.geometrychange),this._map.on(ur,this._mapHandlers.placementblocked),this._map.on(lr,this._mapHandlers.interfacetypechange),this._map.on(tr,this._mapHandlers.modechange),this._map.on(fr,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=null!==(t=r.featureId)&&void 0!==t?t:null);"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(r=Hi(Hi({},r),{},{resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)})),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){ji({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>I.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=Ji(t,e.coordinates);r&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:r.feature,numVertices:r.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update(Hi(Hi({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(lr,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if(("edit_vertex"===t||"edit_point"===t)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(rr,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==t&&"draw_line"!==t||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();"draw_polygon"!==t&&"draw_line"!==t||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(sr)}nudgeSelectedVertex(e,t,r){this._map.fire(dr,{dx:e,dy:t,isLargeStep:r})}getVertexItems(){var e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;var t=this._draw.get(this._editingFeatureId);if(!t)return e;var r=(e=>"Polygon"===e.type?Hi(Hi({},e),{},{coordinates:e.coordinates.map(e=>e.slice(0,-1))}):"MultiPolygon"===e.type?Hi(Hi({},e),{},{coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}):e)(t.geometry);return{vertices:gr(r),midpoints:yr(r)}}selectVertex(e){this._map.fire(pr,{index:e})}insertVertexAtMidpoint(e){this._map.fire(hr,{index:e})}setGeometryValid(e){this._map._drawGeometryValid=e}set _geometryValidator(e){this._map._drawGeometryValidator=e}get _geometryValidator(){return this._map._drawGeometryValidator}setInvalid(e){this._liveStroke.set(e)}_applyStrokeInvalid(e){this._setLayerVisibility("stroke-active",!e),this._setLayerVisibility("stroke-active-invalid",e),this._setLayerVisibility("fill-active",!e)}_setLayerVisibility(e,t){["hot","cold"].forEach(r=>{var n="".concat(e,".").concat(r);this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){var t,r,n=null==(null===(t=e.properties)||void 0===t?void 0:t.sortKey)?Hi(Hi({},e.properties),{},{sortKey:this._nextSortKey()}):e.properties,o=Hi(Hi({},e),{},{properties:n}),i=this._draw.add(o);return"Point"===(null===(r=o.geometry)||void 0===r?void 0:r.type)&&S(n)&&this._resolvePointSymbol(i[0],n),i}setStyle(e,t){var r=this._draw.get(e);r&&this.add(Hi(Hi({},r),{},{properties:Hi(Hi({},r.properties),t)}))}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=Sr(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(kr(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=Sr(this._map);null!=t&&t.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,r){this._draw.setFeatureProperty(e,t,r)}setDrawingPreviewProperty(e,t){var r,n=this._currentDrawEvent;null!=n&&n.properties&&(n.properties[e]=t),null==n||null===(r=n.ctx)||void 0===r||null===(r=r.store)||void 0===r||r.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]).has(e.mode)||Lr(Sr(this._map),this._map)}_handleStyleData(){var e,t=this._map.getStyle();if(t){this._liveStroke.refresh();var r=t.layers||[];!r.length||null!==(e=r[r.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||r.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>this._map.moveLayer(e.id))}}remove(){this._map.off(Qt,this._mapHandlers.create),this._map.off(rr,this._mapHandlers.editfinish),this._map.off(nr,this._mapHandlers.cancel),this._map.off(or,this._mapHandlers.vertexselection),this._map.off(ir,this._mapHandlers.vertexchange),this._map.off(ar,this._mapHandlers.undochange),this._map.off(er,this._mapHandlers.update),this._map.off(cr,this._mapHandlers.geometrychange),this._map.off(ur,this._mapHandlers.placementblocked),this._map.off(lr,this._mapHandlers.interfacetypechange),this._map.off(tr,this._mapHandlers.modechange),this._map.off(fr,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{$i as MaplibreDrawAdapter,Ji as displayedShape};
|
|
1
|
+
import{i as e,c as t,T as n,K as r,M as o,v as i,a as s,b as a,d as c,S as l,e as u,r as d,l as p,p as h,f,g,m,h as y,j as v,k as _,n as x,o as E,q as I,C as S,s as M,t as b,u as T,A as P}from"./im-draw-plugin.js";import{c as C,r as w,a as L,s as O,b as A,d as k,e as F,f as V}from"./liveDrawChecks.js";import"preact/compat";import"preact/jsx-runtime";const N={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},D={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},R={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},U={POLYGON:"polygon",LINE:"line_string",POINT:"point"},B={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},j={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},G={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},H={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},Y={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},X={ACTIVE:"true",INACTIVE:"false"},$=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var K=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:X,classes:N,cursors:R,events:G,geojsonTypes:B,interactions:$,meta:Y,modes:j,sources:D,types:U,updateActions:H});function J(e){return function(t){const n=t.featureTarget;return!!n&&(!!n.properties&&n.properties.meta===e)}}function q(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function Z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===X.ACTIVE&&e.featureTarget.properties.meta===Y.FEATURE))}function z(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===X.INACTIVE&&e.featureTarget.properties.meta===Y.FEATURE))}function W(e){return void 0===e.featureTarget}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===Y.FEATURE)}function ee(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===Y.VERTEX)}function te(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function ne(e){return"Escape"===e.key||27===e.keyCode}function re(e){return"Enter"===e.key||13===e.keyCode}function oe(e){return"Backspace"===e.key||8===e.keyCode}function ie(e){return"Delete"===e.key||46===e.keyCode}function se(e){return"1"===e.key||49===e.keyCode}function ae(e){return"2"===e.key||50===e.keyCode}function ce(e){return"3"===e.key||51===e.keyCode}function le(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var ue=Object.freeze({__proto__:null,isActiveFeature:Z,isBackspaceKey:oe,isDeleteKey:ie,isDigit1Key:se,isDigit2Key:ae,isDigit3Key:ce,isDigitKey:le,isEnterKey:re,isEscapeKey:ne,isFeature:Q,isInactiveFeature:z,isOfMetaType:J,isShiftDown:te,isShiftMousedown:q,isTrue:function(){return!0},isVertex:ee,noTarget:W});function de(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function pe(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){var n=!1;try{n=this instanceof e}catch{}return n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var he,fe,ge={},me={};function ye(){return he||(he=1,me.RADIUS=6378137,me.FLATTENING=1/298.257223563,me.POLAR_RADIUS=6356752.3142),me}var ve=function(){if(fe)return ge;fe=1;var e=ye();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(n(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(n(e[r]))}return t}function n(t){var n,o,i,s,a,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,s=u-1,a=0):c===u-1?(i=u-1,s=0,a=1):(i=c,s=c+1,a=c+2),n=t[i],o=t[s],l+=(r(t[a][0])-r(n[0]))*Math.sin(r(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function r(e){return e*Math.PI/180}return ge.geometry=function e(n){var r,o=0;switch(n.type){case"Polygon":return t(n.coordinates);case"MultiPolygon":for(r=0;r<n.coordinates.length;r++)o+=t(n.coordinates[r]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(r=0;r<n.geometries.length;r++)o+=e(n.geometries[r]);return o}},ge.ring=n,ge}(),_e=de(ve);const xe={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Ee(e,t){const n=xe[e.geometry.type]-xe[t.geometry.type];return 0===n&&e.geometry.type===B.POLYGON?e.area-t.area:n}function Ie(e){return e.map(e=>(e.geometry.type===B.POLYGON&&(e.area=_e.geometry({type:B.FEATURE,property:{},geometry:e.geometry})),e)).sort(Ee).map(e=>(delete e.area,e))}function Se(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Me(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,n=e.length;t<n;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}Me.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Me.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Me.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Me.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((e,t)=>e.v-t.v).map(e=>e.k)},Me.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const be=[Y.FEATURE,Y.MIDPOINT,Y.VERTEX];var Te={click:function(e,t,n){return Pe(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return Pe(e,t,n,n.options.touchBuffer)}};function Pe(e,t,n,r){if(null===n.map)return[];const o=e?Se(e,r):t,i={};n.options.styles&&(i.layers=n.options.styles.map(e=>e.id).filter(e=>null!=n.map.getLayer(e)));const s=n.map.queryRenderedFeatures(o,i).filter(e=>-1!==be.indexOf(e.properties.meta)),a=new Me,c=[];return s.forEach(e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),Ie(c)}function Ce(e,t){const n=Te.click(e,null,t),r={mouse:R.NONE};return n[0]&&(r.mouse=n[0].properties.active===X.ACTIVE?R.MOVE:R.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=R.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function we(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Le(e,t,n={}){const r=null!=n.fineTolerance?n.fineTolerance:4,o=null!=n.grossTolerance?n.grossTolerance:12,i=null!=n.interval?n.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const s=we(e.point,t.point);return s<r||s<o&&t.time-e.time<i}function Oe(e,t,n={}){const r=null!=n.tolerance?n.tolerance:25,o=null!=n.interval?n.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return we(e.point,t.point)<r&&t.time-e.time<o}const Ae=function(e,t){const n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on(e,t,r){if(void 0===n[e])throw new Error(`Invalid event type: ${e}`);n[e].push({selector:t,fn:r})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=n[e];let s=i.length;for(;s--;){const e=i[s];if(e.selector(o)){e.fn.call(r,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(r),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const ke=((e,t=21)=>(n=t)=>{let r="",o=0|n;for(;o--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Fe(){return ke()}const Ve=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Fe(),this.type=t.geometry.type};Ve.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Ve.prototype.incomingCoords=function(e){this.setCoordinates(e)},Ve.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ve.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Ve.prototype.setProperty=function(e,t){this.properties[e]=t},Ve.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:B.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Ve.prototype.internal=function(e){const t={id:this.id,meta:Y.FEATURE,"meta:type":this.type,active:X.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:B.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ne=function(e,t){Ve.call(this,e,t)};(Ne.prototype=Object.create(Ve.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ne.prototype.updateCoordinate=function(e,t,n){this.coordinates=3===arguments.length?[t,n]:[e,t],this.changed()},Ne.prototype.getCoordinate=function(){return this.getCoordinates()};const De=function(e,t){Ve.call(this,e,t)};(De.prototype=Object.create(Ve.prototype)).isValid=function(){return this.coordinates.length>1},De.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},De.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},De.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},De.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const Re=function(e,t){Ve.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Re.prototype=Object.create(Ve.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Re.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Re.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Re.prototype.addCoordinate=function(e,t,n){this.changed();const r=e.split(".").map(e=>parseInt(e,10));this.coordinates[r[0]].splice(r[1],0,[t,n])},Re.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},Re.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},Re.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Re.prototype.updateCoordinate=function(e,t,n){this.changed();const r=e.split("."),o=parseInt(r[0],10),i=parseInt(r[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,n]};const Ue={MultiPoint:Ne,MultiLineString:De,MultiPolygon:Re},Be=(e,t,n,r,o)=>{const i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,r,o)},je=function(e,t){if(Ve.call(this,e,t),delete this.coordinates,this.model=Ue[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function Ge(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(je.prototype=Object.create(Ve.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Fe(),type:B.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},je.prototype.isValid=function(){return this.features.every(e=>e.isValid())},je.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},je.prototype.getCoordinate=function(e){return Be(this.features,"getCoordinate",e)},je.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===B.POLYGON?e.getCoordinates():e.coordinates)))},je.prototype.updateCoordinate=function(e,t,n){Be(this.features,"updateCoordinate",e,t,n),this.changed()},je.prototype.addCoordinate=function(e,t,n){Be(this.features,"addCoordinate",e,t,n),this.changed()},je.prototype.removeCoordinate=function(e){Be(this.features,"removeCoordinate",e),this.changed()},je.prototype.getFeatures=function(){return this.features},Ge.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Ge.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Ge.prototype.getSelected=function(){return this._ctx.store.getSelected()},Ge.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Ge.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Ge.prototype.getFeature=function(e){return this._ctx.store.get(e)},Ge.prototype.select=function(e){return this._ctx.store.select(e)},Ge.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Ge.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Ge.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Ge.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Ge.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Ge.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Ge.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},Ge.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Ge.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Ge.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Ge.prototype.featuresAt=function(e,t,n="click"){if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return Te[n](e,t,this._ctx)},Ge.prototype.newFeature=function(e){const t=e.geometry.type;return t===B.POINT?new Ne(this._ctx,e):t===B.LINE_STRING?new De(this._ctx,e):t===B.POLYGON?new Re(this._ctx,e):new je(this._ctx,e)},Ge.prototype.isInstanceOf=function(e,t){if(e===B.POINT)return t instanceof Ne;if(e===B.LINE_STRING)return t instanceof De;if(e===B.POLYGON)return t instanceof Re;if("MultiFeature"===e)return t instanceof je;throw new Error(`Unknown feature class: ${e}`)},Ge.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Ge.prototype.onSetup=function(){},Ge.prototype.onDrag=function(){},Ge.prototype.onClick=function(){},Ge.prototype.onMouseMove=function(){},Ge.prototype.onMouseDown=function(){},Ge.prototype.onMouseUp=function(){},Ge.prototype.onMouseOut=function(){},Ge.prototype.onKeyUp=function(){},Ge.prototype.onKeyDown=function(){},Ge.prototype.onTouchStart=function(){},Ge.prototype.onTouchMove=function(){},Ge.prototype.onTouchEnd=function(){},Ge.prototype.onTap=function(){},Ge.prototype.onStop=function(){},Ge.prototype.onTrash=function(){},Ge.prototype.onCombineFeature=function(){},Ge.prototype.onUncombineFeature=function(){},Ge.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const He={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Ye=Object.keys(He);function Xe(e){const t=Object.keys(e);return function(n,r={}){let o={};const i=t.reduce((t,n)=>(t[n]=e[n],t),new Ge(n));return{start(){o=i.onSetup(r),Ye.forEach(t=>{const n=He[t];let r=()=>!1;var s;e[n]&&(r=()=>!0),this.on(t,r,(s=n,e=>i[s](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function $e(e){return[].concat(e).filter(e=>void 0!==e)}function Ke(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(D.HOT)))return a();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let n=[],r=[];e.isDirty?r=e.getAllIds():(n=e.getChangedIds().filter(t=>void 0!==e.get(t)),r=e.sources.hot.filter(t=>t.properties.id&&-1===n.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===n.indexOf(t)});const i=o!==e.sources.cold.length||r.length>0;function s(n,r){const o=e.get(n).internal(t);e.ctx.events.currentModeRender(o,n=>{n.properties.mode=t,e.sources[r].push(n)})}function a(){e.isDirty=!1,e.clearChangedIds()}n.forEach(e=>s(e,"hot")),r.forEach(e=>s(e,"cold")),i&&e.ctx.map.getSource(D.COLD).setData({type:B.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(D.HOT).setData({type:B.FEATURE_COLLECTION,features:e.sources.hot}),a()}function Je(e){let t;this._features={},this._featureIds=new Me,this._selectedFeatureIds=new Me,this._selectedCoordinates=[],this._changedFeatureIds=new Me,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ke.call(this),this._emitSelectionChange&&(this.ctx.events.fire(G.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(G.RENDER,{})}))},this.isDirty=!1}function qe(e,t={}){const n=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===n.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=n}Je.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Je.prototype.setDirty=function(){return this.isDirty=!0,this},Je.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(G.CREATE,{features:[t.toGeoJSON()]})}return this},Je.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(G.UPDATE,{action:t.action?t.action:H.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Je.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Je.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Je.prototype.getAllIds=function(){return this._featureIds.values()},Je.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Je.prototype.delete=function(e,t={}){const n=[];return $e(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===n.indexOf(this._features[e])&&n.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),n.length&&this.ctx.events.fire(G.DELETE,{features:n}),qe(this,t),this},Je.prototype.get=function(e){return this._features[e]},Je.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Je.prototype.select=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Je.prototype.deselect=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),qe(this,t),this},Je.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Je.prototype.setSelected=function(e,t={}){return e=$e(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},Je.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Je.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Je.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Je.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Je.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Je.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Je.prototype.setFeatureProperty=function(e,t,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:H.CHANGE_PROPERTIES})},Je.prototype.storeMapConfig=function(){$.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Je.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Je.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Ze=["mode","feature","mouse"];function ze(e){let t=null,n=null;const r={onRemove(){return e.map.off("load",r.connect),clearInterval(n),r.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",r.connect),clearInterval(n),r.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,n)=>(t[n]=Xe(e.options.modes[n]),t),{});let n={},r={};const o={};let i=null,s=null;o.drag=function(t,n){n({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:R.DRAG}),s.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Le(n,e))},o.touchdrag=function(e){o.drag(e,e=>!Oe(r,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const n=Ce(t,e);t.featureTarget=n,s.mousemove(t)},o.mousedown=function(t){n={time:(new Date).getTime(),point:t.point};const r=Ce(t,e);t.featureTarget=r,s.mousedown(t)},o.mouseup=function(t){const r=Ce(t,e);t.featureTarget=r,Le(n,{point:t.point,time:(new Date).getTime()})?s.click(t):s.mouseup(t)},o.mouseout=function(e){s.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;r={time:(new Date).getTime(),point:t.point};const n=Te.touch(t,null,e)[0];t.featureTarget=n,s.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return s.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const n=Te.touch(t,null,e)[0];t.featureTarget=n,Oe(r,{time:(new Date).getTime(),point:t.point})?s.tap(t):s.touchend(t)};const a=e=>{const t=oe(e),n=ie(e),r=le(e);return!(t||n||r)};function c(n,r,o={}){s.stop();const a=t[n];if(void 0===a)throw new Error(`${n} is not valid`);i=n;const c=a(e,r);s=Ae(c,e),o.silent||e.map.fire(G.MODE_CHANGE,{mode:n}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(N.CANVAS)&&((oe(t)||ie(t))&&e.options.controls.trash?(t.preventDefault(),s.trash()):a(t)?s.keydown(t):se(t)&&e.options.controls.point?c(j.DRAW_POINT):ae(t)&&e.options.controls.line_string?c(j.DRAW_LINE_STRING):ce(t)&&e.options.controls.polygon&&c(j.DRAW_POLYGON))},o.keyup=function(e){a(e)&&s.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:n,options:r,store:o}=e;r.styles.some(e=>n.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,s=Ae(t[i](e),e)},changeMode:c,actionable:function(t){let n=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(n=!0),l[e]=t[e]}),n&&e.map.fire(G.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>s.render(e,t),fire(t,n){e.map&&e.map.fire(t,n)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){s.trash(e)},combineFeatures(){s.combineFeatures()},uncombineFeatures(){s.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let n=null,r={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function s(){if(!e.container)return;const t=[],n=[];Ze.forEach(e=>{o[e]!==r[e]&&(t.push(`${e}-${r[e]}`),null!==o[e]&&n.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),n.length>0&&e.container.classList.add(...n),r=Object.assign(r,o)}function a(e,t={}){const r=document.createElement("button");return r.className=`${N.CONTROL_BUTTON} ${t.className}`,r.setAttribute("title",t.title),t.container.appendChild(r),r.addEventListener("click",r=>{if(r.preventDefault(),r.stopPropagation(),r.target===n)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),r}function c(){n&&(n.classList.remove(N.ACTIVE_BUTTON),n=null)}function l(e){c();const r=t[e];r&&r&&"trash"!==e&&(r.classList.add(N.ACTIVE_BUTTON),n=r)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:s,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),s()},addButtons:function(){const n=e.options.controls,r=document.createElement("div");return r.className=`${N.CONTROL_GROUP} ${N.CONTROL_BASE}`,n?(n[U.POINT]&&(t[U.POINT]=a(U.POINT,{container:r,className:N.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(j.DRAW_POINT),onDeactivate:()=>e.events.trash()})),n[U.LINE]&&(t[U.LINE]=a(U.LINE,{container:r,className:N.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(j.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),n[U.POLYGON]&&(t[U.POLYGON]=a(U.POLYGON,{container:r,className:N.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(j.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),n.trash&&(t.trash=a("trash",{container:r,className:N.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),n.combine_features&&(t.combine_features=a("combineFeatures",{container:r,className:N.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),n.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:r,className:N.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),r):r},removeButtons:function(){Object.keys(t).forEach(e=>{const n=t[e];n.parentNode&&n.parentNode.removeChild(n),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new Je(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?r.connect():(o.on("load",r.connect),n=setInterval(()=>{o.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(D.COLD,{data:{type:B.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(D.HOT,{data:{type:B.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(D.COLD)&&e.map.removeSource(D.COLD),e.map.getSource(D.HOT)&&e.map.removeSource(D.HOT)}};return e.setup=r,r}const We="#3bb2d0",Qe="#fbb03b",et="#fff";var tt=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Qe,We],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],Qe,We],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":et}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],Qe,We]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":et}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":Qe}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Qe}}];function nt(e,t){this.x=e,this.y=t}function rt(e,t){const n=t.getBoundingClientRect();return new nt(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function ot(e,t,n,r){return{type:B.FEATURE,properties:{meta:Y.VERTEX,parent:e,coord_path:n,active:r?X.ACTIVE:X.INACTIVE},geometry:{type:B.POINT,coordinates:t}}}function it(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return st(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(e=>st(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ct(e);default:throw new Error("unknown GeoJSON type")}}function st(e){const t={type:"Feature"};return Object.keys(e).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=at(e.properties),null==e.geometry?t.geometry=null:t.geometry=ct(e.geometry),t}function at(e){const t={};return e?(Object.keys(e).forEach(n=>{const r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(e=>e):t[n]=at(r):t[n]=r}),t):t}function ct(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ct(e)),t):(t.coordinates=lt(e.coordinates),t)}function lt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>lt(e))}function ut(e,t={}){return dt(e,"mercator",t)}function dt(n,r,o={}){var i=(o=o||{}).mutate;if(!n)throw new Error("geojson is required");return Array.isArray(n)&&e(n[0])?n="mercator"===r?pt(n):ht(n):(!0!==i&&(n=it(n)),t(n,function(e){var t="mercator"===r?pt(e):ht(e);e[0]=t[0],e[1]=t[1]})),n}function pt(e){var t,n=Math.PI/180,r=6378137,o=20037508.342789244,i=[r*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*n,r*Math.log(Math.tan(.25*Math.PI+.5*e[1]*n))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function ht(e){var t=180/Math.PI,n=6378137;return[e[0]*t/n,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/n)))*t]}function ft(e,t,n){const r=t.geometry.coordinates,o=n.geometry.coordinates;if(r[1]>85||r[1]<-85||o[1]>85||o[1]<-85)return null;const i=ut(r),s=ut(o),a=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return dt(e,"wgs84",t)}([c(i[0],s[0]),c(i[1],s[1])]),u=[a(l[0]),a(l[1])];return{type:B.FEATURE,properties:{meta:Y.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:n.properties.coord_path},geometry:{type:B.POINT,coordinates:u}}}function gt(e,t={},n=null){const{type:r,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let s=[];function a(e,n){let r="",o=null;e.forEach((e,a)=>{const l=null!=n?`${n}.${a}`:String(a),u=ot(i,e,l,c(l));if(t.midpoints&&o){const e=ft(i,o,u);e&&s.push(e)}o=u;const d=JSON.stringify(e);r!==d&&s.push(u),0===a&&(r=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return r===B.POINT?s.push(ot(i,o,n,c(n))):r===B.POLYGON?o.forEach((e,t)=>{a(e,null!==n?`${n}.${t}`:String(t))}):r===B.LINE_STRING?a(o,n):0===r.indexOf(B.MULTI_PREFIX)&&function(){const n=r.replace(B.MULTI_PREFIX,"");o.forEach((r,o)=>{const i={type:B.FEATURE,properties:e.properties,geometry:{type:n,coordinates:r}};s=s.concat(gt(i,t,o))})}(),s}nt.prototype={clone(){return new nt(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,n=e.y-this.y;return t*t+n*n},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),n=Math.sin(e),r=t*this.x-n*this.y,o=n*this.x+t*this.y;return this.x=r,this.y=o,this},_rotateAround(e,t){const n=Math.cos(e),r=Math.sin(e),o=t.x+n*(this.x-t.x)-r*(this.y-t.y),i=t.y+r*(this.x-t.x)+n*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:nt},nt.convert=function(e){if(e instanceof nt)return e;if(Array.isArray(e))return new nt(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new nt(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var mt={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:yt,LAT_MAX:vt,LAT_RENDERED_MIN:_t,LAT_RENDERED_MAX:xt,LNG_MIN:Et,LNG_MAX:It}=K;function St(e,t){let n=yt,r=vt,o=yt,i=vt,s=It,a=Et;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],n=[e.geometry.coordinates].flat(t),r=n.map(e=>e[0]),o=n.map(e=>e[1]),i=e=>Math.min.apply(null,e),s=e=>Math.max.apply(null,e);return[i(r),i(o),s(r),s(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>n&&(n=c),l<r&&(r=l),l>o&&(o=l),c<i&&(i=c),u<s&&(s=u),d>a&&(a=d)});const c=t;return n+c.lat>xt&&(c.lat=xt-n),o+c.lat>vt&&(c.lat=vt-o),r+c.lat<_t&&(c.lat=_t-r),i+c.lat<yt&&(c.lat=yt-i),s+c.lng<=Et&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=It&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Mt(e,t){const n=St(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),r=e=>{const t={lng:e[0]+n.lng,lat:e[1]+n.lat};return[t.lng,t.lat]},o=e=>e.map(e=>r(e)),i=e=>e.map(e=>o(e));let s;e.type===B.POINT?s=r(t):e.type===B.LINE_STRING||e.type===B.MULTI_POINT?s=t.map(r):e.type===B.POLYGON||e.type===B.MULTI_LINE_STRING?s=t.map(o):e.type===B.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)})}const bt={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(G.UPDATE,{action:H.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let n=!1;if(e.length>1){n=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(n=!1)})}const r=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:n,uncombineFeatures:r,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new Me).values()},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){mt.enable(this)},onMouseMove:function(e,t){return Q(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};bt.onTap=bt.onClick=function(e,t){return W(t)?this.clickAnywhere(e,t):J(Y.VERTEX)(t)?this.clickOnVertex(e,t):Q(t)?this.clickOnFeature(e,t):void 0},bt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),mt.enable(this),this.stopExtendedInteractions(e)},bt.clickOnVertex=function(e,t){this.changeMode(j.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:R.MOVE})},bt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},bt.clickOnFeature=function(e,t){mt.disable(this),this.stopExtendedInteractions(e);const n=te(t),r=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!n&&i&&this.getFeature(o).type!==B.POINT)return this.changeMode(j.DIRECT_SELECT,{featureId:o});i&&n?(this.deselect(o),this.updateUIClasses({mouse:R.POINTER}),1===r.length&&mt.enable(this)):!i&&n?(this.select(o),this.updateUIClasses({mouse:R.MOVE})):i||n||(r.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:R.MOVE})),this.doRender(o)},bt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),Z(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&q(t)?this.startBoxSelect(e,t):void 0},bt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=rt(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},bt.onTouchStart=function(e,t){if(Z(t))return this.startOnActiveFeature(e,t)},bt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},bt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:R.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(N.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=rt(t.originalEvent,this.map.getContainer()),r=Math.min(e.boxSelectStartLocation.x,n.x),o=Math.max(e.boxSelectStartLocation.x,n.x),i=Math.min(e.boxSelectStartLocation.y,n.y),s=Math.max(e.boxSelectStartLocation.y,n.y),a=`translate(${r}px, ${i}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=o-r+"px",e.boxSelectElement.style.height=s-i+"px"},bt.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};Mt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},bt.onTouchEnd=bt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,rt(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),o=this.getUniqueIds(r).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:R.MOVE}))}this.stopExtendedInteractions(e)},bt.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?X.ACTIVE:X.INACTIVE,n(t),this.fireActionable(),t.properties.active===X.ACTIVE&&t.geometry.type!==B.POINT&>(t).forEach(n)},bt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},bt.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],n=[],r=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==r)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),n.push(i.toGeoJSON())}if(n.length>1){const e=this.newFeature({type:B.FEATURE,properties:n[0].properties,geometry:{type:`Multi${r}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(G.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},bt.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],n=[];for(let r=0;r<e.length;r++){const o=e[r];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),n.push(o.toGeoJSON()))}t.length>1&&this.fire(G.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const Tt=J(Y.VERTEX),Pt=J(Y.MIDPOINT),Ct={fireUpdate:function(){this.fire(G.UPDATE,{action:H.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties,r=e.selectedCoordPaths.indexOf(n.coord_path);te(t)||-1!==r?te(t)&&-1===r&&e.selectedCoordPaths.push(n.coord_path):e.selectedCoordPaths=[n.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,n){Mt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,n){const r=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=St(r.map(e=>({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:e}})),n);for(let t=0;t<r.length;t++){const n=r[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],n[0]+o.lng,n[1]+o.lat)}},clickNoTarget:function(){this.changeMode(j.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(j.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===B.POINT)throw new TypeError("direct_select mode doesn't handle point features");const r={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,r.selectedCoordPaths)),this.setSelected(t),mt.disable(this),this.setActionableState({trash:!0}),r},onStop:function(){mt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=X.ACTIVE,n(t),gt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=X.INACTIVE,n(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(j.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=Z(t),r=Tt(t),o=Pt(t),i=0===e.selectedCoordPaths.length;n&&i||r&&!i?this.updateUIClasses({mouse:R.MOVE}):this.updateUIClasses({mouse:R.NONE});return(r||n||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ct.onTouchStart=Ct.onMouseDown=function(e,t){return Tt(t)?this.onVertex(e,t):Z(t)?this.onFeature(e,t):Pt(t)?this.onMidpoint(e,t):void 0},Ct.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat},Ct.onClick=function(e,t){return W(t)?this.clickNoTarget(e,t):Z(t)?this.clickActiveFeature(e,t):z(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ct.onTap=function(e,t){return W(t)?this.clickNoTarget(e,t):Z(t)?this.clickActiveFeature(e,t):z(t)?this.clickInactive(e,t):void 0},Ct.onTouchEnd=Ct.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const wt={};function Lt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}wt.onSetup=function(){const e=this.newFeature({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:R.ADD}),this.activateUIButton(U.POINT),this.setActionableState({trash:!0}),{point:e}},wt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)},wt.onTap=wt.onClick=function(e,t){this.updateUIClasses({mouse:R.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(G.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.point.id]})},wt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},wt.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?X.ACTIVE:X.INACTIVE,!r)return n(t)},wt.onTrash=wt.stopDrawingAndRemove,wt.onKeyUp=function(e,t){if(ne(t)||re(t))return this.stopDrawingAndRemove(e,t)};const Ot={onSetup:function(){const e=this.newFeature({type:B.FEATURE,properties:{},geometry:{type:B.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),mt.disable(this),this.updateUIClasses({mouse:R.ADD}),this.activateUIButton(U.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Lt(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:R.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),ee(t)&&this.updateUIClasses({mouse:R.POINTER})}};Ot.onTap=Ot.onClick=function(e,t){return ee(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ot.onKeyUp=function(e,t){ne(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)):re(t)&&this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ot.onStop=function(e){this.updateUIClasses({mouse:R.NONE}),mt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(G.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT,{},{silent:!0})))},Ot.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?X.ACTIVE:X.INACTIVE,!r)return n(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=Y.FEATURE,n(ot(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const r=t.geometry.coordinates[0].length-3;n(ot(e.polygon.id,t.geometry.coordinates[0][r],`0.${r}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(n({type:B.FEATURE,properties:t.properties,geometry:{coordinates:e,type:B.LINE_STRING}}),3===o)return}return n(t)}},Ot.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)};const At={onSetup:function(e){const t=(e=e||{}).featureId;let n,r,o="forward";if(t){if(n=this.getFeature(t),!n)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const s=n.coordinates.length-1;if(n.coordinates[s][0]===i[0]&&n.coordinates[s][1]===i[1])r=s+1,n.addCoordinate(r,...n.coordinates[s]);else{if(n.coordinates[0][0]!==i[0]||n.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",r=0,n.addCoordinate(r,...n.coordinates[0])}}else n=this.newFeature({type:B.FEATURE,properties:{},geometry:{type:B.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),mt.disable(this),this.updateUIClasses({mouse:R.ADD}),this.activateUIButton(U.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Lt(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&Lt(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:R.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),ee(t)&&this.updateUIClasses({mouse:R.POINTER})}};At.onTap=At.onClick=function(e,t){if(ee(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},At.onKeyUp=function(e,t){re(t)?this.changeMode(j.SIMPLE_SELECT,{featureIds:[e.line.id]}):ne(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT))},At.onStop=function(e){mt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(G.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT,{},{silent:!0})))},At.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(j.SIMPLE_SELECT)},At.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?X.ACTIVE:X.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=Y.FEATURE,n(ot(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),n(t))};var kt={simple_select:bt,direct_select:Ct,draw_point:wt,draw_polygon:Ot,draw_line_string:At};const Ft={defaultMode:j.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:tt,modes:kt,controls:{},userProperties:!1,suppressAPIEvents:!0},Vt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Nt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Dt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?D.HOT:D.COLD}))}var Rt,Ut;var Bt,jt,Gt=de(Ut?Rt:(Ut=1,Rt=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,o,i;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(o=r;0!==o--;)if(!e(t[o],n[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(o=r;0!==o--;)if(!Object.prototype.hasOwnProperty.call(n,i[o]))return!1;for(o=r;0!==o--;){var s=i[o];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n}));var Ht=function(){if(jt)return Bt;jt=1,Bt=function(t){if(!t||!t.type)return null;var n=e[t.type];if(!n)return null;if("geometry"===n)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===n)return{type:"FeatureCollection",features:[t]};if("featurecollection"===n)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Bt}(),Yt=de(Ht);function Xt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const $t={Polygon:Re,LineString:De,Point:Ne,MultiPolygon:je,MultiLineString:je,MultiPoint:je};var Kt=Object.freeze({__proto__:null,CommonSelectors:ue,ModeHandler:Ae,StringSet:Me,constrainFeatureMovement:St,createMidPoint:ft,createSupplementaryPoints:gt,createVertex:ot,doubleClickZoom:mt,euclideanDistance:we,featuresAt:Te,getFeatureAtAndSetCursors:Ce,isClick:Le,isEventAtCoordinates:Lt,isTap:Oe,mapEventToBoundingBox:Se,moveFeatures:Mt,sortFeatures:Ie,stringSetsAreEqual:Xt,theme:tt,toDenseArray:$e});const Jt=function(e,t){const n={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Nt,e.controls):t.controls=Object.assign({},Vt,e.controls),t=Object.assign({},Ft,t),t.styles=Dt(t.styles,"cold").concat(Dt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=j;const n=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Te.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:B.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:B.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:B.FEATURE,properties:{},geometry:{type:B.POINT,coordinates:e.coordinates}}))}},t.set=function(n){if(void 0===n.type||n.type!==B.FEATURE_COLLECTION||!Array.isArray(n.features))throw new Error("Invalid FeatureCollection");const r=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(n),s=new Me(i);return o=o.filter(e=>!s.has(e)),o.length&&t.delete(o),r(),i},t.add=function(t){const r=JSON.parse(JSON.stringify(Yt(t))).features.map(t=>{if(t.id=t.id||Fe(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const r=$t[t.geometry.type];if(void 0===r)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new r(e,t);e.store.add(o,{silent:n})}else{const r=e.store.get(t.id),o=r.properties;r.properties=t.properties,Gt(o,t.properties)||e.store.featureChanged(r.id,{silent:n}),Gt(r.getCoordinates(),t.geometry.coordinates)||r.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),r},t.get=function(t){const n=e.store.get(t);if(n)return n.toGeoJSON()},t.getAll=function(){return{type:B.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()!==j.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(j.SIMPLE_SELECT,void 0,{silent:n}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===j.DIRECT_SELECT?e.events.changeMode(j.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,o={}){return r===j.SIMPLE_SELECT&&t.getMode()===j.SIMPLE_SELECT?(Xt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:n}),e.store.render()),t):(r===j.DIRECT_SELECT&&t.getMode()===j.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,o,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,o,i){return e.store.setFeatureProperty(r,o,i,{silent:n}),t},t}(n,t),n.api=t;const r=ze(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=U,t.options=e,t};function qt(e){Jt(e,this)}qt.modes=kt,qt.constants=K,qt.lib=Kt;const Zt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,n){t.properties.active="false",n(t)}},zt="draw.create",Wt="draw.update",Qt="draw.modechange",en="draw.editfinish",tn="draw.cancel",nn="draw.vertexselection",rn="draw.vertexchange",on="draw.undochange",sn="draw.undo",an="draw.geometrychange",cn="draw.interfacetypechange",ln="draw.placementblocked",un="draw.nudgevertex",dn="draw.selectvertex",pn="draw.insertvertexatmidpoint",hn="styledata",fn=e=>{if(!e?.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},gn=e=>{const t=fn(e),n=mn(e);if(!t.length||!n.length)return[];const r=[];for(const e of n){const n=e.closed?e.length:e.length-1;for(let o=0;o<n;o++){const n=e.start+o,i=e.start+(o+1)%e.length,[s,a]=t[n],[c,l]=t[i];r.push([(s+c)/2,(a+l)/2])}}return r},mn=e=>{if(!e?.coordinates)return[];const t=[];let n=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!0}),n+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,r)=>{t.push({start:n,length:e.length,path:[r],closed:!1}),n+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,r)=>{e.forEach((e,o)=>{t.push({start:n,length:e.length,path:[r,o],closed:!0}),n+=e.length})})}return t},yn=(e,t)=>{for(const n of e)if(t>=n.start&&t<n.start+n.length)return{segment:n,localIdx:t-n.start};return null},vn=(e,t)=>{let n=e.geometry.coordinates;for(const e of t)n=n[e];return n},_n=(e,t)=>{const n=t.split(".").map(Number),r=mn(e);for(const e of r){if(e.path.every((e,t)=>e===n[t])&&n.length===e.path.length+1){const t=n[n.length-1];return e.start+t}}return n[n.length-1]},xn=(e,t)=>({x:e.x*t,y:e.y*t}),En=e=>e instanceof window.SVGElement||e.ownerSVGElement;function In(e){return e?._snapInstance??null}function Sn(e){return!!(e?.status&&e?.snapStatus&&e.snapCoords?.length>=2)}function Mn(e){return Sn(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function bn(e,t,n){if(!e||!t||!e.status)return!1;const r=t.unproject(n);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Tn(e,t){e&&(e._autoSnapSuspended=t)}function Pn(e,t){if(!e||!t||!e.status)return!1;const n=t.getCenter(),r=t.project(n);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function Cn(e,t){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0)),t?.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function wn(e){e&&(e.snapStatus=!1,e.snapCoords=null,e.snappedFeatures?.length&&(e.snappedFeatures.length=0),e.closeFeatures?.length&&(e.closeFeatures.length=0),e.lines?.length&&(e.lines.length=0))}function Ln(e){return"function"==typeof e?.getSnapEnabled&&!0===e.getSnapEnabled()}const On=(e,t,n={})=>{const r=n=>r=>n.call(e,t,r),o={keydown:r(e.onKeydown),keyup:r(e.onKeyup),pointerdown:r(e.onPointerevent),pointermove:r(e.onPointerevent),pointerup:r(e.onPointerevent),click:r(e.onButtonClick),touchstart:r(e.onTouchstart),touchmove:r(e.onTouchmove),touchend:r(e.onTouchend),scalechange:r(e.onScaleChange),move:r(e.onMove),interfacetypechange:r(e.onInterfaceTypeChange)};for(const[e,t]of Object.entries(n))o[e]=r(t);return o},An=(e,t,n)=>{window.addEventListener("keydown",n.keydown,{capture:!0}),window.addEventListener("keyup",n.keyup,{capture:!0}),window.addEventListener("click",n.click),e.container.addEventListener("pointerdown",n.pointerdown),e.container.addEventListener("pointermove",n.pointermove),e.container.addEventListener("pointerup",n.pointerup),e.container.addEventListener("touchstart",n.touchstart,{passive:!1}),e.container.addEventListener("touchmove",n.touchmove,{passive:!1}),e.container.addEventListener("touchend",n.touchend,{passive:!1}),t.on("draw.scalechange",n.scalechange),t.on("move",n.move),t.on(cn,n.interfacetypechange),t.on(un,n.nudge)},kn=(e,t,n)=>{e.container.removeEventListener("pointerdown",n.pointerdown),e.container.removeEventListener("pointermove",n.pointermove),e.container.removeEventListener("pointerup",n.pointerup),e.container.removeEventListener("touchstart",n.touchstart),e.container.removeEventListener("touchmove",n.touchmove),e.container.removeEventListener("touchend",n.touchend),t.off("draw.scalechange",n.scalechange),t.off("move",n.move),t.off(cn,n.interfacetypechange),t.off(un,n.nudge),t.dragPan.enable(),window.removeEventListener("click",n.click),window.removeEventListener("keydown",n.keydown,{capture:!0}),window.removeEventListener("keyup",n.keyup,{capture:!0})},Fn=e=>{const t=In(e);t&&Cn(t,e)},Vn={fireGeometryChange(e){const t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,n){e&&setTimeout(()=>{const r=this.getFeature(n);r&&this.map.fire("draw.geometrychange",{feature:r.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){const t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}},Nn={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},Dn={...Vn,UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Nn,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_vertex"===n.type?this.undoMoveVertex(e,n):"insert_vertex"===n.type?this.undoInsertVertex(e,n):"delete_vertex"===n.type&&this.undoDeleteVertex(e,n),this.emitGeometryValidation(Nn[n.type],n.vertexIndex,n.featureId)},undoMoveVertex(e,t){const{vertexIndex:n,previousPosition:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=mn(i),c=yn(a,n);if(!c)return;vn(s,c.segment.path)[c.localIdx]=r,this._applyUndoAndSync(e,s,o);const l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,xn(this.map.project(l),e.scale))},undoInsertVertex(e,t){const{vertexIndex:n,featureId:r}=t,o=this.getFeature(r);if(!o)return;const i=o.toGeoJSON(),s=mn(o),a=yn(s,n);if(!a)return;vn(i,a.segment.path).splice(a.localIdx,1),this._applyUndoAndSync(e,i,r),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})},undoDeleteVertex(e,t){const{vertexIndex:n,position:r,featureId:o}=t,i=this.getFeature(o);if(!i)return;const s=i.toGeoJSON(),a=mn(i);let c=yn(a,n);if(!c)for(const e of a)if(n===e.start+e.length){c={segment:e,localIdx:e.length};break}if(!c)return;vn(s,c.segment.path).splice(c.localIdx,0,r),this._applyUndoAndSync(e,s,o),this.updateTouchVertexTarget(e,xn(this.map.project(e.vertices[n]),e.scale)),this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,n)})},_applyUndoAndSync(e,t,n){this._ctx.api.add(t),e.vertices=this.getVertices(n),e.midpoints=this.getMidpoints(n),this._ctx.store.render(),this.fireGeometryChange(e)}},Rn=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Un=(e,t,n,r,o)=>{const i=window.getComputedStyle(t),s={x:n.x-Number.parseFloat(i.left),y:n.y-Number.parseFloat(i.top)},a=e.project(r);return{deltaTarget:s,deltaVertex:{x:n.x/o-a.x,y:n.y/o-a.y}}},Bn=(e,t,n)=>{const r={x:n.x/t.scale-t.deltaVertex.x,y:n.y/t.scale-t.deltaVertex.y};let o=e.unproject(r);if(Ln(t)){const t=In(e);bn(t,e,r),o=Mn(t)||o}return o},jn=(e,t,n={})=>{if(!e)return;const{editActive:r,editHalo:o,editVertex:i}=w(t,n);L(e,{editActive:r,editHalo:o,editVertex:i})},Gn={addTouchVertexTarget(e){e.touchVertexTarget=C(e.container),jn(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:`${t.y}px`,left:`${t.x}px`}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||En(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(wn(In(this.map)),e?.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;const t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xn(this.map.project(t),e.scale))}},onTap(e,t){const n=In(this.map);n&&Cn(n,this.map);const r=t.featureTarget?.properties.meta,o=t.featureTarget?.properties.coord_path;if("vertex"===r){const t=this.getFeature(e.featureId),n=_n(t,o);this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:o})}else"midpoint"===r?this.insertVertex({...e,selectedVertexIndex:this.getVertexIndexFromMidpoint(e,o),selectedVertexType:"midpoint"}):this.clickNoTarget(e)},onTouchstart(e,t){wn(In(this.map));const n=this.getVertices(e.featureId),r=n?.[e.selectedVertexIndex];if(!r||!En(t.target.parentNode))return;e._moveStartPosition=[...r],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;const o=Rn(t);Object.assign(e,Un(this.map,e.touchVertexTarget,o,r,e.scale))},onTouchmove(e,t){if(e.selectedVertexIndex<0||!En(t.target.parentNode))return;e._touchMoved=!0;const n=Rn(t);this.moveVertex(e,Bn(this.map,e,n)),this.updateTouchVertexTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},Hn=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Yn={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Xn=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),$n=e=>{const t=document.activeElement;return!(!t||t===document.body)&&(!e.container?.contains(t)&&(Xn.has(t.tagName)||t.isContentEditable||t.hasAttribute("tabindex")))},Kn=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,Jn={handleUndoShortcut(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))}},qn={getOffset(e,t){const n=this.map.project(e),o=t?.shiftKey?r.nudgeAmount:r.stepAmount,[i,s]=t?Yn[t.key].map(e=>e*o):[0,0];return this.map.unproject({x:n.x+i,y:n.y+s})},getOffsetByDelta(e,t,n,o){const i=this.map.project(e),s=o?r.stepAmount:r.nudgeAmount;return this.map.unproject({x:i.x+t*s,y:i.y+n*s})},resolveSnapTarget(e,t,r,o,i){const s=In(this.map);if(Ln(e)&&e._isSnapped&&s){const i=function(e){return e?.options?.radius??n.snapRadius}(s)+1,a=this.map.project(o);return e._isSnapped=!1,Cn(s,this.map),this.map.unproject({x:a.x+t*i,y:a.y+r*i})}const a=i();return Ln(e)&&s&&(bn(s,this.map,this.map.project(a)),Sn(s))?(e._isSnapped=!0,Mn(s)):(e._isSnapped=!1,a)}},Zn={...qn,updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(e,t){const[n,r]=this.getVertexOrMidpoint(e,t);n<0||!r||this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:r,..."vertex"===r&&{coordPath:this.getCoordPath(e,n)}})},getNewCoord(e,t){return this.getOffset(fn(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,n,r){if("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)return;const o=this.getFeature(e.featureId),i=o&&fn(o)?.[e.selectedVertexIndex];if(!i)return;const s=[...i],a=e.selectedVertexIndex,c=this.resolveSnapTarget(e,t,n,i,()=>this.getOffsetByDelta(i,t,n,r));this.moveVertex(e,c),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:a,previousPosition:s})},insertVertex(e,t){const n=e.selectedVertexIndex-e.vertices.length,r=this.getOffset(e.midpoints[n],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),s=mn(o);let a=n+1,c=null,l=0,u=0;for(const e of s){const t=e.closed?e.length:e.length-1;if(n<u+t){c=e,l=n-u+1,a=e.start+l;break}u+=t}if(!c)return;vn(i,c.path).splice(l,0,[r.lng,r.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:a}),this.changeMode(e,{selectedVertexIndex:a,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,a)})},moveVertex(e,t,n={}){if(n.checkSnap&&!1!==e.enableSnap){const e=this.map._snapInstance;e?.snapStatus&&e.snapCoords?.length>=2&&(t={lng:e.snapCoords[0],lat:e.snapCoords[1]})}const r=this.getFeature(e.featureId),o=r.toGeoJSON(),i=mn(r),s=yn(i,e.selectedVertexIndex);if(!s)return;vn(o,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(o),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature)},deleteVertex(e){const t=this.getFeature(e.featureId);if(!t)return;const n=mn(t),r=yn(n,e.selectedVertexIndex);if(!r)return;const{segment:i}=r,s=i.closed?o.Polygon:o.LineString;if(i.length<=s)return;const a=[...e.vertices[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...r.segment.path,r.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:a}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},zn={findVertexIndex(e,t,n){const r=[];return e.forEach((e,n)=>{e[0]===t[0]&&e[1]===t[1]&&r.push(n)}),0===r.length?-1:1===r.length?r[0]:n>=0?r.reduce((e,t)=>Math.abs(t-n)<Math.abs(e-n)?t:e,r[0]):r[0]},getCoordPath(e,t){const n=this.getFeature(e.featureId);if(!n)return"0";const r=mn(n),o=yn(r,t);if(!o)return"0";const{segment:i,localIdx:s}=o;return[...i.path,s].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return fn(this.getFeature(e))},getMidpoints(e){return gn(this.getFeature(e))},getVertexOrMidpoint(e,t){if(e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),!e.vertices?.length)return[-1,null];const n=e=>e?Object.values(this.map.project(e)):null,r=[...e.vertices.map(n),...e.midpoints.map(n)].filter(Boolean);if(!r.length)return[-1,null];const o=r[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),i=O(o,r,t);return[i,i<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){const n=this.getFeature(e.featureId),r=mn(n),o=t.split(".").map(Number);let i=0;for(const t of r){if(t.path.every((e,t)=>e===o[t])&&o.length===t.path.length+1){const n=o[o.length-1],r=n>0?n-1:t.length-2;return e.vertices.length+i+r}i+=t.closed?t.length:t.length-1}return e.vertices.length}},Wn={...Jn,onKeydown(e,t){$n(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Hn.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?Kn(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){const t=In(this.map);t&&Cn(t,this.map),e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),e.vertices?.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){if("midpoint"===e.selectedVertexType)return void this.insertVertex(e,t);const n=this.getFeature(e.featureId),r=n&&fn(n)?.[e.selectedVertexIndex];r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,n){const[r,o]=Yn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){$n(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&A(t),Hn.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&null!=e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=null)),"Delete"===t.key&&this.deleteVertex(e))}},Qn={onMouseDown(e,t){wn(In(this.map));const n=t.featureTarget?.properties.meta,r=t.featureTarget?.properties.coord_path;if(["vertex","midpoint"].includes(n)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,Ct.onMouseDown.call(this,e,t),"vertex"===n&&r)){const t=this.getFeature(e.featureId),n=_n(t,r);e.selectedVertexIndex=n,e.selectedVertexType="vertex",e.coordPath=r;const o=e.vertices?.[n];o&&(e._moveStartPosition=[...o],e._moveStartIndex=n)}if("midpoint"===n){const t=this.getFeature(e.featureId),n=_n(t,r);e._insertedVertexIndex=n,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,r),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(nn,{index:e.selectedVertexIndex,numVertices:e.vertices.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){const t=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(nn,{index:t,numVertices:e.vertices.length})}Ct.onClick.call(this,e,t)},onMouseUp(e,t){wn(In(this.map));const n=e._isInsertingVertex&&null!=e._insertedVertexIndex,r=this._didVertexMove(e);(e.dragMoving||r||n)&&(this.syncVertices(e),n?this._recordInsertionUndo(e):r&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,Ct.onMouseUp.call(this,e,t)},_didVertexMove(e){if(!e._moveStartPosition||null==e._moveStartIndex)return!1;const t=this.getFeature(e.featureId),n=t&&fn(t)?.[e._moveStartIndex];return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){const t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(nn,{index:t,numVertices:e.vertices.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=In(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!Ln(e)||!n?.status)return void Ct.onDrag.call(this,e,t);if(!e.selectedCoordPaths?.length||!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation(),bn(n,this.map,t.point);const r=Mn(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],r.lng,r.lat),e.dragMoveLocation=t.lngLat}},er={...qt.modes.direct_select,...Dn,...Gn,...Zn,...zn,...Wn,...Qn,onSetup(e){const t=qt.modes.direct_select.onSetup.call(this,e);Object.assign(t,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:t.featureId,selectedVertexIndex:e.selectedVertexIndex??-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:e.scale??1}),this.map._lastEditFeatureId!==t.featureId&&(this.map._undoStack?.clear(),this.map._lastEditFeatureId=t.featureId);const n=this.getFeature(t.featureId);if(t.featureType=n?.type,t.vertices=this.getVertices(t.featureId),t.midpoints=this.getMidpoints(t.featureId),this.setupEventListeners(t),this.applyVertexSelection(t,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(t),Fn(this.map),"touch"===t.interfaceType&&t.selectedVertexIndex>=0&&"vertex"===t.selectedVertexType){const e=t.vertices[t.selectedVertexIndex];e&&setTimeout(()=>{this.updateTouchVertexTarget(t,xn(this.map.project(e),t.scale))},0)}return t._ignorePointermoveDeselect=!0,setTimeout(()=>{t._ignorePointermoveDeselect=!1},100),t},setupEventListeners(e){const t=this.handlers=On(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint});An(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(dn,t.selectvertex),this.map.on(pn,t.insertvertexatmidpoint)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertices.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){this.syncVertices(e);const n=t.points[t.points.length-1]?.geometry.coordinates;if("keyboard"!==e.interfaceType&&n&&!e.coordPath){const r=t.features[0]?.geometry,o=fn(r);e.selectedVertexIndex=this.findVertexIndex(o,n,e.selectedVertexIndex)}e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null,this.map.fire(nn,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});const r=n||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,r?xn(this.map.project(r),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;const n=e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,n?xn(this.map.project(n),e.scale):null)},onUpdate(e){new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,e.selectedVertexType??=null)},onMove(e){const t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xn(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);const n=e.vertices[e.selectedVertexIndex];n&&this.updateTouchVertexTarget(e,xn(this.map.project(n),e.scale))},onSelectVertex(e,t){e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));const n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,{selectedVertexIndex:t.index,selectedVertexType:n,..."vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}})},onInsertVertexAtMidpoint(e,t){e.vertices?.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex({...e,selectedVertexIndex:t.index,selectedVertexType:"midpoint"})},onButtonClick(e,t){t.target.closest(`#${e.deleteVertexButtonId}`)&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",{...e,...t})},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;const t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(dn,t.selectvertex),this.map.off(pn,t.insertvertexatmidpoint),kn(e,this.map,t),this.hideTouchVertexIndicator(e)}},tr={move_point:"commit-move"},nr={...Vn,UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:tr,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_point"===n.type&&this.undoMovePoint(e,n),this.emitGeometryValidation(tr[n.type],n.vertexIndex,n.featureId)},undoMovePoint(e,t){const{previousPosition:n,featureId:r}=t,o=this.getFeature(r);o&&(o.updateCoordinate("",n[0],n[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,xn(this.map.project(n),e.scale)))}},rr={addTouchPointTarget(e){e.touchPointTarget=C(e.container),jn(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:`${t.y}px`,left:`${t.x}px`}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){wn(In(this.map)),e._touchMoved&&e._moveStartPosition&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._touchMoved=!1,e.feature&&this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){wn(In(this.map));const n=this.getPointCoord(e);if(!n||!En(t.target.parentNode))return;e._moveStartPosition=[...n],e._touchMoved=!1;const r=Rn(t);Object.assign(e,Un(this.map,e.touchPointTarget,r,n,e.scale))},onTouchmove(e,t){if(!En(t.target.parentNode))return;e._touchMoved=!0;const n=Rn(t);this.movePoint(e,Bn(this.map,e,n)),this.updateTouchPointTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},or={...qn,getPointCoord(e){return this.getFeature(e.featureId)?.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,n,r){const o=this.getPointCoord(e);if(!o)return;const i=[...o],s=this.resolveSnapTarget(e,t,n,o,()=>this.getOffsetByDelta(o,t,n,r));this.movePoint(e,s),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}},ir={...Jn,onKeydown(e,t){$n(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Hn.has(t.key)?this.handleArrowKey(e,t):Kn(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){const n=this.getPointCoord(e);n&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...n]),this.movePoint(e,this._keyboardMoveTarget(e,t,n)))},_keyboardMoveTarget(e,t,n){const[r,o]=Yn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){$n(e)||(e.interfaceType="keyboard",A(t),Hn.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}},sr="edit_point",ar={onFeature(e,t){e.dragMoving||(e._moveStartPosition=[...e.feature.coordinates],e._grabOffset=[e.feature.coordinates[0]-t.lngLat.lng,e.feature.coordinates[1]-t.lngLat.lat],Tn(In(this.map),!0)),Ct.onFeature.call(this,e,t)},onClick(e,t){if(Z(t))return;if(!((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:r,reason:o}=i(n,{mode:sr,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return r||e.fire("draw.placementblocked",{feature:n,reason:o??null,phase:"place",mode:sr,vertexIndex:0}),r})(this.map,[t.lngLat.lng,t.lngLat.lat]))return;const n=[...e.feature.coordinates],r=In(this.map);let o=t.lngLat;Ln(e)&&r&&(bn(r,this.map,t.point),o=Mn(r)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:n})},onMouseUp(e,t){const n=In(this.map);wn(n),Tn(n,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Ct.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;const t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"===e.interfaceType)return;this.map.fire("draw.geometrychange",e.feature);const n=In(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),!Ln(e)||!n?.status)return void Ct.onDrag.call(this,e,t);if(!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};bn(n,this.map,this.map.project([r.lng,r.lat]));const o=Mn(n)||r;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat},onTrash(){}},cr={...qt.modes.direct_select,...nr,...rr,...or,...ir,...ar,onSetup(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter edit_point mode");const r={featureId:t,feature:n,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};return this.setSelectedCoordinates([]),this.setSelected(t),mt.disable(this),this.setActionableState({trash:!1}),Object.assign(r,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:e.scale??1}),this.map._lastEditFeatureId!==r.featureId&&(this.map._undoStack?.clear(),this.map._lastEditFeatureId=r.featureId),this.setupEventListeners(r),this.map._drawEditContainer=e.container,this.addTouchPointTarget(r),r.container?.focus({preventScroll:!0}),Fn(this.map),"touch"===r.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(r,xn(this.map.project(r.feature.coordinates),r.scale))},0),this.map.fire(nn,{index:0,numVertices:1}),r},setupEventListeners(e){const t=this.handlers=On(this,e,{nudge:this.onNudgePoint});An(e,this.map,t)},toDisplayFeatures(e,t,n){t.properties.active=e.featureId===t.properties.id?"true":"false",n(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,xn(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,kn(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}},lr=({ParentMode:e,featureProp:t,excludeFeatureIdFromSetup:n})=>({onSetup(r){const{map:o}=this,i=n?{...r,featureId:null}:r,s={...e.onSetup.call(this,i),...r};s[t].properties=r.properties;const{container:a,vertexMarkerId:c,getInterfaceType:l}=s,u=l?l():s.interfaceType;s.interfaceType=u;const d=a.querySelector(`#${c}`);s.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(s):this._hideCrossHair(s),s.crossHair&&(s.crossHair.activate=()=>this._placeAtCrossHair?.(s));const p=(e,t)=>this[e]=t.bind(this,s),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(([e,t])=>p(e,t)),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"keyup",A,{capture:!0}],[window,"click",this.vertexButtonClickHandler],[a,"blur",this.blurHandler],[a,"pointermove",this.pointermoveHandler],[a,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(([e,t,n,r])=>e.addEventListener?e.addEventListener(t,n,r):e.on(t,n)),s},onStop(t){e.onStop.call(this,t),this._listeners.forEach(([e,t,n,r])=>e.removeEventListener?e.removeEventListener(t,n,r):e.off(t,n)),t.crossHair?.activate&&(t.crossHair.activate=null),["touch","keyboard"].includes(t.interfaceType)||this._hideCrossHair(t),this.map.fire("draw.interfacetypechange",{interfaceType:t.interfaceType})}}),ur=(e,t,n,r,o)=>{setTimeout(()=>{const i=t(r);i&&e.fire("draw.geometrychange",((e,t,n)=>{const r=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[r]}:{type:"LineString",coordinates:r},properties:{}},phase:n,vertexIndex:Math.max(0,r.length-1)}})(i,n,o))},0)},dr=({geometryType:e,getFeature:t,getCoords:n})=>({_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(r,o){const i=t(r);if(!i||!o)return!0;const a=s({placed:n(i).slice(0,-1),point:o,geometryType:e,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e,r="commit-add"){ur(this.map,t,n,e,r)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this.doClick(e)},onCreate(e,t){((e,t,n)=>{e.delete(t.id),t.id=n,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}),pr=({ParentMode:e,getFeature:t,getCoords:n,validateClick:r,finishOnInvalidClick:o})=>({onClick(i,s){if(this._isIgnorableClick(s))return;if(!1===this.map._drawGeometryValid&&"vertex"===s.featureTarget?.properties?.meta)return;const a=In(this.map);if(Ln(i)&&Sn(a))s=function(e,t){const n=Mn(t);return n?{...e,lngLat:n}:e}(s,a);else if(!((e,i)=>{const s=n(t(e));return s.length>0&&(s[s.length-1]=[i.lngLat.lng,i.lngLat.lat]),o||r(t(e))})(i,s))return;if(!this._canPlaceVertex(i,[s.lngLat.lng,s.lngLat.lat]))return;const c=n(t(i)).length;e.onClick.call(this,i,s),n(t(i)).length>c&&(this.pushDrawUndo(i),this.dispatchVertexChange(n(t(i))),this.emitDrawValidation(i))},doClick(i){if(this.map._undoInProgress)return;const s=t(i),a=n(s);if(this.dispatchVertexChange(a),!r(s))return void(o&&!1!==this.map._drawGeometryValid&&(a.pop(),this.map.fire("draw.create",{features:[s.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[s.id]})));const c=In(this.map),l=Ln(i)&&function(e,t){const n=Mn(t);if(!n)return null;const r=e.project([n.lng,n.lat]);return{lngLat:n,point:r,originalEvent:new MouseEvent("click",{clientX:r.x,clientY:r.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(!this._canPlaceVertex(i,[u.lng,u.lat]))return;l?(e.onClick.call(this,i,l),this._ctx.store.render()):this._simulateMouse("click",e.onClick,i);const d=n(t(i));this.pushDrawUndo(i),this.dispatchVertexChange(d),this.emitDrawValidation(i)},_placeAtCrossHair(e){this.doClick(e)}}),hr=e=>({...dr(e),...pr(e)}),fr=({geometryType:e,getFeature:t})=>({pushDrawUndo(n){const r=this.map._undoStack;r&&!this.map._undoInProgress&&r.push({type:"draw_vertex",geometryType:e,featureId:t(n).id})},onUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"draw_vertex"===n?.type&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))},_handleUndoKeydown(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}),gr=({ParentMode:e,geometryType:t,getCoords:n,getFeature:r,RUBBER_BAND_OFFSET:o})=>({undoVertex(e){const t=r(e),o=n(t);return!(o.length<2)&&(2===o.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,o),!0))},_removeLastVertex(e,r,i){const s="Polygon"===t?r.coordinates[0]:i;s.splice(-o,1),s[s.length-1]=[...s[s.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(r))},_updateRubberBand(n,r){if(["touch","keyboard"].includes(n.interfaceType))this._simulateMouse("mousemove",e.onMouseMove,n),this._ctx.store.render();else{const o=r["Polygon"===t?r.length-2:r.length-1],i={lng:o[0],lat:o[1]},s=this.map.project(i);e.onMouseMove.call(this,n,{lngLat:i,point:s,originalEvent:new MouseEvent("mousemove",{clientX:s.x,clientY:s.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",n.polygon||n.line)}this.dispatchVertexChange(r)}}),mr=({ParentMode:e,featureProp:t,geometryType:n})=>({_reinitializeFeature(r,o){const i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(r,i);const s=this.map.getCenter(),a=[[s.lng,s.lat],[s.lng,s.lat]],c=this.newFeature({type:"Feature",properties:r.properties||{},geometry:{type:n,coordinates:[a]}});return c.id=i,this._ctx.store.add(c),r[t]=c,r.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",e.onMouseMove,r),this._ctx.store.render(),this.dispatchVertexChange(a),!0},_restartLineStringDraw(e,t){const n=this.map._undoStack;return n&&n.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}),yr=e=>({...fr(e),...gr(e),...mr(e)}),vr=({ParentMode:e,getFeature:t,INTERFACE_KEYS:n})=>({onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(n,r){const o=document.activeElement;if(!o||o===n.container||!n.container.contains(o))if("Escape"!==r.key)o!==n.container&&e.onKeyUp.call(this,n,r);else if("keyboard"===n.interfaceType){const e=this.map._undoStack;e&&e.clear(),this._reinitializeFeature(n,t(n))}}}),_r=({ParentMode:e,getFeature:t,getCoords:n})=>({onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(t,n){if(Ln(t)){const e=In(this.map);bn(e,this.map,n.point);const t=Mn(e);t&&(n={...n,lngLat:t})}e.onMouseMove.call(this,t,n),this.map.fire("draw.geometrychange",t.polygon||t.line)},onMove(t,n){const r="move"===n?.type&&!n.originalEvent;if(["touch","keyboard"].includes(t.interfaceType)||r){Ln(t)&&Pn(In(this.map),this.map);const n=In(this.map),r=Ln(t)&&Mn(n);if(r){const n=this.map.project([r.lng,r.lat]);e.onMouseMove.call(this,t,{lngLat:r,point:n,originalEvent:new MouseEvent("mousemove",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",t.polygon||t.line)}else this._simulateMouse("mousemove",e.onMouseMove,t)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(t(e)))}}),xr=({ParentMode:e,geometryType:t,getFeature:n,getPlacedCoords:r})=>({_simulateMouse(e,t,n){const{map:r}=this,o=r.getCenter(),i=r.project(o);t.call(this,n,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",n.polygon||n.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},toDisplayFeatures(o,i,s){e.toDisplayFeatures.call(this,o,i,s);const a=n(o);i.geometry.type===t&&i.properties.id===a.id&&r(i).forEach(e=>s({type:"Feature",properties:{meta:"draw-vertex",parent:a.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}),Er=(e,t)=>{const{featureProp:n,geometryType:r,getCoords:o,validateClick:i,getPlacedCoords:s,excludeFeatureIdFromSetup:a=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:n,geometryType:r,getCoords:o,validateClick:i,getPlacedCoords:s,excludeFeatureIdFromSetup:a,finishOnInvalidClick:c,getFeature:e=>e[n],RUBBER_BAND_OFFSET:2,INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return{...e,...lr(l),...hr(l),...yr(l),...vr(l),..._r(l),...xr(l)}},Ir=Er(qt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>a(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Sr=Er(qt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>c(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),Mr="draw_point",br=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),Tr=qt.modes.draw_point,Pr=lr({ParentMode:Tr,featureProp:"point",excludeFeatureIdFromSetup:!1}),Cr={onKeyUp(){},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t,n=!0){e.interfaceType=t,n&&this._showCrossHair(e)},onCreate(e,t){const n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),e.resolvePointSymbol?.(e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){const n="move"===t?.type&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||n)&&Ln(e)&&Pn(In(this.map),this.map)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onTouchStart(e){this._setInterface(e,"touch"),this.onMove(e)},onTouchEnd(e){this._setInterface(e,"touch"),this.onMove(e)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onMouseMove(e,t){Ln(e)&&bn(In(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest(`#${e.addVertexButtonId}`)&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),br.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&br.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())return;const n=In(this.map),r=Ln(e)&&Sn(n)?Mn(n):null;this._commit(e,r||t.lngLat)},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){const t=In(this.map);Ln(e)&&Pn(t,this.map);const n=Ln(e)&&Sn(t)?Mn(t):null;this._commit(e,n||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:r,reason:o}=i(n,{mode:Mr,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return r||e.fire("draw.placementblocked",{feature:n,reason:o??null,phase:"place",mode:Mr,vertexIndex:0}),r})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},wr={...Tr,...Pr,...Cr},Lr=(e,t,n)=>["coalesce",["get",`user_${t}${e.id.charAt(0).toUpperCase()+e.id.slice(1)}`],["get",`user_${t}`],n],Or=["coalesce",["get","user_sortKey"],0],Ar=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":Or},paint:{"fill-color":Lr(e,"fill",t.shapeFill)}}),kr=(e,t)=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round","line-sort-key":Or},paint:{"line-color":Lr(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),Fr=e=>({id:"stroke-preview-line",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),Vr=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),Nr=(e,t,n)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":n,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Dr=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Rr=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),Ur=(e,t,n)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":n,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),Br=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),jr=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Gr=(e,t={})=>{const n=w(e,t),{vertexRadius:r,midpointRadius:o,vertexHaloRadius:i,midpointHaloRadius:s}=l;return[Ar(e,n),(p=n.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":p}}),(d=n.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":d,"line-width":2,"line-opacity":1}}),(u=n.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":u,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),kr(e,n),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":Or},paint:{}},(c=n.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":c,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(a=n.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":a,"line-width":2,"line-opacity":1}}),Fr(n.editStroke),Rr(n.editMidpoint,o),Ur(n.editHalo,n.editActive,s),Br(n.editMidpoint,o),Vr(n.editVertex,r),Nr(n.editHalo,n.editActive,i),Dr(n.editVertex,r),jr(n.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}];var a,c,u,d,p};function Hr(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Yr(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Xr(e,t,n){void 0===n&&(n={});var r=Hr(e),o=Hr(t),i=u(o[1]-r[1]),s=u(o[0]-r[0]),a=u(r[1]),c=u(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return d(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}function $r(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Kr(e,t,n,r={}){const o=$r(e),i=u(o[0]),s=u(o[1]),a=u(n),c=p(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),d=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),g=f(d),m=f(l);return void 0!==o[2]?h([g,m,o[2]],r.properties):h([g,m],r.properties)}function Jr(e,t){var n;return void 0===t&&(t={}),function(e,t){if(e.length>1)return m(e,t);return y(e[0],t)}(("Feature"===(n=e).type?n.geometry:n).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function qr(e,t,n={}){if(!0===n.final)return function(e,t){let n=qr(t,e);return n=(n+180)%360,n}(e,t);const r=$r(e),o=$r(t),i=u(r[0]),s=u(o[0]),a=u(r[1]),c=u(o[1]),l=Math.sin(s-i)*Math.cos(c),d=Math.cos(a)*Math.sin(c)-Math.sin(a)*Math.cos(c)*Math.cos(s-i);return f(Math.atan2(l,d))}var Zr=qr;function zr(e,t,n,r){void 0===r&&(r={});var o=Hr(e),i=u(o[0]),s=u(o[1]),a=u(n),c=p(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),d=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),g=f(d),m=f(l);return h([g,m],r.properties)}function Wr(e){if(!e)throw new Error("geojson is required");var t=[];return v(e,function(e){!function(e,t){var n=[],r=e.geometry;if(null!==r){switch(r.type){case"Polygon":n=Yr(r);break;case"LineString":n=[Yr(r)]}n.forEach(function(n){var r=function(e,t){var n=[];return e.reduce(function(e,r){var o,i,s,a,c,l,u=y([e,r],t);return u.bbox=(i=r,s=(o=e)[0],a=o[1],c=i[0],l=i[1],[s<c?s:c,a<l?a:l,s>c?s:c,a>l?a:l]),n.push(u),r}),n}(n,e.properties);r.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),_(t)}var Qr={exports:{}};function eo(e,t,n,r,o){to(e,t,n||0,r||e.length-1,o||ro)}function to(e,t,n,r,o){for(;r>n;){if(r-n>600){var i=r-n+1,s=t-n+1,a=Math.log(i),c=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*c*(i-c)/i)*(s-i/2<0?-1:1);to(e,t,Math.max(n,Math.floor(t-s*c/i+l)),Math.min(r,Math.floor(t+(i-s)*c/i+l)),o)}var u=e[t],d=n,p=r;for(no(e,n,t),o(e[r],u)>0&&no(e,n,r);d<p;){for(no(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[n],u)?no(e,n,p):no(e,++p,r),p<=t&&(n=p+1),t<=p&&(r=p-1)}}function no(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function ro(e,t){return e<t?-1:e>t?1:0}function oo(e,t,n){if(!n)return t.indexOf(e);for(let r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function io(e,t){so(e,0,e.children.length,t,e)}function so(e,t,n,r,o){o||(o=yo(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<n;i++){const t=e.children[i];ao(o,e.leaf?r(t):t)}return o}function ao(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function co(e,t){return e.minX-t.minX}function lo(e,t){return e.minY-t.minY}function uo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function po(e){return e.maxX-e.minX+(e.maxY-e.minY)}function ho(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function fo(e,t){const n=Math.max(e.minX,t.minX),r=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,i-r)}function go(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function mo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function yo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function vo(e,t,n,r,o){const i=[t,n];for(;i.length;){if((n=i.pop())-(t=i.pop())<=r)continue;const s=t+Math.ceil((n-t)/r/2)*r;eo(e,s,t,n,o),i.push(t,s,s,n)}}var _o,xo=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!mo(e,t))return n;const r=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const s=t.children[i],a=t.leaf?r(s):s;mo(e,a)&&(t.leaf?n.push(s):go(e,a)?this._all(s,n):o.push(s))}t=o.pop()}return n}collides(e){let t=this.data;if(!mo(e,t))return!1;const n=[];for(;t;){for(let r=0;r<t.children.length;r++){const o=t.children[r],i=t.leaf?this.toBBox(o):o;if(mo(e,i)){if(t.leaf||go(e,i))return!0;n.push(o)}}t=n.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=yo([]),this}remove(e,t){if(!e)return this;let n=this.data;const r=this.toBBox(e),o=[],i=[];let s,a,c;for(;n||o.length;){if(n||(n=o.pop(),a=o[o.length-1],s=i.pop(),c=!0),n.leaf){const r=oo(e,n.children,t);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}c||n.leaf||!go(n,r)?a?(s++,n=a.children[s],c=!1):n=null:(o.push(n),i.push(s),s=0,a=n,n=n.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){const o=n-t+1;let i,s=this._maxEntries;if(o<=s)return i=yo(e.slice(t,n+1)),io(i,this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,r-1))),i=yo([]),i.leaf=!1,i.height=r;const a=Math.ceil(o/s),c=a*Math.ceil(Math.sqrt(s));vo(e,t,n,c,this.compareMinX);for(let o=t;o<=n;o+=c){const t=Math.min(o+c-1,n);vo(e,o,t,a,this.compareMinY);for(let n=o;n<=t;n+=a){const o=Math.min(n+a-1,t);i.children.push(this._build(e,n,o,r-1))}}return io(i,this.toBBox),i}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const s=t.children[i],a=uo(s),c=ho(e,s)-a;c<o?(o=c,r=a<r?a:r,n=s):c===o&&a<r&&(r=a,n=s)}t=n||t.children[0]}return t}_insert(e,t,n){const r=n?e:this.toBBox(e),o=[],i=this._chooseSubtree(r,this.data,t,o);for(i.children.push(e),ao(i,r);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(r,o,t)}_split(e,t){const n=e[t],r=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,r);const i=this._chooseSplitIndex(n,o,r),s=yo(n.children.splice(i,n.children.length-i));s.height=n.height,s.leaf=n.leaf,io(n,this.toBBox),io(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this.data=yo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,io(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,o=1/0,i=1/0;for(let s=t;s<=n-t;s++){const t=so(e,0,s,this.toBBox),a=so(e,s,n,this.toBBox),c=fo(t,a),l=uo(t)+uo(a);c<o?(o=c,r=s,i=l<i?l:i):c===o&&l<i&&(i=l,r=s)}return r||n-t}_chooseSplitAxis(e,t,n){const r=e.leaf?this.compareMinX:co,o=e.leaf?this.compareMinY:lo;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,o)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);const o=this.toBBox,i=so(e,0,t,o),s=so(e,n-t,n,o);let a=po(i)+po(s);for(let r=t;r<n-t;r++){const t=e.children[r];ao(i,e.leaf?o(t):t),a+=po(i)}for(let r=n-t-1;r>=t;r--){const t=e.children[r];ao(s,e.leaf?o(t):t),a+=po(s)}return a}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)ao(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)0===e[n].children.length?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():io(e[n],this.toBBox)}}}),Eo=pe(xo),Io={};function So(){if(_o)return Io;_o=1,Object.defineProperty(Io,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},n={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function r(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function o(e,t,n={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return r({type:"Point",coordinates:e},t,n)}function i(e,t,n={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return r({type:"Polygon",coordinates:e},t,n)}function s(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return r({type:"LineString",coordinates:e},t,n)}function a(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function c(e,t,n={}){return r({type:"MultiLineString",coordinates:e},t,n)}function l(e,t,n={}){return r({type:"MultiPoint",coordinates:e},t,n)}function u(e,t,n={}){return r({type:"MultiPolygon",coordinates:e},t,n)}function d(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e*r}function p(e,n="kilometers"){const r=t[n];if(!r)throw new Error(n+" units is invalid");return e/r}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Io.areaFactors=n,Io.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Io.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Io.convertArea=function(e,t="meters",r="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=n[t];if(!o)throw new Error("invalid original units");const i=n[r];if(!i)throw new Error("invalid final units");return e/o*i},Io.convertLength=function(e,t="kilometers",n="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),n)},Io.degreesToRadians=function(e){return e%360*Math.PI/180},Io.earthRadius=e,Io.factors=t,Io.feature=r,Io.featureCollection=a,Io.geometry=function(e,t,n={}){switch(e){case"Point":return o(t).geometry;case"LineString":return s(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},Io.geometryCollection=function(e,t,n={}){return r({type:"GeometryCollection",geometries:e},t,n)},Io.isNumber=f,Io.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Io.lengthToDegrees=function(e,t){return h(p(e,t))},Io.lengthToRadians=p,Io.lineString=s,Io.lineStrings=function(e,t,n={}){return a(e.map(e=>s(e,t)),n)},Io.multiLineString=c,Io.multiPoint=l,Io.multiPolygon=u,Io.point=o,Io.points=function(e,t,n={}){return a(e.map(e=>o(e,t)),n)},Io.polygon=i,Io.polygons=function(e,t,n={}){return a(e.map(e=>i(e,t)),n)},Io.radiansToDegrees=h,Io.radiansToLength=d,Io.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const n=Math.pow(10,t||0);return Math.round(e*n)/n},Io.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach(e=>{if(!f(e))throw new Error("bbox must only contain numbers")})},Io.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},Io}var Mo,bo={};function To(){if(Mo)return bo;Mo=1,Object.defineProperty(bo,"__esModule",{value:!0});var e=So();function t(e,n,r){if(null!==e)for(var o,i,s,a,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,m="Feature"===f,y=g?e.features.length:1,v=0;v<y;v++){c=(d=!!(u=g?e.features[v].geometry:m?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var _=0;_<c;_++){var x=0,E=0;if(null!==(a=d?u.geometries[_]:u)){l=a.coordinates;var I=a.type;switch(p=!r||"Polygon"!==I&&"MultiPolygon"!==I?0:1,I){case null:break;case"Point":if(!1===n(l,h,v,x,E))return!1;h++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===n(l[o],h,v,x,E))return!1;h++,"MultiPoint"===I&&x++}"LineString"===I&&x++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===n(l[o][i],h,v,x,E))return!1;h++}"MultiLineString"===I&&x++,"Polygon"===I&&E++}"Polygon"===I&&x++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(E=0,i=0;i<l[o].length;i++){for(s=0;s<l[o][i].length-p;s++){if(!1===n(l[o][i][s],h,v,x,E))return!1;h++}E++}x++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===t(a.geometries[o],n,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function n(e,t){var n;switch(e.type){case"FeatureCollection":for(n=0;n<e.features.length&&!1!==t(e.features[n].properties,n);n++);break;case"Feature":t(e.properties,0)}}function r(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function o(e,t){var n,r,o,i,s,a,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(n=0;n<g;n++){for(a=h?e.features[n].geometry:f?e.geometry:e,l=h?e.features[n].properties:f?e.properties:{},u=h?e.features[n].bbox:f?e.bbox:void 0,d=h?e.features[n].id:f?e.id:void 0,s=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,o=0;o<s;o++)if(null!==(i=c?a.geometries[o]:a))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(r=0;r<i.geometries.length;r++)if(!1===t(i.geometries[r],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,n){o(t,function(t,r,o,i,s){var a,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==n(e.feature.call(void 0,t,o,{bbox:i,id:s}),r,0)&&void 0}switch(c){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:a,coordinates:t.coordinates[l]};if(!1===n(e.feature.call(void 0,u,o),r,l))return!1}})}function s(n,r){i(n,function(n,o,i){var s=0;if(n.geometry){var a=n.geometry.type;if("Point"!==a&&"MultiPoint"!==a){var c,l=0,u=0,d=0;return!1!==t(n,function(t,a,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(s=0);var g=e.lineString.call(void 0,[c,t],n.properties);if(!1===r(g,o,i,f,s))return!1;s++,c=t})&&void 0}}})}function a(t,n){if(!t)throw new Error("geojson is required");i(t,function(t,r,o){if(null!==t.geometry){var i=t.geometry.type,s=t.geometry.coordinates;switch(i){case"LineString":if(!1===n(t,r,o,0,0))return!1;break;case"Polygon":for(var a=0;a<s.length;a++)if(!1===n(e.lineString.call(void 0,s[a],t.properties),r,o,a))return!1}}})}return bo.coordAll=function(e){var n=[];return t(e,function(e){n.push(e)}),n},bo.coordEach=t,bo.coordReduce=function(e,n,r,o){var i=r;return t(e,function(e,t,o,s,a){i=0===t&&void 0===r?e:n(i,e,t,o,s,a)},o),i},bo.featureEach=r,bo.featureReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},bo.findPoint=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.coordIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":return e.point.call(void 0,l,c,n);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,n);case"LineString":return a<0&&(a=l.length+a),e.point.call(void 0,l[a],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a),e.point.call(void 0,l[s][a],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),e.point.call(void 0,l[i][a],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a),e.point.call(void 0,l[i][s][a],c,n)}throw new Error("geojson is invalid")},bo.findSegment=function(t,n){if(n=n||{},!e.isObject.call(void 0,n))throw new Error("options is invalid");var r,o=n.featureIndex||0,i=n.multiFeatureIndex||0,s=n.geometryIndex||0,a=n.segmentIndex||0,c=n.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,r=t.features[o].geometry;break;case"Feature":c=c||t.properties,r=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":r=t;break;default:throw new Error("geojson is invalid")}if(null===r)return null;var l=r.coordinates;switch(r.type){case"Point":case"MultiPoint":return null;case"LineString":return a<0&&(a=l.length+a-1),e.lineString.call(void 0,[l[a],l[a+1]],c,n);case"Polygon":return s<0&&(s=l.length+s),a<0&&(a=l[s].length+a-1),e.lineString.call(void 0,[l[s][a],l[s][a+1]],c,n);case"MultiLineString":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a-1),e.lineString.call(void 0,[l[i][a],l[i][a+1]],c,n);case"MultiPolygon":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),a<0&&(a=l[i][s].length-a-1),e.lineString.call(void 0,[l[i][s][a],l[i][s][a+1]],c,n)}throw new Error("geojson is invalid")},bo.flattenEach=i,bo.flattenReduce=function(e,t,n){var r=n;return i(e,function(e,o,i){r=0===o&&0===i&&void 0===n?e:t(r,e,o,i)}),r},bo.geomEach=o,bo.geomReduce=function(e,t,n){var r=n;return o(e,function(e,o,i,s,a){r=0===o&&void 0===n?e:t(r,e,o,i,s,a)}),r},bo.lineEach=a,bo.lineReduce=function(e,t,n){var r=n;return a(e,function(e,o,i,s){r=0===o&&void 0===n?e:t(r,e,o,i,s)}),r},bo.propEach=n,bo.propReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},bo.segmentEach=s,bo.segmentReduce=function(e,t,n){var r=n,o=!1;return s(e,function(e,i,s,a,c){r=!1===o&&void 0===n?e:t(r,e,i,s,a,c),o=!0}),r},bo}var Po,Co,wo={};function Lo(){if(Po)return wo;Po=1,Object.defineProperty(wo,"__esModule",{value:!0});var e=To();function t(t,n={}){if(null!=t.bbox&&!0!==n.recompute)return t.bbox;const r=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r}var n=t;return wo.bbox=t,wo.default=n,wo}var Oo=function(){if(Co)return Qr.exports;Co=1;var e=Eo,t=So(),n=To(),r=Lo().default,o=n.featureEach;n.coordEach,t.polygon;var i=t.featureCollection;function s(t){var n=new e(t);return n.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.insert.call(this,t)},n.load=function(t){var n=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:r(e),n.push(e)}),e.prototype.load.call(this,n)},n.remove=function(t,n){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:r(t),e.prototype.remove.call(this,t,n)},n.clear=function(){return e.prototype.clear.call(this)},n.search=function(t){var n=e.prototype.search.call(this,this.toBBox(t));return i(n)},n.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},n.all=function(){var t=e.prototype.all.call(this);return i(t)},n.toJSON=function(){return e.prototype.toJSON.call(this)},n.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},n.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=r(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=r(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},n}return Qr.exports=s,Qr.exports.default=s,Qr.exports}(),Ao=de(Oo);function ko(e,t){var n={},r=[];if("LineString"===e.type&&(e=x(e)),"LineString"===t.type&&(t=x(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=Fo(e,t);return o&&r.push(o),_(r)}var i=Ao();return i.load(Wr(t)),E(Wr(e),function(e){E(i.search(e),function(t){var o=Fo(e,t);if(o){var i=Yr(o).join(",");n[i]||(n[i]=!0,r.push(o))}})}),_(r)}function Fo(e,t){var n=Yr(e),r=Yr(t);if(2!==n.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==r.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=n[0][0],i=n[0][1],s=n[1][0],a=n[1][1],c=r[0][0],l=r[0][1],u=r[1][0],d=r[1][1],p=(d-l)*(s-o)-(u-c)*(a-i),f=(u-c)*(i-l)-(d-l)*(o-c),g=(s-o)*(i-l)-(a-i)*(o-c);if(0===p)return null;var m=f/p,y=g/p;return m>=0&&m<=1&&y>=0&&y<=1?h([o+m*(s-o),i+m*(a-i)]):null}function Vo(e,t,n){void 0===n&&(n={});var r=h([1/0,1/0],{dist:1/0}),o=0;return v(e,function(e){for(var i=Yr(e),s=0;s<i.length-1;s++){var a=h(i[s]);a.properties.dist=Xr(t,a,n);var c=h(i[s+1]);c.properties.dist=Xr(t,c,n);var l=Xr(a,c,n),u=Math.max(a.properties.dist,c.properties.dist),d=Zr(a,c),p=zr(t,u,d+90,n),f=zr(t,u,d-90,n),g=ko(y([p.geometry.coordinates,f.geometry.coordinates]),y([a.geometry.coordinates,c.geometry.coordinates])),m=null;g.features.length>0&&((m=g.features[0]).properties.dist=Xr(t,m,n),m.properties.location=o+Xr(a,m,n)),a.properties.dist<r.properties.dist&&((r=a).properties.index=s,r.properties.location=o),c.properties.dist<r.properties.dist&&((r=c).properties.index=s+1,r.properties.location=o+l),m&&m.properties.dist<r.properties.dist&&((r=m).properties.index=s),o+=l}}),r}function No(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Do(e,t){var n=function(e,t,n,r){void 0===r&&(r={});var o=No(e),i=u(o[0]),s=u(o[1]),a=u(n),c=p(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),d=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),g=f(d),m=f(l);return h([g,m],r.properties)}(e,function(e,t,n){void 0===n&&(n={});var r=No(e),o=No(t),i=u(o[1]-r[1]),s=u(o[0]-r[0]),a=u(r[1]),c=u(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return d(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}(e,t)/2,Zr(e,t));return n}var Ro=function(){return Ro=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ro.apply(this,arguments)},Uo=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],n=0;n<e.features.length;n++){var r=e.features[n],o=r.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var s=this.features.unknow.snapPoints;i=Ro(Ro({},i),s)}var a=this.doSnap(r,i);t.push(a)}else if(void 0!==this.features.unknow){s=this.features.unknow.snapPoints,a=this.doSnap(r,s);t.push(a)}else t.push(r)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return Xr(h(e),h(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var n=e.geometry.coordinates;for(var r in t)this.isPointSnapped(n,t[r])&&(e.geometry.coordinates=t[r]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],s=0;s<o.length;s++){for(var a=o[s],c=[],l=0;l<a.length;l++){var u=a[l],d=!1;for(var r in t)if(this.isPointSnapped(u,t[r])){d=!0,c.push(t[r]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var r in t)if(this.isPointSnapped(h,t[r])){d=!0,c.push(t[r]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,n=this.map.unproject(t),r=[t.x+this.options.radius,t.y],o=this.map.unproject(r),i=Xr(h([n.lng,n.lat]),h([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var s=!1,a=this.getCloseFeatures(e,i);a?(this.snapStatus=!0,this.snapCoords=a.coords,s=function(e,t,n={}){const r=n.steps||64,o=n.properties?n.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<r;o++)i.push(Kr(e,t,-360*o/r,n).geometry.coordinates);return i.push(i[0]),g([i],o)}(a.coords,i,{steps:64,units:"meters",properties:{color:a.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=_(0==s?[]:[s]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(_([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var n=e.map.getSource("mapbox-gl-draw-hot");if(n){var r=n._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];r.features.length>0&&(r.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],n=t[0].toFixed(6),r=t[1].toFixed(6),o={};if(o["".concat(n,"_").concat(r)]=t,e){var i=e._data;if(i.features.length>0){var s=i.features.find(function(e){return"feature"==e.properties.meta});if(s){var a=s.properties.id;this.features[a]?this.features[a].snapPoints["".concat(n,"_").concat(r)]=t:this.features[a]={id:a,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(n,"_").concat(r)]=t:this.features.unknow={id:a,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,n){var r=I(e),o=[];if(r.map(function(e){var r=Xr(h(e),h([t.lng,t.lat]),{units:"meters"});r<n&&o.push({coords:e,dist:r,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,n){var r=[];switch(e.geometry.type){case"LineString":r.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){r.push(y(e))});break;case"Polygon":var o=Jr(e.geometry);r.push(o);break;case"MultiPolygon":Jr(e.geometry).coodinates.map(function(e){r.push(y(e))})}return r},e.prototype.searchInMidPoint=function(e,t,n){var r=this.getLines(e,t,n),o=[];r.map(function(e){o=o.concat(Wr(e).features)});var i=[];if(o.map(function(e){var r=Do(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Xr(r,h([t.lng,t.lat]),{units:"meters"});o<n&&i.push({coords:r.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,n){for(var r=this.getLines(e,t,n),o=[],i=0;i<r.length;i++){var s=Vo(r[i],h([t.lng,t.lat]),{units:"meters"});void 0!==s.properties.dist&&s.properties.dist<n&&o.push({coords:s.geometry.coordinates,dist:s.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var n=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(n.length>0){for(var r,o=!1,i=0;i<n.length;i++){var s=n[i],a=this.options.rules,c=e.lngLat;if(o=!1,-1!==a.indexOf("vertex")&&null==r&&(r=this.searchInVertex(s,c,t))){o=!0;break}if(-1!==a.indexOf("midpoint")&&null==r&&(r=this.searchInMidPoint(s,c,t))){o=!0;break}if(-1!==a.indexOf("edge")&&null==r&&(r=this.searchInEdge(s,c,t))){o=!0;break}}return!!o&&r}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}();const Bo="snap-helper-circle",jo="mapbox-gl-draw-hot";function Go(e){if(Uo.prototype.__snapPatched)return;Uo.prototype.__snapPatched=!0;const t=Uo.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){if(!this.status)return;const n=t.setMapData.call(this,e);return e?.features?.length>0&&this.map?.getLayer(Bo)&&this.map.setLayoutProperty(Bo,"visibility","visible"),n},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,n,r){const o=e.geometry;if(!o?.coordinates)return[];const i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>g(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>y(e)):t.getLines.call(this,e,n,r)}catch{return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];const o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));const i=this.options.radius||n.snapRadius,s=e.point;e.point=[[s.x-i,s.y-i],[s.x+i,s.y+i]];const a=t.getCloseFeatures.call(this,e,r);return e.point=s,a}}(t,r),function(e,t,n){e.searchInVertex=function(...e){const r=t.searchInVertex.apply(this,e);return r&&(r.color=n.vertex),r},e.searchInMidPoint=function(...e){const r=t.searchInMidPoint.apply(this,e);return r&&(r.color=n.midpoint),r},e.searchInEdge=function(...e){const r=t.searchInEdge.apply(this,e);return r&&(r.color=n.edge),r}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){if(this.status&&!this.map?._isZooming&&(!this._autoSnapSuspended||e._explicit))try{const n=t.snapToClosestPoint.call(this,e);return this.closeFeatures?.length>100&&(this.closeFeatures.length=0),this.lines?.length>100&&(this.lines.length=0),n}catch{return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}function Ho(e,t){!function n(){const r=e();null!==r&&(r?t(r):requestAnimationFrame(n))}()}function Yo(e){if(!e||e._data&&Array.isArray(e._data?.features))return;let t={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>t,set:e=>{t=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}const Xo=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function $o(e,t,n,r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(Bo)&&e.removeLayer(Bo),e.getSource(Bo)&&e.removeSource(Bo)}(e),Yo(n);const o=new Uo({map:e,drawing:t,options:{layers:r.layers,radius:r.radius,rules:r.rules},status:r.status,onSnapped:r.onSnapped});return function(e,t,n){let r=t;Object.defineProperty(e,"status",{get:()=>r&&Xo.has(n.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{r=e}}(o,r.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,r.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function Ko(e,t,n){e.on("style.load",()=>{Ho(()=>e._removed?null:e.getSource(jo),r=>{Yo(r),function(e){e.getSource(Bo)||e.addSource(Bo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Bo)||e.addLayer({id:Bo,type:"fill",source:Bo,paint:{"fill-color":["get","color"]},layout:{visibility:e._snapInstance?.status?"visible":"none"}})}(e),e._snapInstance||$o(e,t,r,n)})})}function Jo(e,t,r={}){if(e._snapInitialized)return e._snapInstance;e._snapInitialized=!0;const{layers:o=[],radius:i=n.snapRadius,rules:s=["vertex","midpoint","edge"],status:a=!1,onSnapped:c=()=>{},colors:l={}}=r,u={layers:o,radius:i,rules:s,status:a,onSnapped:c};return Go({vertex:S.snapVertex,midpoint:S.snapMidpoint,edge:S.snapEdge,...l}),Ko(e,t,u),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(Bo)){e.setLayoutProperty(Bo,"visibility","none");const t=e._snapInstance;t?.status&&e.setLayoutProperty(Bo,"visibility","visible")}})}(e),Ho(()=>e._removed?null:e.getSource(jo),n=>$o(e,t,n,u)),e._snapInstance}const qo="point-symbol",Zo=new Set([`${qo}.hot`,`${qo}.cold`]),zo=(e,t)=>{const n=(e=>{const t=["match",["get","user_symbolImageId"]];for(const[n,r]of Object.entries(e))t.push(n,["literal",r]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);t.options?.styles?.forEach(e=>{Zo.has(e.id)&&(e.layout={...e.layout,"icon-offset":n})}),Zo.forEach(t=>{e.getLayer(t)&&e.setLayoutProperty(t,"icon-offset",n)})},Wo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:o,properties:i,pixelRatioOverride:s})=>{if(!M(i))return null;const a=n._drawCurrentMapStyle,c=s??(e=>e.getPixelRatio?.()||1)(n);await t.addSymbolsToMap([i],a,r,c);const l=e.get(o);if(!l)return null;const u=r.getSymbolImageId(i,a,"normal",c);if(!u)return null;const d=t.getActiveSymbolImageId(u),p=t.getSelectedSymbolImageId(u),h=t.getSymbolIconLayout(r.getSymbolDef(i));return((e,t,n,r)=>{e._symbolIconOffsetMap??={},e._symbolIconOffsetMap[n]||(e._symbolIconOffsetMap[n]=r,zo(e,t))})(n,e,u,h["icon-offset"]),{...l,properties:{...i,symbolImageId:u,symbolIconAnchor:h["icon-anchor"],symbolActiveImageId:d,symbolSelectedImageId:p}}},Qo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,pixelRatioOverride:o})=>{n._pointSymbolRefreshId=(n._pointSymbolRefreshId??0)+1;const i=n._pointSymbolRefreshId,s=e.getAll().features.filter(e=>"Point"===e.geometry.type&&M(e.properties)),a=await Promise.allSettled(s.map(i=>Wo({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:i.id,properties:i.properties,pixelRatioOverride:o})));if(a.filter(e=>"rejected"===e.status).forEach(e=>{b.error("[draw] failed to resolve point symbol",e.reason)}),n._pointSymbolRefreshId!==i)return;const c=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);c.length&&e.add({type:"FeatureCollection",features:c}),((e,t)=>{const n=e._symbolIconOffsetMap;if(!n)return;const r=new Set(t.getAll().features.map(e=>e.properties?.symbolImageId)),o=Object.keys(n).filter(e=>!r.has(e));o.length&&(o.forEach(e=>delete n[e]),zo(e,t))})(n,e)},ei="mapbox-gl-draw-cold",ti="mapbox-gl-draw-hot",ni=({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,onDone:i})=>{const s=e._drawCurrentMapStyle;e.once("idle",()=>{const a=((e,t)=>{if(e.getSource(ei))return!1;const n={type:"FeatureCollection",features:[]};return e.addSource(ei,{data:n,type:"geojson"}),e.addSource(ti,{data:n,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(e,t);((e,t,n={})=>{Gr(t,n).forEach(t=>{Object.entries(t.paint).forEach(([n,r])=>{e.getLayer(`${t.id}.cold`)&&e.setPaintProperty(`${t.id}.cold`,n,r),e.getLayer(`${t.id}.hot`)&&e.setPaintProperty(`${t.id}.hot`,n,r)})})})(e,s,o);const c=e._drawEditContainer?.querySelector("[data-im-draw-touch-target]");jn(c,s,o),Qo({draw:t,mapProvider:n,map:e,symbolRegistry:r}).then(()=>{a&&t.set(t.getAll()),e.triggerRepaint(),i()}).catch(e=>b.error("[draw] failed to refresh point symbols after a style change",e))})},ri=({mapStyle:e,mapProvider:t,symbolRegistry:r,events:o,eventBus:i,snapLayers:s,pluginConfig:a={}})=>{const{map:c}=t;qt.constants.classes.CONTROL_BASE="maplibregl-ctrl",qt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",qt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";const l={...qt.modes,disabled:Zt,edit_vertex:er,edit_point:cr,draw_polygon:Ir,draw_line:Sr,draw_point:wr};let u=t._mapboxDrawInstance;u?Object.assign(u.modes,l):(u=new qt({modes:l,styles:Gr(e,a),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),c.addControl(u),t._mapboxDrawInstance=u);const d=((e,t)=>{const n=e.getCanvas();let r=null;const o=e=>{1===e.touches.length&&(r={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"!==t.getMode()||!r)return void(r=null);const o=e.changedTouches[0],i=o.clientX-r.x,s=o.clientY-r.y;Date.now()-r.time<300&&Math.abs(i)<10&&Math.abs(s)<10&&n.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),r=null};return n.addEventListener("touchstart",o,{passive:!0}),n.addEventListener("touchend",i,{passive:!0}),{remove(){n.removeEventListener("touchstart",o),n.removeEventListener("touchend",i)}}})(c,u);t.draw=u,c._drawCurrentMapStyle=e,c._drawPluginConfig=a,t.snapEnabled=!1;let p=t.undoStack;p||(p=k(e=>c.fire("draw.undochange",{length:e})),t.undoStack=p),c._undoStack=p;const h=w(e,a);Jo(c,u,{layers:s,radius:a.snapRadius??n.snapRadius,rules:["vertex","edge"],colors:{vertex:h.snapVertex,edge:h.snapEdge}});const f=()=>i.emit(o.MAP_DATA_CHANGE),{handleSetMapStyle:g,handleStyleChanged:m}=(({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,eventBus:i,events:s,notifyPointSymbolsRefreshed:a})=>{const c=t=>{e._drawCurrentMapStyle=t};i.on(s.MAP_SET_STYLE,c);let l=!1;const u=()=>{l||(l=!0,ni({map:e,draw:t,mapProvider:n,symbolRegistry:r,pluginConfig:o,onDone:()=>{l=!1,a()}}))};return i.on(s.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:c,draw:u,mapProvider:t,symbolRegistry:r,pluginConfig:a,eventBus:i,events:o,notifyPointSymbolsRefreshed:f}),y=e=>{c.fire("draw.scalechange",{scale:T[e]})};i.on(o.MAP_SET_SIZE,y);const v=e=>{Qo({draw:u,mapProvider:t,map:c,symbolRegistry:r,pixelRatioOverride:e}).then(()=>{c.triggerRepaint(),f()}).catch(e=>b.error("[draw] failed to refresh point symbols",e))};return i.on(o.MAP_SET_PIXEL_RATIO,v),{draw:u,remove(){d.remove(),i.off(o.MAP_SET_STYLE,g),i.off(o.MAP_STYLE_CHANGE,m),i.off(o.MAP_SET_SIZE,y),i.off(o.MAP_SET_PIXEL_RATIO,v),u.changeMode("disabled"),t.draw=null}}},oi=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),ii=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),si=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),ai=(e,t)=>{if("draw_polygon"===e)return{feature:oi(t),numVertices:(t[0]?.length??1)-1};if("draw_line"===e)return{feature:ii(t),numVertices:(t?.length??1)-1};if("edit_vertex"===e){const e=t[0];return Array.isArray(e?.[0])?{feature:oi(t),numVertices:e.length}:{feature:ii(t),numVertices:t?.length??0}}return"edit_point"===e?{feature:si(t),numVertices:1}:null};class ci{constructor(e,t){this._mapProvider=e,this._map=e.map,this._symbolRegistry=t.symbolRegistry,this._bus=(()=>{const e=new Map;return{on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)},emit(t,...n){const r=e.get(t);r&&Array.from(r).forEach(e=>e(...n))}}})(),this._editingFeatureId=null,this._sortKeyCounter=0;const{draw:n,remove:r}=ri({mapStyle:t.mapStyle,mapProvider:e,symbolRegistry:t.symbolRegistry,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:t.pluginConfig??{}});this._draw=n,this._cleanupDraw=r,this._liveStroke=F({onChange:(e,t)=>{this._applyStrokeInvalid(e);const n=this._draw.getMode();"edit_vertex"!==n&&"edit_point"!==n||this._bus.emit(P.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=V({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(P.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{const t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(P.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(P.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(P.CANCEL),vertexselection:e=>this._bus.emit(P.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(P.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(P.UNDO_CHANGE,e.length),update:e=>this._bus.emit(P.UPDATE,e.features[0]),geometrychange:e=>{e?.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(P.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(P.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(P.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(zt,this._mapHandlers.create),this._map.on(en,this._mapHandlers.editfinish),this._map.on(tn,this._mapHandlers.cancel),this._map.on(nn,this._mapHandlers.vertexselection),this._map.on(rn,this._mapHandlers.vertexchange),this._map.on(on,this._mapHandlers.undochange),this._map.on(Wt,this._mapHandlers.update),this._map.on(an,this._mapHandlers.geometrychange),this._map.on(ln,this._mapHandlers.placementblocked),this._map.on(cn,this._mapHandlers.interfacetypechange),this._map.on(Qt,this._mapHandlers.modechange),this._map.on(hn,this._mapHandlers.styledata)}changeMode(e,t={}){"edit_vertex"!==e&&"edit_point"!==e||(this._editingFeatureId=t.featureId??null),"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),"draw_point"===e&&(t={...t,resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)}),this._draw.changeMode(e,t),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){(async e=>{const t=await Wo(e);t&&e.draw.add(t)})({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>b.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(!e?.coordinates)return;const t=this._draw.getMode(),n=ai(t,e.coordinates);n&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:n.feature,numVertices:n.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update({...n,context:{mode:t},onGeometryChange:this._geometryValidator}))}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(cn,{interfaceType:e})}done(){this._mapProvider.undoStack?.clear();const e=this._draw.getMode();if(("edit_vertex"===e||"edit_point"===e)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(en,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==e&&"draw_line"!==e||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){this._mapProvider.undoStack?.clear();const e=this._draw.getMode();"draw_polygon"!==e&&"draw_line"!==e||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(sn)}nudgeSelectedVertex(e,t,n){this._map.fire(un,{dx:e,dy:t,isLargeStep:n})}getVertexItems(){const e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;const t=this._draw.get(this._editingFeatureId);if(!t)return e;const n=(e=>"Polygon"===e.type?{...e,coordinates:e.coordinates.map(e=>e.slice(0,-1))}:"MultiPolygon"===e.type?{...e,coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}:e)(t.geometry);return{vertices:fn(n),midpoints:gn(n)}}selectVertex(e){this._map.fire(dn,{index:e})}insertVertexAtMidpoint(e){this._map.fire(pn,{index:e})}setGeometryValid(e){this._map._drawGeometryValid=e}set _geometryValidator(e){this._map._drawGeometryValidator=e}get _geometryValidator(){return this._map._drawGeometryValidator}setInvalid(e){this._liveStroke.set(e)}_applyStrokeInvalid(e){this._setLayerVisibility("stroke-active",!e),this._setLayerVisibility("stroke-active-invalid",e),this._setLayerVisibility("fill-active",!e)}_setLayerVisibility(e,t){["hot","cold"].forEach(n=>{const r=`${e}.${n}`;this._map.getLayer(r)&&this._map.setLayoutProperty(r,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){const t=null==e.properties?.sortKey?{...e.properties,sortKey:this._nextSortKey()}:e.properties,n={...e,properties:t},r=this._draw.add(n);return"Point"===n.geometry?.type&&M(t)&&this._resolvePointSymbol(r[0],t),r}setStyle(e,t){const n=this._draw.get(e);n&&this.add({...n,properties:{...n.properties,...t}})}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;const t=In(this._map);t?.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(wn(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){const t=In(this._map);t?.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,n){this._draw.setFeatureProperty(e,t,n)}setDrawingPreviewProperty(e,t){const n=this._currentDrawEvent;n?.properties&&(n.properties[e]=t),n?.ctx?.store?.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]).has(e.mode)||Cn(In(this._map),this._map)}_handleStyleData(){const e=this._map.getStyle();if(!e)return;this._liveStroke.refresh();const t=e.layers||[];t.length&&!t[t.length-1].source?.startsWith("mapbox-gl-draw")&&t.filter(e=>e.source?.startsWith("mapbox-gl-draw")).forEach(e=>this._map.moveLayer(e.id))}remove(){this._map.off(zt,this._mapHandlers.create),this._map.off(en,this._mapHandlers.editfinish),this._map.off(tn,this._mapHandlers.cancel),this._map.off(nn,this._mapHandlers.vertexselection),this._map.off(rn,this._mapHandlers.vertexchange),this._map.off(on,this._mapHandlers.undochange),this._map.off(Wt,this._mapHandlers.update),this._map.off(an,this._mapHandlers.geometrychange),this._map.off(ln,this._mapHandlers.placementblocked),this._map.off(cn,this._mapHandlers.interfacetypechange),this._map.off(Qt,this._mapHandlers.modechange),this._map.off(hn,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{ci as MaplibreDrawAdapter,ai as displayedShape};
|