dumbymap
Version:
Generate interactive maps from Semantic HTML
1 lines • 1.24 MB
JavaScript
!function(M,et){"object"==typeof exports&&"undefined"!=typeof module?et(exports):"function"==typeof define&&define.amd?define(["exports"],et):et((M="undefined"!=typeof globalThis?globalThis:M||self).maplibre={})}(this,(function(M){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(M){for(var et=1;et<arguments.length;et++){var Bt=arguments[et];for(var Wt in Bt)Object.prototype.hasOwnProperty.call(Bt,Wt)&&(M[Wt]=Bt[Wt])}return M},t.apply(this,arguments)}function e(M,et=9){const Bt=Math.pow(10,et);return Math.round(M*Bt)/Bt}const i=(M,et)=>{const{x:Bt,y:Wt}=M,{x:Nt,y:$t}=et,Gr=Nt-Bt,mn=$t-Wt;return Math.sqrt(mn*mn+Gr*Gr)};class o{constructor({name:M,callback:et,unregister:Bt,register:Wt}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=M,this.register=()=>{this.registered||(this.registered=!0,Wt(et))},this.unregister=()=>{this.register&&(this.registered=!1,Bt(et))},this.callback=et}}class s{constructor(M){this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._minPixelDragDistance="number"==typeof M.minPixelDragDistance?M.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof M.minPixelDragDistanceSelecting?M.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof M.minPixelDragDistanceDrawing?M.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof M.coordinatePrecision?M.coordinatePrecision:9}getButton(M){return-1===M.button?"neither":0===M.button?"left":1===M.button?"middle":2===M.button?"right":"neither"}getMapElementXYPosition(M){const et=this.getMapEventElement(),{left:Bt,top:Wt}=et.getBoundingClientRect();return{containerX:M.clientX-Bt,containerY:M.clientY-Wt}}getDrawEventFromEvent(M){const et=this.getLngLatFromEvent(M);if(!et)return null;const{lng:Bt,lat:Wt}=et,{containerX:Nt,containerY:$t}=this.getMapElementXYPosition(M),Gr=this.getButton(M),mn=Array.from(this._heldKeys);return{lng:e(Bt,this._coordinatePrecision),lat:e(Wt,this._coordinatePrecision),containerX:Nt,containerY:$t,button:Gr,heldKeys:mn}}register(M){this._currentModeCallbacks=M,this._listeners=this.getAdapterListeners(),this._listeners.forEach((M=>{M.register()}))}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new o({name:"pointerdown",callback:M=>{if(!this._currentModeCallbacks)return;if(!M.isPrimary)return;const et=this.getDrawEventFromEvent(M);et&&(this._dragState="pre-dragging",this._lastDrawEvent=et)},register:M=>{this.getMapEventElement().addEventListener("pointerdown",M)},unregister:M=>{this.getMapEventElement().removeEventListener("pointerdown",M)}}),new o({name:"pointermove",callback:M=>{if(!this._currentModeCallbacks)return;if(!M.isPrimary)return;M.preventDefault();const et=this.getDrawEventFromEvent(M);if(et)if("not-dragging"===this._dragState)this._currentModeCallbacks.onMouseMove(et),this._lastDrawEvent=et;else if("pre-dragging"===this._dragState){if(!this._lastDrawEvent)return;const M={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},Bt={x:et.containerX,y:et.containerY},Wt=this._currentModeCallbacks.getState(),Nt=i(M,Bt);let $t=!1;if($t="drawing"===Wt?Nt<this._minPixelDragDistanceDrawing:"selecting"===Wt?Nt<this._minPixelDragDistanceSelecting:Nt<this._minPixelDragDistance,$t)return;this._dragState="dragging",this._currentModeCallbacks.onDragStart(et,(M=>{this.setDraggability.bind(this)(M)}))}else"dragging"===this._dragState&&this._currentModeCallbacks.onDrag(et,(M=>{this.setDraggability.bind(this)(M)}))},register:M=>{this.getMapEventElement().addEventListener("pointermove",M)},unregister:M=>{this.getMapEventElement().removeEventListener("pointermove",M)}}),new o({name:"contextmenu",callback:M=>{this._currentModeCallbacks&&M.preventDefault()},register:M=>{this.getMapEventElement().addEventListener("contextmenu",M)},unregister:M=>{this.getMapEventElement().removeEventListener("contextmenu",M)}}),new o({name:"pointerup",callback:M=>{if(!this._currentModeCallbacks)return;if(M.target!==this.getMapEventElement())return;if(!M.isPrimary)return;const et=this.getDrawEventFromEvent(M);et&&("dragging"===this._dragState?this._currentModeCallbacks.onDragEnd(et,(M=>{this.setDraggability.bind(this)(M)})):"not-dragging"!==this._dragState&&"pre-dragging"!==this._dragState||this._currentModeCallbacks.onClick(et),this._dragState="not-dragging",this.setDraggability(!0))},register:M=>{this.getMapEventElement().addEventListener("pointerup",M)},unregister:M=>{this.getMapEventElement().removeEventListener("pointerup",M)}}),new o({name:"keyup",callback:M=>{this._currentModeCallbacks&&(this._heldKeys.delete(M.key),this._currentModeCallbacks.onKeyUp({key:M.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>M.preventDefault()}))},register:M=>{this.getMapEventElement().addEventListener("keyup",M)},unregister:M=>{this.getMapEventElement().removeEventListener("keyup",M)}}),new o({name:"keydown",callback:M=>{this._currentModeCallbacks&&(this._heldKeys.add(M.key),this._currentModeCallbacks.onKeyDown({key:M.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>M.preventDefault()}))},register:M=>{this.getMapEventElement().addEventListener("keydown",M)},unregister:M=>{this.getMapEventElement().removeEventListener("keydown",M)}})]}unregister(){this._listeners.forEach((M=>{M.unregister()})),this.clear()}}class a extends s{constructor(M){super(M),this._nextRender=void 0,this._map=void 0,this._container=void 0,this._rendered=!1,this.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},this._map=M.map,this._container=this._map.getContainer()}clearLayers(){this._rendered&&(["point","linestring","polygon"].forEach((M=>{const et=`td-${M.toLowerCase()}`;this._map.removeLayer(et),"polygon"===M&&this._map.removeLayer(et+"-outline"),this._map.removeSource(et)})),this._rendered=!1,this._nextRender&&(cancelAnimationFrame(this._nextRender),this._nextRender=void 0))}_addGeoJSONSource(M,et){this._map.addSource(M,{type:"geojson",data:{type:"FeatureCollection",features:et},tolerance:0})}_addFillLayer(M){return this._map.addLayer({id:M,source:M,type:"fill",paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})}_addFillOutlineLayer(M,et){const Bt=this._map.addLayer({id:M+"-outline",source:M,type:"line",paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}});return et&&this._map.moveLayer(M,et),Bt}_addLineLayer(M,et){const Bt=this._map.addLayer({id:M,source:M,type:"line",paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}});return et&&this._map.moveLayer(M,et),Bt}_addPointLayer(M,et){const Bt=this._map.addLayer({id:M,source:M,type:"circle",paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return et&&this._map.moveLayer(M,et),Bt}_addLayer(M,et,Bt){"Point"===et&&this._addPointLayer(M,Bt),"LineString"===et&&this._addLineLayer(M,Bt),"Polygon"===et&&(this._addFillLayer(M),this._addFillOutlineLayer(M,Bt))}_addGeoJSONLayer(M,et){const Bt=`td-${M.toLowerCase()}`;return this._addGeoJSONSource(Bt,et),this._addLayer(Bt,M),Bt}_setGeoJSONLayerData(M,et){const Bt=`td-${M.toLowerCase()}`;return this._map.getSource(Bt).setData({type:"FeatureCollection",features:et}),Bt}getEmptyGeometries(){return{points:[],linestrings:[],polygons:[]}}updateChangedIds(M){[...M.updated,...M.created].forEach((M=>{"Point"===M.geometry.type?this.changedIds.points=!0:"LineString"===M.geometry.type?this.changedIds.linestrings=!0:"Polygon"===M.geometry.type&&(this.changedIds.polygons=!0)})),M.deletedIds.length>0&&(this.changedIds.deletion=!0),0===M.created.length&&0===M.updated.length&&0===M.deletedIds.length&&(this.changedIds.styling=!0)}getLngLatFromEvent(M){const{left:et,top:Bt}=this._container.getBoundingClientRect();return this.unproject(M.clientX-et,M.clientY-Bt)}getMapEventElement(){return this._map.getCanvas()}setDraggability(M){M?(this._map.dragRotate.enable(),this._map.dragPan.enable()):(this._map.dragRotate.disable(),this._map.dragPan.disable())}project(M,et){const{x:Bt,y:Wt}=this._map.project({lng:M,lat:et});return{x:Bt,y:Wt}}unproject(M,et){const{lng:Bt,lat:Wt}=this._map.unproject({x:M,y:et});return{lng:Bt,lat:Wt}}setCursor(M){const et=this._map.getCanvas();"unset"===M?et.style.removeProperty("cursor"):et.style.cursor=M}setDoubleClickToZoom(M){M?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(M,et){this.updateChangedIds(M),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame((()=>{const Bt=[...M.created,...M.updated,...M.unchanged],Wt=this.getEmptyGeometries();for(let M=0;M<Bt.length;M++){const Nt=Bt[M];Object.keys(et).forEach((M=>{const{properties:Bt}=Nt;if(Bt.mode!==M)return;const $t=et[M](Nt);"Point"===Nt.geometry.type?(Bt.pointColor=$t.pointColor,Bt.pointOutlineColor=$t.pointOutlineColor,Bt.pointOutlineWidth=$t.pointOutlineWidth,Bt.pointWidth=$t.pointWidth,Wt.points.push(Nt)):"LineString"===Nt.geometry.type?(Bt.lineStringColor=$t.lineStringColor,Bt.lineStringWidth=$t.lineStringWidth,Wt.linestrings.push(Nt)):"Polygon"===Nt.geometry.type&&(Bt.polygonFillColor=$t.polygonFillColor,Bt.polygonFillOpacity=$t.polygonFillOpacity,Bt.polygonOutlineColor=$t.polygonOutlineColor,Bt.polygonOutlineWidth=$t.polygonOutlineWidth,Wt.polygons.push(Nt))}))}const{points:Nt,linestrings:$t,polygons:Gr}=Wt;if(this._rendered){const M=this.changedIds.deletion||this.changedIds.styling,et=M||this.changedIds.linestrings,Bt=M||this.changedIds.polygons;let Wt;(M||this.changedIds.points)&&(Wt=this._setGeoJSONLayerData("Point",Nt)),et&&this._setGeoJSONLayerData("LineString",$t),Bt&&this._setGeoJSONLayerData("Polygon",Gr),Wt&&this._map.moveLayer(Wt)}else{const M=this._addGeoJSONLayer("Point",Nt);this._addGeoJSONLayer("LineString",$t),this._addGeoJSONLayer("Polygon",Gr),this._rendered=!0,M&&this._map.moveLayer(M)}this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}}))}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}getCoordinatePrecision(){return super.getCoordinatePrecision()}unregister(){return super.unregister()}register(M){super.register(M),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()}}class l extends s{constructor(M){super(M),this.mapboxglAdapter=void 0,this.mapboxglAdapter=new a(M)}register(M){this.mapboxglAdapter.register(M)}unregister(){this.mapboxglAdapter.unregister()}getCoordinatePrecision(){return this.mapboxglAdapter.getCoordinatePrecision()}getLngLatFromEvent(M){return this.mapboxglAdapter.getLngLatFromEvent(M)}getMapEventElement(){return this.mapboxglAdapter.getMapEventElement()}setDraggability(M){this.mapboxglAdapter.setDraggability(M)}project(M,et){return this.mapboxglAdapter.project(M,et)}unproject(M,et){return this.mapboxglAdapter.unproject(M,et)}setCursor(M){this.mapboxglAdapter.setCursor(M)}setDoubleClickToZoom(M){this.mapboxglAdapter.setDoubleClickToZoom(M)}render(M,et){this.mapboxglAdapter.render(M,et)}clear(){this.mapboxglAdapter.clear()}}let et=0;const Bt="undefined"!=typeof navigator&&void 0!==navigator.userAgent?navigator.userAgent.toLowerCase():"";Bt.includes("firefox"),Bt.includes("safari")&&!Bt.includes("chrom")&&(Bt.includes("version/15.4")||/cpu (os|iphone os) 15_4 like mac os x/.test(Bt)),Bt.includes("webkit")&&Bt.includes("edge"),Bt.includes("macintosh"),"undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof OffscreenCanvas&&(self,WorkerGlobalScope),function(){let M=!1;try{const et=Object.defineProperty({},"passive",{get:function(){M=!0}});window.addEventListener("_",null,et),window.removeEventListener("_",null,et)}catch(M){}}();var Wt=class{constructor(){this.disposed=!1}dispose(){this.disposed||(this.disposed=!0,this.disposeInternal())}disposeInternal(){}},Nt=class{constructor(M){this.type=M,this.target=null}preventDefault(){this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0}};function W(){}function j(M){for(const et in M)delete M[et]}var $t=class extends Wt{constructor(M){super(),this.eventTarget_=M,this.pendingRemovals_=null,this.dispatching_=null,this.listeners_=null}addEventListener(M,et){if(!M||!et)return;const Bt=this.listeners_||(this.listeners_={}),Wt=Bt[M]||(Bt[M]=[]);Wt.includes(et)||Wt.push(et)}dispatchEvent(M){const et="string"==typeof M,Bt=et?M:M.type,Wt=this.listeners_&&this.listeners_[Bt];if(!Wt)return;const $t=et?new Nt(M):M;$t.target||($t.target=this.eventTarget_||this);const Gr=this.dispatching_||(this.dispatching_={}),mn=this.pendingRemovals_||(this.pendingRemovals_={});let Hn;Bt in Gr||(Gr[Bt]=0,mn[Bt]=0),++Gr[Bt];for(let M=0,et=Wt.length;M<et;++M)if(Hn="handleEvent"in Wt[M]?Wt[M].handleEvent($t):Wt[M].call(this,$t),!1===Hn||$t.propagationStopped){Hn=!1;break}if(0==--Gr[Bt]){let M=mn[Bt];for(delete mn[Bt];M--;)this.removeEventListener(Bt,W);delete Gr[Bt]}return Hn}disposeInternal(){this.listeners_&&j(this.listeners_)}getListeners(M){return this.listeners_&&this.listeners_[M]||void 0}hasListener(M){return!!this.listeners_&&(M?M in this.listeners_:Object.keys(this.listeners_).length>0)}removeEventListener(M,et){if(!this.listeners_)return;const Bt=this.listeners_[M];if(!Bt)return;const Wt=Bt.indexOf(et);-1!==Wt&&(this.pendingRemovals_&&M in this.pendingRemovals_?(Bt[Wt]=W,++this.pendingRemovals_[M]):(Bt.splice(Wt,1),0===Bt.length&&delete this.listeners_[M]))}};function N(M,et,Bt,Wt,Nt){if(Nt){const Wt=Bt;Bt=function(){M.removeEventListener(et,Bt),Wt.apply(this,arguments)}}const $t={target:M,type:et,listener:Bt};return M.addEventListener(et,Bt),$t}function A(M,et,Bt,Wt){return N(M,et,Bt,0,!0)}function R(M){M&&M.target&&(M.target.removeEventListener(M.type,M.listener),j(M))}var Gr=class extends $t{constructor(){super(),this.on=this.onInternal,this.once=this.onceInternal,this.un=this.unInternal,this.revision_=0}changed(){++this.revision_,this.dispatchEvent("change")}getRevision(){return this.revision_}onInternal(M,et){if(Array.isArray(M)){const Bt=M.length,Wt=new Array(Bt);for(let Nt=0;Nt<Bt;++Nt)Wt[Nt]=N(this,M[Nt],et);return Wt}return N(this,M,et)}onceInternal(M,et){let Bt;if(Array.isArray(M)){const Wt=M.length;Bt=new Array(Wt);for(let Nt=0;Nt<Wt;++Nt)Bt[Nt]=A(this,M[Nt],et)}else Bt=A(this,M,et);return et.ol_key=Bt,Bt}unInternal(M,et){const Bt=et.ol_key;if(Bt)!function(M){if(Array.isArray(M))for(let et=0,Bt=M.length;et<Bt;++et)R(M[et]);else R(M)}(Bt);else if(Array.isArray(M))for(let Bt=0,Wt=M.length;Bt<Wt;++Bt)this.removeEventListener(M[Bt],et);else this.removeEventListener(M,et)}};class K extends Nt{constructor(M,et,Bt){super(M),this.key=et,this.oldValue=Bt}}new class extends Gr{constructor(M){super(),this.ol_uid||(this.ol_uid=String(++et)),this.values_=null,void 0!==M&&this.setProperties(M)}get(M){let et;return this.values_&&this.values_.hasOwnProperty(M)&&(et=this.values_[M]),et}getKeys(){return this.values_&&Object.keys(this.values_)||[]}getProperties(){return this.values_&&Object.assign({},this.values_)||{}}getPropertiesInternal(){return this.values_}hasProperties(){return!!this.values_}notify(M,et){let Bt;Bt=`change:${M}`,this.hasListener(Bt)&&this.dispatchEvent(new K(Bt,M,et)),Bt="propertychange",this.hasListener(Bt)&&this.dispatchEvent(new K(Bt,M,et))}addChangeListener(M,et){this.addEventListener(`change:${M}`,et)}removeChangeListener(M,et){this.removeEventListener(`change:${M}`,et)}set(M,et,Bt){const Wt=this.values_||(this.values_={});if(Bt)Wt[M]=et;else{const Bt=Wt[M];Wt[M]=et,Bt!==et&&this.notify(M,Bt)}}setProperties(M,et){for(const Bt in M)this.set(Bt,M[Bt],et)}applyProperties(M){M.values_&&Object.assign(this.values_||(this.values_={}),M.values_)}unset(M,et){if(this.values_&&M in this.values_){const Bt=this.values_[M];delete this.values_[M],function(M){let et;for(et in M)return!1;return!et}(this.values_)&&(this.values_=null),et||this.notify(M,Bt)}}};const mn={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var Hn=class{constructor(M){this.code_=M.code,this.units_=M.units,this.extent_=void 0!==M.extent?M.extent:null,this.worldExtent_=void 0!==M.worldExtent?M.worldExtent:null,this.axisOrientation_=void 0!==M.axisOrientation?M.axisOrientation:"enu",this.global_=void 0!==M.global&&M.global,this.canWrapX_=!(!this.global_||!this.extent_),this.getPointResolutionFunc_=M.getPointResolution,this.defaultTileGrid_=null,this.metersPerUnit_=M.metersPerUnit}canWrapX(){return this.canWrapX_}getCode(){return this.code_}getExtent(){return this.extent_}getUnits(){return this.units_}getMetersPerUnit(){return this.metersPerUnit_||mn[this.units_]}getWorldExtent(){return this.worldExtent_}getAxisOrientation(){return this.axisOrientation_}isGlobal(){return this.global_}setGlobal(M){this.global_=M,this.canWrapX_=!(!M||!this.extent_)}getDefaultTileGrid(){return this.defaultTileGrid_}setDefaultTileGrid(M){this.defaultTileGrid_=M}setExtent(M){this.extent_=M,this.canWrapX_=!(!this.global_||!M)}setWorldExtent(M){this.worldExtent_=M}setGetPointResolution(M){this.getPointResolutionFunc_=M}getPointResolutionFunc(){return this.getPointResolutionFunc_}};const so=6378137,uo=Math.PI*so,Io=[-uo,-uo,uo,uo],Po=[-180,-85,180,85],To=so*Math.log(Math.tan(Math.PI/2));class mt extends Hn{constructor(M){super({code:M,units:"m",extent:Io,global:!0,worldExtent:Po,getPointResolution:function(M,et){return M/Math.cosh(et[1]/so)}})}}const Eo=[new mt("EPSG:3857"),new mt("EPSG:102100"),new mt("EPSG:102113"),new mt("EPSG:900913"),new mt("http://www.opengis.net/def/crs/EPSG/0/3857"),new mt("http://www.opengis.net/gml/srs/epsg.xml#3857")],Ia=[-180,-90,180,90],Ba=6378137*Math.PI/180;class Ct extends Hn{constructor(M,et){super({code:M,units:"degrees",extent:Ia,axisOrientation:et,global:!0,metersPerUnit:Ba,worldExtent:Ia})}}const Ta=[new Ct("CRS:84"),new Ct("EPSG:4326","neu"),new Ct("urn:ogc:def:crs:OGC:1.3:CRS84"),new Ct("urn:ogc:def:crs:OGC:2:84"),new Ct("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new Ct("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new Ct("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let Va={};function wt(M,et,Bt){const Wt=M.getCode(),Nt=et.getCode();Wt in Va||(Va[Wt]={}),Va[Wt][Nt]=Bt}function St(M,et){if(void 0!==et)for(let Bt=0,Wt=M.length;Bt<Wt;++Bt)et[Bt]=M[Bt];else et=M.slice();return et}function Et(M){M.getCode(),wt(M,M,St)}function Dt(M){!function(M){M.forEach(Et)}(M),M.forEach((function(et){M.forEach((function(M){et!==M&&wt(et,M,St)}))}))}var za,Fa,Ea,La;Dt(Eo),Dt(Ta),za=Eo,Fa=function(M,et,Bt){const Wt=M.length;Bt=Bt>1?Bt:2,void 0===et&&(et=Bt>2?M.slice():new Array(Wt));for(let Nt=0;Nt<Wt;Nt+=Bt){et[Nt]=uo*M[Nt]/180;let Bt=so*Math.log(Math.tan(Math.PI*(+M[Nt+1]+90)/360));Bt>To?Bt=To:Bt<-To&&(Bt=-To),et[Nt+1]=Bt}return et},Ea=function(M,et,Bt){const Wt=M.length;Bt=Bt>1?Bt:2,void 0===et&&(et=Bt>2?M.slice():new Array(Wt));for(let Nt=0;Nt<Wt;Nt+=Bt)et[Nt]=180*M[Nt]/uo,et[Nt+1]=360*Math.atan(Math.exp(M[Nt+1]/so))/Math.PI-90;return et},Ta.forEach((function(M){za.forEach((function(et){wt(M,et,Fa),wt(et,M,Ea)}))})),function(M){M.Commit="commit",M.Provisional="provisional",M.Finish="finish"}(La||(La={}));const Da="selected",Ka="midPoint",Oa="closingPoint";function Rt(M){return Boolean(M&&"object"==typeof M&&null!==M&&!Array.isArray(M))}function Vt(M){if(!function(M){return"number"==typeof M&&!isNaN(new Date(M).valueOf())}(M))throw new Error("updatedAt and createdAt are not valid timestamps");return!0}var $a;!function(M){M.Drawing="drawing",M.Select="select",M.Static="static",M.Render="render"}($a||($a={}));class Tt{get state(){return this._state}set state(M){throw new Error("Please use the modes lifecycle methods")}get styles(){return this._styles}set styles(M){if("object"!=typeof M)throw new Error("Styling must be an object");this.onStyleChange([],"styling"),this._styles=M}registerBehaviors(M){}constructor(M){this._state=void 0,this._styles=void 0,this.behaviors=[],this.validate=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.projection=void 0,this.type=$a.Drawing,this.mode="base",this._state="unregistered",this._styles=M&&M.styles?t({},M.styles):{},this.pointerDistance=M&&M.pointerDistance||40,this.validate=M&&M.validation,this.projection=M&&M.projection||"web-mercator"}setDrawing(){if("started"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="drawing"}setStarted(){if("stopped"!==this._state&&"registered"!==this._state&&"drawing"!==this._state&&"selecting"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started",this.setDoubleClickToZoom(!1)}setStopped(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped",this.setDoubleClickToZoom(!0)}register(M){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=M.store,this.store.registerOnChange(M.onChange),this.setDoubleClickToZoom=M.setDoubleClickToZoom,this.project=M.project,this.unproject=M.unproject,this.onSelect=M.onSelect,this.onDeselect=M.onDeselect,this.setCursor=M.setCursor,this.onStyleChange=M.onChange,this.onFinish=M.onFinish,this.coordinatePrecision=M.coordinatePrecision,this.registerBehaviors({mode:M.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:M.coordinatePrecision,projection:this.projection})}validateFeature(M){if("unregistered"===this._state)throw new Error("Mode must be registered");const et=function(M,et){let Bt;if(Rt(M))if(null==M.id)Bt="Feature has no id";else if("string"!=typeof M.id&&"number"!=typeof M.id)Bt="Feature must be string or number as per GeoJSON spec";else if(et(M.id))if(Rt(M.geometry))if(Rt(M.properties))if("string"==typeof M.geometry.type&&["Polygon","LineString","Point"].includes(M.geometry.type))if(Array.isArray(M.geometry.coordinates)){if(!M.properties.mode||"string"!=typeof M.properties.mode)throw new Error("Feature does not have a valid mode property")}else Bt="Feature coordinates is not an array";else Bt="Feature is not Point, LineString or Polygon";else Bt="Feature has no properties";else Bt="Feature has no geometry";else Bt="Feature must match the id strategy (default is UUID4)";else Bt="Feature is not object";if(Bt)throw new Error(Bt);return!0}(M,this.store.idStrategy.isValidId);return this.validate?this.validate(M,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:La.Provisional}):et}onFinish(M,et){}onDeselect(M){}onSelect(M){}onKeyDown(M){}onKeyUp(M){}onMouseMove(M){}onClick(M){}onDragStart(M,et){}onDrag(M,et){}onDragEnd(M,et){}getHexColorStylingValue(M,et,Bt){return this.getStylingValue(M,et,Bt)}getNumericStylingValue(M,et,Bt){return this.getStylingValue(M,et,Bt)}getStylingValue(M,et,Bt){return void 0===M?et:"function"==typeof M?M(Bt):M}}class Xt extends Tt{constructor(...M){super(...M),this.type=$a.Select}}function Ut(M,et){const i=M=>M*Math.PI/180,Bt=i(M[1]),Wt=i(M[0]),Nt=i(et[1]),$t=Nt-Bt,Gr=i(et[0])-Wt,mn=Math.sin($t/2)*Math.sin($t/2)+Math.cos(Bt)*Math.cos(Nt)*Math.sin(Gr/2)*Math.sin(Gr/2);return 2*Math.atan2(Math.sqrt(mn),Math.sqrt(1-mn))*6371e3/1e3}const Al=6371008.8;function Ht(M){return M%360*Math.PI/180}function Kt(M){return M/(Al/1e3)}function Jt(M){return M%(2*Math.PI)*180/Math.PI}const Sl=57.29577951308232,Zl=.017453292519943295,Gl=6378137,Qt=(M,et)=>({x:0===M?0:M*Zl*Gl,y:0===et?0:Math.log(Math.tan(Math.PI/4+et*Zl/2))*Gl}),te=(M,et)=>({lng:0===M?0:Sl*(M/Gl),lat:0===et?0:(2*Math.atan(Math.exp(et/Gl))-Math.PI/2)*Sl});function ee(M,et,Bt){const Wt=Ht(M[0]),Nt=Ht(M[1]),$t=Ht(Bt),Gr=Kt(et),mn=Math.asin(Math.sin(Nt)*Math.cos(Gr)+Math.cos(Nt)*Math.sin(Gr)*Math.cos($t));return[Jt(Wt+Math.atan2(Math.sin($t)*Math.sin(Gr)*Math.cos(Nt),Math.cos(Gr)-Math.sin(Nt)*Math.sin(mn))),Jt(mn)]}function ie(M){const{center:et,radiusKilometers:Bt,coordinatePrecision:Wt}=M,Nt=M.steps?M.steps:64,$t=[];for(let M=0;M<Nt;M++){const Gr=ee(et,Bt,-360*M/Nt);$t.push([e(Gr[0],Wt),e(Gr[1],Wt)])}return $t.push($t[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[$t]},properties:{}}}function oe(M){const et=0;let Bt;if("Polygon"===M.geometry.type)Bt=M.geometry.coordinates;else{if("LineString"!==M.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");Bt=[M.geometry.coordinates]}const Wt=[];for(let M=0;M<Bt.length;M++)for(let et=0;et<Bt[M].length-1;et++)for(let Wt=0;Wt<Bt.length;Wt++)for(let Nt=0;Nt<Bt[Wt].length-1;Nt++)r(M,et,Wt,Nt);return Wt.length>0;function s(M){return M<0-et||M>1+et}function r(M,et,Nt,$t){const Gr=Bt[M][et],mn=Bt[M][et+1],Hn=Bt[Nt][$t],so=Bt[Nt][$t+1],uo=function(M,et,Bt,Wt){if(se(M,Bt)||se(M,Wt)||se(et,Bt)||se(Wt,Bt))return null;const Nt=M[0],$t=M[1],Gr=et[0],mn=et[1],Hn=Bt[0],so=Bt[1],uo=Wt[0],Io=Wt[1],Po=(Nt-Gr)*(so-Io)-($t-mn)*(Hn-uo);return 0===Po?null:[((Nt*mn-$t*Gr)*(Hn-uo)-(Nt-Gr)*(Hn*Io-so*uo))/Po,((Nt*mn-$t*Gr)*(so-Io)-($t-mn)*(Hn*Io-so*uo))/Po]}(Gr,mn,Hn,so);if(null===uo)return;let Io,Po;Io=mn[0]!==Gr[0]?(uo[0]-Gr[0])/(mn[0]-Gr[0]):(uo[1]-Gr[1])/(mn[1]-Gr[1]),Po=so[0]!==Hn[0]?(uo[0]-Hn[0])/(so[0]-Hn[0]):(uo[1]-Hn[1])/(so[1]-Hn[1]),s(Io)||s(Po)||(uo.toString(),Wt.push(uo))}}function se(M,et){return M[0]===et[0]&&M[1]===et[1]}function re(M,et){return 2===M.length&&"number"==typeof M[0]&&"number"==typeof M[1]&&1/0!==M[0]&&1/0!==M[1]&&(Wt=M[0])>=-180&&Wt<=180&&(Bt=M[1])>=-90&&Bt<=90&&ne(M[0])<=et&&ne(M[1])<=et;var Bt,Wt}function ne(M){let et=1,Bt=0;for(;Math.round(M*et)/et!==M;)et*=10,Bt++;return Bt}function ae(M,et){return"Polygon"===M.geometry.type&&1===M.geometry.coordinates.length&&M.geometry.coordinates[0].length>=4&&M.geometry.coordinates[0].every((M=>re(M,et)))&&(Bt=M.geometry.coordinates[0][0])[0]===(Wt=M.geometry.coordinates[0][M.geometry.coordinates[0].length-1])[0]&&Bt[1]===Wt[1];var Bt,Wt}function le(M,et){return ae(M,et)&&!oe(M)}class he extends Tt{constructor(M){var et;super(M),this.mode="circle",this.center=void 0,this.clickCount=0,this.currentCircleId=void 0,this.keyEvents=void 0,this.cursors=void 0,this.startingRadiusKilometers=1e-5;const Bt={start:"crosshair"};if(this.cursors=M&&M.cursors?t({},Bt,M.cursors):Bt,null===(null==M?void 0:M.keyEvents))this.keyEvents={cancel:null,finish:null};else{const et={cancel:"Escape",finish:"Enter"};this.keyEvents=M&&M.keyEvents?t({},et,M.keyEvents):et}this.startingRadiusKilometers=null!=(et=null==M?void 0:M.startingRadiusKilometers)?et:1e-5,this.validate=null==M?void 0:M.validation}close(){if(void 0===this.currentCircleId)return;const M=this.currentCircleId;if(this.validate&&M){const et=this.store.getGeometryCopy(M);if(!this.validate({type:"Feature",id:M,geometry:et,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:La.Finish}))return}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(M,{mode:this.mode,action:"draw"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(M){if(0===this.clickCount){this.center=[M.lng,M.lat];const et=ie({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),[Bt]=this.store.create([{geometry:et.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=Bt,this.clickCount++,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.updateCircle(M),this.close()}onMouseMove(M){this.updateCircle(M)}onKeyDown(){}onKeyUp(M){M.key===this.keyEvents.cancel?this.cleanUp():M.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const M=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==M&&this.store.delete([M])}catch(M){}}styleFeature(M){const et=t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===M.type&&"Polygon"===M.geometry.type&&M.properties.mode===this.mode?(et.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,et.polygonFillColor,M),et.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,et.polygonOutlineColor,M),et.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,et.polygonOutlineWidth,M),et.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,et.polygonFillOpacity,M),et.zIndex=10,et):et}validateFeature(M){return!!super.validateFeature(M)&&M.properties.mode===this.mode&&le(M,this.coordinatePrecision)}updateCircle(M){if(1===this.clickCount&&this.center&&this.currentCircleId){const et=Ut(this.center,[M.lng,M.lat]);let Bt;if("web-mercator"===this.projection){const Wt=function(M,et){const Bt=1e3*Ut(M,et);if(0===Bt)return 1;const{x:Wt,y:Nt}=Qt(M[0],M[1]),{x:$t,y:Gr}=Qt(et[0],et[1]);return Math.sqrt(Math.pow($t-Wt,2)+Math.pow(Gr-Nt,2))/Bt}(this.center,[M.lng,M.lat]);Bt=function(M){const{center:et,radiusKilometers:Bt,coordinatePrecision:Wt}=M,Nt=M.steps?M.steps:64,$t=1e3*Bt,[Gr,mn]=et,{x:Hn,y:so}=Qt(Gr,mn),uo=[];for(let M=0;M<Nt;M++){const et=360*M/Nt*Math.PI/180,Bt=$t*Math.cos(et),Gr=$t*Math.sin(et),[mn,Io]=[Hn+Bt,so+Gr],{lng:Po,lat:To}=te(mn,Io);uo.push([e(Po,Wt),e(To,Wt)])}return uo.push(uo[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[uo]},properties:{}}}({center:this.center,radiusKilometers:et*Wt,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");Bt=ie({center:this.center,radiusKilometers:et,coordinatePrecision:this.coordinatePrecision})}if(this.validate&&!this.validate({type:"Feature",id:this.currentCircleId,geometry:Bt.geometry,properties:{radiusKilometers:et}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:La.Provisional}))return;this.store.updateGeometry([{id:this.currentCircleId,geometry:Bt.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:et}])}}}class de{constructor({store:M,mode:et,project:Bt,unproject:Wt,pointerDistance:Nt,coordinatePrecision:$t,projection:Gr}){this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.store=M,this.mode=et,this.project=Bt,this.unproject=Wt,this.pointerDistance=Nt,this.coordinatePrecision=$t,this.projection=Gr}}function ue({unproject:M,point:et,pointerDistance:Bt}){const Wt=Bt/2,{x:Nt,y:$t}=et;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[M(Nt-Wt,$t-Wt),M(Nt+Wt,$t-Wt),M(Nt+Wt,$t+Wt),M(Nt-Wt,$t+Wt),M(Nt-Wt,$t-Wt)].map((M=>[M.lng,M.lat]))]}}}class ge extends de{constructor(M){super(M)}create(M){const{containerX:et,containerY:Bt}=M;return ue({unproject:this.unproject,point:{x:et,y:Bt},pointerDistance:this.pointerDistance})}}class pe extends de{constructor(M){super(M)}measure(M,et){const{x:Bt,y:Wt}=this.project(et[0],et[1]);return i({x:Bt,y:Wt},{x:M.containerX,y:M.containerY})}}class ye extends de{constructor(M,et,Bt){super(M),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=M=>this.getSnappable(M,(M=>Boolean(M.properties&&M.properties.mode===this.mode))),this.getSnappableCoordinate=(M,et)=>this.getSnappable(M,(M=>Boolean(M.properties&&M.properties.mode===this.mode&&M.id!==et))),this.config=M,this.pixelDistance=et,this.clickBoundingBox=Bt}getSnappable(M,et){const Bt=this.clickBoundingBox.create(M),Wt=this.store.search(Bt,et),Nt={coord:void 0,minDist:1/0};return Wt.forEach((et=>{let Bt;if("Polygon"===et.geometry.type)Bt=et.geometry.coordinates[0];else{if("LineString"!==et.geometry.type)return;Bt=et.geometry.coordinates}Bt.forEach((et=>{const Bt=this.pixelDistance.measure(M,et);Bt<Nt.minDist&&Bt<this.pointerDistance&&(Nt.coord=et,Nt.minDist=Bt)}))})),Nt.coord}}function me(M,et,Bt){const Wt=Ht(M[0]),Nt=Ht(M[1]),$t=Ht(Bt),Gr=Kt(et),mn=Math.asin(Math.sin(Nt)*Math.cos(Gr)+Math.cos(Nt)*Math.sin(Gr)*Math.cos($t));return[Jt(Wt+Math.atan2(Math.sin($t)*Math.sin(Gr)*Math.cos(Nt),Math.cos(Gr)-Math.sin(Nt)*Math.sin(mn))),Jt(mn)]}function ve(M,et){const Bt=Ht(M[0]),Wt=Ht(et[0]),Nt=Ht(M[1]),$t=Ht(et[1]),Gr=Math.sin(Wt-Bt)*Math.cos($t),mn=Math.cos(Nt)*Math.sin($t)-Math.sin(Nt)*Math.cos($t)*Math.cos(Wt-Bt);return Jt(Math.atan2(Gr,mn))}function Ce(M,et,Bt){const Wt=[],Nt=M.length;let $t,Gr,mn,Hn=0;for(let Nt=0;Nt<M.length&&!(et>=Hn&&Nt===M.length-1);Nt++){if(Hn>et&&0===Wt.length){if($t=et-Hn,!$t)return Wt.push(M[Nt]),Wt;Gr=ve(M[Nt],M[Nt-1])-180,mn=me(M[Nt],$t,Gr),Wt.push(mn)}if(Hn>=Bt)return $t=Bt-Hn,$t?(Gr=ve(M[Nt],M[Nt-1])-180,mn=me(M[Nt],$t,Gr),Wt.push(mn),Wt):(Wt.push(M[Nt]),Wt);if(Hn>=et&&Wt.push(M[Nt]),Nt===M.length-1)return Wt;Hn+=Ut(M[Nt],M[Nt+1])}if(Hn<et&&M.length===Nt)throw new Error("Start position is beyond line");const so=M[M.length-1];return[so,so]}function Pe(M){return M*(Math.PI/180)}function xe(M){return M*(180/Math.PI)}class Me extends de{constructor(M){super(M),this.config=void 0,this.config=M}generateInsertionCoordinates(M,et,Bt){const Wt=[M,et];let Nt=0;for(let M=0;M<Wt.length-1;M++)Nt+=Ut(Wt[0],Wt[1]);if(Nt<=Bt)return Wt;let $t=Nt/Bt-1;Number.isInteger($t)||($t=Math.floor($t)+1);const Gr=[];for(let M=0;M<$t;M++){const et=Ce(Wt,Bt*M,Bt*(M+1));Gr.push(et)}const mn=[];for(let M=0;M<Gr.length;M++)mn.push(Gr[M][1]);return this.limitCoordinates(mn)}generateInsertionGeodesicCoordinates(M,et,Bt){const Wt=Ut(M,et),Nt=function(M,et,Bt){const Wt=[],Nt=Pe(M[1]),$t=Pe(M[0]),Gr=Pe(et[1]),mn=Pe(et[0]);Bt+=1;const Hn=2*Math.asin(Math.sqrt(Math.sin((Gr-Nt)/2)**2+Math.cos(Nt)*Math.cos(Gr)*Math.sin((mn-$t)/2)**2));if(0===Hn||isNaN(Hn))return Wt;for(let M=0;M<=Bt;M++){const et=M/Bt,so=Math.sin((1-et)*Hn)/Math.sin(Hn),uo=Math.sin(et*Hn)/Math.sin(Hn),Io=so*Math.cos(Nt)*Math.cos($t)+uo*Math.cos(Gr)*Math.cos(mn),Po=so*Math.cos(Nt)*Math.sin($t)+uo*Math.cos(Gr)*Math.sin(mn),To=so*Math.sin(Nt)+uo*Math.sin(Gr);if(isNaN(Io)||isNaN(Po)||isNaN(To))continue;const Eo=Math.atan2(To,Math.sqrt(Io**2+Po**2)),Ia=Math.atan2(Po,Io);isNaN(Eo)||isNaN(Ia)||Wt.push([xe(Ia),xe(Eo)])}return Wt.slice(1,-1)}(M,et,Math.floor(Wt/Bt));return this.limitCoordinates(Nt)}limitCoordinates(M){return M.map((M=>[e(M[0],this.config.coordinatePrecision),e(M[1],this.config.coordinatePrecision)]))}}function we(M,et){return M[0]===et[0]&&M[1]===et[1]}class Se extends Tt{constructor(M){super(M),this.mode="linestring",this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.cursors=void 0,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommitedCoordinates=void 0,this.snapping=void 0,this.insertPoint=void 0;const et={start:"crosshair",close:"pointer"};if(this.cursors=M&&M.cursors?t({},et,M.cursors):et,this.snappingEnabled=!(!M||void 0===M.snapping)&&M.snapping,null===(null==M?void 0:M.keyEvents))this.keyEvents={cancel:null,finish:null};else{const et={cancel:"Escape",finish:"Enter"};this.keyEvents=M&&M.keyEvents?t({},et,M.keyEvents):et}this.validate=null==M?void 0:M.validation,this.insertCoordinates=null==M?void 0:M.insertCoordinates}close(){if(void 0===this.currentId)return;const M=this.store.getGeometryCopy(this.currentId);M.coordinates.pop(),this.updateGeometries([...M.coordinates],void 0,La.Commit);const et=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.lastCommitedCoordinates=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(et,{mode:this.mode,action:"draw"})}updateGeometries(M,et,Bt){if(!this.currentId)return;const Wt={type:"LineString",coordinates:M};if(this.validate&&!this.validate({type:"Feature",geometry:Wt},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Bt}))return;const Nt=[{id:this.currentId,geometry:Wt}];this.closingPointId&&et&&Nt.push({id:this.closingPointId,geometry:{type:"Point",coordinates:et}}),"commit"===Bt&&(this.lastCommitedCoordinates=Wt.coordinates),this.store.updateGeometry(Nt)}generateInsertCoordinates(M,et){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");const Bt=Ut(M,et)/(this.insertCoordinates.value+1);let Wt=[];return"globe"===this.projection?Wt=this.insertPoint.generateInsertionGeodesicCoordinates(M,et,Bt):"web-mercator"===this.projection&&(Wt=this.insertPoint.generateInsertionCoordinates(M,et,Bt)),Wt}createLine(M){const[et]=this.store.create([{geometry:{type:"LineString",coordinates:[M,M]},properties:{mode:this.mode}}]);this.lastCommitedCoordinates=[M,M],this.currentId=et,this.currentCoordinate++,this.setDrawing()}firstUpdateToLine(M){if(!this.currentId)return;const et=this.store.getGeometryCopy(this.currentId).coordinates,[Bt]=this.store.create([{geometry:{type:"Point",coordinates:[...M]},properties:{mode:this.mode}}]);this.closingPointId=Bt,this.setCursor(this.cursors.close);const Wt=[...et,M];this.updateGeometries(Wt,void 0,La.Commit),this.currentCoordinate++}updateToLine(M,et){if(!this.currentId)return;const Bt=this.store.getGeometryCopy(this.currentId).coordinates,[Wt,Nt]=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:Bt[Bt.length-2],{x:$t,y:Gr}=this.project(Wt,Nt);if(i({x:$t,y:Gr},{x:et.x,y:et.y})<this.pointerDistance)return void this.close();this.setCursor(this.cursors.close);const mn=[...Bt,M];this.updateGeometries(mn,Bt[Bt.length-1],La.Commit),this.currentCoordinate++}registerBehaviors(M){this.snapping=new ye(M,new pe(M),new ge(M)),this.insertPoint=new Me(M)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(M){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const et=this.store.getGeometryCopy(this.currentId).coordinates;et.pop();const Bt=this.snappingEnabled&&this.snapping.getSnappableCoordinate(M,this.currentId)||[M.lng,M.lat];if(this.closingPointId){const[Bt,Wt]=et[et.length-1],{x:Nt,y:$t}=this.project(Bt,Wt);i({x:Nt,y:$t},{x:M.containerX,y:M.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}let Wt=[...et,Bt];if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){const M=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],et=Bt;if(!we(M,et)){const Nt=this.generateInsertCoordinates(M,et);Wt=[...this.lastCommitedCoordinates.slice(0,-1),...Nt,Bt]}}this.updateGeometries(Wt,void 0,La.Provisional)}onClick(M){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(M),this.mouseMove=!1;const et=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(M,this.currentId)||[M.lng,M.lat];0===this.currentCoordinate?this.createLine(et):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(et):this.currentId&&this.updateToLine(et,{x:M.containerX,y:M.containerY})}onKeyDown(){}onKeyUp(M){M.key===this.keyEvents.cancel&&this.cleanUp(),M.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const M=this.currentId;this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==M&&this.store.delete([M]),void 0!==this.closingPointId&&this.store.delete([this.closingPointId])}catch(M){}}styleFeature(M){const et=t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===M.type&&"LineString"===M.geometry.type&&M.properties.mode===this.mode?(et.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,et.lineStringColor,M),et.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,et.lineStringWidth,M),et.zIndex=10,et):"Feature"===M.type&&"Point"===M.geometry.type&&M.properties.mode===this.mode?(et.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,et.pointColor,M),et.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,et.pointWidth,M),et.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,"#ffffff",M),et.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,M),et.zIndex=40,et):et}validateFeature(M){return!!super.validateFeature(M)&&"LineString"===M.geometry.type&&M.properties.mode===this.mode&&M.geometry.coordinates.length>=2}}function be(M,et){return"Point"===M.geometry.type&&re(M.geometry.coordinates,et)}class Ee extends Tt{constructor(M){super(M),this.mode="point",this.cursors=void 0;const et={create:"crosshair"};this.cursors=M&&M.cursors?t({},et,M.cursors):et}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(M){if(!this.store)throw new Error("Mode must be registered first");const et={type:"Point",coordinates:[M.lng,M.lat]},Bt={mode:this.mode};if(this.validate&&!this.validate({type:"Feature",geometry:et,properties:Bt},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:La.Finish}))return;const[Wt]=this.store.create([{geometry:et,properties:Bt}]);this.onFinish(Wt,{mode:this.mode,action:"draw"})}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){}onDragStart(){}onDrag(){}onDragEnd(){}styleFeature(M){const et=t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===M.type&&"Point"===M.geometry.type&&M.properties.mode===this.mode&&(et.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,et.pointWidth,M),et.pointColor=this.getHexColorStylingValue(this.styles.pointColor,et.pointColor,M),et.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,et.pointOutlineColor,M),et.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,M),et.zIndex=30),et}validateFeature(M){return!!super.validateFeature(M)&&M.properties.mode===this.mode&&be(M,this.coordinatePrecision)}}class Ie extends de{constructor(M,et){super(M),this.config=void 0,this.pixelDistance=void 0,this._startEndPoints=[],this.config=M,this.pixelDistance=et}get ids(){return this._startEndPoints.concat()}set ids(M){}create(M,et){if(this.ids.length)throw new Error("Opening and closing points already created");if(M.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:M[0]},properties:{mode:et,[Oa]:!0}},{geometry:{type:"Point",coordinates:M[M.length-2]},properties:{mode:et,[Oa]:!0}}])}delete(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])}update(M){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:M[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:M[M.length-3]}}])}isClosingPoint(M){const et=this.store.getGeometryCopy(this.ids[0]),Bt=this.store.getGeometryCopy(this.ids[1]),Wt=this.pixelDistance.measure(M,et.coordinates),Nt=this.pixelDistance.measure(M,Bt.coordinates);return{isClosing:Wt<this.pointerDistance,isPreviousClosing:Nt<this.pointerDistance}}}class De extends Tt{constructor(M){super(M),this.mode="polygon",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.snapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.cursors=void 0,this.mouseMove=!1;const et={start:"crosshair",close:"pointer"};if(this.cursors=M&&M.cursors?t({},et,M.cursors):et,this.snappingEnabled=!(!M||void 0===M.snapping)&&M.snapping,null===(null==M?void 0:M.keyEvents))this.keyEvents={cancel:null,finish:null};else{const et={cancel:"Escape",finish:"Enter"};this.keyEvents=M&&M.keyEvents?t({},et,M.keyEvents):et}}close(){if(void 0===this.currentId)return;const M=this.store.getGeometryCopy(this.currentId).coordinates[0];if(M.length<5)return;if(!this.updatePolygonGeometry([...M.slice(0,-2),M[0]],La.Finish))return;const et=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(et,{mode:this.mode,action:"draw"})}registerBehaviors(M){this.pixelDistance=new pe(M),this.snapping=new ye(M,this.pixelDistance,new ge(M)),this.closingPoints=new Ie(M,this.pixelDistance)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(M){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const et=this.snappingEnabled?this.snapping.getSnappableCoordinate(M,this.currentId):void 0,Bt=this.store.getGeometryCopy(this.currentId).coordinates[0];let Wt;if(et&&(M.lng=et[0],M.lat=et[1]),1===this.currentCoordinate){const et=1/Math.pow(10,this.coordinatePrecision-1),Nt=Math.max(1e-6,et);Wt=[Bt[0],[M.lng,M.lat],[M.lng,M.lat-Nt],Bt[0]]}else if(2===this.currentCoordinate)Wt=[Bt[0],Bt[1],[M.lng,M.lat],Bt[0]];else{const{isClosing:et,isPreviousClosing:Nt}=this.closingPoints.isClosingPoint(M);Nt||et?(this.setCursor(this.cursors.close),Wt=[...Bt.slice(0,-2),Bt[0],Bt[0]]):Wt=[...Bt.slice(0,-2),[M.lng,M.lat],Bt[0]]}this.updatePolygonGeometry(Wt,La.Provisional)}updatePolygonGeometry(M,et){if(!this.currentId)return!1;const Bt={type:"Polygon",coordinates:[M]};return!(this.validate&&!this.validate({type:"Feature",geometry:Bt},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:et})||(this.store.updateGeometry([{id:this.currentId,geometry:Bt}]),0))}onClick(M){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(M),this.mouseMove=!1,0===this.currentCoordinate){const et=this.snappingEnabled?this.snapping.getSnappableCoordinateFirstClick(M):void 0;et&&(M.lng=et[0],M.lat=et[1]);const[Bt]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[M.lng,M.lat],[M.lng,M.lat],[M.lng,M.lat],[M.lng,M.lat]]]},properties:{mode:this.mode}}]);this.currentId=Bt,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const et=this.snappingEnabled?this.snapping.getSnappableCoordinate(M,this.currentId):void 0;et&&(M.lng=et[0],M.lat=et[1]);const Bt=this.store.getGeometryCopy(this.currentId);if(we([M.lng,M.lat],Bt.coordinates[0][0]))return;if(!this.updatePolygonGeometry([Bt.coordinates[0][0],[M.lng,M.lat],[M.lng,M.lat],Bt.coordinates[0][0]],La.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){const et=this.snappingEnabled?this.snapping.getSnappableCoordinate(M,this.currentId):void 0;et&&(M.lng=et[0],M.lat=et[1]);const Bt=this.store.getGeometryCopy(this.currentId).coordinates[0];if(we([M.lng,M.lat],Bt[1]))return;if(!this.updatePolygonGeometry([Bt[0],Bt[1],[M.lng,M.lat],[M.lng,M.lat],Bt[0]],La.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(Bt,"polygon"),this.currentCoordinate++}else if(this.currentId){const et=this.snappingEnabled?this.snapping.getSnappableCoordinate(M,this.currentId):void 0,Bt=this.store.getGeometryCopy(this.currentId).coordinates[0],{isClosing:Wt,isPreviousClosing:Nt}=this.closingPoints.isClosingPoint(M);if(Nt||Wt)this.close();else{if(et&&(M.lng=et[0],M.lat=et[1]),we([M.lng,M.lat],Bt[this.currentCoordinate-1]))return;const Wt=function(M=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]){return{type:"Feature",geometry:{type:"Polygon",coordinates:M},properties:{}}}([[...Bt.slice(0,-1),[M.lng,M.lat],Bt[0]]]);if(!this.updatePolygonGeometry(Wt.geometry.coordinates[0],La.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(Wt.geometry.coordinates[0])}}}onKeyUp(M){M.key===this.keyEvents.cancel?this.cleanUp():M.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){this.setCursor("unset")}onDrag(){}onDragEnd(){this.setCursor(this.cursors.start)}cleanUp(){const M=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==M&&this.store.delete([M]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(M){}}styleFeature(M){const et=t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(M.properties.mode===this.mode){if("Polygon"===M.geometry.type)return et.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,et.polygonFillColor,M),et.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,et.polygonOutlineColor,M),et.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,et.polygonOutlineWidth,M),et.polygonFillOpacity=this.getNumericStylingValue(this.styles