dumbymap
Version:
Generate interactive maps from Semantic HTML
1 lines • 266 kB
JavaScript
function t(){return t=Object.assign?Object.assign.bind():function(c){for(var d=1;d<arguments.length;d++){var p=arguments[d];for(var g in p)Object.prototype.hasOwnProperty.call(p,g)&&(c[g]=p[g])}return c},t.apply(this,arguments)}function e(c,d=9){const p=Math.pow(10,d);return Math.round(c*p)/p}const i=(c,d)=>{const{x:p,y:g}=c,{x:m,y:_}=d,f=m-p,y=_-g;return Math.sqrt(y*y+f*f)};class o{constructor({name:c,callback:d,unregister:p,register:g}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=c,this.register=()=>{this.registered||(this.registered=!0,g(d))},this.unregister=()=>{this.register&&(this.registered=!1,p(d))},this.callback=d}}class s{constructor(c){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 c.minPixelDragDistance?c.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof c.minPixelDragDistanceSelecting?c.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof c.minPixelDragDistanceDrawing?c.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof c.coordinatePrecision?c.coordinatePrecision:9}getButton(c){return-1===c.button?"neither":0===c.button?"left":1===c.button?"middle":2===c.button?"right":"neither"}getMapElementXYPosition(c){const d=this.getMapEventElement(),{left:p,top:g}=d.getBoundingClientRect();return{containerX:c.clientX-p,containerY:c.clientY-g}}getDrawEventFromEvent(c){const d=this.getLngLatFromEvent(c);if(!d)return null;const{lng:p,lat:g}=d,{containerX:m,containerY:_}=this.getMapElementXYPosition(c),f=this.getButton(c),y=Array.from(this._heldKeys);return{lng:e(p,this._coordinatePrecision),lat:e(g,this._coordinatePrecision),containerX:m,containerY:_,button:f,heldKeys:y}}register(c){this._currentModeCallbacks=c,this._listeners=this.getAdapterListeners(),this._listeners.forEach((c=>{c.register()}))}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new o({name:"pointerdown",callback:c=>{if(!this._currentModeCallbacks)return;if(!c.isPrimary)return;const d=this.getDrawEventFromEvent(c);d&&(this._dragState="pre-dragging",this._lastDrawEvent=d)},register:c=>{this.getMapEventElement().addEventListener("pointerdown",c)},unregister:c=>{this.getMapEventElement().removeEventListener("pointerdown",c)}}),new o({name:"pointermove",callback:c=>{if(!this._currentModeCallbacks)return;if(!c.isPrimary)return;c.preventDefault();const d=this.getDrawEventFromEvent(c);if(d)if("not-dragging"===this._dragState)this._currentModeCallbacks.onMouseMove(d),this._lastDrawEvent=d;else if("pre-dragging"===this._dragState){if(!this._lastDrawEvent)return;const c={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},p={x:d.containerX,y:d.containerY},g=this._currentModeCallbacks.getState(),m=i(c,p);let _=!1;if(_="drawing"===g?m<this._minPixelDragDistanceDrawing:"selecting"===g?m<this._minPixelDragDistanceSelecting:m<this._minPixelDragDistance,_)return;this._dragState="dragging",this._currentModeCallbacks.onDragStart(d,(c=>{this.setDraggability.bind(this)(c)}))}else"dragging"===this._dragState&&this._currentModeCallbacks.onDrag(d,(c=>{this.setDraggability.bind(this)(c)}))},register:c=>{this.getMapEventElement().addEventListener("pointermove",c)},unregister:c=>{this.getMapEventElement().removeEventListener("pointermove",c)}}),new o({name:"contextmenu",callback:c=>{this._currentModeCallbacks&&c.preventDefault()},register:c=>{this.getMapEventElement().addEventListener("contextmenu",c)},unregister:c=>{this.getMapEventElement().removeEventListener("contextmenu",c)}}),new o({name:"pointerup",callback:c=>{if(!this._currentModeCallbacks)return;if(c.target!==this.getMapEventElement())return;if(!c.isPrimary)return;const d=this.getDrawEventFromEvent(c);d&&("dragging"===this._dragState?this._currentModeCallbacks.onDragEnd(d,(c=>{this.setDraggability.bind(this)(c)})):"not-dragging"!==this._dragState&&"pre-dragging"!==this._dragState||this._currentModeCallbacks.onClick(d),this._dragState="not-dragging",this.setDraggability(!0))},register:c=>{this.getMapEventElement().addEventListener("pointerup",c)},unregister:c=>{this.getMapEventElement().removeEventListener("pointerup",c)}}),new o({name:"keyup",callback:c=>{this._currentModeCallbacks&&(this._heldKeys.delete(c.key),this._currentModeCallbacks.onKeyUp({key:c.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>c.preventDefault()}))},register:c=>{this.getMapEventElement().addEventListener("keyup",c)},unregister:c=>{this.getMapEventElement().removeEventListener("keyup",c)}}),new o({name:"keydown",callback:c=>{this._currentModeCallbacks&&(this._heldKeys.add(c.key),this._currentModeCallbacks.onKeyDown({key:c.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>c.preventDefault()}))},register:c=>{this.getMapEventElement().addEventListener("keydown",c)},unregister:c=>{this.getMapEventElement().removeEventListener("keydown",c)}})]}unregister(){this._listeners.forEach((c=>{c.unregister()})),this.clear()}}class n extends s{constructor(c){super(c),this._lib=void 0,this._map=void 0,this._panes={},this._container=void 0,this._layers={},this._lib=c.lib,this._map=c.map,this._container=this._map.getContainer()}createPaneStyleSheet(c,d){const p=document.createElement("style");return p.innerHTML=`.leaflet-${c}-pane {z-index: ${d+600};}`,document.getElementsByTagName("head")[0].appendChild(p),this._map.createPane(c),p}clearPanes(){Object.values(this._panes).forEach((c=>{c&&c.remove()})),this._panes={}}clearLayers(){Object.values(this._layers).forEach((c=>{this._map.removeLayer(c)})),this._layers={}}styleGeoJSONLayer(c){return{pointToLayer:(d,p)=>{if(!d.properties)throw new Error("Feature has no properties");if("string"!=typeof d.properties.mode)throw new Error("Feature mode is not a string");const g=(0,c[d.properties.mode])(d),m=String(g.zIndex);return this._panes[m]||(this._panes[m]=this.createPaneStyleSheet(m,g.zIndex)),this._lib.circleMarker(p,{radius:g.pointWidth,stroke:g.pointOutlineWidth||!1,color:g.pointOutlineColor,weight:g.pointOutlineWidth,fillOpacity:.8,fillColor:g.pointColor,pane:m,interactive:!1})},style:d=>{if(!d||!d.properties)return{};const p=d,g=(0,c[p.properties.mode])(p),m=String(g.zIndex);return this._panes[m]||(this._panes[m]=this.createPaneStyleSheet(m,g.zIndex)),"LineString"===p.geometry.type?{interactive:!1,color:g.lineStringColor,weight:g.lineStringWidth,pane:m}:"Polygon"===p.geometry.type?{interactive:!1,fillOpacity:g.polygonFillOpacity,fillColor:g.polygonFillColor,weight:g.polygonOutlineWidth,stroke:!0,color:g.polygonFillColor,pane:m}:{}}}}getLngLatFromEvent(c){const{containerX:d,containerY:p}=this.getMapElementXYPosition(c),g={x:d,y:p};if(null===g.x||isNaN(g.x)||null===g.y||isNaN(g.y))return null;const m=this._map.containerPointToLatLng(g);return null===m.lng||isNaN(m.lng)||null===m.lat||isNaN(m.lat)?null:{lng:m.lng,lat:m.lat}}getMapEventElement(){return this._container}setDraggability(c){c?this._map.dragging.enable():this._map.dragging.disable()}project(c,d){const{x:p,y:g}=this._map.latLngToContainerPoint({lng:c,lat:d});return{x:p,y:g}}unproject(c,d){const{lng:p,lat:g}=this._map.containerPointToLatLng({x:c,y:d});return{lng:p,lat:g}}setCursor(c){"unset"===c?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=c}setDoubleClickToZoom(c){c?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(c,d){c.created.forEach((c=>{this._layers[c.id]=this._lib.geoJSON(c,this.styleGeoJSONLayer(d)),this._map.addLayer(this._layers[c.id])})),c.deletedIds.forEach((c=>{this._map.removeLayer(this._layers[c])})),c.updated.forEach((c=>{this._map.removeLayer(this._layers[c.id]),this._layers[c.id]=this._lib.geoJSON(c,this.styleGeoJSONLayer(d)),this._map.addLayer(this._layers[c.id])}))}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers(),this.clearPanes())}register(c){super.register(c),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()}getCoordinatePrecision(){return super.getCoordinatePrecision()}unregister(){return super.unregister()}}let c=0;const d="undefined"!=typeof navigator&&void 0!==navigator.userAgent?navigator.userAgent.toLowerCase():"";d.includes("firefox"),d.includes("safari")&&!d.includes("chrom")&&(d.includes("version/15.4")||/cpu (os|iphone os) 15_4 like mac os x/.test(d)),d.includes("webkit")&&d.includes("edge"),d.includes("macintosh"),"undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof OffscreenCanvas&&(self,WorkerGlobalScope),function(){let c=!1;try{const d=Object.defineProperty({},"passive",{get:function(){c=!0}});window.addEventListener("_",null,d),window.removeEventListener("_",null,d)}catch(c){}}();var p=class{constructor(){this.disposed=!1}dispose(){this.disposed||(this.disposed=!0,this.disposeInternal())}disposeInternal(){}},g=class L{constructor(c){this.type=c,this.target=null}preventDefault(){this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0}};function W(){}function j(c){for(const d in c)delete c[d]}var m=class extends p{constructor(c){super(),this.eventTarget_=c,this.pendingRemovals_=null,this.dispatching_=null,this.listeners_=null}addEventListener(c,d){if(!c||!d)return;const p=this.listeners_||(this.listeners_={}),g=p[c]||(p[c]=[]);g.includes(d)||g.push(d)}dispatchEvent(c){const d="string"==typeof c,p=d?c:c.type,m=this.listeners_&&this.listeners_[p];if(!m)return;const _=d?new g(c):c;_.target||(_.target=this.eventTarget_||this);const f=this.dispatching_||(this.dispatching_={}),y=this.pendingRemovals_||(this.pendingRemovals_={});let v;p in f||(f[p]=0,y[p]=0),++f[p];for(let c=0,d=m.length;c<d;++c)if(v="handleEvent"in m[c]?m[c].handleEvent(_):m[c].call(this,_),!1===v||_.propagationStopped){v=!1;break}if(0==--f[p]){let c=y[p];for(delete y[p];c--;)this.removeEventListener(p,W);delete f[p]}return v}disposeInternal(){this.listeners_&&j(this.listeners_)}getListeners(c){return this.listeners_&&this.listeners_[c]||void 0}hasListener(c){return!!this.listeners_&&(c?c in this.listeners_:Object.keys(this.listeners_).length>0)}removeEventListener(c,d){if(!this.listeners_)return;const p=this.listeners_[c];if(!p)return;const g=p.indexOf(d);-1!==g&&(this.pendingRemovals_&&c in this.pendingRemovals_?(p[g]=W,++this.pendingRemovals_[c]):(p.splice(g,1),0===p.length&&delete this.listeners_[c]))}};function N(c,d,p,g,m){if(m){const g=p;p=function(){c.removeEventListener(d,p),g.apply(this,arguments)}}const _={target:c,type:d,listener:p};return c.addEventListener(d,p),_}function A(c,d,p,g){return N(c,d,p,0,!0)}function R(c){c&&c.target&&(c.target.removeEventListener(c.type,c.listener),j(c))}var _=class extends m{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(c,d){if(Array.isArray(c)){const p=c.length,g=new Array(p);for(let m=0;m<p;++m)g[m]=N(this,c[m],d);return g}return N(this,c,d)}onceInternal(c,d){let p;if(Array.isArray(c)){const g=c.length;p=new Array(g);for(let m=0;m<g;++m)p[m]=A(this,c[m],d)}else p=A(this,c,d);return d.ol_key=p,p}unInternal(c,d){const p=d.ol_key;if(p)!function(c){if(Array.isArray(c))for(let d=0,p=c.length;d<p;++d)R(c[d]);else R(c)}(p);else if(Array.isArray(c))for(let p=0,g=c.length;p<g;++p)this.removeEventListener(c[p],d);else this.removeEventListener(c,d)}};class K extends g{constructor(c,d,p){super(c),this.key=d,this.oldValue=p}}new class extends _{constructor(d){super(),this.ol_uid||(this.ol_uid=String(++c)),this.values_=null,void 0!==d&&this.setProperties(d)}get(c){let d;return this.values_&&this.values_.hasOwnProperty(c)&&(d=this.values_[c]),d}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(c,d){let p;p=`change:${c}`,this.hasListener(p)&&this.dispatchEvent(new K(p,c,d)),p="propertychange",this.hasListener(p)&&this.dispatchEvent(new K(p,c,d))}addChangeListener(c,d){this.addEventListener(`change:${c}`,d)}removeChangeListener(c,d){this.removeEventListener(`change:${c}`,d)}set(c,d,p){const g=this.values_||(this.values_={});if(p)g[c]=d;else{const p=g[c];g[c]=d,p!==d&&this.notify(c,p)}}setProperties(c,d){for(const p in c)this.set(p,c[p],d)}applyProperties(c){c.values_&&Object.assign(this.values_||(this.values_={}),c.values_)}unset(c,d){if(this.values_&&c in this.values_){const p=this.values_[c];delete this.values_[c],function(c){let d;for(d in c)return!1;return!d}(this.values_)&&(this.values_=null),d||this.notify(c,p)}}};const f={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var y=class{constructor(c){this.code_=c.code,this.units_=c.units,this.extent_=void 0!==c.extent?c.extent:null,this.worldExtent_=void 0!==c.worldExtent?c.worldExtent:null,this.axisOrientation_=void 0!==c.axisOrientation?c.axisOrientation:"enu",this.global_=void 0!==c.global&&c.global,this.canWrapX_=!(!this.global_||!this.extent_),this.getPointResolutionFunc_=c.getPointResolution,this.defaultTileGrid_=null,this.metersPerUnit_=c.metersPerUnit}canWrapX(){return this.canWrapX_}getCode(){return this.code_}getExtent(){return this.extent_}getUnits(){return this.units_}getMetersPerUnit(){return this.metersPerUnit_||f[this.units_]}getWorldExtent(){return this.worldExtent_}getAxisOrientation(){return this.axisOrientation_}isGlobal(){return this.global_}setGlobal(c){this.global_=c,this.canWrapX_=!(!c||!this.extent_)}getDefaultTileGrid(){return this.defaultTileGrid_}setDefaultTileGrid(c){this.defaultTileGrid_=c}setExtent(c){this.extent_=c,this.canWrapX_=!(!this.global_||!c)}setWorldExtent(c){this.worldExtent_=c}setGetPointResolution(c){this.getPointResolutionFunc_=c}getPointResolutionFunc(){return this.getPointResolutionFunc_}};const v=6378137,x=Math.PI*v,P=[-x,-x,x,x],C=[-180,-85,180,85],b=v*Math.log(Math.tan(Math.PI/2));class mt extends y{constructor(c){super({code:c,units:"m",extent:P,global:!0,worldExtent:C,getPointResolution:function(c,d){return c/Math.cosh(d[1]/v)}})}}const M=[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")],S=[-180,-90,180,90],E=6378137*Math.PI/180;class Ct extends y{constructor(c,d){super({code:c,units:"degrees",extent:S,axisOrientation:d,global:!0,metersPerUnit:E,worldExtent:S})}}const T=[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 O={};function wt(c,d,p){const g=c.getCode(),m=d.getCode();g in O||(O[g]={}),O[g][m]=p}function St(c,d){if(void 0!==d)for(let p=0,g=c.length;p<g;++p)d[p]=c[p];else d=c.slice();return d}function Et(c){c.getCode(),wt(c,c,St)}function Dt(c){!function(c){c.forEach(Et)}(c),c.forEach((function(d){c.forEach((function(c){d!==c&&wt(d,c,St)}))}))}var k,I,D,B;Dt(M),Dt(T),k=M,I=function(c,d,p){const g=c.length;p=p>1?p:2,void 0===d&&(d=p>2?c.slice():new Array(g));for(let m=0;m<g;m+=p){d[m]=x*c[m]/180;let p=v*Math.log(Math.tan(Math.PI*(+c[m+1]+90)/360));p>b?p=b:p<-b&&(p=-b),d[m+1]=p}return d},D=function(c,d,p){const g=c.length;p=p>1?p:2,void 0===d&&(d=p>2?c.slice():new Array(g));for(let m=0;m<g;m+=p)d[m]=180*c[m]/x,d[m+1]=360*Math.atan(Math.exp(c[m+1]/v))/Math.PI-90;return d},T.forEach((function(c){k.forEach((function(d){wt(c,d,I),wt(d,c,D)}))})),function(c){c.Commit="commit",c.Provisional="provisional",c.Finish="finish"}(B||(B={}));const z="selected",Z="midPoint",H="closingPoint";function Rt(c){return Boolean(c&&"object"==typeof c&&null!==c&&!Array.isArray(c))}function Vt(c){if(!function(c){return"number"==typeof c&&!isNaN(new Date(c).valueOf())}(c))throw new Error("updatedAt and createdAt are not valid timestamps");return!0}var V;!function(c){c.Drawing="drawing",c.Select="select",c.Static="static",c.Render="render"}(V||(V={}));class Tt{get state(){return this._state}set state(c){throw new Error("Please use the modes lifecycle methods")}get styles(){return this._styles}set styles(c){if("object"!=typeof c)throw new Error("Styling must be an object");this.onStyleChange([],"styling"),this._styles=c}registerBehaviors(c){}constructor(c){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=V.Drawing,this.mode="base",this._state="unregistered",this._styles=c&&c.styles?t({},c.styles):{},this.pointerDistance=c&&c.pointerDistance||40,this.validate=c&&c.validation,this.projection=c&&c.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(c){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=c.store,this.store.registerOnChange(c.onChange),this.setDoubleClickToZoom=c.setDoubleClickToZoom,this.project=c.project,this.unproject=c.unproject,this.onSelect=c.onSelect,this.onDeselect=c.onDeselect,this.setCursor=c.setCursor,this.onStyleChange=c.onChange,this.onFinish=c.onFinish,this.coordinatePrecision=c.coordinatePrecision,this.registerBehaviors({mode:c.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:c.coordinatePrecision,projection:this.projection})}validateFeature(c){if("unregistered"===this._state)throw new Error("Mode must be registered");const d=function(c,d){let p;if(Rt(c))if(null==c.id)p="Feature has no id";else if("string"!=typeof c.id&&"number"!=typeof c.id)p="Feature must be string or number as per GeoJSON spec";else if(d(c.id))if(Rt(c.geometry))if(Rt(c.properties))if("string"==typeof c.geometry.type&&["Polygon","LineString","Point"].includes(c.geometry.type))if(Array.isArray(c.geometry.coordinates)){if(!c.properties.mode||"string"!=typeof c.properties.mode)throw new Error("Feature does not have a valid mode property")}else p="Feature coordinates is not an array";else p="Feature is not Point, LineString or Polygon";else p="Feature has no properties";else p="Feature has no geometry";else p="Feature must match the id strategy (default is UUID4)";else p="Feature is not object";if(p)throw new Error(p);return!0}(c,this.store.idStrategy.isValidId);return this.validate?this.validate(c,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:B.Provisional}):d}onFinish(c,d){}onDeselect(c){}onSelect(c){}onKeyDown(c){}onKeyUp(c){}onMouseMove(c){}onClick(c){}onDragStart(c,d){}onDrag(c,d){}onDragEnd(c,d){}getHexColorStylingValue(c,d,p){return this.getStylingValue(c,d,p)}getNumericStylingValue(c,d,p){return this.getStylingValue(c,d,p)}getStylingValue(c,d,p){return void 0===c?d:"function"==typeof c?c(p):c}}class Xt extends Tt{constructor(...c){super(...c),this.type=V.Select}}function Ut(c,d){const i=c=>c*Math.PI/180,p=i(c[1]),g=i(c[0]),m=i(d[1]),_=m-p,f=i(d[0])-g,y=Math.sin(_/2)*Math.sin(_/2)+Math.cos(p)*Math.cos(m)*Math.sin(f/2)*Math.sin(f/2);return 2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y))*6371e3/1e3}const U=6371008.8;function Ht(c){return c%360*Math.PI/180}function Kt(c){return c/(U/1e3)}function Jt(c){return c%(2*Math.PI)*180/Math.PI}const G=57.29577951308232,X=.017453292519943295,Y=6378137,Qt=(c,d)=>({x:0===c?0:c*X*Y,y:0===d?0:Math.log(Math.tan(Math.PI/4+d*X/2))*Y}),te=(c,d)=>({lng:0===c?0:G*(c/Y),lat:0===d?0:(2*Math.atan(Math.exp(d/Y))-Math.PI/2)*G});function ee(c,d,p){const g=Ht(c[0]),m=Ht(c[1]),_=Ht(p),f=Kt(d),y=Math.asin(Math.sin(m)*Math.cos(f)+Math.cos(m)*Math.sin(f)*Math.cos(_));return[Jt(g+Math.atan2(Math.sin(_)*Math.sin(f)*Math.cos(m),Math.cos(f)-Math.sin(m)*Math.sin(y))),Jt(y)]}function ie$1(c){const{center:d,radiusKilometers:p,coordinatePrecision:g}=c,m=c.steps?c.steps:64,_=[];for(let c=0;c<m;c++){const f=ee(d,p,-360*c/m);_.push([e(f[0],g),e(f[1],g)])}return _.push(_[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[_]},properties:{}}}function oe(c){const d=0;let p;if("Polygon"===c.geometry.type)p=c.geometry.coordinates;else{if("LineString"!==c.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");p=[c.geometry.coordinates]}const g=[];for(let c=0;c<p.length;c++)for(let d=0;d<p[c].length-1;d++)for(let g=0;g<p.length;g++)for(let m=0;m<p[g].length-1;m++)r(c,d,g,m);return g.length>0;function s(c){return c<0-d||c>1+d}function r(c,d,m,_){const f=p[c][d],y=p[c][d+1],v=p[m][_],x=p[m][_+1],P=function(c,d,p,g){if(se(c,p)||se(c,g)||se(d,p)||se(g,p))return null;const m=c[0],_=c[1],f=d[0],y=d[1],v=p[0],x=p[1],P=g[0],C=g[1],b=(m-f)*(x-C)-(_-y)*(v-P);return 0===b?null:[((m*y-_*f)*(v-P)-(m-f)*(v*C-x*P))/b,((m*y-_*f)*(x-C)-(_-y)*(v*C-x*P))/b]}(f,y,v,x);if(null===P)return;let C,b;C=y[0]!==f[0]?(P[0]-f[0])/(y[0]-f[0]):(P[1]-f[1])/(y[1]-f[1]),b=x[0]!==v[0]?(P[0]-v[0])/(x[0]-v[0]):(P[1]-v[1])/(x[1]-v[1]),s(C)||s(b)||(P.toString(),g.push(P))}}function se(c,d){return c[0]===d[0]&&c[1]===d[1]}function re(c,d){return 2===c.length&&"number"==typeof c[0]&&"number"==typeof c[1]&&1/0!==c[0]&&1/0!==c[1]&&(g=c[0])>=-180&&g<=180&&(p=c[1])>=-90&&p<=90&&ne(c[0])<=d&&ne(c[1])<=d;var p,g}function ne(c){let d=1,p=0;for(;Math.round(c*d)/d!==c;)d*=10,p++;return p}function ae(c,d){return"Polygon"===c.geometry.type&&1===c.geometry.coordinates.length&&c.geometry.coordinates[0].length>=4&&c.geometry.coordinates[0].every((c=>re(c,d)))&&(p=c.geometry.coordinates[0][0])[0]===(g=c.geometry.coordinates[0][c.geometry.coordinates[0].length-1])[0]&&p[1]===g[1];var p,g}function le(c,d){return ae(c,d)&&!oe(c)}class he extends Tt{constructor(c){var d;super(c),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 p={start:"crosshair"};if(this.cursors=c&&c.cursors?t({},p,c.cursors):p,null===(null==c?void 0:c.keyEvents))this.keyEvents={cancel:null,finish:null};else{const d={cancel:"Escape",finish:"Enter"};this.keyEvents=c&&c.keyEvents?t({},d,c.keyEvents):d}this.startingRadiusKilometers=null!=(d=null==c?void 0:c.startingRadiusKilometers)?d:1e-5,this.validate=null==c?void 0:c.validation}close(){if(void 0===this.currentCircleId)return;const c=this.currentCircleId;if(this.validate&&c){const d=this.store.getGeometryCopy(c);if(!this.validate({type:"Feature",id:c,geometry:d,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:B.Finish}))return}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(c,{mode:this.mode,action:"draw"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(c){if(0===this.clickCount){this.center=[c.lng,c.lat];const d=ie$1({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),[p]=this.store.create([{geometry:d.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=p,this.clickCount++,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.updateCircle(c),this.close()}onMouseMove(c){this.updateCircle(c)}onKeyDown(){}onKeyUp(c){c.key===this.keyEvents.cancel?this.cleanUp():c.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const c=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==c&&this.store.delete([c])}catch(c){}}styleFeature(c){const d=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"===c.type&&"Polygon"===c.geometry.type&&c.properties.mode===this.mode?(d.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,d.polygonFillColor,c),d.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,d.polygonOutlineColor,c),d.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,d.polygonOutlineWidth,c),d.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,d.polygonFillOpacity,c),d.zIndex=10,d):d}validateFeature(c){return!!super.validateFeature(c)&&c.properties.mode===this.mode&&le(c,this.coordinatePrecision)}updateCircle(c){if(1===this.clickCount&&this.center&&this.currentCircleId){const d=Ut(this.center,[c.lng,c.lat]);let p;if("web-mercator"===this.projection){const g=function(c,d){const p=1e3*Ut(c,d);if(0===p)return 1;const{x:g,y:m}=Qt(c[0],c[1]),{x:_,y:f}=Qt(d[0],d[1]);return Math.sqrt(Math.pow(_-g,2)+Math.pow(f-m,2))/p}(this.center,[c.lng,c.lat]);p=function(c){const{center:d,radiusKilometers:p,coordinatePrecision:g}=c,m=c.steps?c.steps:64,_=1e3*p,[f,y]=d,{x:v,y:x}=Qt(f,y),P=[];for(let c=0;c<m;c++){const d=360*c/m*Math.PI/180,p=_*Math.cos(d),f=_*Math.sin(d),[y,C]=[v+p,x+f],{lng:b,lat:M}=te(y,C);P.push([e(b,g),e(M,g)])}return P.push(P[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[P]},properties:{}}}({center:this.center,radiusKilometers:d*g,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");p=ie$1({center:this.center,radiusKilometers:d,coordinatePrecision:this.coordinatePrecision})}if(this.validate&&!this.validate({type:"Feature",id:this.currentCircleId,geometry:p.geometry,properties:{radiusKilometers:d}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:B.Provisional}))return;this.store.updateGeometry([{id:this.currentCircleId,geometry:p.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:d}])}}}class de{constructor({store:c,mode:d,project:p,unproject:g,pointerDistance:m,coordinatePrecision:_,projection:f}){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=c,this.mode=d,this.project=p,this.unproject=g,this.pointerDistance=m,this.coordinatePrecision=_,this.projection=f}}function ue({unproject:c,point:d,pointerDistance:p}){const g=p/2,{x:m,y:_}=d;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[c(m-g,_-g),c(m+g,_-g),c(m+g,_+g),c(m-g,_+g),c(m-g,_-g)].map((c=>[c.lng,c.lat]))]}}}class ge extends de{constructor(c){super(c)}create(c){const{containerX:d,containerY:p}=c;return ue({unproject:this.unproject,point:{x:d,y:p},pointerDistance:this.pointerDistance})}}class pe extends de{constructor(c){super(c)}measure(c,d){const{x:p,y:g}=this.project(d[0],d[1]);return i({x:p,y:g},{x:c.containerX,y:c.containerY})}}class ye extends de{constructor(c,d,p){super(c),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=c=>this.getSnappable(c,(c=>Boolean(c.properties&&c.properties.mode===this.mode))),this.getSnappableCoordinate=(c,d)=>this.getSnappable(c,(c=>Boolean(c.properties&&c.properties.mode===this.mode&&c.id!==d))),this.config=c,this.pixelDistance=d,this.clickBoundingBox=p}getSnappable(c,d){const p=this.clickBoundingBox.create(c),g=this.store.search(p,d),m={coord:void 0,minDist:1/0};return g.forEach((d=>{let p;if("Polygon"===d.geometry.type)p=d.geometry.coordinates[0];else{if("LineString"!==d.geometry.type)return;p=d.geometry.coordinates}p.forEach((d=>{const p=this.pixelDistance.measure(c,d);p<m.minDist&&p<this.pointerDistance&&(m.coord=d,m.minDist=p)}))})),m.coord}}function me(c,d,p){const g=Ht(c[0]),m=Ht(c[1]),_=Ht(p),f=Kt(d),y=Math.asin(Math.sin(m)*Math.cos(f)+Math.cos(m)*Math.sin(f)*Math.cos(_));return[Jt(g+Math.atan2(Math.sin(_)*Math.sin(f)*Math.cos(m),Math.cos(f)-Math.sin(m)*Math.sin(y))),Jt(y)]}function ve(c,d){const p=Ht(c[0]),g=Ht(d[0]),m=Ht(c[1]),_=Ht(d[1]),f=Math.sin(g-p)*Math.cos(_),y=Math.cos(m)*Math.sin(_)-Math.sin(m)*Math.cos(_)*Math.cos(g-p);return Jt(Math.atan2(f,y))}function Ce(c,d,p){const g=[],m=c.length;let _,f,y,v=0;for(let m=0;m<c.length&&!(d>=v&&m===c.length-1);m++){if(v>d&&0===g.length){if(_=d-v,!_)return g.push(c[m]),g;f=ve(c[m],c[m-1])-180,y=me(c[m],_,f),g.push(y)}if(v>=p)return _=p-v,_?(f=ve(c[m],c[m-1])-180,y=me(c[m],_,f),g.push(y),g):(g.push(c[m]),g);if(v>=d&&g.push(c[m]),m===c.length-1)return g;v+=Ut(c[m],c[m+1])}if(v<d&&c.length===m)throw new Error("Start position is beyond line");const x=c[c.length-1];return[x,x]}function Pe(c){return c*(Math.PI/180)}function xe(c){return c*(180/Math.PI)}class Me extends de{constructor(c){super(c),this.config=void 0,this.config=c}generateInsertionCoordinates(c,d,p){const g=[c,d];let m=0;for(let c=0;c<g.length-1;c++)m+=Ut(g[0],g[1]);if(m<=p)return g;let _=m/p-1;Number.isInteger(_)||(_=Math.floor(_)+1);const f=[];for(let c=0;c<_;c++){const d=Ce(g,p*c,p*(c+1));f.push(d)}const y=[];for(let c=0;c<f.length;c++)y.push(f[c][1]);return this.limitCoordinates(y)}generateInsertionGeodesicCoordinates(c,d,p){const g=Ut(c,d),m=function(c,d,p){const g=[],m=Pe(c[1]),_=Pe(c[0]),f=Pe(d[1]),y=Pe(d[0]);p+=1;const v=2*Math.asin(Math.sqrt(Math.sin((f-m)/2)**2+Math.cos(m)*Math.cos(f)*Math.sin((y-_)/2)**2));if(0===v||isNaN(v))return g;for(let c=0;c<=p;c++){const d=c/p,x=Math.sin((1-d)*v)/Math.sin(v),P=Math.sin(d*v)/Math.sin(v),C=x*Math.cos(m)*Math.cos(_)+P*Math.cos(f)*Math.cos(y),b=x*Math.cos(m)*Math.sin(_)+P*Math.cos(f)*Math.sin(y),M=x*Math.sin(m)+P*Math.sin(f);if(isNaN(C)||isNaN(b)||isNaN(M))continue;const S=Math.atan2(M,Math.sqrt(C**2+b**2)),E=Math.atan2(b,C);isNaN(S)||isNaN(E)||g.push([xe(E),xe(S)])}return g.slice(1,-1)}(c,d,Math.floor(g/p));return this.limitCoordinates(m)}limitCoordinates(c){return c.map((c=>[e(c[0],this.config.coordinatePrecision),e(c[1],this.config.coordinatePrecision)]))}}function we(c,d){return c[0]===d[0]&&c[1]===d[1]}class Se extends Tt{constructor(c){super(c),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 d={start:"crosshair",close:"pointer"};if(this.cursors=c&&c.cursors?t({},d,c.cursors):d,this.snappingEnabled=!(!c||void 0===c.snapping)&&c.snapping,null===(null==c?void 0:c.keyEvents))this.keyEvents={cancel:null,finish:null};else{const d={cancel:"Escape",finish:"Enter"};this.keyEvents=c&&c.keyEvents?t({},d,c.keyEvents):d}this.validate=null==c?void 0:c.validation,this.insertCoordinates=null==c?void 0:c.insertCoordinates}close(){if(void 0===this.currentId)return;const c=this.store.getGeometryCopy(this.currentId);c.coordinates.pop(),this.updateGeometries([...c.coordinates],void 0,B.Commit);const d=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(d,{mode:this.mode,action:"draw"})}updateGeometries(c,d,p){if(!this.currentId)return;const g={type:"LineString",coordinates:c};if(this.validate&&!this.validate({type:"Feature",geometry:g},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:p}))return;const m=[{id:this.currentId,geometry:g}];this.closingPointId&&d&&m.push({id:this.closingPointId,geometry:{type:"Point",coordinates:d}}),"commit"===p&&(this.lastCommitedCoordinates=g.coordinates),this.store.updateGeometry(m)}generateInsertCoordinates(c,d){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 p=Ut(c,d)/(this.insertCoordinates.value+1);let g=[];return"globe"===this.projection?g=this.insertPoint.generateInsertionGeodesicCoordinates(c,d,p):"web-mercator"===this.projection&&(g=this.insertPoint.generateInsertionCoordinates(c,d,p)),g}createLine(c){const[d]=this.store.create([{geometry:{type:"LineString",coordinates:[c,c]},properties:{mode:this.mode}}]);this.lastCommitedCoordinates=[c,c],this.currentId=d,this.currentCoordinate++,this.setDrawing()}firstUpdateToLine(c){if(!this.currentId)return;const d=this.store.getGeometryCopy(this.currentId).coordinates,[p]=this.store.create([{geometry:{type:"Point",coordinates:[...c]},properties:{mode:this.mode}}]);this.closingPointId=p,this.setCursor(this.cursors.close);const g=[...d,c];this.updateGeometries(g,void 0,B.Commit),this.currentCoordinate++}updateToLine(c,d){if(!this.currentId)return;const p=this.store.getGeometryCopy(this.currentId).coordinates,[g,m]=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:p[p.length-2],{x:_,y:f}=this.project(g,m);if(i({x:_,y:f},{x:d.x,y:d.y})<this.pointerDistance)return void this.close();this.setCursor(this.cursors.close);const y=[...p,c];this.updateGeometries(y,p[p.length-1],B.Commit),this.currentCoordinate++}registerBehaviors(c){this.snapping=new ye(c,new pe(c),new ge(c)),this.insertPoint=new Me(c)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(c){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const d=this.store.getGeometryCopy(this.currentId).coordinates;d.pop();const p=this.snappingEnabled&&this.snapping.getSnappableCoordinate(c,this.currentId)||[c.lng,c.lat];if(this.closingPointId){const[p,g]=d[d.length-1],{x:m,y:_}=this.project(p,g);i({x:m,y:_},{x:c.containerX,y:c.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}let g=[...d,p];if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){const c=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],d=p;if(!we(c,d)){const m=this.generateInsertCoordinates(c,d);g=[...this.lastCommitedCoordinates.slice(0,-1),...m,p]}}this.updateGeometries(g,void 0,B.Provisional)}onClick(c){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(c),this.mouseMove=!1;const d=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(c,this.currentId)||[c.lng,c.lat];0===this.currentCoordinate?this.createLine(d):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(d):this.currentId&&this.updateToLine(d,{x:c.containerX,y:c.containerY})}onKeyDown(){}onKeyUp(c){c.key===this.keyEvents.cancel&&this.cleanUp(),c.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const c=this.currentId;this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==c&&this.store.delete([c]),void 0!==this.closingPointId&&this.store.delete([this.closingPointId])}catch(c){}}styleFeature(c){const d=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"===c.type&&"LineString"===c.geometry.type&&c.properties.mode===this.mode?(d.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,d.lineStringColor,c),d.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,d.lineStringWidth,c),d.zIndex=10,d):"Feature"===c.type&&"Point"===c.geometry.type&&c.properties.mode===this.mode?(d.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,d.pointColor,c),d.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,d.pointWidth,c),d.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,"#ffffff",c),d.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,c),d.zIndex=40,d):d}validateFeature(c){return!!super.validateFeature(c)&&"LineString"===c.geometry.type&&c.properties.mode===this.mode&&c.geometry.coordinates.length>=2}}function be(c,d){return"Point"===c.geometry.type&&re(c.geometry.coordinates,d)}class Ee extends Tt{constructor(c){super(c),this.mode="point",this.cursors=void 0;const d={create:"crosshair"};this.cursors=c&&c.cursors?t({},d,c.cursors):d}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(c){if(!this.store)throw new Error("Mode must be registered first");const d={type:"Point",coordinates:[c.lng,c.lat]},p={mode:this.mode};if(this.validate&&!this.validate({type:"Feature",geometry:d,properties:p},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:B.Finish}))return;const[g]=this.store.create([{geometry:d,properties:p}]);this.onFinish(g,{mode:this.mode,action:"draw"})}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){}onDragStart(){}onDrag(){}onDragEnd(){}styleFeature(c){const d=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"===c.type&&"Point"===c.geometry.type&&c.properties.mode===this.mode&&(d.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,d.pointWidth,c),d.pointColor=this.getHexColorStylingValue(this.styles.pointColor,d.pointColor,c),d.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,d.pointOutlineColor,c),d.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,c),d.zIndex=30),d}validateFeature(c){return!!super.validateFeature(c)&&c.properties.mode===this.mode&&be(c,this.coordinatePrecision)}}class Ie extends de{constructor(c,d){super(c),this.config=void 0,this.pixelDistance=void 0,this._startEndPoints=[],this.config=c,this.pixelDistance=d}get ids(){return this._startEndPoints.concat()}set ids(c){}create(c,d){if(this.ids.length)throw new Error("Opening and closing points already created");if(c.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:c[0]},properties:{mode:d,[H]:!0}},{geometry:{type:"Point",coordinates:c[c.length-2]},properties:{mode:d,[H]:!0}}])}delete(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])}update(c){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:c[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:c[c.length-3]}}])}isClosingPoint(c){const d=this.store.getGeometryCopy(this.ids[0]),p=this.store.getGeometryCopy(this.ids[1]),g=this.pixelDistance.measure(c,d.coordinates),m=this.pixelDistance.measure(c,p.coordinates);return{isClosing:g<this.pointerDistance,isPreviousClosing:m<this.pointerDistance}}}class De extends Tt{constructor(c){super(c),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 d={start:"crosshair",close:"pointer"};if(this.cursors=c&&c.cursors?t({},d,c.cursors):d,this.snappingEnabled=!(!c||void 0===c.snapping)&&c.snapping,null===(null==c?void 0:c.keyEvents))this.keyEvents={cancel:null,finish:null};else{const d={cancel:"Escape",finish:"Enter"};this.keyEvents=c&&c.keyEvents?t({},d,c.keyEvents):d}}close(){if(void 0===this.currentId)return;const c=this.store.getGeometryCopy(this.currentId).coordinates[0];if(c.length<5)return;if(!this.updatePolygonGeometry([...c.slice(0,-2),c[0]],B.Finish))return;const d=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(d,{mode:this.mode,action:"draw"})}registerBehaviors(c){this.pixelDistance=new pe(c),this.snapping=new ye(c,this.pixelDistance,new ge(c)),this.closingPoints=new Ie(c,this.pixelDistance)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(c){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const d=this.snappingEnabled?this.snapping.getSnappableCoordinate(c,this.currentId):void 0,p=this.store.getGeometryCopy(this.currentId).coordinates[0];let g;if(d&&(c.lng=d[0],c.lat=d[1]),1===this.currentCoordinate){const d=1/Math.pow(10,this.coordinatePrecision-1),m=Math.max(1e-6,d);g=[p[0],[c.lng,c.lat],[c.lng,c.lat-m],p[0]]}else if(2===this.currentCoordinate)g=[p[0],p[1],[c.lng,c.lat],p[0]];else{const{isClosing:d,isPreviousClosing:m}=this.closingPoints.isClosingPoint(c);m||d?(this.setCursor(this.cursors.close),g=[...p.slice(0,-2),p[0],p[0]]):g=[...p.slice(0,-2),[c.lng,c.lat],p[0]]}this.updatePolygonGeometry(g,B.Provisional)}updatePolygonGeometry(c,d){if(!this.currentId)return!1;const p={type:"Polygon",coordinates:[c]};return!(this.validate&&!this.validate({type:"Feature",geometry:p},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d})||(this.store.updateGeometry([{id:this.currentId,geometry:p}]),0))}onClick(c){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(c),this.mouseMove=!1,0===this.currentCoordinate){const d=this.snappingEnabled?this.snapping.getSnappableCoordinateFirstClick(c):void 0;d&&(c.lng=d[0],c.lat=d[1]);const[p]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[c.lng,c.lat],[c.lng,c.lat],[c.lng,c.lat],[c.lng,c.lat]]]},properties:{mode:this.mode}}]);this.currentId=p,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const d=this.snappingEnabled?this.snapping.getSnappableCoordinate(c,this.currentId):void 0;d&&(c.lng=d[0],c.lat=d[1]);const p=this.store.getGeometryCopy(this.currentId);if(we([c.lng,c.lat],p.coordinates[0][0]))return;if(!this.updatePolygonGeometry([p.coordinates[0][0],[c.lng,c.lat],[c.lng,c.lat],p.coordinates[0][0]],B.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){const d=this.snappingEnabled?this.snapping.getSnappableCoordinate(c,this.currentId):void 0;d&&(c.lng=d[0],c.lat=d[1]);const p=this.store.getGeometryCopy(this.currentId).coordinates[0];if(we([c.lng,c.lat],p[1]))return;if(!this.updatePolygonGeometry([p[0],p[1],[c.lng,c.lat],[c.lng,c.lat],p[0]],B.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(p,"polygon"),this.currentCoordinate++}else if(this.currentId){const d=this.snappingEnabled?this.snapping.getSnappableCoordinate(c,this.currentId):void 0,p=this.store.getGeometryCopy(this.currentId).coordinates[0],{isClosing:g,isPreviousClosing:m}=this.closingPoints.isClosingPoint(c);if(m||g)this.close();else{if(d&&(c.lng=d[0],c.lat=d[1]),we([c.lng,c.lat],p[this.currentCoordinate-1]))return;const g=function(c=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]){return{type:"Feature",geometry:{type:"Polygon",coordinates:c},properties:{}}}([[...p.slice(0,-1),[c.lng,c.lat],p[0]]]);if(!this.updatePolygonGeometry(g.geometry.coordinates[0],B.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(g.geometry.coordinates[0])}}}onKeyUp(c){c.key===this.keyEvents.cancel?this.cleanUp():c.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){this.setCursor("unset")}onDrag(){}onDragEnd(){this.setCursor(this.cursors.start)}cleanUp(){const c=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==c&&this.store.delete([c]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(c){}}styleFeature(c){const d=t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(c.properties.mode===this.mode){if("Polygon"===c.geometry.type)return d.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,d.polygonFillColor,c),d.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,d.polygonOutlineColor,c),d.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,d.polygonOutlineWidth,c),d.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,d.polygonFillOpacity,c),d.zIndex=10,d;if("Point"===c.geometry.type)return d.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,d.pointWidth,c),d.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,d.pointColor,c),d.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,d.pointOutlineColor,c),d.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,c),d.zIndex=30,d}return d}validateFeature(c){return!!super.validateFeature(c)&&c.properties.mode===this.mode&&ae(c,this.coordinatePrecision)}}class ke extends Tt{constructor(c){super(c),this.mode="rectangle",this.center=void 0,this.clickCount=0,this.currentRectangleId=void 0,this.keyEvents=void 0,this.cursors=void 0;const d={start:"crosshair"};if(this.cursors=c&&c.cursors?t({},d,c.cursors):d,null===(null==c?void 0:c.keyEvents))this.keyEvents={cancel:null,finish:null};else{const d={cancel:"Escape",finish:"Enter"};this.keyEvents=c&&c.keyEvents?t({},d,c.keyEvents):d}}updateRectangle(c,d){if(1===this.clickCount&&this.center&&this.currentRectangleId){const p=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],g={type:"Polygon",coordinates:[[p,[c.lng,p[1]],[c.lng,c.lat],[p[0],c.lat],p]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:g},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d}))return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:g}])}}close(){const c=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),c&&this.onFinish(c,{mode:this.mode,action:"draw"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(c){if(0===this.clickCount){this.center=[c.lng,c.lat];const[d]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[c.lng,c.lat],[c.lng,c.lat],[c.lng,c.lat],[c.lng,c.lat]]]},properties:{mode:this.mode}}]);this.currentRectangleId=d,this.clickCount++,this.setDrawing()}else this.updateRectangle(c,B.Finish),this.close()}onMouseMove(c){this.updateRectangle(c,B.Provisional)}onKeyDown(){}onKeyUp(c){c.key===this.keyEvents.cancel?this.cleanUp():c.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const c=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==c&&this.store.delete([c])}styleFeature(c){const d=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"===c.type&&"Polygon"===c.geometry.type&&c.properties.mode===this.mode?(d.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,d.polygonFillColor,c),d.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,d.polygonOutlineColor,c),d.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,d.polygonOutlineWidth,c),d.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,d.polygonFillOpacity,c),d.zIndex=10,d):d}validateFeature(c){return!!super.validateFeature(c)&&c.properties.mode===this.mode&&le(c,this.coordinatePrecision)}}class Fe extends Tt{constructor(c){super({styles:c.styles}),this.type=V.Render,this.mode="render",this.mode=c.modeName}registerBehaviors(c){this.mode=c.mode}start(){this.setStarted()}stop(){this.setStopped()}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(c){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",c),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,c),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",c),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,c),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",c),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,c),polygonOutlineColor:this.getHexColor