@defra/interactive-map 0.0.59-alpha → 0.0.61-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 +2 -2
- package/assets/templates/add-symbols.njk +2 -2
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/button-definition.md +11 -0
- package/docs/api/context.md +2 -0
- package/docs/api/panel-definition.md +30 -0
- package/docs/api/symbol-config.md +12 -0
- package/docs/api.md +21 -2
- package/docs/assets/images/slot-map.svg +3 -3
- package/docs/plugins/datasets.md +11 -1
- package/docs/plugins/draw.md +26 -0
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.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/datasets/src/index.js +0 -1
- package/plugins/datasets/src/index.test.js +2 -8
- package/plugins/datasets/src/registry/dataset.test.js +9 -0
- 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/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/DrawInit.jsx +3 -0
- package/plugins/draw/src/DrawInit.test.jsx +16 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
- package/plugins/draw/src/defaults.js +4 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
- package/plugins/draw/src/manifest.js +4 -1
- package/plugins/draw/src/manifest.test.js +15 -2
- package/plugins/draw/src/utils/snapMinZoom.js +8 -0
- package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/src/manifest.js +1 -1
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +1 -0
- package/providers/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/esri/src/esriProvider.js +10 -21
- package/providers/esri/src/utils/coords.js +37 -7
- package/providers/esri/src/utils/coords.test.js +22 -1
- package/providers/esri/src/utils/spatial.js +1 -47
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +5 -14
- package/providers/maplibre/src/maplibreProvider.test.js +143 -146
- package/providers/maplibre/src/utils/spatial.js +0 -40
- package/providers/maplibre/src/utils/spatial.test.js +0 -35
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +5 -14
- package/providers/openlayers/src/openlayersProvider.test.js +12 -10
- package/providers/openlayers/src/utils/spatial.js +0 -39
- package/providers/openlayers/src/utils/spatial.test.js +1 -26
- package/src/App/components/Hints/Hints.jsx +9 -21
- package/src/App/components/Hints/Hints.test.jsx +20 -33
- package/src/App/components/MapButton/MapButton.jsx +20 -2
- package/src/App/components/MapButton/MapButton.module.scss +15 -1
- package/src/App/components/MapButton/MapButton.test.jsx +21 -3
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/components/Tooltip/Tooltip.jsx +29 -11
- package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
- package/src/App/components/Viewport/MapController.jsx +2 -0
- package/src/App/components/Viewport/MapController.test.jsx +3 -0
- package/src/App/hooks/useCrossHairAPI.js +27 -28
- package/src/App/hooks/useCrossHairAPI.test.js +64 -7
- package/src/App/hooks/useLayoutMeasurements.js +175 -131
- package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
- package/src/App/hooks/useMapProviderOverrides.js +114 -35
- package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
- package/src/App/hooks/useModalPanelBehaviour.js +18 -32
- package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
- package/src/App/hooks/useUserMoveTracking.js +65 -0
- package/src/App/hooks/useUserMoveTracking.test.js +99 -0
- package/src/App/hooks/useVisibleGeometry.js +35 -45
- package/src/App/hooks/useVisibleGeometry.test.js +149 -121
- package/src/App/layout/Layout.jsx +4 -4
- package/src/App/layout/layout.module.scss +124 -61
- package/src/App/renderer/mapButtons.js +1 -0
- package/src/App/renderer/mapButtons.test.js +8 -0
- package/src/App/store/AppProvider.jsx +3 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/App/store/mapActionsMap.js +2 -1
- package/src/App/store/mapActionsMap.test.js +6 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +1 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -2
- package/src/InteractiveMap/InteractiveMap.test.js +2 -2
- package/src/config/events.js +1 -1
- package/src/config/mapPanelSlots.js +8 -0
- package/src/config/symbolConfig.js +1 -1
- package/src/scss/settings/_colors.scss +4 -0
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +33 -8
- package/src/utils/getFitMove.js +73 -0
- package/src/utils/getFitMove.test.js +114 -0
- package/src/utils/getSafeZoneInset.js +122 -77
- package/src/utils/getSafeZoneInset.test.js +241 -54
- package/src/utils/getValueForStyle.js +10 -5
- package/src/utils/getValueForStyle.test.js +13 -2
- package/src/utils/renderedBoxes.js +25 -0
- package/src/utils/renderedBoxes.test.js +61 -0
- package/src/utils/screenBox.js +70 -0
- package/src/utils/screenBox.test.js +69 -0
- package/src/utils/symbolUtils.js +9 -9
- package/src/utils/symbolUtils.test.js +21 -0
- package/providers/esri/src/utils/spatial.test.js +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,c as t,T as n,C as r,K as o,M as i,v as s,t as a,a as c,b as l,d as u,S as d,e as p,r as h,l as f,p as g,f as m,g as y,m as v,h as _,j as x,k as I,n as E,o as S,q as M,s as b,u as P,w as T,A as C,x as w}from"./im-draw-plugin.js";import{c as L,r as O,a as A,s as k,b as F,h as V,d as N,e as D,f as R}from"./liveDrawChecks.js";import"preact/compat";const U={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"},B={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},j={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},G={POLYGON:"polygon",LINE:"line_string",POINT:"point"},H={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},Y={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},X={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},$={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},K={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},J={ACTIVE:"true",INACTIVE:"false"},q=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var Z=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:U,cursors:j,events:X,geojsonTypes:H,interactions:q,meta:K,modes:Y,sources:B,types:G,updateActions:$});function z(e){return function(t){const n=t.featureTarget;return!!n&&(!!n.properties&&n.properties.meta===e)}}function W(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.ACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function ee(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.INACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function te(e){return void 0===e.featureTarget}function ne(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 oe(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function ie(e){return"Escape"===e.key||27===e.keyCode}function se(e){return"Enter"===e.key||13===e.keyCode}function ae(e){return"Backspace"===e.key||8===e.keyCode}function ce(e){return"Delete"===e.key||46===e.keyCode}function le(e){return"1"===e.key||49===e.keyCode}function ue(e){return"2"===e.key||50===e.keyCode}function de(e){return"3"===e.key||51===e.keyCode}function pe(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var he=Object.freeze({__proto__:null,isActiveFeature:Q,isBackspaceKey:ae,isDeleteKey:ce,isDigit1Key:le,isDigit2Key:ue,isDigit3Key:de,isDigitKey:pe,isEnterKey:se,isEscapeKey:ie,isFeature:ne,isInactiveFeature:ee,isOfMetaType:z,isShiftDown:oe,isShiftMousedown:W,isTrue:function(){return!0},isVertex:re,noTarget:te});function fe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ge(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 me,ye,ve={},_e={};function xe(){return me||(me=1,_e.RADIUS=6378137,_e.FLATTENING=1/298.257223563,_e.POLAR_RADIUS=6356752.3142),_e}var Ie=function(){if(ye)return ve;ye=1;var e=xe();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 ve.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}},ve.ring=n,ve}(),Ee=fe(Ie);const Se={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Me(e,t){const n=Se[e.geometry.type]-Se[t.geometry.type];return 0===n&&e.geometry.type===H.POLYGON?e.area-t.area:n}function be(e){return e.map(e=>(e.geometry.type===H.POLYGON&&(e.area=Ee.geometry({type:H.FEATURE,property:{},geometry:e.geometry})),e)).sort(Me).map(e=>(delete e.area,e))}function Pe(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Te(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)}Te.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Te.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Te.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Te.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)},Te.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Ce=[K.FEATURE,K.MIDPOINT,K.VERTEX];var we={click:function(e,t,n){return Le(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return Le(e,t,n,n.options.touchBuffer)}};function Le(e,t,n,r){if(null===n.map)return[];const o=e?Pe(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!==Ce.indexOf(e.properties.meta)),a=new Te,c=[];return s.forEach(e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),be(c)}function Oe(e,t){const n=we.click(e,null,t),r={mouse:j.NONE};return n[0]&&(r.mouse=n[0].properties.active===J.ACTIVE?j.MOVE:j.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=j.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function Ae(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function ke(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=Ae(e.point,t.point);return s<r||s<o&&t.time-e.time<i}function Fe(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 Ae(e.point,t.point)<r&&t.time-e.time<o}const Ve=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 Ne=((e,t=21)=>(n=t)=>{let r="",o=0|n;for(;o--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function De(){return Ne()}const Re=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||De(),this.type=t.geometry.type};Re.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Re.prototype.incomingCoords=function(e){this.setCoordinates(e)},Re.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Re.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Re.prototype.setProperty=function(e,t){this.properties[e]=t},Re.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:H.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Re.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:H.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ue=function(e,t){Re.call(this,e,t)};(Ue.prototype=Object.create(Re.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ue.prototype.updateCoordinate=function(e,t,n){this.coordinates=3===arguments.length?[t,n]:[e,t],this.changed()},Ue.prototype.getCoordinate=function(){return this.getCoordinates()};const Be=function(e,t){Re.call(this,e,t)};(Be.prototype=Object.create(Re.prototype)).isValid=function(){return this.coordinates.length>1},Be.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},Be.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Be.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Be.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const je=function(e,t){Re.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(je.prototype=Object.create(Re.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},je.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},je.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},je.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])},je.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))},je.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]]))},je.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},je.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 Ge={MultiPoint:Ue,MultiLineString:Be,MultiPolygon:je},He=(e,t,n,r,o)=>{const i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,r,o)},Ye=function(e,t){if(Re.call(this,e,t),delete this.coordinates,this.model=Ge[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function Xe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ye.prototype=Object.create(Re.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:De(),type:H.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ye.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ye.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ye.prototype.getCoordinate=function(e){return He(this.features,"getCoordinate",e)},Ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===H.POLYGON?e.getCoordinates():e.coordinates)))},Ye.prototype.updateCoordinate=function(e,t,n){He(this.features,"updateCoordinate",e,t,n),this.changed()},Ye.prototype.addCoordinate=function(e,t,n){He(this.features,"addCoordinate",e,t,n),this.changed()},Ye.prototype.removeCoordinate=function(e){He(this.features,"removeCoordinate",e),this.changed()},Ye.prototype.getFeatures=function(){return this.features},Xe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Xe.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Xe.prototype.getSelected=function(){return this._ctx.store.getSelected()},Xe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Xe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Xe.prototype.getFeature=function(e){return this._ctx.store.get(e)},Xe.prototype.select=function(e){return this._ctx.store.select(e)},Xe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Xe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Xe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Xe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Xe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Xe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Xe.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},Xe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Xe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Xe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Xe.prototype.featuresAt=function(e,t,n="click"){if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return we[n](e,t,this._ctx)},Xe.prototype.newFeature=function(e){const t=e.geometry.type;return t===H.POINT?new Ue(this._ctx,e):t===H.LINE_STRING?new Be(this._ctx,e):t===H.POLYGON?new je(this._ctx,e):new Ye(this._ctx,e)},Xe.prototype.isInstanceOf=function(e,t){if(e===H.POINT)return t instanceof Ue;if(e===H.LINE_STRING)return t instanceof Be;if(e===H.POLYGON)return t instanceof je;if("MultiFeature"===e)return t instanceof Ye;throw new Error(`Unknown feature class: ${e}`)},Xe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Xe.prototype.onSetup=function(){},Xe.prototype.onDrag=function(){},Xe.prototype.onClick=function(){},Xe.prototype.onMouseMove=function(){},Xe.prototype.onMouseDown=function(){},Xe.prototype.onMouseUp=function(){},Xe.prototype.onMouseOut=function(){},Xe.prototype.onKeyUp=function(){},Xe.prototype.onKeyDown=function(){},Xe.prototype.onTouchStart=function(){},Xe.prototype.onTouchMove=function(){},Xe.prototype.onTouchEnd=function(){},Xe.prototype.onTap=function(){},Xe.prototype.onStop=function(){},Xe.prototype.onTrash=function(){},Xe.prototype.onCombineFeature=function(){},Xe.prototype.onUncombineFeature=function(){},Xe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const $e={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($e);function Je(e){const t=Object.keys(e);return function(n,r={}){let o={};const i=t.reduce((t,n)=>(t[n]=e[n],t),new Xe(n));return{start(){o=i.onSetup(r),Ke.forEach(t=>{const n=$e[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 qe(e){return[].concat(e).filter(e=>void 0!==e)}function Ze(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(B.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(B.COLD).setData({type:H.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(B.HOT).setData({type:H.FEATURE_COLLECTION,features:e.sources.hot}),a()}function ze(e){let t;this._features={},this._featureIds=new Te,this._selectedFeatureIds=new Te,this._selectedCoordinates=[],this._changedFeatureIds=new Te,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ze.call(this),this._emitSelectionChange&&(this.ctx.events.fire(X.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(X.RENDER,{})}))},this.isDirty=!1}function We(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}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(X.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(X.UPDATE,{action:t.action?t.action:$.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 n=[];return qe(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(X.DELETE,{features:n}),We(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 qe(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 qe(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),We(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=qe(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,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:$.CHANGE_PROPERTIES})},ze.prototype.storeMapConfig=function(){q.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 Qe=["mode","feature","mouse"];function et(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]=Je(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:j.DRAG}),s.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!ke(n,e))},o.touchdrag=function(e){o.drag(e,e=>!Fe(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=Oe(t,e);t.featureTarget=n,s.mousemove(t)},o.mousedown=function(t){n={time:(new Date).getTime(),point:t.point};const r=Oe(t,e);t.featureTarget=r,s.mousedown(t)},o.mouseup=function(t){const r=Oe(t,e);t.featureTarget=r,ke(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=we.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=we.touch(t,null,e)[0];t.featureTarget=n,Fe(r,{time:(new Date).getTime(),point:t.point})?s.tap(t):s.touchend(t)};const a=e=>{const t=ae(e),n=ce(e),r=pe(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=Ve(c,e),o.silent||e.map.fire(X.MODE_CHANGE,{mode:n}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(U.CANVAS)&&((ae(t)||ce(t))&&e.options.controls.trash?(t.preventDefault(),s.trash()):a(t)?s.keydown(t):le(t)&&e.options.controls.point?c(Y.DRAW_POINT):ue(t)&&e.options.controls.line_string?c(Y.DRAW_LINE_STRING):de(t)&&e.options.controls.polygon&&c(Y.DRAW_POLYGON))},o.keyup=function(e){a(e)&&s.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:n,options:r,store:o}=e;r.styles.some(e=>n.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,s=Ve(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(X.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=[];Qe.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=`${U.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(U.ACTIVE_BUTTON),n=null)}function l(e){c();const r=t[e];r&&r&&"trash"!==e&&(r.classList.add(U.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=`${U.CONTROL_GROUP} ${U.CONTROL_BASE}`,n?(n[G.POINT]&&(t[G.POINT]=a(G.POINT,{container:r,className:U.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(Y.DRAW_POINT),onDeactivate:()=>e.events.trash()})),n[G.LINE]&&(t[G.LINE]=a(G.LINE,{container:r,className:U.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(Y.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),n[G.POLYGON]&&(t[G.POLYGON]=a(G.POLYGON,{container:r,className:U.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(Y.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),n.trash&&(t.trash=a("trash",{container:r,className:U.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),n.combine_features&&(t.combine_features=a("combineFeatures",{container:r,className:U.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),n.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:r,className:U.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 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()?r.connect():(o.on("load",r.connect),n=setInterval(()=>{o.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(B.COLD,{data:{type:H.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(B.HOT,{data:{type:H.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(B.COLD)&&e.map.removeSource(B.COLD),e.map.getSource(B.HOT)&&e.map.removeSource(B.HOT)}};return e.setup=r,r}const tt="#3bb2d0",nt="#fbb03b",rt="#fff";var ot=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],nt,tt],"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"],nt,tt],"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"],nt,tt]}},{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":nt}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":nt}}];function it(e,t){this.x=e,this.y=t}function st(e,t){const n=t.getBoundingClientRect();return new it(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function at(e,t,n,r){return{type:H.FEATURE,properties:{meta:K.VERTEX,parent:e,coord_path:n,active:r?J.ACTIVE:J.INACTIVE},geometry:{type:H.POINT,coordinates:t}}}function ct(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lt(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=>lt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return dt(e);default:throw new Error("unknown GeoJSON type")}}function lt(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=ut(e.properties),null==e.geometry?t.geometry=null:t.geometry=dt(e.geometry),t}function ut(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]=ut(r):t[n]=r}),t):t}function dt(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>dt(e)),t):(t.coordinates=pt(e.coordinates),t)}function pt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>pt(e))}function ht(e,t={}){return ft(e,"mercator",t)}function ft(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?gt(n):mt(n):(!0!==i&&(n=ct(n)),t(n,function(e){var t="mercator"===r?gt(e):mt(e);e[0]=t[0],e[1]=t[1]})),n}function gt(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 mt(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 yt(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=ht(r),s=ht(o),a=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ft(e,"wgs84",t)}([c(i[0],s[0]),c(i[1],s[1])]),u=[a(l[0]),a(l[1])];return{type:H.FEATURE,properties:{meta:K.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:n.properties.coord_path},geometry:{type:H.POINT,coordinates:u}}}function vt(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=at(i,e,l,c(l));if(t.midpoints&&o){const e=yt(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===H.POINT?s.push(at(i,o,n,c(n))):r===H.POLYGON?o.forEach((e,t)=>{a(e,null!==n?`${n}.${t}`:String(t))}):r===H.LINE_STRING?a(o,n):0===r.indexOf(H.MULTI_PREFIX)&&function(){const n=r.replace(H.MULTI_PREFIX,"");o.forEach((r,o)=>{const i={type:H.FEATURE,properties:e.properties,geometry:{type:n,coordinates:r}};s=s.concat(vt(i,t,o))})}(),s}it.prototype={clone(){return new it(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:it},it.convert=function(e){if(e instanceof it)return e;if(Array.isArray(e))return new it(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new it(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var _t={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:xt,LAT_MAX:It,LAT_RENDERED_MIN:Et,LAT_RENDERED_MAX:St,LNG_MIN:Mt,LNG_MAX:bt}=Z;function Pt(e,t){let n=xt,r=It,o=xt,i=It,s=bt,a=Mt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],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>St&&(c.lat=St-n),o+c.lat>It&&(c.lat=It-o),r+c.lat<Et&&(c.lat=Et-r),i+c.lat<xt&&(c.lat=xt-i),s+c.lng<=Mt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=bt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Tt(e,t){const n=Pt(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===H.POINT?s=r(t):e.type===H.LINE_STRING||e.type===H.MULTI_POINT?s=t.map(r):e.type===H.POLYGON||e.type===H.MULTI_LINE_STRING?s=t.map(o):e.type===H.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)})}const Ct={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(X.UPDATE,{action:$.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 Te).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(){_t.enable(this)},onMouseMove:function(e,t){return ne(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Ct.onTap=Ct.onClick=function(e,t){return te(t)?this.clickAnywhere(e,t):z(K.VERTEX)(t)?this.clickOnVertex(e,t):ne(t)?this.clickOnFeature(e,t):void 0},Ct.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),_t.enable(this),this.stopExtendedInteractions(e)},Ct.clickOnVertex=function(e,t){this.changeMode(Y.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:j.MOVE})},Ct.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Ct.clickOnFeature=function(e,t){_t.disable(this),this.stopExtendedInteractions(e);const n=oe(t),r=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!n&&i&&this.getFeature(o).type!==H.POINT)return this.changeMode(Y.DIRECT_SELECT,{featureId:o});i&&n?(this.deselect(o),this.updateUIClasses({mouse:j.POINTER}),1===r.length&&_t.enable(this)):!i&&n?(this.select(o),this.updateUIClasses({mouse:j.MOVE})):i||n||(r.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:j.MOVE})),this.doRender(o)},Ct.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),Q(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&W(t)?this.startBoxSelect(e,t):void 0},Ct.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=st(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Ct.onTouchStart=function(e,t){if(Q(t))return this.startOnActiveFeature(e,t)},Ct.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Ct.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:j.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(U.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=st(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"},Ct.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};Tt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Ct.onTouchEnd=Ct.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,st(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:j.MOVE}))}this.stopExtendedInteractions(e)},Ct.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?J.ACTIVE:J.INACTIVE,n(t),this.fireActionable(),t.properties.active===J.ACTIVE&&t.geometry.type!==H.POINT&&vt(t).forEach(n)},Ct.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Ct.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:H.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(X.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},Ct.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(X.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const wt=z(K.VERTEX),Lt=z(K.MIDPOINT),Ot={fireUpdate:function(){this.fire(X.UPDATE,{action:$.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);oe(t)||-1!==r?oe(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){Tt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,n){const r=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=Pt(r.map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e}})),n);for(let t=0;t<r.length;t++){const n=r[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],n[0]+o.lng,n[1]+o.lat)}},clickNoTarget:function(){this.changeMode(Y.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(Y.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===H.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),_t.disable(this),this.setActionableState({trash:!0}),r},onStop:function(){_t.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=J.ACTIVE,n(t),vt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=J.INACTIVE,n(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(Y.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=Q(t),r=wt(t),o=Lt(t),i=0===e.selectedCoordPaths.length;n&&i||r&&!i?this.updateUIClasses({mouse:j.MOVE}):this.updateUIClasses({mouse:j.NONE});return(r||n||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ot.onTouchStart=Ot.onMouseDown=function(e,t){return wt(t)?this.onVertex(e,t):Q(t)?this.onFeature(e,t):Lt(t)?this.onMidpoint(e,t):void 0},Ot.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},Ot.onClick=function(e,t){return te(t)?this.clickNoTarget(e,t):Q(t)?this.clickActiveFeature(e,t):ee(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ot.onTap=function(e,t){return te(t)?this.clickNoTarget(e,t):Q(t)?this.clickActiveFeature(e,t):ee(t)?this.clickInactive(e,t):void 0},Ot.onTouchEnd=Ot.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const At={};function kt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}At.onSetup=function(){const e=this.newFeature({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:j.ADD}),this.activateUIButton(G.POINT),this.setActionableState({trash:!0}),{point:e}},At.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)},At.onTap=At.onClick=function(e,t){this.updateUIClasses({mouse:j.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(X.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.point.id]})},At.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},At.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?J.ACTIVE:J.INACTIVE,!r)return n(t)},At.onTrash=At.stopDrawingAndRemove,At.onKeyUp=function(e,t){if(ie(t)||se(t))return this.stopDrawingAndRemove(e,t)};const Ft={onSetup:function(){const e=this.newFeature({type:H.FEATURE,properties:{},geometry:{type:H.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),_t.disable(this),this.updateUIClasses({mouse:j.ADD}),this.activateUIButton(G.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(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:j.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:j.POINTER})}};Ft.onTap=Ft.onClick=function(e,t){return re(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ft.onKeyUp=function(e,t){ie(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)):se(t)&&this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ft.onStop=function(e){this.updateUIClasses({mouse:j.NONE}),_t.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(X.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT,{},{silent:!0})))},Ft.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?J.ACTIVE:J.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=K.FEATURE,n(at(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const r=t.geometry.coordinates[0].length-3;n(at(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:H.FEATURE,properties:t.properties,geometry:{coordinates:e,type:H.LINE_STRING}}),3===o)return}return n(t)}},Ft.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)};const Vt={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:H.FEATURE,properties:{},geometry:{type:H.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),_t.disable(this),this.updateUIClasses({mouse:j.ADD}),this.activateUIButton(G.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,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(Y.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:j.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:j.POINTER})}};Vt.onTap=Vt.onClick=function(e,t){if(re(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Vt.onKeyUp=function(e,t){se(t)?this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.line.id]}):ie(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT))},Vt.onStop=function(e){_t.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(X.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT,{},{silent:!0})))},Vt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)},Vt.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?J.ACTIVE:J.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=K.FEATURE,n(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)),n(t))};var Nt={simple_select:Ct,direct_select:Ot,draw_point:At,draw_polygon:Ft,draw_line_string:Vt};const Dt={defaultMode:Y.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:ot,modes:Nt,controls:{},userProperties:!1,suppressAPIEvents:!0},Rt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ut={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Bt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?B.HOT:B.COLD}))}var jt,Gt;var Ht,Yt,Xt=fe(Gt?jt:(Gt=1,jt=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 $t=function(){if(Yt)return Ht;Yt=1,Ht=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 Ht}(),Kt=fe($t);function Jt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const qt={Polygon:je,LineString:Be,Point:Ue,MultiPolygon:Ye,MultiLineString:Ye,MultiPoint:Ye};var Zt=Object.freeze({__proto__:null,CommonSelectors:he,ModeHandler:Ve,StringSet:Te,constrainFeatureMovement:Pt,createMidPoint:yt,createSupplementaryPoints:vt,createVertex:at,doubleClickZoom:_t,euclideanDistance:Ae,featuresAt:we,getFeatureAtAndSetCursors:Oe,isClick:ke,isEventAtCoordinates:kt,isTap:Fe,mapEventToBoundingBox:Pe,moveFeatures:Tt,sortFeatures:be,stringSetsAreEqual:Jt,theme:ot,toDenseArray:qe});const zt=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({},Ut,e.controls):t.controls=Object.assign({},Rt,e.controls),t=Object.assign({},Dt,t),t.styles=Bt(t.styles,"cold").concat(Bt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=Y;const n=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return we.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:H.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:H.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e.coordinates}}))}},t.set=function(n){if(void 0===n.type||n.type!==H.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 Te(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(Kt(t))).features.map(t=>{if(t.id=t.id||De(),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=qt[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,Xt(o,t.properties)||e.store.featureChanged(r.id,{silent:n}),Xt(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:H.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()!==Y.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(Y.SIMPLE_SELECT,void 0,{silent:n}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===Y.DIRECT_SELECT?e.events.changeMode(Y.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,o={}){return r===Y.SIMPLE_SELECT&&t.getMode()===Y.SIMPLE_SELECT?(Jt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:n}),e.store.render()),t):(r===Y.DIRECT_SELECT&&t.getMode()===Y.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,o,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,o,i){return e.store.setFeatureProperty(r,o,i,{silent:n}),t},t}(n,t),n.api=t;const r=et(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=G,t.options=e,t};function Wt(e){zt(e,this)}Wt.modes=Nt,Wt.constants=Z,Wt.lib=Zt;const Qt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,n){t.properties.active="false",n(t)}},en="draw.create",tn="draw.update",nn="draw.modechange",rn="draw.editfinish",on="draw.cancel",sn="draw.vertexselection",an="draw.vertexchange",cn="draw.undochange",ln="draw.undo",un="draw.geometrychange",dn="draw.interfacetypechange",pn="draw.placementblocked",hn="draw.nudgevertex",fn="draw.selectvertex",gn="draw.insertvertexatmidpoint",mn="draw.setgeometry",yn="styledata",vn=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[]}},_n=e=>{const t=vn(e),n=xn(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},xn=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},In=(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},En=(e,t)=>{let n=e.geometry.coordinates;for(const e of t)n=n[e];return n},Sn=(e,t)=>{const n=t.split(".").map(Number),r=xn(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]},Mn=(e,t)=>({x:e.x*t,y:e.y*t}),bn=e=>e instanceof window.SVGElement||e.ownerSVGElement;function Pn(e){return e?._snapInstance??null}function Tn(e){return!!(e?.status&&e?.snapStatus&&e.snapCoords?.length>=2)}function Cn(e){return Tn(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function wn(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 Ln(e,t){e&&(e._autoSnapSuspended=t)}function On(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 An(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 kn(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 Fn(e){return"function"==typeof e?.getSnapEnabled&&!0===e.getSnapEnabled()}const Vn=(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},Nn=(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(dn,n.interfacetypechange),t.on(hn,n.nudge),t.on(mn,n.setgeometry)},Dn=(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(dn,n.interfacetypechange),t.off(hn,n.nudge),t.off(mn,n.setgeometry),t.dragPan.enable(),window.removeEventListener("click",n.click),window.removeEventListener("keydown",n.keydown,{capture:!0}),window.removeEventListener("keyup",n.keyup,{capture:!0})},Rn=e=>{const t=Pn(e);t&&An(t,e)},Un=(e,t,n,r)=>{if("touch"===t.interfaceType)return;const o=Pn(e.map);o&&(o.snapStatus=!1,o.snapCoords=null),Fn(t)&&o?.status?r.call(e,t,n,o):Ot.onDrag.call(e,t,n),t.dragMoving&&e.map.fire(un,t.feature)},Bn={fireGeometryChange(e){const t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t){setTimeout(()=>{const n=this.getFeature(t);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:r,vertexIndex:e})},0)},pushUndo(e){const t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(e.vertexIndex,e.featureId))}},jn={...Bn,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):"replace_geometry"===n.type&&this.replaceGeometry(e,n.featureId,n.previousGeometry),this.emitGeometryValidation(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=xn(i),c=In(a,n);if(!c)return;En(s,c.segment.path)[c.localIdx]=r,this._applyUndoAndSync(e,s,o);const l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Mn(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=xn(o),a=In(s,n);if(!a)return;En(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=xn(i);let c=In(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;En(s,c.segment.path).splice(c.localIdx,0,r),this._applyUndoAndSync(e,s,o),this.updateTouchVertexTarget(e,Mn(this.map.project(e.vertices[n]),e.scale)),this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,n)})},replaceGeometry(e,t,n){const r=this.getFeature(t);r&&(this._applyUndoAndSync(e,{...r.toGeoJSON(),geometry:n},t),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null}))},_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)}},Gn=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Hn=(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}}},Yn=(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(Fn(t)){const t=Pn(e);wn(t,e,r),o=Cn(t)||o}return o},Xn=(e,t,n={})=>{if(!e)return;const{editActive:r,editHalo:o,editVertex:i}=O(t,n);A(e,{editActive:r,editHalo:o,editVertex:i})},$n={addTouchVertexTarget(e){e.touchVertexTarget=L(e.container),Xn(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||bn(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(kn(Pn(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,Mn(this.map.project(t),e.scale))}},onTap(e,t){const n=Pn(this.map);n&&An(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=Sn(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){kn(Pn(this.map));const n=this.getVertices(e.featureId),r=n?.[e.selectedVertexIndex];if(!r||!bn(t.target.parentNode))return;e._moveStartPosition=[...r],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;const o=Gn(t);Object.assign(e,Hn(this.map,e.touchVertexTarget,o,r,e.scale))},onTouchmove(e,t){if(e.selectedVertexIndex<0||!bn(t.target.parentNode))return;e._touchMoved=!0;const n=Gn(t);this.moveVertex(e,Yn(this.map,e,n)),this.updateTouchVertexTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},Kn=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Jn={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},qn=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Zn=e=>{const t=document.activeElement;return!(!t||t===document.body)&&(!e.container?.contains(t)&&(qn.has(t.tagName)||t.isContentEditable||t.hasAttribute("tabindex")))},zn=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,Wn={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),r=t?.shiftKey?o.nudgeAmount:o.stepAmount,[i,s]=t?Jn[t.key].map(e=>e*r):[0,0];return this.map.unproject({x:n.x+i,y:n.y+s})},getOffsetByDelta(e,t,n,r){const i=this.map.project(e),s=r?o.stepAmount:o.nudgeAmount;return this.map.unproject({x:i.x+t*s,y:i.y+n*s})},resolveSnapTarget(e,t,r,o,i){const s=Pn(this.map);if(Fn(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,An(s,this.map),this.map.unproject({x:a.x+t*i,y:a.y+r*i})}const a=i();return Fn(e)&&s&&(wn(s,this.map,this.map.project(a)),Tn(s))?(e._isSnapped=!0,Cn(s)):(e._isSnapped=!1,a)}},er={...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(vn(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&&vn(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=xn(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;En(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=xn(r),s=In(i,e.selectedVertexIndex);if(!s)return;En(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=xn(t),r=In(n,e.selectedVertexIndex);if(!r)return;const{segment:o}=r,s=o.closed?i.Polygon:i.LineString;if(o.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})}},tr={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=xn(n),o=In(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 vn(this.getFeature(e))},getMidpoints(e){return _n(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=k(o,r,t);return[i,i<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){const n=this.getFeature(e.featureId),r=xn(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}},nr={...Wn,onKeydown(e,t){Zn(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Kn.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?zn(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=Pn(this.map);t&&An(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&&vn(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]=Jn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){Zn(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&F(t),Kn.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))}},rr={onMouseDown(e,t){kn(Pn(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,Ot.onMouseDown.call(this,e,t),"vertex"===n&&r)){const t=this.getFeature(e.featureId),n=Sn(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=Sn(t,r);e._insertedVertexIndex=n,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,r),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(sn,{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(sn,{index:t,numVertices:e.vertices.length})}Ot.onClick.call(this,e,t)},onMouseUp(e,t){kn(Pn(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,Ot.onMouseUp.call(this,e,t)},_didVertexMove(e){if(!e._moveStartPosition||null==e._moveStartIndex)return!1;const t=this.getFeature(e.featureId),n=t&&vn(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(sn,{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){Un(this,e,t,this._snapDrag)},_snapDrag(e,t,n){if(!e.selectedCoordPaths?.length||!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation(),wn(n,this.map,t.point);const r=Cn(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],r.lng,r.lat),e.dragMoveLocation=t.lngLat}},or={...Wt.modes.direct_select,...jn,...$n,...er,...tr,...nr,...rr,onSetup(e){const t=Wt.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),Rn(this.map),"touch"===t.interfaceType&&t.selectedVertexIndex>=0&&"vertex"===t.selectedVertexType){const e=t.vertices[t.selectedVertexIndex];e&&setTimeout(()=>{this.updateTouchVertexTarget(t,Mn(this.map.project(e),t.scale))},0)}return t._ignorePointermoveDeselect=!0,setTimeout(()=>{t._ignorePointermoveDeselect=!1},100),t},setupEventListeners(e){const t=this.handlers=Vn(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint,setgeometry:this.onSetGeometry});Nn(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(fn,t.selectvertex),this.map.on(gn,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=vn(r);e.selectedVertexIndex=this.findVertexIndex(o,n,e.selectedVertexIndex)}e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null,this.map.fire(sn,{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?Mn(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?Mn(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,Mn(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,Mn(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"})},onSetGeometry(e,t){const n=this.getFeature(e.featureId);if(!n)return;const r=n.toGeoJSON().geometry;this.replaceGeometry(e,e.featureId,t.geometry),this.pushUndo({type:"replace_geometry",featureId:e.featureId,previousGeometry:r})},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(fn,t.selectvertex),this.map.off(gn,t.insertvertexatmidpoint),Dn(e,this.map,t),this.hideTouchVertexIndicator(e)}},ir={...Bn,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_point"!==n.type&&"replace_geometry"!==n.type||this.undoMovePoint(e,n),this.emitGeometryValidation(n.vertexIndex,n.featureId)},undoMovePoint(e,t){this.setPointPosition(e,t.featureId,t.previousPosition)},setPointPosition(e,t,n){const r=this.getFeature(t);r&&(r.updateCoordinate("",n[0],n[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,Mn(this.map.project(n),e.scale)))}},sr={addTouchPointTarget(e){e.touchPointTarget=L(e.container),Xn(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){kn(Pn(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,Mn(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){kn(Pn(this.map));const n=this.getPointCoord(e);if(!n||!bn(t.target.parentNode))return;e._moveStartPosition=[...n],e._touchMoved=!1;const r=Gn(t);Object.assign(e,Hn(this.map,e.touchPointTarget,r,n,e.scale))},onTouchmove(e,t){if(!bn(t.target.parentNode))return;e._touchMoved=!0;const n=Gn(t);this.movePoint(e,Yn(this.map,e,n)),this.updateTouchPointTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},ar={...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})}},cr={...Wn,onKeydown(e,t){Zn(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Kn.has(t.key)?this.handleArrowKey(e,t):zn(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]=Jn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){Zn(e)||(e.interfaceType="keyboard",F(t),Kn.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}},lr={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],Ln(Pn(this.map),!0)),Ot.onFeature.call(this,e,t)},onClick(e,t){if(Q(t))return;if(!((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},r={mode:"edit_point",vertexIndex:0},o=s(n,r,{onGeometryPreview:e._drawPreviewValidator});return o.valid||e.fire("draw.placementblocked",a(n,o,r)),o.valid})(this.map,[t.lngLat.lng,t.lngLat.lat]))return;const n=[...e.feature.coordinates],r=Pn(this.map);let o=t.lngLat;Fn(e)&&r&&(wn(r,this.map,t.point),o=Cn(r)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:n})},onMouseUp(e,t){const n=Pn(this.map);kn(n),Ln(n,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Ot.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){Un(this,e,t,this._snapDrag)},_snapDrag(e,t,n){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]};wn(n,this.map,this.map.project([r.lng,r.lat]));const o=Cn(n)||r;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat},onTrash(){}},ur={...Wt.modes.direct_select,...ir,...sr,...ar,...cr,...lr,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),_t.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}),Rn(this.map),"touch"===r.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(r,Mn(this.map.project(r.feature.coordinates),r.scale))},0),this.map.fire(sn,{index:0,numVertices:1}),r},setupEventListeners(e){const t=this.handlers=Vn(this,e,{nudge:this.onNudgePoint,setgeometry:this.onSetGeometry});Nn(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,Mn(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,Mn(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,Mn(this.map.project(e.feature.coordinates),e.scale))},onSetGeometry(e,t){const n=this.getFeature(e.featureId);if(!n)return;const r=n.getCoordinates();this.setPointPosition(e,e.featureId,t.geometry.coordinates),this.pushUndo({type:"replace_geometry",featureId:e.featureId,previousPosition:r})},onButtonClick(e,t){t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Dn(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}},dr=({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",F,{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})}}),pr=(e,t,n,o)=>{setTimeout(()=>{const i=t(o);i&&e.fire("draw.geometrychange",((e,t)=>{const 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,n))},0)},hr=({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 s=c({placed:n(i).slice(0,-1),point:o,geometryType:e,onGeometryPreview:this.map._drawPreviewValidator});return s.valid||this.map.fire("draw.placementblocked",s.blocked),s.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){pr(this.map,t,n,e)},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)}}),fr=({ParentMode:e,getFeature:t,getCoords:n,validateClick:r,finishOnInvalidClick:o})=>({onClick(i,s){if(this._isIgnorableClick(s))return;if(!1===this.map._drawCanFinish&&"vertex"===s.featureTarget?.properties?.meta)return;const a=Pn(this.map);if(Fn(i)&&Tn(a))s=function(e,t){const n=Cn(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._drawCanFinish&&(a.pop(),this.map.fire("draw.create",{features:[s.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[s.id]})));const c=Pn(this.map),l=Fn(i)&&function(e,t){const n=Cn(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)}}),gr=e=>({...hr(e),...fr(e)}),mr=({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))},_handleUndoKeydown(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}),yr=({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)}}),vr=({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}}),_r=e=>({...mr(e),...yr(e),...vr(e)}),xr=({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))}}}),Ir=({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(Fn(t)){const e=Pn(this.map);wn(e,this.map,n.point);const t=Cn(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){Fn(t)&&On(Pn(this.map),this.map);const n=Pn(this.map),r=Fn(t)&&Cn(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)))}}),Er=({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}}))}}),Sr=(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,...dr(l),...gr(l),..._r(l),...xr(l),...Ir(l),...Er(l)}},Mr=Sr(Wt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>l(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),br=Sr(Wt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>u(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),Pr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),Tr=Wt.modes.draw_point,Cr=dr({ParentMode:Tr,featureProp:"point",excludeFeatureIdFromSetup:!1}),wr={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)&&Fn(e)&&On(Pn(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){Fn(e)&&wn(Pn(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),Pr.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&Pr.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=Pn(this.map),r=Fn(e)&&Tn(n)?Cn(n):null;this._commit(e,r||t.lngLat)},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){const t=Pn(this.map);Fn(e)&&On(t,this.map);const n=Fn(e)&&Tn(t)?Cn(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:{}},r={mode:"draw_point",vertexIndex:0},o=s(n,r,{onGeometryPreview:e._drawPreviewValidator});return o.valid||e.fire("draw.placementblocked",a(n,o,r)),o.valid})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},Lr={...Tr,...Cr,...wr},Or=(e,t,n)=>["coalesce",["get",`user_${t}${e.id.charAt(0).toUpperCase()+e.id.slice(1)}`],["get",`user_${t}`],n],Ar=["coalesce",["get","user_sortKey"],0],kr=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":Ar},paint:{"fill-color":Or(e,"fill",t.shapeFill)}}),Fr=(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":Ar},paint:{"line-color":Or(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),Vr=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}}),Nr=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),Dr=(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}}),Rr=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Ur=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),Br=(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}}),jr=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Gr=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Hr=(e,t={})=>{const n=O(e,t),{vertexRadius:r,midpointRadius:o,vertexHaloRadius:i,midpointHaloRadius:s}=d;return[kr(e,n),(p=n.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":p}}),(u=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":u,"line-width":2,"line-opacity":1}}),(l=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":l,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),Fr(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":Ar},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}}),Vr(n.editStroke),Ur(n.editMidpoint,o),Br(n.editHalo,n.editActive,s),jr(n.editMidpoint,o),Nr(n.editVertex,r),Dr(n.editHalo,n.editActive,i),Rr(n.editVertex,r),Gr(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,l,u,p};function Yr(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 Xr(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 $r(e,t,n){void 0===n&&(n={});var r=Yr(e),o=Yr(t),i=p(o[1]-r[1]),s=p(o[0]-r[0]),a=p(r[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}function Kr(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Jr(e,t,n,r={}){const o=Kr(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return void 0!==o[2]?g([d,h,o[2]],r.properties):g([d,h],r.properties)}function qr(e,t){var n;return void 0===t&&(t={}),function(e,t){if(e.length>1)return v(e,t);return _(e[0],t)}(("Feature"===(n=e).type?n.geometry:n).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Zr(e,t,n={}){if(!0===n.final)return function(e,t){let n=Zr(t,e);return n=(n+180)%360,n}(e,t);const r=Kr(e),o=Kr(t),i=p(r[0]),s=p(o[0]),a=p(r[1]),c=p(o[1]),l=Math.sin(s-i)*Math.cos(c),u=Math.cos(a)*Math.sin(c)-Math.sin(a)*Math.cos(c)*Math.cos(s-i);return m(Math.atan2(l,u))}var zr=Zr;function Wr(e,t,n,r){void 0===r&&(r={});var o=Yr(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return g([d,h],r.properties)}function Qr(e){if(!e)throw new Error("geojson is required");var t=[];return x(e,function(e){!function(e,t){var n=[],r=e.geometry;if(null!==r){switch(r.type){case"Polygon":n=Xr(r);break;case"LineString":n=[Xr(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=_([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)}),I(t)}var eo={exports:{}};function to(e,t,n,r,o){no(e,t,n||0,r||e.length-1,o||oo)}function no(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);no(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(ro(e,n,t),o(e[r],u)>0&&ro(e,n,r);d<p;){for(ro(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[n],u)?ro(e,n,p):ro(e,++p,r),p<=t&&(n=p+1),t<=p&&(r=p-1)}}function ro(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function oo(e,t){return e<t?-1:e>t?1:0}function io(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 so(e,t){ao(e,0,e.children.length,t,e)}function ao(e,t,n,r,o){o||(o=vo(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];co(o,e.leaf?r(t):t)}return o}function co(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 lo(e,t){return e.minX-t.minX}function uo(e,t){return e.minY-t.minY}function po(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ho(e){return e.maxX-e.minX+(e.maxY-e.minY)}function fo(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 go(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 mo(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function yo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function vo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function _o(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;to(e,s,t,n,o),i.push(t,s,s,n)}}var xo,Io=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(!yo(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;yo(e,a)&&(t.leaf?n.push(s):mo(e,a)?this._all(s,n):o.push(s))}t=o.pop()}return n}collides(e){let t=this.data;if(!yo(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(yo(e,i)){if(t.leaf||mo(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=vo([]),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=io(e,n.children,t);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}c||n.leaf||!mo(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=vo(e.slice(t,n+1)),so(i,this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,r-1))),i=vo([]),i.leaf=!1,i.height=r;const a=Math.ceil(o/s),c=a*Math.ceil(Math.sqrt(s));_o(e,t,n,c,this.compareMinX);for(let o=t;o<=n;o+=c){const t=Math.min(o+c-1,n);_o(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 so(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=po(s),c=fo(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),co(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=vo(n.children.splice(i,n.children.length-i));s.height=n.height,s.leaf=n.leaf,so(n,this.toBBox),so(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this.data=vo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,so(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=ao(e,0,s,this.toBBox),a=ao(e,s,n,this.toBBox),c=go(t,a),l=po(t)+po(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:lo,o=e.leaf?this.compareMinY:uo;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,o)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);const o=this.toBBox,i=ao(e,0,t,o),s=ao(e,n-t,n,o);let a=ho(i)+ho(s);for(let r=t;r<n-t;r++){const t=e.children[r];co(i,e.leaf?o(t):t),a+=ho(i)}for(let r=n-t-1;r>=t;r--){const t=e.children[r];co(s,e.leaf?o(t):t),a+=ho(s)}return a}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)co(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():so(e[n],this.toBBox)}}}),Eo=ge(Io),So={};function Mo(){if(xo)return So;xo=1,Object.defineProperty(So,"__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 So.areaFactors=n,So.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},So.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},So.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},So.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)},So.degreesToRadians=function(e){return e%360*Math.PI/180},So.earthRadius=e,So.factors=t,So.feature=r,So.featureCollection=a,So.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")}},So.geometryCollection=function(e,t,n={}){return r({type:"GeometryCollection",geometries:e},t,n)},So.isNumber=f,So.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},So.lengthToDegrees=function(e,t){return h(p(e,t))},So.lengthToRadians=p,So.lineString=s,So.lineStrings=function(e,t,n={}){return a(e.map(e=>s(e,t)),n)},So.multiLineString=c,So.multiPoint=l,So.multiPolygon=u,So.point=o,So.points=function(e,t,n={}){return a(e.map(e=>o(e,t)),n)},So.polygon=i,So.polygons=function(e,t,n={}){return a(e.map(e=>i(e,t)),n)},So.radiansToDegrees=h,So.radiansToLength=d,So.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},So.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")})},So.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")},So}var bo,Po={};function To(){if(bo)return Po;bo=1,Object.defineProperty(Po,"__esModule",{value:!0});var e=Mo();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,I=0;if(null!==(a=d?u.geometries[_]:u)){l=a.coordinates;var E=a.type;switch(p=!r||"Polygon"!==E&&"MultiPolygon"!==E?0:1,E){case null:break;case"Point":if(!1===n(l,h,v,x,I))return!1;h++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===n(l[o],h,v,x,I))return!1;h++,"MultiPoint"===E&&x++}"LineString"===E&&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,I))return!1;h++}"MultiLineString"===E&&x++,"Polygon"===E&&I++}"Polygon"===E&&x++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(I=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,I))return!1;h++}I++}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 Po.coordAll=function(e){var n=[];return t(e,function(e){n.push(e)}),n},Po.coordEach=t,Po.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},Po.featureEach=r,Po.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},Po.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")},Po.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")},Po.flattenEach=i,Po.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},Po.geomEach=o,Po.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},Po.lineEach=a,Po.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},Po.propEach=n,Po.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},Po.segmentEach=s,Po.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},Po}var Co,wo,Lo={};function Oo(){if(Co)return Lo;Co=1,Object.defineProperty(Lo,"__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 Lo.bbox=t,Lo.default=n,Lo}var Ao=function(){if(wo)return eo.exports;wo=1;var e=Eo,t=Mo(),n=To(),r=Oo().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 eo.exports=s,eo.exports.default=s,eo.exports}(),ko=fe(Ao);function Fo(e,t){var n={},r=[];if("LineString"===e.type&&(e=E(e)),"LineString"===t.type&&(t=E(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=Vo(e,t);return o&&r.push(o),I(r)}var i=ko();return i.load(Qr(t)),S(Qr(e),function(e){S(i.search(e),function(t){var o=Vo(e,t);if(o){var i=Xr(o).join(",");n[i]||(n[i]=!0,r.push(o))}})}),I(r)}function Vo(e,t){var n=Xr(e),r=Xr(t);if(2!==n.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==r.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=n[0][0],i=n[0][1],s=n[1][0],a=n[1][1],c=r[0][0],l=r[0][1],u=r[1][0],d=r[1][1],p=(d-l)*(s-o)-(u-c)*(a-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(s-o)*(i-l)-(a-i)*(o-c);if(0===p)return null;var m=h/p,y=f/p;return m>=0&&m<=1&&y>=0&&y<=1?g([o+m*(s-o),i+m*(a-i)]):null}function No(e,t,n){void 0===n&&(n={});var r=g([1/0,1/0],{dist:1/0}),o=0;return x(e,function(e){for(var i=Xr(e),s=0;s<i.length-1;s++){var a=g(i[s]);a.properties.dist=$r(t,a,n);var c=g(i[s+1]);c.properties.dist=$r(t,c,n);var l=$r(a,c,n),u=Math.max(a.properties.dist,c.properties.dist),d=zr(a,c),p=Wr(t,u,d+90,n),h=Wr(t,u,d-90,n),f=Fo(_([p.geometry.coordinates,h.geometry.coordinates]),_([a.geometry.coordinates,c.geometry.coordinates])),m=null;f.features.length>0&&((m=f.features[0]).properties.dist=$r(t,m,n),m.properties.location=o+$r(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 Do(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Ro(e,t){var n=function(e,t,n,r){void 0===r&&(r={});var o=Do(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return g([d,h],r.properties)}(e,function(e,t,n){void 0===n&&(n={});var r=Do(e),o=Do(t),i=p(o[1]-r[1]),s=p(o[0]-r[0]),a=p(r[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}(e,t)/2,zr(e,t));return n}var Uo=function(){return Uo=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},Uo.apply(this,arguments)},Bo=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=Uo(Uo({},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 $r(g(e),g(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=$r(g([n.lng,n.lat]),g([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(Jr(e,t,-360*o/r,n).geometry.coordinates);return i.push(i[0]),y([i],o)}(a.coords,i,{steps:64,units:"meters",properties:{color:a.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=I(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(I([])))}),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=M(e),o=[];if(r.map(function(e){var r=$r(g(e),g([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(_(e))});break;case"Polygon":var o=qr(e.geometry);r.push(o);break;case"MultiPolygon":qr(e.geometry).coodinates.map(function(e){r.push(_(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(Qr(e).features)});var i=[];if(o.map(function(e){var r=Ro(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=$r(r,g([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=No(r[i],g([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 jo="snap-helper-circle",Go="mapbox-gl-draw-hot";function Ho(e){if(Bo.prototype.__snapPatched)return;Bo.prototype.__snapPatched=!0;const t=Bo.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(jo)&&this.map.setLayoutProperty(jo,"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=>y(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>_(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 Yo(e,t){!function n(){const r=e();null!==r&&(r?t(r):requestAnimationFrame(n))}()}function Xo(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 $o=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Ko(e,t,n,r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(jo)&&e.removeLayer(jo),e.getSource(jo)&&e.removeSource(jo)}(e),Xo(n);const o=new Bo({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&&$o.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 Jo(e,t,n){e.on("style.load",()=>{Yo(()=>e._removed?null:e.getSource(Go),r=>{Xo(r),function(e){e.getSource(jo)||e.addSource(jo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(jo)||e.addLayer({id:jo,type:"fill",source:jo,paint:{"fill-color":["get","color"]},layout:{visibility:e._snapInstance?.status?"visible":"none"}})}(e),e._snapInstance||Ko(e,t,r,n)})})}function qo(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 Ho({vertex:b.snapVertex,midpoint:b.snapMidpoint,edge:b.snapEdge,...l}),Jo(e,t,u),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(jo)){e.setLayoutProperty(jo,"visibility","none");const t=e._snapInstance;t?.status&&e.setLayoutProperty(jo,"visibility","visible")}})}(e),Yo(()=>e._removed?null:e.getSource(Go),n=>Ko(e,t,n,u)),e._snapInstance}const Zo="point-symbol",zo=new Set([`${Zo}.hot`,`${Zo}.cold`]),Wo=(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)})},Qo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:o,properties:i,pixelRatioOverride:s})=>{if(!V(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,Wo(e,t))})(n,e,u,h["icon-offset"]),{...l,properties:{...i,symbolImageId:u,symbolIconAnchor:h["icon-anchor"],symbolActiveImageId:d,symbolSelectedImageId:p}}},ei=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&&V(e.properties)),a=await Promise.allSettled(s.map(i=>Qo({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=>{P.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]),Wo(e,t))})(n,e)},ti="mapbox-gl-draw-cold",ni="mapbox-gl-draw-hot",ri=({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(ti))return!1;const n={type:"FeatureCollection",features:[]};return e.addSource(ti,{data:n,type:"geojson"}),e.addSource(ni,{data:n,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(e,t);((e,t,n={})=>{Hr(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]");Xn(c,s,o),ei({draw:t,mapProvider:n,map:e,symbolRegistry:r}).then(()=>{a&&t.set(t.getAll()),e.triggerRepaint(),i()}).catch(e=>P.error("[draw] failed to refresh point symbols after a style change",e))})},oi=({mapStyle:e,mapProvider:t,symbolRegistry:r,events:o,eventBus:i,snapLayers:s,pluginConfig:a={}})=>{const{map:c}=t;Wt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Wt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Wt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";const l={...Wt.modes,disabled:Qt,edit_vertex:or,edit_point:ur,draw_polygon:Mr,draw_line:br,draw_point:Lr};let u=t._mapboxDrawInstance;u?Object.assign(u.modes,l):(u=new Wt({modes:l,styles:Hr(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=N(e=>c.fire("draw.undochange",{length:e})),t.undoStack=p),c._undoStack=p;const h=O(e,a);qo(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,ri({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=>{ei({draw:u,mapProvider:t,map:c,symbolRegistry:r,pixelRatioOverride:e}).then(()=>{c.triggerRepaint(),f()}).catch(e=>P.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}}},ii=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),si=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),ai=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),ci=(e,t)=>{if("draw_polygon"===e)return{feature:ii(t),numVertices:(t[0]?.length??1)-1};if("draw_line"===e)return{feature:si(t),numVertices:(t?.length??1)-1};if("edit_vertex"===e){const e=t[0];return Array.isArray(e?.[0])?{feature:ii(t),numVertices:e.length}:{feature:si(t),numVertices:t?.length??0}}return"edit_point"===e?{feature:ai(t),numVertices:1}:null};class li{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}=oi({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=D({onChange:(e,t)=>{this._applyStrokeInvalid(e);const n=this._draw.getMode();"edit_vertex"!==n&&"edit_point"!==n||this._bus.emit(C.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=R({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(C.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(C.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(C.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(C.CANCEL),vertexselection:e=>this._bus.emit(C.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(C.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(C.UNDO_CHANGE,e.length),update:e=>this._bus.emit(C.UPDATE,e.features[0]),geometrychange:e=>{e?.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(C.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(C.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(C.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(en,this._mapHandlers.create),this._map.on(rn,this._mapHandlers.editfinish),this._map.on(on,this._mapHandlers.cancel),this._map.on(sn,this._mapHandlers.vertexselection),this._map.on(an,this._mapHandlers.vertexchange),this._map.on(cn,this._mapHandlers.undochange),this._map.on(tn,this._mapHandlers.update),this._map.on(un,this._mapHandlers.geometrychange),this._map.on(pn,this._mapHandlers.placementblocked),this._map.on(dn,this._mapHandlers.interfacetypechange),this._map.on(nn,this._mapHandlers.modechange),this._map.on(yn,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 Qo(e);t&&e.draw.add(t)})({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>P.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(!e?.coordinates)return;const t=this._draw.getMode(),n=ci(t,e.coordinates);n&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:n.feature,numVertices:n.numVertices,context:{mode:t},onGeometryPreview:this._previewValidator}):this._liveStroke.update({...n,context:{mode:t},onGeometryPreview:this._previewValidator}))}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(dn,{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(rn,{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(ln)}nudgeSelectedVertex(e,t,n){this._map.fire(hn,{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:vn(n),midpoints:_n(n)}}selectVertex(e){this._map.fire(fn,{index:e})}insertVertexAtMidpoint(e){this._map.fire(gn,{index:e})}setGeometry(e){this._map.fire(mn,{geometry:e})}setCanFinish(e){this._map._drawCanFinish=e}set _previewValidator(e){this._map._drawPreviewValidator=e}get _previewValidator(){return this._map._drawPreviewValidator}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&&V(t)&&this._resolvePointSymbol(r[0],t),r}setStyle(e,t){const n=this._draw.get(e);n&&this.add({...n,properties:w({...n.properties,...t})})}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;const t=Pn(this._map);t?.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(kn(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){const t=Pn(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)}setProperties(e,t){if(this._draw.get(e))for(const[n,r]of Object.entries(t))this._draw.setFeatureProperty(e,n,r)}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)||An(Pn(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(en,this._mapHandlers.create),this._map.off(rn,this._mapHandlers.editfinish),this._map.off(on,this._mapHandlers.cancel),this._map.off(sn,this._mapHandlers.vertexselection),this._map.off(an,this._mapHandlers.vertexchange),this._map.off(cn,this._mapHandlers.undochange),this._map.off(tn,this._mapHandlers.update),this._map.off(un,this._mapHandlers.geometrychange),this._map.off(pn,this._mapHandlers.placementblocked),this._map.off(dn,this._mapHandlers.interfacetypechange),this._map.off(nn,this._mapHandlers.modechange),this._map.off(yn,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{li as MaplibreDrawAdapter,ci as displayedShape};
|
|
1
|
+
import{i as e,c as t,T as n,C as r,K as o,M as i,v as s,t as a,a as c,b as l,d as u,S as d,e as p,r as h,l as f,p as g,f as m,g as y,m as v,h as _,j as x,k as I,n as E,o as S,q as M,s as b,u as P,w as T,A as C,x as w}from"./im-draw-plugin.js";import{c as L,r as O,a as A,s as k,b as F,h as V,d as N,e as D,f as R}from"./liveDrawChecks.js";import"preact/compat";const U={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"},B={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},j={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},G={POLYGON:"polygon",LINE:"line_string",POINT:"point"},H={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},Y={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},X={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},$={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},K={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},J={ACTIVE:"true",INACTIVE:"false"},q=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var Z=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:U,cursors:j,events:X,geojsonTypes:H,interactions:q,meta:K,modes:Y,sources:B,types:G,updateActions:$});function z(e){return function(t){const n=t.featureTarget;return!!n&&(!!n.properties&&n.properties.meta===e)}}function W(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.ACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function ee(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.INACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function te(e){return void 0===e.featureTarget}function ne(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 oe(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function ie(e){return"Escape"===e.key||27===e.keyCode}function se(e){return"Enter"===e.key||13===e.keyCode}function ae(e){return"Backspace"===e.key||8===e.keyCode}function ce(e){return"Delete"===e.key||46===e.keyCode}function le(e){return"1"===e.key||49===e.keyCode}function ue(e){return"2"===e.key||50===e.keyCode}function de(e){return"3"===e.key||51===e.keyCode}function pe(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var he=Object.freeze({__proto__:null,isActiveFeature:Q,isBackspaceKey:ae,isDeleteKey:ce,isDigit1Key:le,isDigit2Key:ue,isDigit3Key:de,isDigitKey:pe,isEnterKey:se,isEscapeKey:ie,isFeature:ne,isInactiveFeature:ee,isOfMetaType:z,isShiftDown:oe,isShiftMousedown:W,isTrue:function(){return!0},isVertex:re,noTarget:te});function fe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ge(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 me,ye,ve={},_e={};function xe(){return me||(me=1,_e.RADIUS=6378137,_e.FLATTENING=1/298.257223563,_e.POLAR_RADIUS=6356752.3142),_e}var Ie=function(){if(ye)return ve;ye=1;var e=xe();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 ve.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}},ve.ring=n,ve}(),Ee=fe(Ie);const Se={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Me(e,t){const n=Se[e.geometry.type]-Se[t.geometry.type];return 0===n&&e.geometry.type===H.POLYGON?e.area-t.area:n}function be(e){return e.map(e=>(e.geometry.type===H.POLYGON&&(e.area=Ee.geometry({type:H.FEATURE,property:{},geometry:e.geometry})),e)).sort(Me).map(e=>(delete e.area,e))}function Pe(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Te(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)}Te.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Te.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Te.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Te.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)},Te.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Ce=[K.FEATURE,K.MIDPOINT,K.VERTEX];var we={click:function(e,t,n){return Le(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return Le(e,t,n,n.options.touchBuffer)}};function Le(e,t,n,r){if(null===n.map)return[];const o=e?Pe(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!==Ce.indexOf(e.properties.meta)),a=new Te,c=[];return s.forEach(e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),be(c)}function Oe(e,t){const n=we.click(e,null,t),r={mouse:j.NONE};return n[0]&&(r.mouse=n[0].properties.active===J.ACTIVE?j.MOVE:j.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=j.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function Ae(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function ke(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=Ae(e.point,t.point);return s<r||s<o&&t.time-e.time<i}function Fe(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 Ae(e.point,t.point)<r&&t.time-e.time<o}const Ve=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 Ne=((e,t=21)=>(n=t)=>{let r="",o=0|n;for(;o--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function De(){return Ne()}const Re=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||De(),this.type=t.geometry.type};Re.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Re.prototype.incomingCoords=function(e){this.setCoordinates(e)},Re.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Re.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Re.prototype.setProperty=function(e,t){this.properties[e]=t},Re.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:H.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Re.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:H.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Ue=function(e,t){Re.call(this,e,t)};(Ue.prototype=Object.create(Re.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Ue.prototype.updateCoordinate=function(e,t,n){this.coordinates=3===arguments.length?[t,n]:[e,t],this.changed()},Ue.prototype.getCoordinate=function(){return this.getCoordinates()};const Be=function(e,t){Re.call(this,e,t)};(Be.prototype=Object.create(Re.prototype)).isValid=function(){return this.coordinates.length>1},Be.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},Be.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Be.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Be.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const je=function(e,t){Re.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(je.prototype=Object.create(Re.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},je.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},je.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},je.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])},je.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))},je.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]]))},je.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},je.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 Ge={MultiPoint:Ue,MultiLineString:Be,MultiPolygon:je},He=(e,t,n,r,o)=>{const i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,r,o)},Ye=function(e,t){if(Re.call(this,e,t),delete this.coordinates,this.model=Ge[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function Xe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ye.prototype=Object.create(Re.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:De(),type:H.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ye.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ye.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ye.prototype.getCoordinate=function(e){return He(this.features,"getCoordinate",e)},Ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===H.POLYGON?e.getCoordinates():e.coordinates)))},Ye.prototype.updateCoordinate=function(e,t,n){He(this.features,"updateCoordinate",e,t,n),this.changed()},Ye.prototype.addCoordinate=function(e,t,n){He(this.features,"addCoordinate",e,t,n),this.changed()},Ye.prototype.removeCoordinate=function(e){He(this.features,"removeCoordinate",e),this.changed()},Ye.prototype.getFeatures=function(){return this.features},Xe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Xe.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},Xe.prototype.getSelected=function(){return this._ctx.store.getSelected()},Xe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Xe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Xe.prototype.getFeature=function(e){return this._ctx.store.get(e)},Xe.prototype.select=function(e){return this._ctx.store.select(e)},Xe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Xe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Xe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Xe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Xe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Xe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Xe.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},Xe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Xe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Xe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Xe.prototype.featuresAt=function(e,t,n="click"){if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return we[n](e,t,this._ctx)},Xe.prototype.newFeature=function(e){const t=e.geometry.type;return t===H.POINT?new Ue(this._ctx,e):t===H.LINE_STRING?new Be(this._ctx,e):t===H.POLYGON?new je(this._ctx,e):new Ye(this._ctx,e)},Xe.prototype.isInstanceOf=function(e,t){if(e===H.POINT)return t instanceof Ue;if(e===H.LINE_STRING)return t instanceof Be;if(e===H.POLYGON)return t instanceof je;if("MultiFeature"===e)return t instanceof Ye;throw new Error(`Unknown feature class: ${e}`)},Xe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Xe.prototype.onSetup=function(){},Xe.prototype.onDrag=function(){},Xe.prototype.onClick=function(){},Xe.prototype.onMouseMove=function(){},Xe.prototype.onMouseDown=function(){},Xe.prototype.onMouseUp=function(){},Xe.prototype.onMouseOut=function(){},Xe.prototype.onKeyUp=function(){},Xe.prototype.onKeyDown=function(){},Xe.prototype.onTouchStart=function(){},Xe.prototype.onTouchMove=function(){},Xe.prototype.onTouchEnd=function(){},Xe.prototype.onTap=function(){},Xe.prototype.onStop=function(){},Xe.prototype.onTrash=function(){},Xe.prototype.onCombineFeature=function(){},Xe.prototype.onUncombineFeature=function(){},Xe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const $e={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($e);function Je(e){const t=Object.keys(e);return function(n,r={}){let o={};const i=t.reduce((t,n)=>(t[n]=e[n],t),new Xe(n));return{start(){o=i.onSetup(r),Ke.forEach(t=>{const n=$e[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 qe(e){return[].concat(e).filter(e=>void 0!==e)}function Ze(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(B.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(B.COLD).setData({type:H.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(B.HOT).setData({type:H.FEATURE_COLLECTION,features:e.sources.hot}),a()}function ze(e){let t;this._features={},this._featureIds=new Te,this._selectedFeatureIds=new Te,this._selectedCoordinates=[],this._changedFeatureIds=new Te,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ze.call(this),this._emitSelectionChange&&(this.ctx.events.fire(X.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(X.RENDER,{})}))},this.isDirty=!1}function We(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}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(X.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(X.UPDATE,{action:t.action?t.action:$.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 n=[];return qe(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(X.DELETE,{features:n}),We(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 qe(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 qe(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),We(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=qe(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,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:$.CHANGE_PROPERTIES})},ze.prototype.storeMapConfig=function(){q.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 Qe=["mode","feature","mouse"];function et(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]=Je(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:j.DRAG}),s.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!ke(n,e))},o.touchdrag=function(e){o.drag(e,e=>!Fe(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=Oe(t,e);t.featureTarget=n,s.mousemove(t)},o.mousedown=function(t){n={time:(new Date).getTime(),point:t.point};const r=Oe(t,e);t.featureTarget=r,s.mousedown(t)},o.mouseup=function(t){const r=Oe(t,e);t.featureTarget=r,ke(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=we.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=we.touch(t,null,e)[0];t.featureTarget=n,Fe(r,{time:(new Date).getTime(),point:t.point})?s.tap(t):s.touchend(t)};const a=e=>{const t=ae(e),n=ce(e),r=pe(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=Ve(c,e),o.silent||e.map.fire(X.MODE_CHANGE,{mode:n}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(U.CANVAS)&&((ae(t)||ce(t))&&e.options.controls.trash?(t.preventDefault(),s.trash()):a(t)?s.keydown(t):le(t)&&e.options.controls.point?c(Y.DRAW_POINT):ue(t)&&e.options.controls.line_string?c(Y.DRAW_LINE_STRING):de(t)&&e.options.controls.polygon&&c(Y.DRAW_POLYGON))},o.keyup=function(e){a(e)&&s.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:n,options:r,store:o}=e;r.styles.some(e=>n.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,s=Ve(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(X.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=[];Qe.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=`${U.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(U.ACTIVE_BUTTON),n=null)}function l(e){c();const r=t[e];r&&r&&"trash"!==e&&(r.classList.add(U.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=`${U.CONTROL_GROUP} ${U.CONTROL_BASE}`,n?(n[G.POINT]&&(t[G.POINT]=a(G.POINT,{container:r,className:U.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(Y.DRAW_POINT),onDeactivate:()=>e.events.trash()})),n[G.LINE]&&(t[G.LINE]=a(G.LINE,{container:r,className:U.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(Y.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),n[G.POLYGON]&&(t[G.POLYGON]=a(G.POLYGON,{container:r,className:U.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(Y.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),n.trash&&(t.trash=a("trash",{container:r,className:U.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),n.combine_features&&(t.combine_features=a("combineFeatures",{container:r,className:U.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),n.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:r,className:U.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 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()?r.connect():(o.on("load",r.connect),n=setInterval(()=>{o.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(B.COLD,{data:{type:H.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(B.HOT,{data:{type:H.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(B.COLD)&&e.map.removeSource(B.COLD),e.map.getSource(B.HOT)&&e.map.removeSource(B.HOT)}};return e.setup=r,r}const tt="#3bb2d0",nt="#fbb03b",rt="#fff";var ot=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],nt,tt],"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"],nt,tt],"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"],nt,tt]}},{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":nt}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":nt}}];function it(e,t){this.x=e,this.y=t}function st(e,t){const n=t.getBoundingClientRect();return new it(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function at(e,t,n,r){return{type:H.FEATURE,properties:{meta:K.VERTEX,parent:e,coord_path:n,active:r?J.ACTIVE:J.INACTIVE},geometry:{type:H.POINT,coordinates:t}}}function ct(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lt(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=>lt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return dt(e);default:throw new Error("unknown GeoJSON type")}}function lt(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=ut(e.properties),null==e.geometry?t.geometry=null:t.geometry=dt(e.geometry),t}function ut(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]=ut(r):t[n]=r}),t):t}function dt(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>dt(e)),t):(t.coordinates=pt(e.coordinates),t)}function pt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>pt(e))}function ht(e,t={}){return ft(e,"mercator",t)}function ft(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?gt(n):mt(n):(!0!==i&&(n=ct(n)),t(n,function(e){var t="mercator"===r?gt(e):mt(e);e[0]=t[0],e[1]=t[1]})),n}function gt(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 mt(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 yt(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=ht(r),s=ht(o),a=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ft(e,"wgs84",t)}([c(i[0],s[0]),c(i[1],s[1])]),u=[a(l[0]),a(l[1])];return{type:H.FEATURE,properties:{meta:K.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:n.properties.coord_path},geometry:{type:H.POINT,coordinates:u}}}function vt(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=at(i,e,l,c(l));if(t.midpoints&&o){const e=yt(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===H.POINT?s.push(at(i,o,n,c(n))):r===H.POLYGON?o.forEach((e,t)=>{a(e,null!==n?`${n}.${t}`:String(t))}):r===H.LINE_STRING?a(o,n):0===r.indexOf(H.MULTI_PREFIX)&&function(){const n=r.replace(H.MULTI_PREFIX,"");o.forEach((r,o)=>{const i={type:H.FEATURE,properties:e.properties,geometry:{type:n,coordinates:r}};s=s.concat(vt(i,t,o))})}(),s}it.prototype={clone(){return new it(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:it},it.convert=function(e){if(e instanceof it)return e;if(Array.isArray(e))return new it(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new it(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var _t={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:xt,LAT_MAX:It,LAT_RENDERED_MIN:Et,LAT_RENDERED_MAX:St,LNG_MIN:Mt,LNG_MAX:bt}=Z;function Pt(e,t){let n=xt,r=It,o=xt,i=It,s=bt,a=Mt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],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>St&&(c.lat=St-n),o+c.lat>It&&(c.lat=It-o),r+c.lat<Et&&(c.lat=Et-r),i+c.lat<xt&&(c.lat=xt-i),s+c.lng<=Mt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=bt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Tt(e,t){const n=Pt(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===H.POINT?s=r(t):e.type===H.LINE_STRING||e.type===H.MULTI_POINT?s=t.map(r):e.type===H.POLYGON||e.type===H.MULTI_LINE_STRING?s=t.map(o):e.type===H.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)})}const Ct={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(X.UPDATE,{action:$.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 Te).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(){_t.enable(this)},onMouseMove:function(e,t){return ne(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Ct.onTap=Ct.onClick=function(e,t){return te(t)?this.clickAnywhere(e,t):z(K.VERTEX)(t)?this.clickOnVertex(e,t):ne(t)?this.clickOnFeature(e,t):void 0},Ct.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),_t.enable(this),this.stopExtendedInteractions(e)},Ct.clickOnVertex=function(e,t){this.changeMode(Y.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:j.MOVE})},Ct.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Ct.clickOnFeature=function(e,t){_t.disable(this),this.stopExtendedInteractions(e);const n=oe(t),r=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!n&&i&&this.getFeature(o).type!==H.POINT)return this.changeMode(Y.DIRECT_SELECT,{featureId:o});i&&n?(this.deselect(o),this.updateUIClasses({mouse:j.POINTER}),1===r.length&&_t.enable(this)):!i&&n?(this.select(o),this.updateUIClasses({mouse:j.MOVE})):i||n||(r.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:j.MOVE})),this.doRender(o)},Ct.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),Q(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&W(t)?this.startBoxSelect(e,t):void 0},Ct.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=st(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Ct.onTouchStart=function(e,t){if(Q(t))return this.startOnActiveFeature(e,t)},Ct.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Ct.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:j.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(U.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=st(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"},Ct.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};Tt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Ct.onTouchEnd=Ct.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,st(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:j.MOVE}))}this.stopExtendedInteractions(e)},Ct.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?J.ACTIVE:J.INACTIVE,n(t),this.fireActionable(),t.properties.active===J.ACTIVE&&t.geometry.type!==H.POINT&&vt(t).forEach(n)},Ct.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Ct.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:H.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(X.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},Ct.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(X.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const wt=z(K.VERTEX),Lt=z(K.MIDPOINT),Ot={fireUpdate:function(){this.fire(X.UPDATE,{action:$.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);oe(t)||-1!==r?oe(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){Tt(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,n){const r=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=Pt(r.map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e}})),n);for(let t=0;t<r.length;t++){const n=r[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],n[0]+o.lng,n[1]+o.lat)}},clickNoTarget:function(){this.changeMode(Y.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(Y.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===H.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),_t.disable(this),this.setActionableState({trash:!0}),r},onStop:function(){_t.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=J.ACTIVE,n(t),vt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=J.INACTIVE,n(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(Y.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=Q(t),r=wt(t),o=Lt(t),i=0===e.selectedCoordPaths.length;n&&i||r&&!i?this.updateUIClasses({mouse:j.MOVE}):this.updateUIClasses({mouse:j.NONE});return(r||n||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ot.onTouchStart=Ot.onMouseDown=function(e,t){return wt(t)?this.onVertex(e,t):Q(t)?this.onFeature(e,t):Lt(t)?this.onMidpoint(e,t):void 0},Ot.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},Ot.onClick=function(e,t){return te(t)?this.clickNoTarget(e,t):Q(t)?this.clickActiveFeature(e,t):ee(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ot.onTap=function(e,t){return te(t)?this.clickNoTarget(e,t):Q(t)?this.clickActiveFeature(e,t):ee(t)?this.clickInactive(e,t):void 0},Ot.onTouchEnd=Ot.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const At={};function kt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}At.onSetup=function(){const e=this.newFeature({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:j.ADD}),this.activateUIButton(G.POINT),this.setActionableState({trash:!0}),{point:e}},At.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)},At.onTap=At.onClick=function(e,t){this.updateUIClasses({mouse:j.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(X.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.point.id]})},At.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},At.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?J.ACTIVE:J.INACTIVE,!r)return n(t)},At.onTrash=At.stopDrawingAndRemove,At.onKeyUp=function(e,t){if(ie(t)||se(t))return this.stopDrawingAndRemove(e,t)};const Ft={onSetup:function(){const e=this.newFeature({type:H.FEATURE,properties:{},geometry:{type:H.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),_t.disable(this),this.updateUIClasses({mouse:j.ADD}),this.activateUIButton(G.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(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:j.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:j.POINTER})}};Ft.onTap=Ft.onClick=function(e,t){return re(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ft.onKeyUp=function(e,t){ie(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)):se(t)&&this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ft.onStop=function(e){this.updateUIClasses({mouse:j.NONE}),_t.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(X.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT,{},{silent:!0})))},Ft.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?J.ACTIVE:J.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=K.FEATURE,n(at(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const r=t.geometry.coordinates[0].length-3;n(at(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:H.FEATURE,properties:t.properties,geometry:{coordinates:e,type:H.LINE_STRING}}),3===o)return}return n(t)}},Ft.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)};const Vt={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:H.FEATURE,properties:{},geometry:{type:H.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),_t.disable(this),this.updateUIClasses({mouse:j.ADD}),this.activateUIButton(G.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,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(Y.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:j.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:j.POINTER})}};Vt.onTap=Vt.onClick=function(e,t){if(re(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Vt.onKeyUp=function(e,t){se(t)?this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.line.id]}):ie(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT))},Vt.onStop=function(e){_t.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(X.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT,{},{silent:!0})))},Vt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)},Vt.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?J.ACTIVE:J.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=K.FEATURE,n(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)),n(t))};var Nt={simple_select:Ct,direct_select:Ot,draw_point:At,draw_polygon:Ft,draw_line_string:Vt};const Dt={defaultMode:Y.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:ot,modes:Nt,controls:{},userProperties:!1,suppressAPIEvents:!0},Rt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ut={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Bt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?B.HOT:B.COLD}))}var jt,Gt;var Ht,Yt,Xt=fe(Gt?jt:(Gt=1,jt=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 $t=function(){if(Yt)return Ht;Yt=1,Ht=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 Ht}(),Kt=fe($t);function Jt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const qt={Polygon:je,LineString:Be,Point:Ue,MultiPolygon:Ye,MultiLineString:Ye,MultiPoint:Ye};var Zt=Object.freeze({__proto__:null,CommonSelectors:he,ModeHandler:Ve,StringSet:Te,constrainFeatureMovement:Pt,createMidPoint:yt,createSupplementaryPoints:vt,createVertex:at,doubleClickZoom:_t,euclideanDistance:Ae,featuresAt:we,getFeatureAtAndSetCursors:Oe,isClick:ke,isEventAtCoordinates:kt,isTap:Fe,mapEventToBoundingBox:Pe,moveFeatures:Tt,sortFeatures:be,stringSetsAreEqual:Jt,theme:ot,toDenseArray:qe});const zt=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({},Ut,e.controls):t.controls=Object.assign({},Rt,e.controls),t=Object.assign({},Dt,t),t.styles=Bt(t.styles,"cold").concat(Bt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=Y;const n=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return we.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:H.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:H.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e.coordinates}}))}},t.set=function(n){if(void 0===n.type||n.type!==H.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 Te(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(Kt(t))).features.map(t=>{if(t.id=t.id||De(),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=qt[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,Xt(o,t.properties)||e.store.featureChanged(r.id,{silent:n}),Xt(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:H.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()!==Y.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(Y.SIMPLE_SELECT,void 0,{silent:n}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===Y.DIRECT_SELECT?e.events.changeMode(Y.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,o={}){return r===Y.SIMPLE_SELECT&&t.getMode()===Y.SIMPLE_SELECT?(Jt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:n}),e.store.render()),t):(r===Y.DIRECT_SELECT&&t.getMode()===Y.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,o,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,o,i){return e.store.setFeatureProperty(r,o,i,{silent:n}),t},t}(n,t),n.api=t;const r=et(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=G,t.options=e,t};function Wt(e){zt(e,this)}Wt.modes=Nt,Wt.constants=Z,Wt.lib=Zt;const Qt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,n){t.properties.active="false",n(t)}},en="draw.create",tn="draw.update",nn="draw.modechange",rn="draw.editfinish",on="draw.cancel",sn="draw.vertexselection",an="draw.vertexchange",cn="draw.undochange",ln="draw.undo",un="draw.geometrychange",dn="draw.interfacetypechange",pn="draw.placementblocked",hn="draw.nudgevertex",fn="draw.selectvertex",gn="draw.insertvertexatmidpoint",mn="draw.setgeometry",yn="styledata",vn=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[]}},_n=e=>{const t=vn(e),n=xn(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},xn=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},In=(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},En=(e,t)=>{let n=e.geometry.coordinates;for(const e of t)n=n[e];return n},Sn=(e,t)=>{const n=t.split(".").map(Number),r=xn(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]},Mn=(e,t)=>({x:e.x*t,y:e.y*t}),bn=e=>e instanceof window.SVGElement||e.ownerSVGElement;function Pn(e){return e?._snapInstance??null}function Tn(e){return!!(e?.status&&e?.snapStatus&&e.snapCoords?.length>=2)}function Cn(e){return Tn(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function wn(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 Ln(e,t){e&&(e._autoSnapSuspended=t)}function On(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 An(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 kn(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 Fn(e){return"function"==typeof e?.getSnapEnabled&&!0===e.getSnapEnabled()}const Vn=(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},Nn=(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(dn,n.interfacetypechange),t.on(hn,n.nudge),t.on(mn,n.setgeometry)},Dn=(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(dn,n.interfacetypechange),t.off(hn,n.nudge),t.off(mn,n.setgeometry),t.dragPan.enable(),window.removeEventListener("click",n.click),window.removeEventListener("keydown",n.keydown,{capture:!0}),window.removeEventListener("keyup",n.keyup,{capture:!0})},Rn=e=>{const t=Pn(e);t&&An(t,e)},Un=(e,t,n,r)=>{if("touch"===t.interfaceType)return;const o=Pn(e.map);o&&(o.snapStatus=!1,o.snapCoords=null),Fn(t)&&o?.status?r.call(e,t,n,o):Ot.onDrag.call(e,t,n),t.dragMoving&&e.map.fire(un,t.feature)},Bn={fireGeometryChange(e){const t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t){setTimeout(()=>{const n=this.getFeature(t);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:r,vertexIndex:e})},0)},pushUndo(e){const t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(e.vertexIndex,e.featureId))}},jn={...Bn,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):"replace_geometry"===n.type&&this.replaceGeometry(e,n.featureId,n.previousGeometry),this.emitGeometryValidation(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=xn(i),c=In(a,n);if(!c)return;En(s,c.segment.path)[c.localIdx]=r,this._applyUndoAndSync(e,s,o);const l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Mn(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=xn(o),a=In(s,n);if(!a)return;En(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=xn(i);let c=In(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;En(s,c.segment.path).splice(c.localIdx,0,r),this._applyUndoAndSync(e,s,o),this.updateTouchVertexTarget(e,Mn(this.map.project(e.vertices[n]),e.scale)),this.changeMode(e,{selectedVertexIndex:n,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,n)})},replaceGeometry(e,t,n){const r=this.getFeature(t);r&&(this._applyUndoAndSync(e,{...r.toGeoJSON(),geometry:n},t),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null}))},_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)}},Gn=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Hn=(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}}},Yn=(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(Fn(t)){const t=Pn(e);wn(t,e,r),o=Cn(t)||o}return o},Xn=(e,t,n={})=>{if(!e)return;const{editActive:r,editHalo:o,editVertex:i}=O(t,n);A(e,{editActive:r,editHalo:o,editVertex:i})},$n={addTouchVertexTarget(e){e.touchVertexTarget=L(e.container),Xn(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||bn(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(kn(Pn(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,Mn(this.map.project(t),e.scale))}},onTap(e,t){const n=Pn(this.map);n&&An(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=Sn(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){kn(Pn(this.map));const n=this.getVertices(e.featureId),r=n?.[e.selectedVertexIndex];if(!r||!bn(t.target.parentNode))return;e._moveStartPosition=[...r],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;const o=Gn(t);Object.assign(e,Hn(this.map,e.touchVertexTarget,o,r,e.scale))},onTouchmove(e,t){if(e.selectedVertexIndex<0||!bn(t.target.parentNode))return;e._touchMoved=!0;const n=Gn(t);this.moveVertex(e,Yn(this.map,e,n)),this.updateTouchVertexTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},Kn=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Jn={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},qn=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Zn=e=>{const t=document.activeElement;return!(!t||t===document.body)&&(!e.container?.contains(t)&&(qn.has(t.tagName)||t.isContentEditable||t.hasAttribute("tabindex")))},zn=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,Wn={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),r=t?.shiftKey?o.nudgeAmount:o.stepAmount,[i,s]=t?Jn[t.key].map(e=>e*r):[0,0];return this.map.unproject({x:n.x+i,y:n.y+s})},getOffsetByDelta(e,t,n,r){const i=this.map.project(e),s=r?o.stepAmount:o.nudgeAmount;return this.map.unproject({x:i.x+t*s,y:i.y+n*s})},resolveSnapTarget(e,t,r,o,i){const s=Pn(this.map);if(Fn(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,An(s,this.map),this.map.unproject({x:a.x+t*i,y:a.y+r*i})}const a=i();return Fn(e)&&s&&(wn(s,this.map,this.map.project(a)),Tn(s))?(e._isSnapped=!0,Cn(s)):(e._isSnapped=!1,a)}},er={...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(vn(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&&vn(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=xn(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;En(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=xn(r),s=In(i,e.selectedVertexIndex);if(!s)return;En(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=xn(t),r=In(n,e.selectedVertexIndex);if(!r)return;const{segment:o}=r,s=o.closed?i.Polygon:i.LineString;if(o.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})}},tr={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=xn(n),o=In(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 vn(this.getFeature(e))},getMidpoints(e){return _n(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=k(o,r,t);return[i,i<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){const n=this.getFeature(e.featureId),r=xn(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}},nr={...Wn,onKeydown(e,t){Zn(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Kn.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?zn(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=Pn(this.map);t&&An(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&&vn(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]=Jn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){Zn(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&F(t),Kn.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))}},rr={onMouseDown(e,t){kn(Pn(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,Ot.onMouseDown.call(this,e,t),"vertex"===n&&r)){const t=this.getFeature(e.featureId),n=Sn(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=Sn(t,r);e._insertedVertexIndex=n,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,r),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(sn,{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(sn,{index:t,numVertices:e.vertices.length})}Ot.onClick.call(this,e,t)},onMouseUp(e,t){kn(Pn(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,Ot.onMouseUp.call(this,e,t)},_didVertexMove(e){if(!e._moveStartPosition||null==e._moveStartIndex)return!1;const t=this.getFeature(e.featureId),n=t&&vn(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(sn,{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){Un(this,e,t,this._snapDrag)},_snapDrag(e,t,n){if(!e.selectedCoordPaths?.length||!e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation(),wn(n,this.map,t.point);const r=Cn(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],r.lng,r.lat),e.dragMoveLocation=t.lngLat}},or={...Wt.modes.direct_select,...jn,...$n,...er,...tr,...nr,...rr,onSetup(e){const t=Wt.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),Rn(this.map),"touch"===t.interfaceType&&t.selectedVertexIndex>=0&&"vertex"===t.selectedVertexType){const e=t.vertices[t.selectedVertexIndex];e&&setTimeout(()=>{this.updateTouchVertexTarget(t,Mn(this.map.project(e),t.scale))},0)}return t._ignorePointermoveDeselect=!0,setTimeout(()=>{t._ignorePointermoveDeselect=!1},100),t},setupEventListeners(e){const t=this.handlers=Vn(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint,setgeometry:this.onSetGeometry});Nn(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(fn,t.selectvertex),this.map.on(gn,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=vn(r);e.selectedVertexIndex=this.findVertexIndex(o,n,e.selectedVertexIndex)}e.selectedVertexType??=e.selectedVertexIndex>=0?"vertex":null,this.map.fire(sn,{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?Mn(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?Mn(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,Mn(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,Mn(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"})},onSetGeometry(e,t){const n=this.getFeature(e.featureId);if(!n)return;const r=n.toGeoJSON().geometry;this.replaceGeometry(e,e.featureId,t.geometry),this.pushUndo({type:"replace_geometry",featureId:e.featureId,previousGeometry:r})},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(fn,t.selectvertex),this.map.off(gn,t.insertvertexatmidpoint),Dn(e,this.map,t),this.hideTouchVertexIndicator(e)}},ir={...Bn,handleUndo(e){const t=this.map._undoStack;if(!t||0===t.length)return;const n=t.pop();"move_point"!==n.type&&"replace_geometry"!==n.type||this.undoMovePoint(e,n),this.emitGeometryValidation(n.vertexIndex,n.featureId)},undoMovePoint(e,t){this.setPointPosition(e,t.featureId,t.previousPosition)},setPointPosition(e,t,n){const r=this.getFeature(t);r&&(r.updateCoordinate("",n[0],n[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,Mn(this.map.project(n),e.scale)))}},sr={addTouchPointTarget(e){e.touchPointTarget=L(e.container),Xn(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){kn(Pn(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,Mn(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){kn(Pn(this.map));const n=this.getPointCoord(e);if(!n||!bn(t.target.parentNode))return;e._moveStartPosition=[...n],e._touchMoved=!1;const r=Gn(t);Object.assign(e,Hn(this.map,e.touchPointTarget,r,n,e.scale))},onTouchmove(e,t){if(!bn(t.target.parentNode))return;e._touchMoved=!0;const n=Gn(t);this.movePoint(e,Yn(this.map,e,n)),this.updateTouchPointTarget(e,{x:n.x-e.deltaTarget.x,y:n.y-e.deltaTarget.y})}},ar={...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})}},cr={...Wn,onKeydown(e,t){Zn(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Kn.has(t.key)?this.handleArrowKey(e,t):zn(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]=Jn[t.key];return this.resolveSnapTarget(e,r,o,n,()=>this.getNewCoord(e,t))},onKeyup(e,t){Zn(e)||(e.interfaceType="keyboard",F(t),Kn.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}},lr={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],Ln(Pn(this.map),!0)),Ot.onFeature.call(this,e,t)},onClick(e,t){if(Q(t))return;if(!((e,t)=>{const n={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},r={mode:"edit_point",vertexIndex:0},o=s(n,r,{onGeometryPreview:e._drawPreviewValidator});return o.valid||e.fire("draw.placementblocked",a(n,o,r)),o.valid})(this.map,[t.lngLat.lng,t.lngLat.lat]))return;const n=[...e.feature.coordinates],r=Pn(this.map);let o=t.lngLat;Fn(e)&&r&&(wn(r,this.map,t.point),o=Cn(r)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:n})},onMouseUp(e,t){const n=Pn(this.map);kn(n),Ln(n,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Ot.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){Un(this,e,t,this._snapDrag)},_snapDrag(e,t,n){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]};wn(n,this.map,this.map.project([r.lng,r.lat]));const o=Cn(n)||r;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat},onTrash(){}},ur={...Wt.modes.direct_select,...ir,...sr,...ar,...cr,...lr,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),_t.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}),Rn(this.map),"touch"===r.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(r,Mn(this.map.project(r.feature.coordinates),r.scale))},0),this.map.fire(sn,{index:0,numVertices:1}),r},setupEventListeners(e){const t=this.handlers=Vn(this,e,{nudge:this.onNudgePoint,setgeometry:this.onSetGeometry});Nn(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,Mn(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,Mn(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,Mn(this.map.project(e.feature.coordinates),e.scale))},onSetGeometry(e,t){const n=this.getFeature(e.featureId);if(!n)return;const r=n.getCoordinates();this.setPointPosition(e,e.featureId,t.geometry.coordinates),this.pushUndo({type:"replace_geometry",featureId:e.featureId,previousPosition:r})},onButtonClick(e,t){t.target.closest(`#${e.undoButtonId}`)&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Dn(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}},dr=({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",F,{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})}}),pr=(e,t,n,o)=>{setTimeout(()=>{const i=t(o);i&&e.fire("draw.geometrychange",((e,t)=>{const 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,n))},0)},hr=({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 s=c({placed:n(i).slice(0,-1),point:o,geometryType:e,onGeometryPreview:this.map._drawPreviewValidator});return s.valid||this.map.fire("draw.placementblocked",s.blocked),s.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){pr(this.map,t,n,e)},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)}}),fr=({ParentMode:e,getFeature:t,getCoords:n,validateClick:r,finishOnInvalidClick:o})=>({onClick(i,s){if(this._isIgnorableClick(s))return;if(!1===this.map._drawCanFinish&&"vertex"===s.featureTarget?.properties?.meta)return;const a=Pn(this.map);if(Fn(i)&&Tn(a))s=function(e,t){const n=Cn(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._drawCanFinish&&(a.pop(),this.map.fire("draw.create",{features:[s.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[s.id]})));const c=Pn(this.map),l=Fn(i)&&function(e,t){const n=Cn(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)}}),gr=e=>({...hr(e),...fr(e)}),mr=({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))},_handleUndoKeydown(e,t){const n=document.activeElement?.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}),yr=({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)}}),vr=({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}}),_r=e=>({...mr(e),...yr(e),...vr(e)}),xr=({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))}}}),Ir=({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(Fn(t)){const e=Pn(this.map);wn(e,this.map,n.point);const t=Cn(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){Fn(t)&&On(Pn(this.map),this.map);const n=Pn(this.map),r=Fn(t)&&Cn(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)))}}),Er=({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}}))}}),Sr=(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,...dr(l),...gr(l),..._r(l),...xr(l),...Ir(l),...Er(l)}},Mr=Sr(Wt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>l(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),br=Sr(Wt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>u(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),Pr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),Tr=Wt.modes.draw_point,Cr=dr({ParentMode:Tr,featureProp:"point",excludeFeatureIdFromSetup:!1}),wr={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)&&Fn(e)&&On(Pn(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){Fn(e)&&wn(Pn(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),Pr.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&Pr.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=Pn(this.map),r=Fn(e)&&Tn(n)?Cn(n):null;this._commit(e,r||t.lngLat)},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){const t=Pn(this.map);Fn(e)&&On(t,this.map);const n=Fn(e)&&Tn(t)?Cn(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:{}},r={mode:"draw_point",vertexIndex:0},o=s(n,r,{onGeometryPreview:e._drawPreviewValidator});return o.valid||e.fire("draw.placementblocked",a(n,o,r)),o.valid})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},Lr={...Tr,...Cr,...wr},Or=(e,t,n)=>["coalesce",["get",`user_${t}${e.id.charAt(0).toUpperCase()+e.id.slice(1)}`],["get",`user_${t}`],n],Ar=["coalesce",["get","user_sortKey"],0],kr=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":Ar},paint:{"fill-color":Or(e,"fill",t.shapeFill)}}),Fr=(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":Ar},paint:{"line-color":Or(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),Vr=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}}),Nr=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),Dr=(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}}),Rr=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Ur=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),Br=(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}}),jr=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),Gr=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Hr=(e,t={})=>{const n=O(e,t),{vertexRadius:r,midpointRadius:o,vertexHaloRadius:i,midpointHaloRadius:s}=d;return[kr(e,n),(p=n.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":p}}),(u=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":u,"line-width":2,"line-opacity":1}}),(l=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":l,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),Fr(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":Ar},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}}),Vr(n.editStroke),Ur(n.editMidpoint,o),Br(n.editHalo,n.editActive,s),jr(n.editMidpoint,o),Nr(n.editVertex,r),Dr(n.editHalo,n.editActive,i),Rr(n.editVertex,r),Gr(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,l,u,p};function Yr(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 Xr(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 $r(e,t,n){void 0===n&&(n={});var r=Yr(e),o=Yr(t),i=p(o[1]-r[1]),s=p(o[0]-r[0]),a=p(r[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}function Kr(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Jr(e,t,n,r={}){const o=Kr(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return void 0!==o[2]?g([d,h,o[2]],r.properties):g([d,h],r.properties)}function qr(e,t){var n;return void 0===t&&(t={}),function(e,t){if(e.length>1)return v(e,t);return _(e[0],t)}(("Feature"===(n=e).type?n.geometry:n).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Zr(e,t,n={}){if(!0===n.final)return function(e,t){let n=Zr(t,e);return n=(n+180)%360,n}(e,t);const r=Kr(e),o=Kr(t),i=p(r[0]),s=p(o[0]),a=p(r[1]),c=p(o[1]),l=Math.sin(s-i)*Math.cos(c),u=Math.cos(a)*Math.sin(c)-Math.sin(a)*Math.cos(c)*Math.cos(s-i);return m(Math.atan2(l,u))}var zr=Zr;function Wr(e,t,n,r){void 0===r&&(r={});var o=Yr(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return g([d,h],r.properties)}function Qr(e){if(!e)throw new Error("geojson is required");var t=[];return x(e,function(e){!function(e,t){var n=[],r=e.geometry;if(null!==r){switch(r.type){case"Polygon":n=Xr(r);break;case"LineString":n=[Xr(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=_([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)}),I(t)}var eo={exports:{}};function to(e,t,n,r,o){no(e,t,n||0,r||e.length-1,o||oo)}function no(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);no(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(ro(e,n,t),o(e[r],u)>0&&ro(e,n,r);d<p;){for(ro(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[n],u)?ro(e,n,p):ro(e,++p,r),p<=t&&(n=p+1),t<=p&&(r=p-1)}}function ro(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function oo(e,t){return e<t?-1:e>t?1:0}function io(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 so(e,t){ao(e,0,e.children.length,t,e)}function ao(e,t,n,r,o){o||(o=vo(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];co(o,e.leaf?r(t):t)}return o}function co(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 lo(e,t){return e.minX-t.minX}function uo(e,t){return e.minY-t.minY}function po(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function ho(e){return e.maxX-e.minX+(e.maxY-e.minY)}function fo(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 go(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 mo(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function yo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function vo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function _o(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;to(e,s,t,n,o),i.push(t,s,s,n)}}var xo,Io=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(!yo(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;yo(e,a)&&(t.leaf?n.push(s):mo(e,a)?this._all(s,n):o.push(s))}t=o.pop()}return n}collides(e){let t=this.data;if(!yo(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(yo(e,i)){if(t.leaf||mo(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=vo([]),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=io(e,n.children,t);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}c||n.leaf||!mo(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=vo(e.slice(t,n+1)),so(i,this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,r-1))),i=vo([]),i.leaf=!1,i.height=r;const a=Math.ceil(o/s),c=a*Math.ceil(Math.sqrt(s));_o(e,t,n,c,this.compareMinX);for(let o=t;o<=n;o+=c){const t=Math.min(o+c-1,n);_o(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 so(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=po(s),c=fo(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),co(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=vo(n.children.splice(i,n.children.length-i));s.height=n.height,s.leaf=n.leaf,so(n,this.toBBox),so(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)}_splitRoot(e,t){this.data=vo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,so(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=ao(e,0,s,this.toBBox),a=ao(e,s,n,this.toBBox),c=go(t,a),l=po(t)+po(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:lo,o=e.leaf?this.compareMinY:uo;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,o)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);const o=this.toBBox,i=ao(e,0,t,o),s=ao(e,n-t,n,o);let a=ho(i)+ho(s);for(let r=t;r<n-t;r++){const t=e.children[r];co(i,e.leaf?o(t):t),a+=ho(i)}for(let r=n-t-1;r>=t;r--){const t=e.children[r];co(s,e.leaf?o(t):t),a+=ho(s)}return a}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)co(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():so(e[n],this.toBBox)}}}),Eo=ge(Io),So={};function Mo(){if(xo)return So;xo=1,Object.defineProperty(So,"__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 So.areaFactors=n,So.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},So.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},So.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},So.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)},So.degreesToRadians=function(e){return e%360*Math.PI/180},So.earthRadius=e,So.factors=t,So.feature=r,So.featureCollection=a,So.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")}},So.geometryCollection=function(e,t,n={}){return r({type:"GeometryCollection",geometries:e},t,n)},So.isNumber=f,So.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},So.lengthToDegrees=function(e,t){return h(p(e,t))},So.lengthToRadians=p,So.lineString=s,So.lineStrings=function(e,t,n={}){return a(e.map(e=>s(e,t)),n)},So.multiLineString=c,So.multiPoint=l,So.multiPolygon=u,So.point=o,So.points=function(e,t,n={}){return a(e.map(e=>o(e,t)),n)},So.polygon=i,So.polygons=function(e,t,n={}){return a(e.map(e=>i(e,t)),n)},So.radiansToDegrees=h,So.radiansToLength=d,So.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},So.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")})},So.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")},So}var bo,Po={};function To(){if(bo)return Po;bo=1,Object.defineProperty(Po,"__esModule",{value:!0});var e=Mo();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,I=0;if(null!==(a=d?u.geometries[_]:u)){l=a.coordinates;var E=a.type;switch(p=!r||"Polygon"!==E&&"MultiPolygon"!==E?0:1,E){case null:break;case"Point":if(!1===n(l,h,v,x,I))return!1;h++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===n(l[o],h,v,x,I))return!1;h++,"MultiPoint"===E&&x++}"LineString"===E&&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,I))return!1;h++}"MultiLineString"===E&&x++,"Polygon"===E&&I++}"Polygon"===E&&x++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(I=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,I))return!1;h++}I++}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 Po.coordAll=function(e){var n=[];return t(e,function(e){n.push(e)}),n},Po.coordEach=t,Po.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},Po.featureEach=r,Po.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},Po.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")},Po.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")},Po.flattenEach=i,Po.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},Po.geomEach=o,Po.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},Po.lineEach=a,Po.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},Po.propEach=n,Po.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},Po.segmentEach=s,Po.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},Po}var Co,wo,Lo={};function Oo(){if(Co)return Lo;Co=1,Object.defineProperty(Lo,"__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 Lo.bbox=t,Lo.default=n,Lo}var Ao=function(){if(wo)return eo.exports;wo=1;var e=Eo,t=Mo(),n=To(),r=Oo().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 eo.exports=s,eo.exports.default=s,eo.exports}(),ko=fe(Ao);function Fo(e,t){var n={},r=[];if("LineString"===e.type&&(e=E(e)),"LineString"===t.type&&(t=E(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=Vo(e,t);return o&&r.push(o),I(r)}var i=ko();return i.load(Qr(t)),S(Qr(e),function(e){S(i.search(e),function(t){var o=Vo(e,t);if(o){var i=Xr(o).join(",");n[i]||(n[i]=!0,r.push(o))}})}),I(r)}function Vo(e,t){var n=Xr(e),r=Xr(t);if(2!==n.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==r.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=n[0][0],i=n[0][1],s=n[1][0],a=n[1][1],c=r[0][0],l=r[0][1],u=r[1][0],d=r[1][1],p=(d-l)*(s-o)-(u-c)*(a-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(s-o)*(i-l)-(a-i)*(o-c);if(0===p)return null;var m=h/p,y=f/p;return m>=0&&m<=1&&y>=0&&y<=1?g([o+m*(s-o),i+m*(a-i)]):null}function No(e,t,n){void 0===n&&(n={});var r=g([1/0,1/0],{dist:1/0}),o=0;return x(e,function(e){for(var i=Xr(e),s=0;s<i.length-1;s++){var a=g(i[s]);a.properties.dist=$r(t,a,n);var c=g(i[s+1]);c.properties.dist=$r(t,c,n);var l=$r(a,c,n),u=Math.max(a.properties.dist,c.properties.dist),d=zr(a,c),p=Wr(t,u,d+90,n),h=Wr(t,u,d-90,n),f=Fo(_([p.geometry.coordinates,h.geometry.coordinates]),_([a.geometry.coordinates,c.geometry.coordinates])),m=null;f.features.length>0&&((m=f.features[0]).properties.dist=$r(t,m,n),m.properties.location=o+$r(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 Do(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Ro(e,t){var n=function(e,t,n,r){void 0===r&&(r={});var o=Do(e),i=p(o[0]),s=p(o[1]),a=p(n),c=f(t,r.units),l=Math.asin(Math.sin(s)*Math.cos(c)+Math.cos(s)*Math.sin(c)*Math.cos(a)),u=i+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(s),Math.cos(c)-Math.sin(s)*Math.sin(l)),d=m(u),h=m(l);return g([d,h],r.properties)}(e,function(e,t,n){void 0===n&&(n={});var r=Do(e),o=Do(t),i=p(o[1]-r[1]),s=p(o[0]-r[0]),a=p(r[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),n.units)}(e,t)/2,zr(e,t));return n}var Uo=function(){return Uo=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},Uo.apply(this,arguments)},Bo=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=Uo(Uo({},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 $r(g(e),g(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=$r(g([n.lng,n.lat]),g([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(Jr(e,t,-360*o/r,n).geometry.coordinates);return i.push(i[0]),y([i],o)}(a.coords,i,{steps:64,units:"meters",properties:{color:a.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=I(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(I([])))}),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=M(e),o=[];if(r.map(function(e){var r=$r(g(e),g([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(_(e))});break;case"Polygon":var o=qr(e.geometry);r.push(o);break;case"MultiPolygon":qr(e.geometry).coodinates.map(function(e){r.push(_(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(Qr(e).features)});var i=[];if(o.map(function(e){var r=Ro(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=$r(r,g([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=No(r[i],g([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 jo="snap-helper-circle",Go="mapbox-gl-draw-hot";function Ho(e){if(Bo.prototype.__snapPatched)return;Bo.prototype.__snapPatched=!0;const t=Bo.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(jo)&&this.map.setLayoutProperty(jo,"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=>y(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>_(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 Yo(e,t){!function n(){const r=e();null!==r&&(r?t(r):requestAnimationFrame(n))}()}function Xo(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 $o=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Ko(e,t,n,r){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(jo)&&e.removeLayer(jo),e.getSource(jo)&&e.removeSource(jo)}(e),Xo(n);const o=new Bo({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&&$o.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 Jo(e,t,n){e.on("style.load",()=>{Yo(()=>e._removed?null:e.getSource(Go),r=>{Xo(r),function(e){e.getSource(jo)||e.addSource(jo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(jo)||e.addLayer({id:jo,type:"fill",source:jo,paint:{"fill-color":["get","color"]},layout:{visibility:e._snapInstance?.status?"visible":"none"}})}(e),e._snapInstance||Ko(e,t,r,n)})})}function qo(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 Ho({vertex:b.snapVertex,midpoint:b.snapMidpoint,edge:b.snapEdge,...l}),Jo(e,t,u),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(jo)){e.setLayoutProperty(jo,"visibility","none");const t=e._snapInstance;t?.status&&e.setLayoutProperty(jo,"visibility","visible")}})}(e),Yo(()=>e._removed?null:e.getSource(Go),n=>Ko(e,t,n,u)),e._snapInstance}const Zo="point-symbol",zo=new Set([`${Zo}.hot`,`${Zo}.cold`]),Wo=(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)})},Qo=async({draw:e,mapProvider:t,map:n,symbolRegistry:r,featureId:o,properties:i,pixelRatioOverride:s})=>{if(!V(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,Wo(e,t))})(n,e,u,h["icon-offset"]),{...l,properties:{...i,symbolImageId:u,symbolIconAnchor:h["icon-anchor"],symbolActiveImageId:d,symbolSelectedImageId:p}}},ei=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&&V(e.properties)),a=await Promise.allSettled(s.map(i=>Qo({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=>{P.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]),Wo(e,t))})(n,e)},ti="mapbox-gl-draw-cold",ni="mapbox-gl-draw-hot",ri=({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(ti))return!1;const n={type:"FeatureCollection",features:[]};return e.addSource(ti,{data:n,type:"geojson"}),e.addSource(ni,{data:n,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(e,t);((e,t,n={})=>{Hr(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]");Xn(c,s,o),ei({draw:t,mapProvider:n,map:e,symbolRegistry:r}).then(()=>{a&&t.set(t.getAll()),e.triggerRepaint(),i()}).catch(e=>P.error("[draw] failed to refresh point symbols after a style change",e))})},oi=({mapStyle:e,mapProvider:t,symbolRegistry:r,events:o,eventBus:i,snapLayers:s,pluginConfig:a={}})=>{const{map:c}=t;Wt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Wt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Wt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";const l={...Wt.modes,disabled:Qt,edit_vertex:or,edit_point:ur,draw_polygon:Mr,draw_line:br,draw_point:Lr};let u=t._mapboxDrawInstance;u?Object.assign(u.modes,l):(u=new Wt({modes:l,styles:Hr(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=N(e=>c.fire("draw.undochange",{length:e})),t.undoStack=p),c._undoStack=p;const h=O(e,a);qo(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,ri({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=>{ei({draw:u,mapProvider:t,map:c,symbolRegistry:r,pixelRatioOverride:e}).then(()=>{c.triggerRepaint(),f()}).catch(e=>P.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}}},ii=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),si=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),ai=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),ci=(e,t)=>{if("draw_polygon"===e)return{feature:ii(t),numVertices:(t[0]?.length??1)-1};if("draw_line"===e)return{feature:si(t),numVertices:(t?.length??1)-1};if("edit_vertex"===e){const e=t[0];return Array.isArray(e?.[0])?{feature:ii(t),numVertices:e.length}:{feature:si(t),numVertices:t?.length??0}}return"edit_point"===e?{feature:ai(t),numVertices:1}:null};class li{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,this._snapAvailable=!0;const{draw:n,remove:r}=oi({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=D({onChange:(e,t)=>{this._applyStrokeInvalid(e);const n=this._draw.getMode();"edit_vertex"!==n&&"edit_point"!==n||this._bus.emit(C.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=R({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(C.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(C.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(C.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(C.CANCEL),vertexselection:e=>this._bus.emit(C.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(C.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(C.UNDO_CHANGE,e.length),update:e=>this._bus.emit(C.UPDATE,e.features[0]),geometrychange:e=>{e?.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(C.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(C.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(C.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(en,this._mapHandlers.create),this._map.on(rn,this._mapHandlers.editfinish),this._map.on(on,this._mapHandlers.cancel),this._map.on(sn,this._mapHandlers.vertexselection),this._map.on(an,this._mapHandlers.vertexchange),this._map.on(cn,this._mapHandlers.undochange),this._map.on(tn,this._mapHandlers.update),this._map.on(un,this._mapHandlers.geometrychange),this._map.on(pn,this._mapHandlers.placementblocked),this._map.on(dn,this._mapHandlers.interfacetypechange),this._map.on(nn,this._mapHandlers.modechange),this._map.on(yn,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 Qo(e);t&&e.draw.add(t)})({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>P.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(!e?.coordinates)return;const t=this._draw.getMode(),n=ci(t,e.coordinates);n&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:n.feature,numVertices:n.numVertices,context:{mode:t},onGeometryPreview:this._previewValidator}):this._liveStroke.update({...n,context:{mode:t},onGeometryPreview:this._previewValidator}))}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(dn,{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(rn,{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(ln)}nudgeSelectedVertex(e,t,n){this._map.fire(hn,{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:vn(n),midpoints:_n(n)}}selectVertex(e){this._map.fire(fn,{index:e})}insertVertexAtMidpoint(e){this._map.fire(gn,{index:e})}setGeometry(e){this._map.fire(mn,{geometry:e})}setCanFinish(e){this._map._drawCanFinish=e}set _previewValidator(e){this._map._drawPreviewValidator=e}get _previewValidator(){return this._map._drawPreviewValidator}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&&V(t)&&this._resolvePointSymbol(r[0],t),r}setStyle(e,t){const n=this._draw.get(e);n&&this.add({...n,properties:w({...n.properties,...t})})}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e,this._applySnapStatus()}setSnapAvailable(e){e!==this._snapAvailable&&(this._snapAvailable=e,this._applySnapStatus())}_applySnapStatus(){const e=this.isSnapEnabled(),t=Pn(this._map);t?.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(kn(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){const t=Pn(this._map);t?.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled&&this._snapAvailable}setFeatureProperty(e,t,n){this._draw.setFeatureProperty(e,t,n)}setProperties(e,t){if(this._draw.get(e))for(const[n,r]of Object.entries(t))this._draw.setFeatureProperty(e,n,r)}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)||An(Pn(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(en,this._mapHandlers.create),this._map.off(rn,this._mapHandlers.editfinish),this._map.off(on,this._mapHandlers.cancel),this._map.off(sn,this._mapHandlers.vertexselection),this._map.off(an,this._mapHandlers.vertexchange),this._map.off(cn,this._mapHandlers.undochange),this._map.off(tn,this._mapHandlers.update),this._map.off(un,this._mapHandlers.geometrychange),this._map.off(pn,this._mapHandlers.placementblocked),this._map.off(dn,this._mapHandlers.interfacetypechange),this._map.off(nn,this._mapHandlers.modechange),this._map.off(yn,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{li as MaplibreDrawAdapter,ci as displayedShape};
|