var e,t;e=this,t=function(){const e=function(e,t){const o={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===o[e])throw new Error(`Invalid event type: ${e}`);o[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},r=function(e,r){const i=o[e];let s=i.length;for(;s--;){const e=i[s];if(e.selector(r)){e.fn.call(n,r)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){r("drag",e)},click(e){r("click",e)},mousemove(e){r("mousemove",e)},mousedown(e){r("mousedown",e)},mouseup(e){r("mouseup",e)},mouseout(e){r("mouseout",e)},keydown(e){r("keydown",e)},keyup(e){r("keyup",e)},touchstart(e){r("touchstart",e)},touchmove(e){r("touchmove",e)},touchend(e){r("touchend",e)},tap(e){r("tap",e)}}};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var o,n,r={},i={};function s(){return o||(o=1,i.RADIUS=6378137,i.FLATTENING=1/298.257223563,i.POLAR_RADIUS=6356752.3142),i}var a=function(){if(n)return r;n=1;var e=s();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(o(e[0]));for(var n=1;n2){for(c=0;c(e.geometry.type===h.POLYGON&&(e.area=c.geometry({type:h.FEATURE,property:{},geometry:e.geometry})),e))).sort(S).map((e=>(delete e.area,e)))}function L(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function M(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,o=e.length;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))},M.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const N=[y.FEATURE,y.MIDPOINT,y.VERTEX];var b={click:function(e,t,o){return x(e,t,o,o.options.clickBuffer)},touch:function(e,t,o){return x(e,t,o,o.options.touchBuffer)}};function x(e,t,o,n){if(null===o.map)return[];const r=e?L(e,n):t,i={};o.options.styles&&(i.layers=o.options.styles.map((e=>e.id)).filter((e=>null!=o.map.getLayer(e))));const s=o.map.queryRenderedFeatures(r,i).filter((e=>-1!==N.indexOf(e.properties.meta))),a=new M,c=[];return s.forEach((e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))})),O(c)}function A(e,t){const o=b.click(e,null,t),n={mouse:d.NONE};return o[0]&&(n.mouse=o[0].properties.active===E.ACTIVE?d.MOVE:d.POINTER,n.feature=o[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=d.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),o[0]}function P(e,t){const o=e.x-t.x,n=e.y-t.y;return Math.sqrt(o*o+n*n)}const F=4,R=12,w=500;function D(e,t,o={}){const n=null!=o.fineTolerance?o.fineTolerance:F,r=null!=o.grossTolerance?o.grossTolerance:R,i=null!=o.interval?o.interval:w;e.point=e.point||t.point,e.time=e.time||t.time;const s=P(e.point,t.point);return s(o=t)=>{let n="",r=0|o;for(;r--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function B(){return G()}const j=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||B(),this.type=t.geometry.type};j.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},j.prototype.incomingCoords=function(e){this.setCoordinates(e)},j.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},j.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},j.prototype.setProperty=function(e,t){this.properties[e]=t},j.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:h.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},j.prototype.internal=function(e){const t={id:this.id,meta:y.FEATURE,"meta:type":this.type,active:E.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:h.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const J=function(e,t){j.call(this,e,t)};(J.prototype=Object.create(j.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},J.prototype.updateCoordinate=function(e,t,o){this.coordinates=3===arguments.length?[t,o]:[e,t],this.changed()},J.prototype.getCoordinate=function(){return this.getCoordinates()};const $=function(e,t){j.call(this,e,t)};($.prototype=Object.create(j.prototype)).isValid=function(){return this.coordinates.length>1},$.prototype.addCoordinate=function(e,t,o){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,o])},$.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},$.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},$.prototype.updateCoordinate=function(e,t,o){const n=parseInt(e,10);this.coordinates[n]=[t,o],this.changed()};const Y=function(e,t){j.call(this,e,t),this.coordinates=this.coordinates.map((e=>e.slice(0,-1)))};(Y.prototype=Object.create(j.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every((e=>e.length>2))},Y.prototype.incomingCoords=function(e){this.coordinates=e.map((e=>e.slice(0,-1))),this.changed()},Y.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Y.prototype.addCoordinate=function(e,t,o){this.changed();const n=e.split(".").map((e=>parseInt(e,10)));this.coordinates[n[0]].splice(n[1],0,[t,o])},Y.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map((e=>parseInt(e,10))),o=this.coordinates[t[0]];o&&(o.splice(t[1],1),o.length<3&&this.coordinates.splice(t[0],1))},Y.prototype.getCoordinate=function(e){const t=e.split(".").map((e=>parseInt(e,10))),o=this.coordinates[t[0]];return JSON.parse(JSON.stringify(o[t[1]]))},Y.prototype.getCoordinates=function(){return this.coordinates.map((e=>e.concat([e[0]])))},Y.prototype.updateCoordinate=function(e,t,o){this.changed();const n=e.split("."),r=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[r]&&(this.coordinates[r]=[]),this.coordinates[r][i]=[t,o]};const H={MultiPoint:J,MultiLineString:$,MultiPolygon:Y},X=(e,t,o,n,r)=>{const i=o.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,n,r)},q=function(e,t){if(j.call(this,e,t),delete this.coordinates,this.model=H[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 Z(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(q.prototype=Object.create(j.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map((e=>new t(this.ctx,{id:B(),type:h.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}})))},q.prototype.isValid=function(){return this.features.every((e=>e.isValid()))},q.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},q.prototype.getCoordinate=function(e){return X(this.features,"getCoordinate",e)},q.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map((e=>e.type===h.POLYGON?e.getCoordinates():e.coordinates))))},q.prototype.updateCoordinate=function(e,t,o){X(this.features,"updateCoordinate",e,t,o),this.changed()},q.prototype.addCoordinate=function(e,t,o){X(this.features,"addCoordinate",e,t,o),this.changed()},q.prototype.removeCoordinate=function(e){X(this.features,"removeCoordinate",e),this.changed()},q.prototype.getFeatures=function(){return this.features},Z.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Z.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)),{})},Z.prototype.getSelected=function(){return this._ctx.store.getSelected()},Z.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Z.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Z.prototype.getFeature=function(e){return this._ctx.store.get(e)},Z.prototype.select=function(e){return this._ctx.store.select(e)},Z.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Z.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Z.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Z.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Z.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Z.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Z.prototype.changeMode=function(e,t={},o={}){return this._ctx.events.changeMode(e,t,o)},Z.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Z.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Z.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Z.prototype.featuresAt=function(e,t,o="click"){if("click"!==o&&"touch"!==o)throw new Error("invalid buffer type");return b[o](e,t,this._ctx)},Z.prototype.newFeature=function(e){const t=e.geometry.type;return t===h.POINT?new J(this._ctx,e):t===h.LINE_STRING?new $(this._ctx,e):t===h.POLYGON?new Y(this._ctx,e):new q(this._ctx,e)},Z.prototype.isInstanceOf=function(e,t){if(e===h.POINT)return t instanceof J;if(e===h.LINE_STRING)return t instanceof $;if(e===h.POLYGON)return t instanceof Y;if("MultiFeature"===e)return t instanceof q;throw new Error(`Unknown feature class: ${e}`)},Z.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Z.prototype.onSetup=function(){},Z.prototype.onDrag=function(){},Z.prototype.onClick=function(){},Z.prototype.onMouseMove=function(){},Z.prototype.onMouseDown=function(){},Z.prototype.onMouseUp=function(){},Z.prototype.onMouseOut=function(){},Z.prototype.onKeyUp=function(){},Z.prototype.onKeyDown=function(){},Z.prototype.onTouchStart=function(){},Z.prototype.onTouchMove=function(){},Z.prototype.onTouchEnd=function(){},Z.prototype.onTap=function(){},Z.prototype.onStop=function(){},Z.prototype.onTrash=function(){},Z.prototype.onCombineFeature=function(){},Z.prototype.onUncombineFeature=function(){},Z.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const W={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},K=Object.keys(W);function z(e){const t=Object.keys(e);return function(o,n={}){let r={};const i=t.reduce(((t,o)=>(t[o]=e[o],t)),new Z(o));return{start(){r=i.onSetup(n),K.forEach((t=>{const o=W[t];let n=()=>!1;var s;e[o]&&(n=()=>!0),this.on(t,n,(s=o,e=>i[s](r,e)))}))},stop(){i.onStop(r)},trash(){i.onTrash(r)},combineFeatures(){i.onCombineFeatures(r)},uncombineFeatures(){i.onUncombineFeatures(r)},render(e,t){i.toDisplayFeatures(r,e,t)}}}}function Q(e){return[].concat(e).filter((e=>void 0!==e))}function ee(){const e=this;if(!e.ctx.map||void 0===e.ctx.map.getSource(l.HOT))return a();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let o=[],n=[];e.isDirty?n=e.getAllIds():(o=e.getChangedIds().filter((t=>void 0!==e.get(t))),n=e.sources.hot.filter((t=>t.properties.id&&-1===o.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id))).map((e=>e.properties.id))),e.sources.hot=[];const r=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter((e=>{const t=e.properties.id||e.properties.parent;return-1===o.indexOf(t)}));const i=r!==e.sources.cold.length||n.length>0;function s(o,n){const r=e.get(o).internal(t);e.ctx.events.currentModeRender(r,(o=>{o.properties.mode=t,e.sources[n].push(o)}))}function a(){e.isDirty=!1,e.clearChangedIds()}o.forEach((e=>s(e,"hot"))),n.forEach((e=>s(e,"cold"))),i&&e.ctx.map.getSource(l.COLD).setData({type:h.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(l.HOT).setData({type:h.FEATURE_COLLECTION,features:e.sources.hot}),a()}function te(e){let t;this._features={},this._featureIds=new M,this._selectedFeatureIds=new M,this._selectedCoordinates=[],this._changedFeatureIds=new M,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame((()=>{t=null,ee.call(this),this._emitSelectionChange&&(this.ctx.events.fire(g.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(g.RENDER,{})})))},this.isDirty=!1}function oe(e,t={}){const o=e._selectedCoordinates.filter((t=>e._selectedFeatureIds.has(t.feature_id)));e._selectedCoordinates.length===o.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=o}te.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},te.prototype.setDirty=function(){return this.isDirty=!0,this},te.prototype.featureCreated=function(e,t={}){if(this._changedFeatureIds.add(e),!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(g.CREATE,{features:[t.toGeoJSON()]})}return this},te.prototype.featureChanged=function(e,t={}){return this._changedFeatureIds.add(e),!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(g.UPDATE,{action:t.action?t.action:m.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},te.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},te.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},te.prototype.getAllIds=function(){return this._featureIds.values()},te.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},te.prototype.delete=function(e,t={}){const o=[];return Q(e).forEach((e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===o.indexOf(this._features[e])&&o.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)})),o.length&&this.ctx.events.fire(g.DELETE,{features:o}),oe(this,t),this},te.prototype.get=function(e){return this._features[e]},te.prototype.getAll=function(){return Object.keys(this._features).map((e=>this._features[e]))},te.prototype.select=function(e,t={}){return Q(e).forEach((e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))})),this},te.prototype.deselect=function(e,t={}){return Q(e).forEach((e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))})),oe(this,t),this},te.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},te.prototype.setSelected=function(e,t={}){return e=Q(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},te.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},te.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},te.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},te.prototype.getSelected=function(){return this.getSelectedIds().map((e=>this.get(e)))},te.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map((e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)})))},te.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},te.prototype.setFeatureProperty=function(e,t,o,n={}){this.get(e).setProperty(t,o),this.featureChanged(e,{silent:n.silent,action:m.CHANGE_PROPERTIES})},te.prototype.storeMapConfig=function(){T.forEach((e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())}))},te.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach((e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()}))},te.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const ne=["mode","feature","mouse"];function re(t){let o=null,n=null;const r={onRemove(){return t.map.off("load",r.connect),clearInterval(n),r.removeLayers(),t.store.restoreMapConfig(),t.ui.removeButtons(),t.events.removeEventListeners(),t.ui.clearMapClasses(),t.boxZoomInitial&&t.map.boxZoom.enable(),t.map=null,t.container=null,t.store=null,o&&o.parentNode&&o.parentNode.removeChild(o),o=null,this},connect(){t.map.off("load",r.connect),clearInterval(n),r.addLayers(),t.store.storeMapConfig(),t.events.addEventListeners()},onAdd(i){if(t.map=i,t.events=function(t){const o=Object.keys(t.options.modes).reduce(((e,o)=>(e[o]=z(t.options.modes[o]),e)),{});let n={},r={};const i={};let s=null,a=null;i.drag=function(e,o){o({point:e.point,time:(new Date).getTime()})?(t.ui.queueMapClasses({mouse:d.DRAG}),a.drag(e)):e.originalEvent.stopPropagation()},i.mousedrag=function(e){i.drag(e,(e=>!D(n,e)))},i.touchdrag=function(e){i.drag(e,(e=>!V(r,e)))},i.mousemove=function(e){if(1===(void 0!==e.originalEvent.buttons?e.originalEvent.buttons:e.originalEvent.which))return i.mousedrag(e);const o=A(e,t);e.featureTarget=o,a.mousemove(e)},i.mousedown=function(e){n={time:(new Date).getTime(),point:e.point};const o=A(e,t);e.featureTarget=o,a.mousedown(e)},i.mouseup=function(e){const o=A(e,t);e.featureTarget=o,D(n,{point:e.point,time:(new Date).getTime()})?a.click(e):a.mouseup(e)},i.mouseout=function(e){a.mouseout(e)},i.touchstart=function(e){if(!t.options.touchEnabled)return;r={time:(new Date).getTime(),point:e.point};const o=b.touch(e,null,t)[0];e.featureTarget=o,a.touchstart(e)},i.touchmove=function(e){if(t.options.touchEnabled)return a.touchmove(e),i.touchdrag(e)},i.touchend=function(e){if(e.originalEvent.preventDefault(),!t.options.touchEnabled)return;const o=b.touch(e,null,t)[0];e.featureTarget=o,V(r,{time:(new Date).getTime(),point:e.point})?a.tap(e):a.touchend(e)};const c=e=>!(8===e||46===e||e>=48&&e<=57);function l(n,r,i={}){a.stop();const c=o[n];if(void 0===c)throw new Error(`${n} is not valid`);s=n;const u=c(t,r);a=e(u,t),i.silent||t.map.fire(g.MODE_CHANGE,{mode:n}),t.store.setDirty(),t.store.render()}i.keydown=function(e){(e.srcElement||e.target).classList.contains(u.CANVAS)&&(8!==e.keyCode&&46!==e.keyCode||!t.options.controls.trash?c(e.keyCode)?a.keydown(e):49===e.keyCode&&t.options.controls.point?l(f.DRAW_POINT):50===e.keyCode&&t.options.controls.line_string?l(f.DRAW_LINE_STRING):51===e.keyCode&&t.options.controls.polygon&&l(f.DRAW_POLYGON):(e.preventDefault(),a.trash()))},i.keyup=function(e){c(e.keyCode)&&a.keyup(e)},i.zoomend=function(){t.store.changeZoom()},i.data=function(e){if("style"===e.dataType){const{setup:e,map:o,options:n,store:r}=t;n.styles.some((e=>o.getLayer(e.id)))||(e.addLayers(),r.setDirty(),r.render())}};const p={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){s=t.options.defaultMode,a=e(o[s](t),t)},changeMode:l,actionable:function(e){let o=!1;Object.keys(e).forEach((t=>{if(void 0===p[t])throw new Error("Invalid action type");p[t]!==e[t]&&(o=!0),p[t]=e[t]})),o&&t.map.fire(g.ACTIONABLE,{actions:p})},currentModeName:()=>s,currentModeRender:(e,t)=>a.render(e,t),fire(e,o){t.map&&t.map.fire(e,o)},addEventListeners(){t.map.on("mousemove",i.mousemove),t.map.on("mousedown",i.mousedown),t.map.on("mouseup",i.mouseup),t.map.on("data",i.data),t.map.on("touchmove",i.touchmove),t.map.on("touchstart",i.touchstart),t.map.on("touchend",i.touchend),t.container.addEventListener("mouseout",i.mouseout),t.options.keybindings&&(t.container.addEventListener("keydown",i.keydown),t.container.addEventListener("keyup",i.keyup))},removeEventListeners(){t.map.off("mousemove",i.mousemove),t.map.off("mousedown",i.mousedown),t.map.off("mouseup",i.mouseup),t.map.off("data",i.data),t.map.off("touchmove",i.touchmove),t.map.off("touchstart",i.touchstart),t.map.off("touchend",i.touchend),t.container.removeEventListener("mouseout",i.mouseout),t.options.keybindings&&(t.container.removeEventListener("keydown",i.keydown),t.container.removeEventListener("keyup",i.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>s}}(t),t.ui=function(e){const t={};let o=null,n={mode:null,feature:null,mouse:null},r={mode:null,feature:null,mouse:null};function i(e){r=Object.assign(r,e)}function s(){if(!e.container)return;const t=[],o=[];ne.forEach((e=>{r[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==r[e]&&o.push(`${e}-${r[e]}`))})),t.length>0&&e.container.classList.remove(...t),o.length>0&&e.container.classList.add(...o),n=Object.assign(n,r)}function a(e,t={}){const n=document.createElement("button");return n.className=`${u.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",(n=>{if(n.preventDefault(),n.stopPropagation(),n.target===o)return c(),void t.onDeactivate();l(e),t.onActivate()}),!0),n}function c(){o&&(o.classList.remove(u.ACTIVE_BUTTON),o=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(u.ACTIVE_BUTTON),o=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:s,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),s()},addButtons:function(){const o=e.options.controls,n=document.createElement("div");return n.className=`${u.CONTROL_GROUP} ${u.CONTROL_BASE}`,o?(o[p.LINE]&&(t[p.LINE]=a(p.LINE,{container:n,className:u.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(l)":""),onActivate:()=>e.events.changeMode(f.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),o[p.POLYGON]&&(t[p.POLYGON]=a(p.POLYGON,{container:n,className:u.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(p)":""),onActivate:()=>e.events.changeMode(f.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),o[p.POINT]&&(t[p.POINT]=a(p.POINT,{container:n,className:u.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(m)":""),onActivate:()=>e.events.changeMode(f.DRAW_POINT),onDeactivate:()=>e.events.trash()})),o.trash&&(t.trash=a("trash",{container:n,className:u.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),o.combine_features&&(t.combine_features=a("combineFeatures",{container:n,className:u.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),o.uncombine_features&&(t.uncombine_features=a("uncombineFeatures",{container:n,className:u.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach((e=>{const o=t[e];o.parentNode&&o.parentNode.removeChild(o),delete t[e]}))}}}(t),t.container=i.getContainer(),t.store=new te(t),o=t.ui.addButtons(),t.options.boxSelect){t.boxZoomInitial=i.boxZoom.isEnabled(),i.boxZoom.disable();const e=i.dragPan.isEnabled();i.dragPan.disable(),i.dragPan.enable(),e||i.dragPan.disable()}return i.loaded()?r.connect():(i.on("load",r.connect),n=setInterval((()=>{i.loaded()&&r.connect()}),16)),t.events.start(),o},addLayers(){t.map.addSource(l.COLD,{data:{type:h.FEATURE_COLLECTION,features:[]},type:"geojson"}),t.map.addSource(l.HOT,{data:{type:h.FEATURE_COLLECTION,features:[]},type:"geojson"}),t.options.styles.forEach((e=>{t.map.addLayer(e)})),t.store.setDirty(!0),t.store.render()},removeLayers(){t.options.styles.forEach((e=>{t.map.getLayer(e.id)&&t.map.removeLayer(e.id)})),t.map.getSource(l.COLD)&&t.map.removeSource(l.COLD),t.map.getSource(l.HOT)&&t.map.removeSource(l.HOT)}};return t.setup=r,r}const ie="#3bb2d0",se="#fbb03b",ae="#fff";var ce=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],se,ie],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],se,ie],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":ae}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],se,ie]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":ae}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":se}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":se}}];function ue(e){return function(t){const o=t.featureTarget;return!!o&&!!o.properties&&o.properties.meta===e}}function le(e){return!!e.originalEvent&&!!e.originalEvent.shiftKey&&0===e.originalEvent.button}function de(e){return!!e.featureTarget&&!!e.featureTarget.properties&&e.featureTarget.properties.active===E.ACTIVE&&e.featureTarget.properties.meta===y.FEATURE}function pe(e){return!!e.featureTarget&&!!e.featureTarget.properties&&e.featureTarget.properties.active===E.INACTIVE&&e.featureTarget.properties.meta===y.FEATURE}function he(e){return void 0===e.featureTarget}function fe(e){return!!e.featureTarget&&!!e.featureTarget.properties&&e.featureTarget.properties.meta===y.FEATURE}function ge(e){const t=e.featureTarget;return!!t&&!!t.properties&&t.properties.meta===y.VERTEX}function me(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function ye(e){return 27===e.keyCode}function Ee(e){return 13===e.keyCode}var Te=Object.freeze({__proto__:null,isActiveFeature:de,isEnterKey:Ee,isEscapeKey:ye,isFeature:fe,isInactiveFeature:pe,isOfMetaType:ue,isShiftDown:me,isShiftMousedown:le,isTrue:function(){return!0},isVertex:ge,noTarget:he});function Ce(e,t){this.x=e,this.y=t}function _e(e,t){const o=t.getBoundingClientRect();return new Ce(e.clientX-o.left-(t.clientLeft||0),e.clientY-o.top-(t.clientTop||0))}function ve(e,t,o,n){return{type:h.FEATURE,properties:{meta:y.VERTEX,parent:e,coord_path:o,active:n?E.ACTIVE:E.INACTIVE},geometry:{type:h.POINT,coordinates:t}}}function Ie(e,t,o){const n=t.geometry.coordinates,r=o.geometry.coordinates;if(n[1]>_||n[1]_||r[1]{const u=null!=o?`${o}.${a}`:String(a),l=ve(i,e,u,c(u));if(t.midpoints&&r){const e=Ie(i,r,l);e&&s.push(e)}r=l;const d=JSON.stringify(e);n!==d&&s.push(l),0===a&&(n=d)}))}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===h.POINT?s.push(ve(i,r,o,c(o))):n===h.POLYGON?r.forEach(((e,t)=>{a(e,null!==o?`${o}.${t}`:String(t))})):n===h.LINE_STRING?a(r,o):0===n.indexOf(h.MULTI_PREFIX)&&function(){const o=n.replace(h.MULTI_PREFIX,"");r.forEach(((n,r)=>{const i={type:h.FEATURE,properties:e.properties,geometry:{type:o,coordinates:n}};s=s.concat(Se(i,t,r))}))}(),s}Ce.prototype={clone(){return new Ce(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,o=e.y-this.y;return t*t+o*o},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,o=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=o,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),o=Math.sin(e),n=t*this.x-o*this.y,r=o*this.x+t*this.y;return this.x=n,this.y=r,this},_rotateAround(e,t){const o=Math.cos(e),n=Math.sin(e),r=t.x+o*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+o*(this.y-t.y);return this.x=r,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Ce},Ce.convert=function(e){if(e instanceof Ce)return e;if(Array.isArray(e))return new Ce(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Ce(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var Oe={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:Le,LAT_MAX:Me,LAT_RENDERED_MIN:Ne,LAT_RENDERED_MAX:be,LNG_MIN:xe,LNG_MAX:Ae}=v;function Pe(e,t){let o=Le,n=Me,r=Le,i=Me,s=Ae,a=xe;e.forEach((e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],o=[e.geometry.coordinates].flat(t),n=o.map((e=>e[0])),r=o.map((e=>e[1])),i=e=>Math.min.apply(null,e),s=e=>Math.max.apply(null,e);return[i(n),i(r),s(n),s(r)]}(e),c=t[1],u=t[3],l=t[0],d=t[2];c>o&&(o=c),ur&&(r=u),ca&&(a=d)}));const c=t;return o+c.lat>be&&(c.lat=be-o),r+c.lat>Me&&(c.lat=Me-r),n+c.lat=Ae&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Fe(e,t){const o=Pe(e.map((e=>e.toGeoJSON())),t);e.forEach((e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+o.lng,lat:e[1]+o.lat};return[t.lng,t.lat]},r=e=>e.map((e=>n(e))),i=e=>e.map((e=>r(e)));let s;e.type===h.POINT?s=n(t):e.type===h.LINE_STRING||e.type===h.MULTI_POINT?s=t.map(n):e.type===h.POLYGON||e.type===h.MULTI_LINE_STRING?s=t.map(r):e.type===h.MULTI_POLYGON&&(s=t.map(i)),e.incomingCoords(s)}))}const Re={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter((e=>void 0!==this.getFeature(e)))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(g.UPDATE,{action:m.MOVE,features:this.getSelected().map((e=>e.toGeoJSON()))})},fireActionable:function(){const e=this.getSelected(),t=e.filter((e=>this.isInstanceOf("MultiFeature",e)));let o=!1;if(e.length>1){o=!0;const t=e[0].type.replace("Multi","");e.forEach((e=>{e.type.replace("Multi","")!==t&&(o=!1)}))}const n=t.length>0,r=e.length>0;this.setActionableState({combineFeatures:o,uncombineFeatures:n,trash:r})},getUniqueIds:function(e){return e.length?e.map((e=>e.properties.id)).filter((e=>void 0!==e)).reduce(((e,t)=>(e.add(t),e)),new M).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(){Oe.enable(this)},onMouseMove:function(e,t){return fe(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Re.onTap=Re.onClick=function(e,t){return he(t)?this.clickAnywhere(e,t):ue(y.VERTEX)(t)?this.clickOnVertex(e,t):fe(t)?this.clickOnFeature(e,t):void 0},Re.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach((e=>this.doRender(e)))),Oe.enable(this),this.stopExtendedInteractions(e)},Re.clickOnVertex=function(e,t){this.changeMode(f.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:d.MOVE})},Re.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Re.clickOnFeature=function(e,t){Oe.disable(this),this.stopExtendedInteractions(e);const o=me(t),n=this.getSelectedIds(),r=t.featureTarget.properties.id,i=this.isSelected(r);if(!o&&i&&this.getFeature(r).type!==h.POINT)return this.changeMode(f.DIRECT_SELECT,{featureId:r});i&&o?(this.deselect(r),this.updateUIClasses({mouse:d.POINTER}),1===n.length&&Oe.enable(this)):!i&&o?(this.select(r),this.updateUIClasses({mouse:d.MOVE})):i||o||(n.forEach((e=>this.doRender(e))),this.setSelected(r),this.updateUIClasses({mouse:d.MOVE})),this.doRender(r)},Re.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),de(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&le(t)?this.startBoxSelect(e,t):void 0},Re.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=_e(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Re.onTouchStart=function(e,t){if(de(t))return this.startOnActiveFeature(e,t)},Re.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Re.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:d.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(u.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const o=_e(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,o.x),r=Math.max(e.boxSelectStartLocation.x,o.x),i=Math.min(e.boxSelectStartLocation.y,o.y),s=Math.max(e.boxSelectStartLocation.y,o.y),a=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=r-n+"px",e.boxSelectElement.style.height=s-i+"px"},Re.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const o={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};Fe(this.getSelected(),o),e.dragMoveLocation=t.lngLat},Re.onTouchEnd=Re.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const o=[e.boxSelectStartLocation,_e(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,o,"click"),r=this.getUniqueIds(n).filter((e=>!this.isSelected(e)));r.length&&(this.select(r),r.forEach((e=>this.doRender(e))),this.updateUIClasses({mouse:d.MOVE}))}this.stopExtendedInteractions(e)},Re.toDisplayFeatures=function(e,t,o){t.properties.active=this.isSelected(t.properties.id)?E.ACTIVE:E.INACTIVE,o(t),this.fireActionable(),t.properties.active===E.ACTIVE&&t.geometry.type!==h.POINT&&Se(t).forEach(o)},Re.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Re.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],o=[],n=e[0].type.replace("Multi","");for(let r=0;r{t.push(e)})):t.push(i.getCoordinates()),o.push(i.toGeoJSON())}if(o.length>1){const e=this.newFeature({type:h.FEATURE,properties:o[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(g.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:o})}this.fireActionable()},Re.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],o=[];for(let n=0;n{this.addFeature(e),e.properties=r.properties,t.push(e.toGeoJSON()),this.select([e.id])})),this.deleteFeature(r.id,{silent:!0}),o.push(r.toGeoJSON()))}t.length>1&&this.fire(g.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:o}),this.fireActionable()};const we=ue(y.VERTEX),De=ue(y.MIDPOINT),Ue={fireUpdate:function(){this.fire(g.UPDATE,{action:m.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){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.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const o=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(o.coord_path);me(t)||-1!==n?me(t)&&-1===n&&e.selectedCoordPaths.push(o.coord_path):e.selectedCoordPaths=[o.coord_path];const r=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(r)},onMidpoint:function(e,t){this.startDragging(e,t);const o=t.featureTarget.properties;e.feature.addCoordinate(o.coord_path,o.lng,o.lat),this.fireUpdate(),e.selectedCoordPaths=[o.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,o){Fe(this.getSelected(),o),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,o){const n=e.selectedCoordPaths.map((t=>e.feature.getCoordinate(t))),r=Pe(n.map((e=>({type:h.FEATURE,properties:{},geometry:{type:h.POINT,coordinates:e}}))),o);for(let t=0;tt.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(f.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const o=de(t),n=we(t),r=De(t),i=0===e.selectedCoordPaths.length;return o&&i||n&&!i?this.updateUIClasses({mouse:d.MOVE}):this.updateUIClasses({mouse:d.NONE}),(n||o||r)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ue.onTouchStart=Ue.onMouseDown=function(e,t){return we(t)?this.onVertex(e,t):de(t)?this.onFeature(e,t):De(t)?this.onMidpoint(e,t):void 0},Ue.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const o={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,o):this.dragFeature(e,t,o),e.dragMoveLocation=t.lngLat},Ue.onClick=function(e,t){return he(t)?this.clickNoTarget(e,t):de(t)?this.clickActiveFeature(e,t):pe(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ue.onTap=function(e,t){return he(t)?this.clickNoTarget(e,t):de(t)?this.clickActiveFeature(e,t):pe(t)?this.clickInactive(e,t):void 0},Ue.onTouchEnd=Ue.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const ke={};function Ve(e,t){return!!e.lngLat&&e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]}ke.onSetup=function(){const e=this.newFeature({type:h.FEATURE,properties:{},geometry:{type:h.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:d.ADD}),this.activateUIButton(p.POINT),this.setActionableState({trash:!0}),{point:e}},ke.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT)},ke.onTap=ke.onClick=function(e,t){this.updateUIClasses({mouse:d.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(g.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(f.SIMPLE_SELECT,{featureIds:[e.point.id]})},ke.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},ke.toDisplayFeatures=function(e,t,o){const n=t.properties.id===e.point.id;if(t.properties.active=n?E.ACTIVE:E.INACTIVE,!n)return o(t)},ke.onTrash=ke.stopDrawingAndRemove,ke.onKeyUp=function(e,t){if(ye(t)||Ee(t))return this.stopDrawingAndRemove(e,t)};const Ge={onSetup:function(){const e=this.newFeature({type:h.FEATURE,properties:{},geometry:{type:h.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),Oe.disable(this),this.updateUIClasses({mouse:d.ADD}),this.activateUIButton(p.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Ve(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(f.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:d.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(f.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),ge(t)&&this.updateUIClasses({mouse:d.POINTER})}};Ge.onTap=Ge.onClick=function(e,t){return ge(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ge.onKeyUp=function(e,t){ye(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT)):Ee(t)&&this.changeMode(f.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ge.onStop=function(e){this.updateUIClasses({mouse:d.NONE}),Oe.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(g.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT,{},{silent:!0})))},Ge.toDisplayFeatures=function(e,t,o){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?E.ACTIVE:E.INACTIVE,!n)return o(t);if(0===t.geometry.coordinates.length)return;const r=t.geometry.coordinates[0].length;if(!(r<3)){if(t.properties.meta=y.FEATURE,o(ve(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),r>3){const n=t.geometry.coordinates[0].length-3;o(ve(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(r<=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(o({type:h.FEATURE,properties:t.properties,geometry:{coordinates:e,type:h.LINE_STRING}}),3===r)return}return o(t)}},Ge.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT)};const Be={onSetup:function(e){const t=(e=e||{}).featureId;let o,n,r="forward";if(t){if(o=this.getFeature(t),!o)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=o.coordinates.length-1;if(o.coordinates[s][0]===i[0]&&o.coordinates[s][1]===i[1])n=s+1,o.addCoordinate(n,...o.coordinates[s]);else{if(o.coordinates[0][0]!==i[0]||o.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");r="backwards",n=0,o.addCoordinate(n,...o.coordinates[0])}}else o=this.newFeature({type:h.FEATURE,properties:{},geometry:{type:h.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(o);return this.clearSelectedFeatures(),Oe.disable(this),this.updateUIClasses({mouse:d.ADD}),this.activateUIButton(p.LINE),this.setActionableState({trash:!0}),{line:o,currentVertexPosition:n,direction:r}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&Ve(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&Ve(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(f.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:d.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(f.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),ge(t)&&this.updateUIClasses({mouse:d.POINTER})}};Be.onTap=Be.onClick=function(e,t){if(ge(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Be.onKeyUp=function(e,t){Ee(t)?this.changeMode(f.SIMPLE_SELECT,{featureIds:[e.line.id]}):ye(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT))},Be.onStop=function(e){Oe.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(g.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT,{},{silent:!0})))},Be.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(f.SIMPLE_SELECT)},Be.toDisplayFeatures=function(e,t,o){const n=t.properties.id===e.line.id;if(t.properties.active=n?E.ACTIVE:E.INACTIVE,!n)return o(t);t.geometry.coordinates.length<2||(t.properties.meta=y.FEATURE,o(ve(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)),o(t))};var je={simple_select:Re,direct_select:Ue,draw_point:ke,draw_polygon:Ge,draw_line_string:Be};const Je={defaultMode:f.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:ce,modes:je,controls:{},userProperties:!1,suppressAPIEvents:!0},$e={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Ye={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function He(e,t){return e.map((e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?l.HOT:l.COLD})))}var Xe,qe,Ze,We,Ke=t(qe?Xe:(qe=1,Xe=function e(t,o){if(t===o)return!0;if(t&&o&&"object"==typeof t&&"object"==typeof o){if(t.constructor!==o.constructor)return!1;var n,r,i;if(Array.isArray(t)){if((n=t.length)!=o.length)return!1;for(r=n;0!=r--;)if(!e(t[r],o[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===o.source&&t.flags===o.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===o.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===o.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(o).length)return!1;for(r=n;0!=r--;)if(!Object.prototype.hasOwnProperty.call(o,i[r]))return!1;for(r=n;0!=r--;){var s=i[r];if(!e(t[s],o[s]))return!1}return!0}return t!=t&&o!=o})),ze=function(){if(We)return Ze;We=1,Ze=function(t){if(!t||!t.type)return null;var o=e[t.type];return o?"geometry"===o?{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]}:"feature"===o?{type:"FeatureCollection",features:[t]}:"featurecollection"===o?t:void 0:null};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Ze}(),Qe=t(ze);function et(e,t){return e.length===t.length&&JSON.stringify(e.map((e=>e)).sort())===JSON.stringify(t.map((e=>e)).sort())}const tt={Polygon:Y,LineString:$,Point:J,MultiPolygon:q,MultiLineString:q,MultiPoint:q};var ot=Object.freeze({__proto__:null,CommonSelectors:Te,ModeHandler:e,StringSet:M,constrainFeatureMovement:Pe,createMidPoint:Ie,createSupplementaryPoints:Se,createVertex:ve,doubleClickZoom:Oe,euclideanDistance:P,featuresAt:b,getFeatureAtAndSetCursors:A,isClick:D,isEventAtCoordinates:Ve,isTap:V,mapEventToBoundingBox:L,moveFeatures:Fe,sortFeatures:O,stringSetsAreEqual:et,theme:ce,toDenseArray:Q});const nt=function(e,t){const o={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Ye,e.controls):t.controls=Object.assign({},$e,e.controls),t=Object.assign({},Je,t),t.styles=He(t.styles,"cold").concat(He(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=f;const o=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return b.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(o){if(void 0===o.type||o.type!==h.FEATURE_COLLECTION||!Array.isArray(o.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let r=e.store.getAllIds().slice();const i=t.add(o),s=new M(i);return r=r.filter((e=>!s.has(e))),r.length&&t.delete(r),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Qe(t))).features.map((t=>{if(t.id=t.id||B(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=tt[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const r=new n(e,t);e.store.add(r,{silent:o})}else{const n=e.store.get(t.id),r=n.properties;n.properties=t.properties,Ke(r,t.properties)||e.store.featureChanged(n.id,{silent:o}),Ke(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id}));return e.store.render(),n},t.get=function(t){const o=e.store.get(t);if(o)return o.toGeoJSON()},t.getAll=function(){return{type:h.FEATURE_COLLECTION,features:e.store.getAll().map((e=>e.toGeoJSON()))}},t.delete=function(n){return e.store.delete(n,{silent:o}),t.getMode()!==f.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(f.SIMPLE_SELECT,void 0,{silent:o}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:o}),t.getMode()===f.DIRECT_SELECT?e.events.changeMode(f.SIMPLE_SELECT,void 0,{silent:o}):e.store.render(),t},t.changeMode=function(n,r={}){return n===f.SIMPLE_SELECT&&t.getMode()===f.SIMPLE_SELECT?(et(r.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(r.featureIds,{silent:o}),e.store.render()),t):(n===f.DIRECT_SELECT&&t.getMode()===f.DIRECT_SELECT&&r.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,r,{silent:o}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:o}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:o}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:o}),t},t.setFeatureProperty=function(n,r,i){return e.store.setFeatureProperty(n,r,i,{silent:o}),t},t}(o,t),o.api=t;const n=re(o);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=p,t.options=e,t};function rt(e){nt(e,this)}return rt.modes=je,rt.constants=v,rt.lib=ot,rt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).MapboxDraw=t(); //# sourceMappingURL=mapbox-gl-draw.js.map