UNPKG

dumbymap

Version:

Generate interactive maps from Semantic HTML

1 lines 539 kB
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)({}).hasOwnProperty.call(i,o)&&(t[o]=i[o]);}return t},t.apply(null,arguments)}function e(t,e=9){const i=Math.pow(10,e);return Math.round(t*i)/i}const i=(t,e)=>{const{x:i,y:o}=t,{x:r,y:s}=e,n=r-i,a=s-o;return Math.sqrt(a*a+n*n)};class o{constructor({name:t,callback:e,unregister:i,register:o}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=t,this.register=()=>{this.registered||(this.registered=!0,o(e));},this.unregister=()=>{this.register&&(this.registered=!1,i(e));},this.callback=e;}}class r{constructor(t){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 t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9;}getButton(t){return -1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"}getMapElementXYPosition(t){const e=this.getMapEventElement(),{left:i,top:o}=e.getBoundingClientRect();return {containerX:t.clientX-i,containerY:t.clientY-o}}getDrawEventFromEvent(t){const i=this.getLngLatFromEvent(t);if(!i)return null;const{lng:o,lat:r}=i,{containerX:s,containerY:n}=this.getMapElementXYPosition(t),a=this.getButton(t),l=Array.from(this._heldKeys);return {lng:e(o,this._coordinatePrecision),lat:e(r,this._coordinatePrecision),containerX:s,containerY:n,button:a,heldKeys:l}}register(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(t=>{t.register();});}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return [new o({name:"pointerdown",callback:t=>{if(!this._currentModeCallbacks)return;if(!t.isPrimary)return;const e=this.getDrawEventFromEvent(t);e&&(this._dragState="pre-dragging",this._lastDrawEvent=e);},register:t=>{this.getMapEventElement().addEventListener("pointerdown",t);},unregister:t=>{this.getMapEventElement().removeEventListener("pointerdown",t);}}),new o({name:"pointermove",callback:t=>{if(!this._currentModeCallbacks)return;if(!t.isPrimary)return;t.preventDefault();const e=this.getDrawEventFromEvent(t);if(e)if("not-dragging"===this._dragState)this._currentModeCallbacks.onMouseMove(e),this._lastDrawEvent=e;else if("pre-dragging"===this._dragState){if(!this._lastDrawEvent)return;const t={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},o={x:e.containerX,y:e.containerY},r=this._currentModeCallbacks.getState(),s=i(t,o);let n=!1;if(n="drawing"===r?s<this._minPixelDragDistanceDrawing:"selecting"===r?s<this._minPixelDragDistanceSelecting:s<this._minPixelDragDistance,n)return;this._dragState="dragging",this._currentModeCallbacks.onDragStart(e,t=>{this.setDraggability.bind(this)(t);});}else "dragging"===this._dragState&&this._currentModeCallbacks.onDrag(e,t=>{this.setDraggability.bind(this)(t);});},register:t=>{this.getMapEventElement().addEventListener("pointermove",t);},unregister:t=>{this.getMapEventElement().removeEventListener("pointermove",t);}}),new o({name:"contextmenu",callback:t=>{this._currentModeCallbacks&&t.preventDefault();},register:t=>{this.getMapEventElement().addEventListener("contextmenu",t);},unregister:t=>{this.getMapEventElement().removeEventListener("contextmenu",t);}}),new o({name:"pointerup",callback:t=>{if(!this._currentModeCallbacks)return;if(t.target!==this.getMapEventElement())return;if(!t.isPrimary)return;const e=this.getDrawEventFromEvent(t);e&&("dragging"===this._dragState?this._currentModeCallbacks.onDragEnd(e,t=>{this.setDraggability.bind(this)(t);}):"not-dragging"!==this._dragState&&"pre-dragging"!==this._dragState||this._currentModeCallbacks.onClick(e),this._dragState="not-dragging",this.setDraggability(!0));},register:t=>{this.getMapEventElement().addEventListener("pointerup",t);},unregister:t=>{this.getMapEventElement().removeEventListener("pointerup",t);}}),new o({name:"keyup",callback:t=>{this._currentModeCallbacks&&(this._heldKeys.delete(t.key),this._currentModeCallbacks.onKeyUp({key:t.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>t.preventDefault()}));},register:t=>{this.getMapEventElement().addEventListener("keyup",t);},unregister:t=>{this.getMapEventElement().removeEventListener("keyup",t);}}),new o({name:"keydown",callback:t=>{this._currentModeCallbacks&&(this._heldKeys.add(t.key),this._currentModeCallbacks.onKeyDown({key:t.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>t.preventDefault()}));},register:t=>{this.getMapEventElement().addEventListener("keydown",t);},unregister:t=>{this.getMapEventElement().removeEventListener("keydown",t);}})]}unregister(){this._listeners.forEach(t=>{t.unregister();}),this.clear();}}class n extends r{constructor(t){super(t),this._lib=void 0,this._map=void 0,this._panes={},this._container=void 0,this._layers={},this._lib=t.lib,this._map=t.map,this._container=this._map.getContainer();}createPaneStyleSheet(t,e){const i=document.createElement("style");return i.innerHTML=`.leaflet-${t}-pane {z-index: ${e+600}`,document.getElementsByTagName("head")[0].appendChild(i),this._map.createPane(t),i}clearPanes(){Object.values(this._panes).forEach(t=>{t&&t.remove();}),this._panes={};}clearLayers(){Object.values(this._layers).forEach(t=>{this._map.removeLayer(t);}),this._layers={};}styleGeoJSONLayer(t){return {pointToLayer:(e,i)=>{if(!e.properties)throw new Error("Feature has no properties");if("string"!=typeof e.properties.mode)throw new Error("Feature mode is not a string");const o=(0, t[e.properties.mode])(e),r=String(o.zIndex);return this._panes[r]||(this._panes[r]=this.createPaneStyleSheet(r,o.zIndex)),this._lib.circleMarker(i,{radius:o.pointWidth,stroke:o.pointOutlineWidth||!1,color:o.pointOutlineColor,weight:o.pointOutlineWidth,fillOpacity:.8,fillColor:o.pointColor,pane:r,interactive:!1})},style:e=>{if(!e||!e.properties)return {};const i=e,o=(0, t[i.properties.mode])(i),r=String(o.zIndex);return this._panes[r]||(this._panes[r]=this.createPaneStyleSheet(r,o.zIndex)),"LineString"===i.geometry.type?{interactive:!1,color:o.lineStringColor,weight:o.lineStringWidth,pane:r}:"Polygon"===i.geometry.type?{interactive:!1,fillOpacity:o.polygonFillOpacity,fillColor:o.polygonFillColor,weight:o.polygonOutlineWidth,stroke:!0,color:o.polygonFillColor,pane:r}:{}}}}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t),o=this._map.containerPointToLatLng({x:e,y:i});return null===o.lng||isNaN(o.lng)||null===o.lat||isNaN(o.lat)?null:{lng:o.lng,lat:o.lat}}getMapEventElement(){return this._container}setDraggability(t){t?this._map.dragging.enable():this._map.dragging.disable();}project(t,e){const{x:i,y:o}=this._map.latLngToContainerPoint({lng:t,lat:e});return {x:i,y:o}}unproject(t,e){const{lng:i,lat:o}=this._map.containerPointToLatLng({x:t,y:e});return {lng:i,lat:o}}setCursor(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t;}setDoubleClickToZoom(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable();}render(t,e){t.created.forEach(t=>{this._layers[t.id]=this._lib.geoJSON(t,this.styleGeoJSONLayer(e)),this._map.addLayer(this._layers[t.id]);}),t.deletedIds.forEach(t=>{this._map.removeLayer(this._layers[t]);}),t.updated.forEach(t=>{this._map.removeLayer(this._layers[t.id]),this._layers[t.id]=this._lib.geoJSON(t,this.styleGeoJSONLayer(e)),this._map.addLayer(this._layers[t.id]);});}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers(),this.clearPanes());}register(t){super.register(t),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady();}getCoordinatePrecision(){return super.getCoordinatePrecision()}unregister(){return super.unregister()}}const h={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var c=class{constructor(t){this.code_=t.code,this.units_=t.units,this.extent_=void 0!==t.extent?t.extent:null,this.worldExtent_=void 0!==t.worldExtent?t.worldExtent:null,this.axisOrientation_=void 0!==t.axisOrientation?t.axisOrientation:"enu",this.global_=void 0!==t.global&&t.global,this.canWrapX_=!(!this.global_||!this.extent_),this.getPointResolutionFunc_=t.getPointResolution,this.defaultTileGrid_=null,this.metersPerUnit_=t.metersPerUnit;}canWrapX(){return this.canWrapX_}getCode(){return this.code_}getExtent(){return this.extent_}getUnits(){return this.units_}getMetersPerUnit(){return this.metersPerUnit_||h[this.units_]}getWorldExtent(){return this.worldExtent_}getAxisOrientation(){return this.axisOrientation_}isGlobal(){return this.global_}setGlobal(t){this.global_=t,this.canWrapX_=!(!t||!this.extent_);}getDefaultTileGrid(){return this.defaultTileGrid_}setDefaultTileGrid(t){this.defaultTileGrid_=t;}setExtent(t){this.extent_=t,this.canWrapX_=!(!this.global_||!t);}setWorldExtent(t){this.worldExtent_=t;}setGetPointResolution(t){this.getPointResolutionFunc_=t;}getPointResolutionFunc(){return this.getPointResolutionFunc_}};const d=6378137,u=Math.PI*d,g=[-u,-u,u,u],p=[-180,-85,180,85],y=d*Math.log(Math.tan(Math.PI/2));class m extends c{constructor(t){super({code:t,units:"m",extent:g,global:!0,worldExtent:p,getPointResolution:function(t,e){return t/Math.cosh(e[1]/d)}});}}const f=[new m("EPSG:3857"),new m("EPSG:102100"),new m("EPSG:102113"),new m("EPSG:900913"),new m("http://www.opengis.net/def/crs/EPSG/0/3857"),new m("http://www.opengis.net/gml/srs/epsg.xml#3857")],C=[-180,-90,180,90],v=6378137*Math.PI/180;class P extends c{constructor(t,e){super({code:t,units:"degrees",extent:C,axisOrientation:e,global:!0,metersPerUnit:v,worldExtent:C});}}const _=[new P("CRS:84"),new P("EPSG:4326","neu"),new P("urn:ogc:def:crs:OGC:1.3:CRS84"),new P("urn:ogc:def:crs:OGC:2:84"),new P("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new P("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new P("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let M={};function b(t,e,i){const o=t.getCode(),r=e.getCode();o in M||(M[o]={}),M[o][r]=i;}function S(t,e){if(void 0!==e)for(let i=0,o=t.length;i<o;++i)e[i]=t[i];else e=t.slice();return e}function w(t){!function(t,e){}(t.getCode()),b(t,t,S);}function F(t){!function(t){t.forEach(w);}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&b(e,t,S);});});}var k,O,j,L$2;F(f),F(_),k=f,O=function(t,e,i){const o=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(o));for(let r=0;r<o;r+=i){e[r]=u*t[r]/180;let i=d*Math.log(Math.tan(Math.PI*(+t[r+1]+90)/360));i>y?i=y:i<-y&&(i=-y),e[r+1]=i;}return e},j=function(t,e,i){const o=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(o));for(let r=0;r<o;r+=i)e[r]=180*t[r]/u,e[r+1]=360*Math.atan(Math.exp(t[r+1]/d))/Math.PI-90;return e},_.forEach(function(t){k.forEach(function(e){b(t,e,O),b(e,t,j);});});!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish";}(L$2||(L$2={}));const G="selected",N="midPoint",V="closingPoint";function A(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function R(t){if(!function(t){return "number"==typeof t&&!isNaN(new Date(t).valueOf())}(t))throw new Error("updatedAt and createdAt are not valid timestamps");return !0}var T;!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render";}(T||(T={}));class X{get state(){return this._state}set state(t){throw new Error("Please use the modes lifecycle methods")}get styles(){return this._styles}set styles(t){if("object"!=typeof t)throw new Error("Styling must be an object");this.onStyleChange([],"styling"),this._styles=t;}registerBehaviors(t){}constructor(e){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=T.Drawing,this.mode="base",this._state="unregistered",this._styles=e&&e.styles?t({},e.styles):{},this.pointerDistance=e&&e.pointerDistance||40,this.validate=e&&e.validation,this.projection=e&&e.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(t){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=t.store,this.store.registerOnChange(t.onChange),this.setDoubleClickToZoom=t.setDoubleClickToZoom,this.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.onFinish=t.onFinish,this.coordinatePrecision=t.coordinatePrecision,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:t.coordinatePrecision,projection:this.projection});}validateFeature(t){if("unregistered"===this._state)throw new Error("Mode must be registered");const e=function(t,e){let i;if(A(t))if(null==t.id)i="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)i="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(A(t.geometry))if(A(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)throw new Error("Feature does not have a valid mode property")}else i="Feature coordinates is not an array";else i="Feature is not Point, LineString or Polygon";else i="Feature has no properties";else i="Feature has no geometry";else i="Feature must match the id strategy (default is UUID4)";else i="Feature is not object";if(i)throw new Error(i);return !0}(t,this.store.idStrategy.isValidId);return this.validate?this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:L$2.Provisional}):e}onFinish(t,e){}onDeselect(t){}onSelect(t){}onKeyDown(t){}onKeyUp(t){}onMouseMove(t){}onClick(t){}onDragStart(t,e){}onDrag(t,e){}onDragEnd(t,e){}getHexColorStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getNumericStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getStylingValue(t,e,i){return void 0===t?e:"function"==typeof t?t(i):t}}class U extends X{constructor(...t){super(...t),this.type=T.Select;}}function Y(t,e){const i=t=>t*Math.PI/180,o=i(t[1]),r=i(t[0]),s=i(e[1]),n=s-o,a=i(e[0])-r,l=Math.sin(n/2)*Math.sin(n/2)+Math.cos(o)*Math.cos(s)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}const K=6371008.8;function z(t){return t%360*Math.PI/180}function H(t){return t/(K/1e3)}function $(t){return t%(2*Math.PI)*180/Math.PI}const J=57.29577951308232,Z=.017453292519943295,q=6378137,Q=(t,e)=>({x:0===t?0:t*Z*q,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*Z/2))*q}),tt=(t,e)=>({lng:0===t?0:J*(t/q),lat:0===e?0:(2*Math.atan(Math.exp(e/q))-Math.PI/2)*J});function et(t,e,i){const o=z(t[0]),r=z(t[1]),s=z(i),n=H(e),a=Math.asin(Math.sin(r)*Math.cos(n)+Math.cos(r)*Math.sin(n)*Math.cos(s));return [$(o+Math.atan2(Math.sin(s)*Math.sin(n)*Math.cos(r),Math.cos(n)-Math.sin(r)*Math.sin(a))),$(a)]}function it(t){const{center:i,radiusKilometers:o,coordinatePrecision:r}=t,s=t.steps?t.steps:64,n=[];for(let t=0;t<s;t++){const a=et(i,o,-360*t/s);n.push([e(a[0],r),e(a[1],r)]);}return n.push(n[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[n]},properties:{}}}function ot(t){const e={epsilon:0};let i;if("Polygon"===t.geometry.type)i=t.geometry.coordinates;else {if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");i=[t.geometry.coordinates];}const o=[];for(let t=0;t<i.length;t++)for(let e=0;e<i[t].length-1;e++)for(let o=0;o<i.length;o++)for(let r=0;r<i[o].length-1;r++)s(t,e,o,r);return o.length>0;function r(t){return t<0-e.epsilon||t>1+e.epsilon}function s(t,e,s,n){const a=i[t][e],l=i[t][e+1],h=i[s][n],c=i[s][n+1],d=function(t,e,i,o){if(rt(t,i)||rt(t,o)||rt(e,i)||rt(o,i))return null;const r=t[0],s=t[1],n=e[0],a=e[1],l=i[0],h=i[1],c=o[0],d=o[1],u=(r-n)*(h-d)-(s-a)*(l-c);return 0===u?null:[((r*a-s*n)*(l-c)-(r-n)*(l*d-h*c))/u,((r*a-s*n)*(h-d)-(s-a)*(l*d-h*c))/u]}(a,l,h,c);if(null===d)return;let u,g;u=l[0]!==a[0]?(d[0]-a[0])/(l[0]-a[0]):(d[1]-a[1])/(l[1]-a[1]),g=c[0]!==h[0]?(d[0]-h[0])/(c[0]-h[0]):(d[1]-h[1])/(c[1]-h[1]),r(u)||r(g)||(d.toString(),o.push(d));}}function rt(t,e){return t[0]===e[0]&&t[1]===e[1]}function st(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(o=t[0])>=-180&&o<=180&&(i=t[1])>=-90&&i<=90&&nt(t[0])<=e&&nt(t[1])<=e;var i,o;}function nt(t){let e=1,i=0;for(;Math.round(t*e)/e!==t;)e*=10,i++;return i}function at(t,e){return "Polygon"===t.geometry.type&&1===t.geometry.coordinates.length&&t.geometry.coordinates[0].length>=4&&t.geometry.coordinates[0].every(t=>st(t,e))&&(i=t.geometry.coordinates[0][0])[0]===(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]&&i[1]===o[1];var i,o;}function lt(t,e){return at(t,e)&&!ot(t)}class ht extends X{constructor(e){var i;super(e),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 o={start:"crosshair"};if(this.cursors=e&&e.cursors?t({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else {const i={cancel:"Escape",finish:"Enter"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i;}this.startingRadiusKilometers=null!=(i=null==e?void 0:e.startingRadiusKilometers)?i:1e-5,this.validate=null==e?void 0:e.validation;}close(){if(void 0===this.currentCircleId)return;const t=this.currentCircleId;if(this.validate&&t){const e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:L$2.Finish}))return}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"});}start(){this.setStarted(),this.setCursor(this.cursors.start);}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset");}onClick(t){if(0===this.clickCount){this.center=[t.lng,t.lat];const e=it({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),[i]=this.store.create([{geometry:e.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=i,this.clickCount++,this.setDrawing();}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.updateCircle(t),this.close();}onMouseMove(t){this.updateCircle(t);}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close();}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]);}catch(t){}}styleFeature(e){const i=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"===e.type&&"Polygon"===e.geometry.type&&e.properties.mode===this.mode?(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i):i}validateFeature(t){return !!super.validateFeature(t)&&t.properties.mode===this.mode&&lt(t,this.coordinatePrecision)}updateCircle(t){if(1===this.clickCount&&this.center&&this.currentCircleId){const i=Y(this.center,[t.lng,t.lat]);let o;if("web-mercator"===this.projection){const r=function(t,e){const i=1e3*Y(t,e);if(0===i)return 1;const{x:o,y:r}=Q(t[0],t[1]),{x:s,y:n}=Q(e[0],e[1]);return Math.sqrt(Math.pow(s-o,2)+Math.pow(n-r,2))/i}(this.center,[t.lng,t.lat]);o=function(t){const{center:i,radiusKilometers:o,coordinatePrecision:r}=t,s=t.steps?t.steps:64,n=1e3*o,[a,l]=i,{x:h,y:c}=Q(a,l),d=[];for(let t=0;t<s;t++){const i=360*t/s*Math.PI/180,o=n*Math.cos(i),a=n*Math.sin(i),[l,u]=[h+o,c+a],{lng:g,lat:p}=tt(l,u);d.push([e(g,r),e(p,r)]);}return d.push(d[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[d]},properties:{}}}({center:this.center,radiusKilometers:i*r,coordinatePrecision:this.coordinatePrecision});}else {if("globe"!==this.projection)throw new Error("Invalid projection");o=it({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision});}if(this.validate&&!this.validate({type:"Feature",id:this.currentCircleId,geometry:o.geometry,properties:{radiusKilometers:i}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:L$2.Provisional}))return;this.store.updateGeometry([{id:this.currentCircleId,geometry:o.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}]);}}}class dt{constructor({store:t,mode:e,project:i,unproject:o,pointerDistance:r,coordinatePrecision:s,projection:n}){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=t,this.mode=e,this.project=i,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=n;}}function ut({unproject:t,point:e,pointerDistance:i}){const o=i/2,{x:r,y:s}=e;return {type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[t(r-o,s-o),t(r+o,s-o),t(r+o,s+o),t(r-o,s+o),t(r-o,s-o)].map(t=>[t.lng,t.lat])]}}}class gt extends dt{constructor(t){super(t);}create(t){const{containerX:e,containerY:i}=t;return ut({unproject:this.unproject,point:{x:e,y:i},pointerDistance:this.pointerDistance})}}class pt extends dt{constructor(t){super(t);}measure(t,e){const{x:o,y:r}=this.project(e[0],e[1]);return i({x:o,y:r},{x:t.containerX,y:t.containerY})}}class yt extends dt{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=t=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode)),this.getSnappableCoordinate=(t,e)=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode&&t.id!==e)),this.config=t,this.pixelDistance=e,this.clickBoundingBox=i;}getSnappable(t,e){const i=this.clickBoundingBox.create(t),o=this.store.search(i,e),r={coord:void 0,minDist:Infinity};return o.forEach(e=>{let i;if("Polygon"===e.geometry.type)i=e.geometry.coordinates[0];else {if("LineString"!==e.geometry.type)return;i=e.geometry.coordinates;}i.forEach(e=>{const i=this.pixelDistance.measure(t,e);i<r.minDist&&i<this.pointerDistance&&(r.coord=e,r.minDist=i);});}),r.coord}}function mt(t,e,i){const o=z(t[0]),r=z(t[1]),s=z(i),n=H(e),a=Math.asin(Math.sin(r)*Math.cos(n)+Math.cos(r)*Math.sin(n)*Math.cos(s));return [$(o+Math.atan2(Math.sin(s)*Math.sin(n)*Math.cos(r),Math.cos(n)-Math.sin(r)*Math.sin(a))),$(a)]}function Ct(t,e){const i=z(t[0]),o=z(e[0]),r=z(t[1]),s=z(e[1]),n=Math.sin(o-i)*Math.cos(s),a=Math.cos(r)*Math.sin(s)-Math.sin(r)*Math.cos(s)*Math.cos(o-i);return $(Math.atan2(n,a))}function vt({x:t,y:e},{x:i,y:o}){let r=Math.atan2(o-e,i-t);return r*=180/Math.PI,r>180?r-=360:r<-180&&(r+=360),r}function Pt(t,e,i){const o=[],r=t.length;let s,n,a,l=0;for(let r=0;r<t.length&&!(e>=l&&r===t.length-1);r++){if(l>e&&0===o.length){if(s=e-l,!s)return o.push(t[r]),o;n=Ct(t[r],t[r-1])-180,a=mt(t[r],s,n),o.push(a);}if(l>=i)return s=i-l,s?(n=Ct(t[r],t[r-1])-180,a=mt(t[r],s,n),o.push(a),o):(o.push(t[r]),o);if(l>=e&&o.push(t[r]),r===t.length-1)return o;l+=Y(t[r],t[r+1]);}if(l<e&&t.length===r)throw new Error("Start position is beyond line");const h=t[t.length-1];return [h,h]}function _t(t){return t*(Math.PI/180)}function xt(t){return t*(180/Math.PI)}class Mt extends dt{constructor(t){super(t),this.config=void 0,this.config=t;}generateInsertionCoordinates(t,e,i){const o=[t,e];let r=0;for(let t=0;t<o.length-1;t++)r+=Y(o[0],o[1]);if(r<=i)return o;let s=r/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);const n=[];for(let t=0;t<s;t++){const e=Pt(o,i*t,i*(t+1));n.push(e);}const a=[];for(let t=0;t<n.length;t++)a.push(n[t][1]);return this.limitCoordinates(a)}generateInsertionGeodesicCoordinates(t,e,i){const o=Y(t,e),r=function(t,e,i){const o=[],r=_t(t[1]),s=_t(t[0]),n=_t(e[1]),a=_t(e[0]);i+=1;const l=2*Math.asin(Math.sqrt(Math.sin((n-r)/2)**2+Math.cos(r)*Math.cos(n)*Math.sin((a-s)/2)**2));if(0===l||isNaN(l))return o;for(let t=0;t<=i;t++){const e=t/i,h=Math.sin((1-e)*l)/Math.sin(l),c=Math.sin(e*l)/Math.sin(l),d=h*Math.cos(r)*Math.cos(s)+c*Math.cos(n)*Math.cos(a),u=h*Math.cos(r)*Math.sin(s)+c*Math.cos(n)*Math.sin(a),g=h*Math.sin(r)+c*Math.sin(n);if(isNaN(d)||isNaN(u)||isNaN(g))continue;const p=Math.atan2(g,Math.sqrt(d**2+u**2)),y=Math.atan2(u,d);isNaN(p)||isNaN(y)||o.push([xt(y),xt(p)]);}return o.slice(1,-1)}(t,e,Math.floor(o/i));return this.limitCoordinates(r)}limitCoordinates(t){return t.map(t=>[e(t[0],this.config.coordinatePrecision),e(t[1],this.config.coordinatePrecision)])}}function bt(t,e){return t[0]===e[0]&&t[1]===e[1]}class St extends X{constructor(e){super(e),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 i={start:"crosshair",close:"pointer"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else {const i={cancel:"Escape",finish:"Enter"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i;}this.validate=null==e?void 0:e.validation,this.insertCoordinates=null==e?void 0:e.insertCoordinates;}close(){if(void 0===this.currentId)return;const t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.updateGeometries([...t.coordinates],void 0,L$2.Commit);const e=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(e,{mode:this.mode,action:"draw"});}updateGeometries(t,e,i){if(!this.currentId)return;const o={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}))return;const r=[{id:this.currentId,geometry:o}];this.closingPointId&&e&&r.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=o.coordinates),this.store.updateGeometry(r);}generateInsertCoordinates(t,e){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 i=Y(t,e)/(this.insertCoordinates.value+1);let o=[];return "globe"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o}createLine(t){const[e]=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}]);this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing();}firstUpdateToLine(t){if(!this.currentId)return;const e=this.store.getGeometryCopy(this.currentId).coordinates,[i]=this.store.create([{geometry:{type:"Point",coordinates:[...t]},properties:{mode:this.mode}}]);this.closingPointId=i,this.setCursor(this.cursors.close);const o=[...e,t];this.updateGeometries(o,void 0,L$2.Commit),this.currentCoordinate++;}updateToLine(t,e){if(!this.currentId)return;const o=this.store.getGeometryCopy(this.currentId).coordinates,[r,s]=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:o[o.length-2],{x:n,y:a}=this.project(r,s);if(i({x:n,y:a},{x:e.x,y:e.y})<this.pointerDistance)return void this.close();this.setCursor(this.cursors.close);const l=[...o,t];this.updateGeometries(l,o[o.length-1],L$2.Commit),this.currentCoordinate++;}registerBehaviors(t){this.snapping=new yt(t,new pt(t),new gt(t)),this.insertPoint=new Mt(t);}start(){this.setStarted(),this.setCursor(this.cursors.start);}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset");}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const e=this.store.getGeometryCopy(this.currentId).coordinates;e.pop();const o=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(this.closingPointId){const[o,r]=e[e.length-1],{x:s,y:n}=this.project(o,r);i({x:s,y:n},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close);}let r=[...e,o];if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){const t=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],e=o;if(!bt(t,e)){const i=this.generateInsertCoordinates(t,e);r=[...this.lastCommitedCoordinates.slice(0,-1),...i,o];}}this.updateGeometries(r,void 0,L$2.Provisional);}onClick(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1;const e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];0===this.currentCoordinate?this.createLine(e):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(e,{x:t.containerX,y:t.containerY});}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close();}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const t=this.currentId;this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==this.closingPointId&&this.store.delete([this.closingPointId]);}catch(t){}}styleFeature(e){const i=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"===e.type&&"LineString"===e.geometry.type&&e.properties.mode===this.mode?(i.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,i.lineStringColor,e),i.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,i.lineStringWidth,e),i.zIndex=10,i):"Feature"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode?(i.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,i.pointColor,e),i.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,i.pointWidth,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,"#ffffff",e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),i.zIndex=40,i):i}validateFeature(t){return !!super.validateFeature(t)&&"LineString"===t.geometry.type&&t.properties.mode===this.mode&&t.geometry.coordinates.length>=2}}function Et(t,e){return "Point"===t.geometry.type&&st(t.geometry.coordinates,e)}class wt extends X{constructor(e){super(e),this.mode="point",this.cursors=void 0;const i={create:"crosshair"};this.cursors=e&&e.cursors?t({},i,e.cursors):i;}start(){this.setStarted(),this.setCursor(this.cursors.create);}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset");}onClick(t){if(!this.store)throw new Error("Mode must be registered first");const e={type:"Point",coordinates:[t.lng,t.lat]},i={mode:this.mode};if(this.validate&&!this.validate({type:"Feature",geometry:e,properties:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:L$2.Finish}))return;const[o]=this.store.create([{geometry:e,properties:i}]);this.onFinish(o,{mode:this.mode,action:"draw"});}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){}onDragStart(){}onDrag(){}onDragEnd(){}styleFeature(e){const i=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"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode&&(i.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(this.styles.pointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,e),i.zIndex=30),i}validateFeature(t){return !!super.validateFeature(t)&&t.properties.mode===this.mode&&Et(t,this.coordinatePrecision)}}class It extends dt{constructor(t,e){super(t),this.config=void 0,this.pixelDistance=void 0,this._startEndPoints=[],this.config=t,this.pixelDistance=e;}get ids(){return this._startEndPoints.concat()}set ids(t){}create(t,e){if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:{mode:e,[V]:!0}},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:{mode:e,[V]:!0}}]);}delete(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[]);}update(t){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:t[t.length-3]}}]);}isClosingPoint(t){const e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),o=this.pixelDistance.measure(t,e.coordinates),r=this.pixelDistance.measure(t,i.coordinates);return {isClosing:o<this.pointerDistance,isPreviousClosing:r<this.pointerDistance}}}class Ft extends X{constructor(e){super(e),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 i={start:"crosshair",close:"pointer"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else {const i={cancel:"Escape",finish:"Enter"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i;}}close(){if(void 0===this.currentId)return;const t=this.store.getGeometryCopy(this.currentId).coordinates[0];if(t.length<5)return;if(!this.updatePolygonGeometry([...t.slice(0,-2),t[0]],L$2.Finish))return;const e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"});}registerBehaviors(t){this.pixelDistance=new pt(t),this.snapping=new yt(t,this.pixelDistance,new gt(t)),this.closingPoints=new It(t,this.pixelDistance);}start(){this.setStarted(),this.setCursor(this.cursors.start);}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset");}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const e=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,i=this.store.getGeometryCopy(this.currentId).coordinates[0];let o;if(e&&(t.lng=e[0],t.lat=e[1]),1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),r=Math.max(1e-6,e);o=[i[0],[t.lng,t.lat],[t.lng,t.lat-r],i[0]];}else if(2===this.currentCoordinate)o=[i[0],i[1],[t.lng,t.lat],i[0]];else {const{isClosing:e,isPreviousClosing:r}=this.closingPoints.isClosingPoint(t);r||e?(this.setCursor(this.cursors.close),o=[...i.slice(0,-2),i[0],i[0]]):o=[...i.slice(0,-2),[t.lng,t.lat],i[0]];}this.updatePolygonGeometry(o,L$2.Provisional);}updatePolygonGeometry(t,e){if(!this.currentId)return !1;const i={type:"Polygon",coordinates:[t]};return !(this.validate&&!this.validate({type:"Feature",geometry:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e})||(this.store.updateGeometry([{id:this.currentId,geometry:i}]),0))}onClick(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){const e=this.snappingEnabled?this.snapping.getSnappableCoordinateFirstClick(t):void 0;e&&(t.lng=e[0],t.lat=e[1]);const[i]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=i,this.currentCoordinate++,this.setDrawing();}else if(1===this.currentCoordinate&&this.currentId){const e=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;e&&(t.lng=e[0],t.lat=e[1]);const i=this.store.getGeometryCopy(this.currentId);if(bt([t.lng,t.lat],i.coordinates[0][0]))return;if(!this.updatePolygonGeometry([i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]],L$2.Commit))return;this.currentCoordinate++;}else if(2===this.currentCoordinate&&this.currentId){const e=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;e&&(t.lng=e[0],t.lat=e[1]);const i=this.store.getGeometryCopy(this.currentId).coordinates[0];if(bt([t.lng,t.lat],i[1]))return;if(!this.updatePolygonGeometry([i[0],i[1],[t.lng,t.lat],[t.lng,t.lat],i[0]],L$2.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(i,"polygon"),this.currentCoordinate++;}else if(this.currentId){const e=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,i=this.store.getGeometryCopy(this.currentId).coordinates[0],{isClosing:o,isPreviousClosing:r}=this.closingPoints.isClosingPoint(t);if(r||o)this.close();else {if(e&&(t.lng=e[0],t.lat=e[1]),bt([t.lng,t.lat],i[this.currentCoordinate-1]))return;const o=function(t=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]){return {type:"Feature",geometry:{type:"Polygon",coordinates:t},properties:{}}}([[...i.slice(0,-1),[t.lng,t.lat],i[0]]]);if(!this.updatePolygonGeometry(o.geometry.coordinates[0],L$2.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(o.geometry.coordinates[0]);}}}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close();}onKeyDown(){}onDragStart(){this.setCursor("unset");}onDrag(){}onDragEnd(){this.setCursor(this.cursors.start);}cleanUp(){const t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),this.closingPoints.ids.length&&this.closingPoints.delete();}catch(t){}}styleFeature(e){const i=t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(e.properties.mode===this.mode){if("Polygon"===e.geometry.type)return i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i;if("Point"===e.geometry.type)return i.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),i.zIndex=30,i}return i}validateFeature(t){return !!super.validateFeature(t)&&t.properties.mode===this.mode&&at(t,this.coordinatePrecision)}}class Dt extends X{constructor(e){super(e),this.mode="rectangle",this.center=void 0,this.clickCount=0,this.currentRectangleId=void 0,this.keyEvents=void 0,this.cursors=void 0;const i={start:"crosshair"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else {const i={cancel:"Escape",finish:"Enter"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i;}}updateRectangle(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){const i=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],o={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}))return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:o}]);}}close(){const t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),t&&this.onFinish(t,{mode:this.mode,action:"draw"});}start(){this.setStarted(),this.setCursor(this.cursors.start);}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset");}onClick(t){if(0===this.clickCount){this.center=[t.lng,t.lat];const[e]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentRectangleId=e,this.clickCount++,this.setDrawing();}else this.updateRectangle(t,L$2.Finish),this.close();}onMouseMove(t){this.updateRectangle(t,L$2.Provisional);}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close();}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&this.store.delete([t]);}styleFeature(e){const i=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"===e.type&&"Polygon"===e.geometry.type&&e.properties.mode===this.mode?(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i):i}validateFeature(t){return !!super.validateFeature(t)&&t.properties.mode===this.mode&&lt(t,this.coordinatePrecision)}}class kt extends X{constructor(t){super({styles:t.styles}),this.type=T.Render,this.mode="render",this.mode=t.modeName;}registerBehaviors(t){this.mode=t.mode;}start(){this.setStarted();}stop(){this.setStopped();}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(t){return {pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}}validateFeature(t){return super.validateFeature(t)&&(Et(t,this.coordinatePrecision)||at(t,this.coordinatePrecision)||function(t,e){return "LineString"===t.geometry.type&&t.geometry.coordinates.length>=2&&t.geometry.coordinates.every(t=>st(t,e))}(t,this.coordinatePrecision))}}function Ot(t,e){const i=t,o=e,r=z(i[1]),s=z(o[1]);let n=z(o[0]-i[0]);n>Math.PI&&(n-=2*Math.PI),n<-Math.PI&&(n+=2*Math.PI);const a=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),l=($(Math.atan2(n,a))+360)%360;return l>180?-(360-l):l}function jt(t,e,i){let o=e;e<0&&(o=-Math.abs(o));const r=o/K,s=t[0]*Math.PI/180,n=z(t[1]),a=z(i),l=r*Math.cos(a);let h=n+l;Math.abs(h)>Math.PI/2&&(h=h>0?Math.PI-h:-Math.PI-h);const c=Math.log(Math.tan(h/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=Math.abs(c)>1e-11?l/c:Math.cos(n),u=[(180*(s+r*Math.sin(a)/d)/Math.PI+540)%360-180,180*h/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function Lt(t,i,o,r,s){const n=r(t[0],t[1]),a=r(i[0],i[1]),{lng:l,lat:h}=s((n.x+a.x)/2,(n.y+a.y)/2);return [e(l,o),e(h,o)]}function Wt(t,i,o){const r=jt(t,1e3*Y(t,i)/2,Ot(t,i));return [e(r[0],o),e(r[1],o)]}function Bt({featureCoords:t,precision:e,unproject:i,project:o,projection:r}){const s=[];for(let n=0;n<t.length-1;n++){let a;if("web-mercator"===r)a=Lt(t[n],t[n+1],e,o,i);else {if("globe"!==r)throw new Error("Invalid projection");a=Wt(t[n],t[n+1],e);}s.push(a);}return s}class Gt extends dt{constructor(t,e){super(t),this.config=void 0,this.selectionPointBehavior=void 0,this._midPoints=[],this.config=t,this.selectionPointBehavior=e;}get ids(){return this._midPoints.concat()}set ids(t){}insert(t,e){const i=this.store.getGeometryCopy(t),{midPointFeatureId:o,midPointSegment:r}=this.store.getPropertiesCopy(t),s=this.store.getGeometryCopy(o),n="Polygon"===s.type?s.coordinates[0]:s.coordinates;n.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[n]:n,this.store.updateGeometry([{id:o,geometry:s}]),this.store.delete([...this._midPoints,...this.selectionPointBehavior.ids]),this.create(n,o,e),this.selectionPointBehavior.create(n,s.type,o);}create(t,e,i){if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,o,r,s){return Bt({featureCoords:t,precision:i,project:o,unproject:r,projection:s}).map((t,i)=>({geometry:{type:"Point",coordinates:t},properties:e(i)}))}(t,t=>({mode:this.mode,[N]:!0,midPointSegment:t,midPointFeatureId:e}),i,this.config.project,this.config.unproject,this.projection));}delete(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[]);}getUpdated(t){if(0!==this._midPoints.length)return Bt({featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}).map((t,e)=>({id:this._midPoints[e],geometry:{type:"Point",coordinates:t}}))}}class Nt extends dt{constructor(t){super(t),this._selectionPoints=[];}get ids(){return this._selectionPoints.concat()}set ids(t){}create(t,e,i){this._selectionPoints=this.store.create(function(t,e,i){const o=[],r="Polygon"===e?t.length-1:t.length;for(let e=0;e<r;e++)o.push({geometry:{type:"Point",coordinates:t[e]},properties:i(e)});return o}(t,e,t=>({mode:this.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t})));}delete(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[]);}getUpdated(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map((e,i)=>({id:e,geometry:{type:"Point",coordinates:t[i]}}))}getOneUpdated(t,e){if(void 0!==this._selectionPoints[t])return {id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}}}function Vt(t,e){let i=!1;for(let n=0,a=e.length;n<a;n++){const a=e[n];for(let e=0,n=a.length,l=n-1;e<n;l=e++)(r=a[e])[1]>(o=t)[1]!=(s=a[l])[1]>o[1]&&o[0]<(s[0]-r[0])*(o[1]-r[1])/(s[1]-r[1])+r[0]&&(i=!i);}var o,r,s;return i}const At=(t,e,i)=>{const o=t=>t*t,r=(t,e)=>o(t.x-e.x)+o(t.y-e.y);return Math.sqrt(((t,e,i)=>{const o=r(e,i);if(0=