terra-draw 0.0.1-alpha.56 → 0.0.1-alpha.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geometry/transform/scale.d.ts +1 -1
- package/dist/modes/select/behaviors/{drag-maintained-shape.behavior.d.ts → drag-coordinate-resize.behavior.d.ts} +4 -2
- package/dist/modes/select/select.mode.d.ts +5 -2
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.modern.js +1 -1
- package/dist/terra-draw.modern.js.map +1 -1
- package/dist/terra-draw.module.js +1 -1
- package/dist/terra-draw.module.js.map +1 -1
- package/dist/terra-draw.umd.js +1 -1
- package/dist/terra-draw.umd.js.map +1 -1
- package/e2e/src/index.ts +13 -0
- package/e2e/tests/leaflet.spec.ts +72 -4
- package/e2e/tests/setup.ts +29 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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 s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},t.apply(this,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:s}=t,{x:o,y:n}=e,r=o-i,a=n-s;return Math.sqrt(a*a+r*r)};class s{constructor({name:t,callback:e,unregister:i,register:s}){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,s(e))},this.unregister=()=>{this.register&&(this.registered=!1,i(e))},this.callback=e}}class o{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:s}=e.getBoundingClientRect();return{containerX:t.clientX-i,containerY:t.clientY-s}}getDrawEventFromEvent(t){const i=this.getLngLatFromEvent(t);if(!i)return null;const{lng:s,lat:o}=i,{containerX:n,containerY:r}=this.getMapElementXYPosition(t),a=this.getButton(t),l=Array.from(this._heldKeys);return{lng:e(s,this._coordinatePrecision),lat:e(o,this._coordinatePrecision),containerX:n,containerY:r,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 s({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 s({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},s={x:e.containerX,y:e.containerY},o=this._currentModeCallbacks.getState(),n=i(t,s);let r=!1;if(r="drawing"===o?n<this._minPixelDragDistanceDrawing:"selecting"===o?n<this._minPixelDragDistanceSelecting:n<this._minPixelDragDistance,r)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 s({name:"contextmenu",callback:t=>{if(this._currentModeCallbacks&&(t.preventDefault(),"not-dragging"===this._dragState||"pre-dragging"===this._dragState)){const e=this.getDrawEventFromEvent(t);if(!e)return;"neither"!==e.button&&this._currentModeCallbacks.onClick(e)}},register:t=>{this.getMapEventElement().addEventListener("contextmenu",t)},unregister:t=>{this.getMapEventElement().removeEventListener("contextmenu",t)}}),new s({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 s({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 s({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 o{constructor(t){if(super(t),this._cursor=void 0,this._cursorStyleSheet=void 0,this._lib=void 0,this._map=void 0,this._overlay=void 0,this._clickEventListener=void 0,this._mouseMoveEventListener=void 0,this.renderedFeatureIds=new Set,this._lib=t.lib,this._map=t.map,!this._map.getDiv().id)throw new Error("Google Map container div requires and id to be set");this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this._overlay=new this._lib.OverlayView,this._overlay.draw=function(){},this._overlay.setMap(this._map)}get _layers(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}circlePath(t,e,i){const s=2*i;return`M ${t} ${e} m -${i}, 0 a ${i},${i} 0 1,0 ${s},0 a ${i},${i} 0 1,0 -${s},0`}register(t){super.register(t),this._clickEventListener=this._map.data.addListener("click",t=>{const e=this._listeners.find(({name:t})=>"click"===t);e&&e.callback(t)}),this._mouseMoveEventListener=this._map.data.addListener("mousemove",t=>{const e=this._listeners.find(({name:t})=>"mousemove"===t);e&&e.callback(t)})}unregister(){var t,e;super.unregister(),null==(t=this._clickEventListener)||t.remove(),null==(e=this._mouseMoveEventListener)||e.remove()}getLngLatFromEvent(t){const e=this._map.getBounds();if(!e)return null;const i=e.getNorthEast(),s=e.getSouthWest(),o=new this._lib.LatLngBounds(s,i),n=this._map.getDiv(),r=t.clientX-n.getBoundingClientRect().left,a=t.clientY-n.getBoundingClientRect().top,l=new this._lib.Point(r,a),h=this._overlay.getProjection();if(!h)return null;const c=h.fromContainerPixelToLatLng(l);return c&&o.contains(c)?{lng:c.lng(),lat:c.lat()}:null}getMapEventElement(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')}project(t,e){if(void 0===this._map.getBounds())throw new Error("cannot get bounds");const i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");const s=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===s)throw new Error("cannot project coordinates");return{x:s.x,y:s.y}}unproject(t,e){const i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");const s=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===s)throw new Error("cannot unproject coordinates");return{lng:s.lng(),lat:s.lat()}}setCursor(t){if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),"unset"!==t){const e=this._map.getDiv(),i=document.querySelector(`#${e.id} .gm-style > div`);if(i){i.classList.add("terra-draw-google-maps");const e=document.createElement("style");e.innerHTML=`.terra-draw-google-maps { cursor: ${t} !important; }`,document.getElementsByTagName("head")[0].appendChild(e),this._cursorStyleSheet=e}}this._cursor=t}}setDoubleClickToZoom(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})}setDraggability(t){this._map.setOptions({draggable:t})}render(t,e){this._layers&&(t.deletedIds.forEach(t=>{const e=this._map.data.getFeatureById(t);e&&(this._map.data.remove(e),this.renderedFeatureIds.delete(t))}),t.updated.forEach(t=>{if(!t||!t.id)throw new Error("Feature is not valid");const e=this._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty((t,i)=>{e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(i=>{e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":{const i=t.geometry.coordinates;e.setGeometry(new this._lib.Data.Point(new this._lib.LatLng(i[1],i[0])))}break;case"LineString":{const i=t.geometry.coordinates,s=[];for(let t=0;t<i.length;t++){const e=i[t],o=new this._lib.LatLng(e[1],e[0]);s.push(o)}e.setGeometry(new this._lib.Data.LineString(s))}break;case"Polygon":{const i=t.geometry.coordinates,s=[];for(let t=0;t<i.length;t++){const e=[];for(let s=0;s<i[t].length;s++){const o=new this._lib.LatLng(i[t][s][1],i[t][s][0]);e.push(o)}s.push(e)}e.setGeometry(new this._lib.Data.Polygon(s))}}}),t.created.forEach(t=>{this.renderedFeatureIds.add(t.id),this._map.data.addGeoJson(t)})),t.created.forEach(t=>{this.renderedFeatureIds.add(t.id)});const i={type:"FeatureCollection",features:[...t.created]};this._map.data.addGeoJson(i),this._map.data.setStyle(t=>{const i=t.getProperty("mode"),s=t.getGeometry();if(!s)throw new Error("Google Maps geometry not found");const o=s.getType(),n={};t.forEachProperty((t,e)=>{n[e]=t});const r=e[i]({type:"Feature",geometry:{type:o,coordinates:[]},properties:n});switch(o){case"Point":return{clickable:!1,icon:{path:this.circlePath(0,0,r.pointWidth),fillColor:r.pointColor,fillOpacity:1,strokeColor:r.pointOutlineColor,strokeWeight:r.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:r.lineStringColor,strokeWeight:r.lineStringWidth};case"Polygon":return{strokeColor:r.polygonOutlineColor,strokeWeight:r.polygonOutlineWidth,fillOpacity:r.polygonFillOpacity,fillColor:r.polygonFillColor}}throw Error("Unknown feature type")})}clearLayers(){this._layers&&(this._map.data.forEach(t=>{const e=t.getId();this.renderedFeatureIds.has(e)&&this._map.data.remove(t)}),this.renderedFeatureIds=new Set)}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}}class r extends o{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} {z-index: ${e};}`,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 s=(0,t[e.properties.mode])(e),o=String(s.zIndex);return this._panes[o]||(this._panes[o]=this.createPaneStyleSheet(o,s.zIndex)),this._lib.circleMarker(i,{radius:s.pointWidth,stroke:s.pointOutlineWidth||!1,color:s.pointOutlineColor,weight:s.pointOutlineWidth,fillOpacity:.8,fillColor:s.pointColor,pane:o,interactive:!1})},style:e=>{if(!e||!e.properties)return{};const i=e,s=(0,t[i.properties.mode])(i),o=String(s.zIndex);return this._panes[o]||(this._panes[o]=this.createPaneStyleSheet(o,s.zIndex)),"LineString"===i.geometry.type?{interactive:!1,color:s.lineStringColor,weight:s.lineStringWidth,pane:o}:"Polygon"===i.geometry.type?{interactive:!1,fillOpacity:s.polygonFillOpacity,fillColor:s.polygonFillColor,weight:s.polygonOutlineWidth,stroke:!0,color:s.polygonFillColor,pane:o}:{}}}}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t),s={x:e,y:i};if(isNaN(s.x)||isNaN(s.y))return null;const o=this._map.containerPointToLatLng(s);return isNaN(o.lng)||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:s}=this._map.latLngToContainerPoint({lng:t,lat:e});return{x:i,y:s}}unproject(t,e){const{lng:i,lat:s}=this._map.containerPointToLatLng({x:t,y:e});return{lng:i,lat:s}}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())}}class a extends o{constructor(t){super(t),this._nextRender=void 0,this._map=void 0,this._container=void 0,this._rendered=!1,this.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},this._map=t.map,this._container=this._map.getContainer()}clearLayers(){this._rendered&&(["point","linestring","polygon"].forEach(t=>{const e=`td-${t.toLowerCase()}`;this._map.removeLayer(e),"polygon"===t&&this._map.removeLayer(e+"-outline"),this._map.removeSource(e)}),this._rendered=!1,this._nextRender&&(cancelAnimationFrame(this._nextRender),this._nextRender=void 0))}_addGeoJSONSource(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e},tolerance:0})}_addFillLayer(t){return this._map.addLayer({id:t,source:t,type:"fill",paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})}_addFillOutlineLayer(t,e){const i=this._map.addLayer({id:t+"-outline",source:t,type:"line",paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}});return e&&this._map.moveLayer(t,e),i}_addLineLayer(t,e){const i=this._map.addLayer({id:t,source:t,type:"line",paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}});return e&&this._map.moveLayer(t,e),i}_addPointLayer(t,e){const i=this._map.addLayer({id:t,source:t,type:"circle",paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return e&&this._map.moveLayer(t,e),i}_addLayer(t,e,i){"Point"===e&&this._addPointLayer(t,i),"LineString"===e&&this._addLineLayer(t,i),"Polygon"===e&&(this._addFillLayer(t),this._addFillOutlineLayer(t,i))}_addGeoJSONLayer(t,e){const i=`td-${t.toLowerCase()}`;return this._addGeoJSONSource(i,e),this._addLayer(i,t),i}_setGeoJSONLayerData(t,e){const i=`td-${t.toLowerCase()}`;return this._map.getSource(i).setData({type:"FeatureCollection",features:e}),i}getEmptyGeometries(){return{points:[],linestrings:[],polygons:[]}}updateChangedIds(t){[...t.updated,...t.created].forEach(t=>{"Point"===t.geometry.type?this.changedIds.points=!0:"LineString"===t.geometry.type?this.changedIds.linestrings=!0:"Polygon"===t.geometry.type&&(this.changedIds.polygons=!0)}),t.deletedIds.length>0&&(this.changedIds.deletion=!0),0===t.created.length&&0===t.updated.length&&0===t.deletedIds.length&&(this.changedIds.styling=!0)}getLngLatFromEvent(t){const{left:e,top:i}=this._container.getBoundingClientRect();return this.unproject(t.clientX-e,t.clientY-i)}getMapEventElement(){return this._map.getCanvas()}setDraggability(t){t?(this._map.dragRotate.enable(),this._map.dragPan.enable()):(this._map.dragRotate.disable(),this._map.dragPan.disable())}project(t,e){const{x:i,y:s}=this._map.project({lng:t,lat:e});return{x:i,y:s}}unproject(t,e){const{lng:i,lat:s}=this._map.unproject({x:t,y:e});return{lng:i,lat:s}}setCursor(t){const e=this._map.getCanvas();"unset"===t?e.style.removeProperty("cursor"):e.style.cursor=t}setDoubleClickToZoom(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(t,e){this.updateChangedIds(t),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(()=>{const i=[...t.created,...t.updated,...t.unchanged],s=this.getEmptyGeometries();for(let t=0;t<i.length;t++){const o=i[t];Object.keys(e).forEach(t=>{const{properties:i}=o;if(i.mode!==t)return;const n=e[t](o);"Point"===o.geometry.type?(i.pointColor=n.pointColor,i.pointOutlineColor=n.pointOutlineColor,i.pointOutlineWidth=n.pointOutlineWidth,i.pointWidth=n.pointWidth,s.points.push(o)):"LineString"===o.geometry.type?(i.lineStringColor=n.lineStringColor,i.lineStringWidth=n.lineStringWidth,s.linestrings.push(o)):"Polygon"===o.geometry.type&&(i.polygonFillColor=n.polygonFillColor,i.polygonFillOpacity=n.polygonFillOpacity,i.polygonOutlineColor=n.polygonOutlineColor,i.polygonOutlineWidth=n.polygonOutlineWidth,s.polygons.push(o))})}const{points:o,linestrings:n,polygons:r}=s;if(this._rendered){const t=this.changedIds.deletion||this.changedIds.styling,e=t||this.changedIds.linestrings,i=t||this.changedIds.polygons;let s;(t||this.changedIds.points)&&(s=this._setGeoJSONLayerData("Point",o)),e&&this._setGeoJSONLayerData("LineString",n),i&&this._setGeoJSONLayerData("Polygon",r),s&&this._map.moveLayer(s)}else this._addGeoJSONLayer("Point",o),this._addGeoJSONLayer("LineString",n),this._addGeoJSONLayer("Polygon",r),this._rendered=!0;this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}}class l extends o{constructor(t){super(t),this.mapboxglAdapter=void 0,this.mapboxglAdapter=new a(t)}register(t){this.mapboxglAdapter.register(t)}unregister(){this.mapboxglAdapter.unregister()}getLngLatFromEvent(t){return this.mapboxglAdapter.getLngLatFromEvent(t)}getMapEventElement(){return this.mapboxglAdapter.getMapEventElement()}setDraggability(t){this.mapboxglAdapter.setDraggability(t)}project(t,e){return this.mapboxglAdapter.project(t,e)}unproject(t,e){return this.mapboxglAdapter.unproject(t,e)}setCursor(t){this.mapboxglAdapter.setCursor(t)}setDoubleClickToZoom(t){this.mapboxglAdapter.setDoubleClickToZoom(t)}render(t,e){this.mapboxglAdapter.render(t,e)}clear(){this.mapboxglAdapter.clear()}}function h(){throw new Error("Unimplemented abstract method.")}let c=0;function d(t,e){return Array.isArray(t)?t:(void 0===e?e=[t,t]:(e[0]=t,e[1]=t),e)}class g{constructor(t){this.opacity_=t.opacity,this.rotateWithView_=t.rotateWithView,this.rotation_=t.rotation,this.scale_=t.scale,this.scaleArray_=d(t.scale),this.displacement_=t.displacement,this.declutterMode_=t.declutterMode}clone(){const t=this.getScale();return new g({opacity:this.getOpacity(),scale:Array.isArray(t)?t.slice():t,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()})}getOpacity(){return this.opacity_}getRotateWithView(){return this.rotateWithView_}getRotation(){return this.rotation_}getScale(){return this.scale_}getScaleArray(){return this.scaleArray_}getDisplacement(){return this.displacement_}getDeclutterMode(){return this.declutterMode_}getAnchor(){return h()}getImage(t){return h()}getHitDetectionImage(){return h()}getPixelRatio(t){return 1}getImageState(){return h()}getImageSize(){return h()}getOrigin(){return h()}getSize(){return h()}setDisplacement(t){this.displacement_=t}setOpacity(t){this.opacity_=t}setRotateWithView(t){this.rotateWithView_=t}setRotation(t){this.rotation_=t}setScale(t){this.scale_=t,this.scaleArray_=d(t)}listenImageChange(t){h()}load(){h()}unlistenImageChange(t){h()}}var u=g;const p={1:"The view center is not defined",2:"The view resolution is not defined",3:"The view rotation is not defined",4:"`image` and `src` cannot be provided at the same time",5:"`imgSize` must be set when `image` is provided",7:"`format` must be set when `url` is set",8:"Unknown `serverType` configured",9:"`url` must be configured or set using `#setUrl()`",10:"The default `geometryFunction` can only handle `Point` geometries",11:"`options.featureTypes` must be an Array",12:"`options.geometryName` must also be provided when `options.bbox` is set",13:"Invalid corner",14:"Invalid color",15:"Tried to get a value for a key that does not exist in the cache",16:"Tried to set a value for a key that is used already",17:"`resolutions` must be sorted in descending order",18:"Either `origin` or `origins` must be configured, never both",19:"Number of `tileSizes` and `resolutions` must be equal",20:"Number of `origins` and `resolutions` must be equal",22:"Either `tileSize` or `tileSizes` must be configured, never both",24:"Invalid extent or geometry provided as `geometry`",25:"Cannot fit empty extent provided as `geometry`",26:"Features must have an id set",27:"Features must have an id set",28:'`renderMode` must be `"hybrid"` or `"vector"`',30:"The passed `feature` was already added to the source",31:"Tried to enqueue an `element` that was already added to the queue",32:"Transformation matrix cannot be inverted",33:"Invalid units",34:"Invalid geometry layout",36:"Unknown SRS type",37:"Unknown geometry type found",38:"`styleMapValue` has an unknown type",39:"Unknown geometry type",40:"Expected `feature` to have a geometry",41:"Expected an `ol/style/Style` or an array of `ol/style/Style.js`",42:"Question unknown, the answer is 42",43:"Expected `layers` to be an array or a `Collection`",47:"Expected `controls` to be an array or an `ol/Collection`",48:"Expected `interactions` to be an array or an `ol/Collection`",49:"Expected `overlays` to be an array or an `ol/Collection`",50:"`options.featureTypes` should be an Array",51:"Either `url` or `tileJSON` options must be provided",52:"Unknown `serverType` configured",53:"Unknown `tierSizeCalculation` configured",55:"The {-y} placeholder requires a tile grid with extent",56:"mapBrowserEvent must originate from a pointer event",57:"At least 2 conditions are required",59:"Invalid command found in the PBF",60:"Missing or invalid `size`",61:"Cannot determine IIIF Image API version from provided image information JSON",62:"A `WebGLArrayBuffer` must either be of type `ELEMENT_ARRAY_BUFFER` or `ARRAY_BUFFER`",64:"Layer opacity must be a number",66:"`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has not been enabled. This is done by providing adequate shaders using the `hitVertexShader` and `hitFragmentShader` properties of `WebGLPointsLayerRenderer`",67:"A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both",68:"A VectorTile source can only be rendered if it has a projection compatible with the view projection"};class y extends Error{constructor(t){const e=p[t];super(e),this.code=t,this.name="AssertionError",this.message=e}}var m=y;function f(t,e,i){return Math.min(Math.max(t,e),i)}const v=/^#([a-f0-9]{3}|[a-f0-9]{4}(?:[a-f0-9]{2}){0,2})$/i,_=/^([a-z]*)$|^hsla?\(.*\)$/i,C=function(){const t={};let e=0;return function(i){let s;if(t.hasOwnProperty(i))s=t[i];else{if(e>=1024){let i=0;for(const s in t)0==(3&i++)&&(delete t[s],--e)}s=function(t){let e,i,s,o,n;if(_.exec(t)&&(t=function(t){const e=document.createElement("div");if(e.style.color=t,""!==e.style.color){document.body.appendChild(e);const t=getComputedStyle(e).color;return document.body.removeChild(e),t}return""}(t)),v.exec(t)){const r=t.length-1;let a;a=r<=4?1:2;const l=4===r||8===r;e=parseInt(t.substr(1+0*a,a),16),i=parseInt(t.substr(1+1*a,a),16),s=parseInt(t.substr(1+2*a,a),16),o=l?parseInt(t.substr(1+3*a,a),16):255,1==a&&(e=(e<<4)+e,i=(i<<4)+i,s=(s<<4)+s,l&&(o=(o<<4)+o)),n=[e,i,s,o/255]}else t.startsWith("rgba(")?(n=t.slice(5,-1).split(",").map(Number),P(n)):t.startsWith("rgb(")?(n=t.slice(4,-1).split(",").map(Number),n.push(1),P(n)):function(t,e){throw new m(14)}();return n}(i),t[i]=s,++e}return s}}();function P(t){return t[0]=f(t[0]+.5|0,0,255),t[1]=f(t[1]+.5|0,0,255),t[2]=f(t[2]+.5|0,0,255),t[3]=f(t[3],0,1),t}function S(t){return Array.isArray(t)?function(t){let e=t[0];e!=(0|e)&&(e=e+.5|0);let i=t[1];i!=(0|i)&&(i=i+.5|0);let s=t[2];return s!=(0|s)&&(s=s+.5|0),"rgba("+e+","+i+","+s+","+(void 0===t[3]?1:Math.round(100*t[3])/100)+")"}(t):t}const x="undefined"!=typeof navigator&&void 0!==navigator.userAgent?navigator.userAgent.toLowerCase():"";x.includes("firefox"),x.includes("safari")&&!x.includes("chrom")&&(x.includes("version/15.4")||/cpu (os|iphone os) 15_4 like mac os x/.test(x)),x.includes("webkit")&&x.includes("edge"),x.includes("macintosh");const E="undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof OffscreenCanvas&&self instanceof WorkerGlobalScope;function w(t,e,i,s){let o;return o=i&&i.length?i.shift():E?new OffscreenCanvas(t||300,e||300):document.createElement("canvas"),t&&(o.width=t),e&&(o.height=e),o.getContext("2d",s)}!function(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("_",null,e),window.removeEventListener("_",null,e)}catch(t){}}();var b=class{constructor(t){this.type=t,this.target=null}preventDefault(){this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0}},M=class{constructor(){this.disposed=!1}dispose(){this.disposed||(this.disposed=!0,this.disposeInternal())}disposeInternal(){}};function I(){}function D(t){for(const e in t)delete t[e]}var k=class extends M{constructor(t){super(),this.eventTarget_=t,this.pendingRemovals_=null,this.dispatching_=null,this.listeners_=null}addEventListener(t,e){if(!t||!e)return;const i=this.listeners_||(this.listeners_={}),s=i[t]||(i[t]=[]);s.includes(e)||s.push(e)}dispatchEvent(t){const e="string"==typeof t,i=e?t:t.type,s=this.listeners_&&this.listeners_[i];if(!s)return;const o=e?new b(t):t;o.target||(o.target=this.eventTarget_||this);const n=this.dispatching_||(this.dispatching_={}),r=this.pendingRemovals_||(this.pendingRemovals_={});let a;i in n||(n[i]=0,r[i]=0),++n[i];for(let t=0,e=s.length;t<e;++t)if(a="handleEvent"in s[t]?s[t].handleEvent(o):s[t].call(this,o),!1===a||o.propagationStopped){a=!1;break}if(0==--n[i]){let t=r[i];for(delete r[i];t--;)this.removeEventListener(i,I);delete n[i]}return a}disposeInternal(){this.listeners_&&D(this.listeners_)}getListeners(t){return this.listeners_&&this.listeners_[t]||void 0}hasListener(t){return!!this.listeners_&&(t?t in this.listeners_:Object.keys(this.listeners_).length>0)}removeEventListener(t,e){const i=this.listeners_&&this.listeners_[t];if(i){const s=i.indexOf(e);-1!==s&&(this.pendingRemovals_&&t in this.pendingRemovals_?(i[s]=I,++this.pendingRemovals_[t]):(i.splice(s,1),0===i.length&&delete this.listeners_[t]))}}};function O(t,e,i,s,o){if(s&&s!==t&&(i=i.bind(s)),o){const s=i;i=function(){t.removeEventListener(e,i),s.apply(this,arguments)}}const n={target:t,type:e,listener:i};return t.addEventListener(e,i),n}function F(t,e,i,s){return O(t,e,i,s,!0)}function L(t){t&&t.target&&(t.target.removeEventListener(t.type,t.listener),D(t))}var W=class extends k{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(t,e){if(Array.isArray(t)){const i=t.length,s=new Array(i);for(let o=0;o<i;++o)s[o]=O(this,t[o],e);return s}return O(this,t,e)}onceInternal(t,e){let i;if(Array.isArray(t)){const s=t.length;i=new Array(s);for(let o=0;o<s;++o)i[o]=F(this,t[o],e)}else i=F(this,t,e);return e.ol_key=i,i}unInternal(t,e){const i=e.ol_key;if(i)!function(t){if(Array.isArray(t))for(let e=0,i=t.length;e<i;++e)L(t[e]);else L(t)}(i);else if(Array.isArray(t))for(let i=0,s=t.length;i<s;++i)this.removeEventListener(t[i],e);else this.removeEventListener(t,e)}};class A extends b{constructor(t,e,i){super(t),this.key=e,this.oldValue=i}}const G="#000",B="round";new class extends W{constructor(t){super(),this.ol_uid||(this.ol_uid=String(++c)),this.values_=null,void 0!==t&&this.setProperties(t)}get(t){let e;return this.values_&&this.values_.hasOwnProperty(t)&&(e=this.values_[t]),e}getKeys(){return this.values_&&Object.keys(this.values_)||[]}getProperties(){return this.values_&&Object.assign({},this.values_)||{}}hasProperties(){return!!this.values_}notify(t,e){let i;i=`change:${t}`,this.hasListener(i)&&this.dispatchEvent(new A(i,t,e)),i="propertychange",this.hasListener(i)&&this.dispatchEvent(new A(i,t,e))}addChangeListener(t,e){this.addEventListener(`change:${t}`,e)}removeChangeListener(t,e){this.removeEventListener(`change:${t}`,e)}set(t,e,i){const s=this.values_||(this.values_={});if(i)s[t]=e;else{const i=s[t];s[t]=e,i!==e&&this.notify(t,i)}}setProperties(t,e){for(const i in t)this.set(i,t[i],e)}applyProperties(t){t.values_&&Object.assign(this.values_||(this.values_={}),t.values_)}unset(t,e){if(this.values_&&t in this.values_){const i=this.values_[t];delete this.values_[t],function(t){let e;for(e in t)return!1;return!e}(this.values_)&&(this.values_=null),e||this.notify(t,i)}}};class N extends u{constructor(t){super({opacity:1,rotateWithView:void 0!==t.rotateWithView&&t.rotateWithView,rotation:void 0!==t.rotation?t.rotation:0,scale:void 0!==t.scale?t.scale:1,displacement:void 0!==t.displacement?t.displacement:[0,0],declutterMode:t.declutterMode}),this.canvas_=void 0,this.hitDetectionCanvas_=null,this.fill_=void 0!==t.fill?t.fill:null,this.origin_=[0,0],this.points_=t.points,this.radius_=void 0!==t.radius?t.radius:t.radius1,this.radius2_=t.radius2,this.angle_=void 0!==t.angle?t.angle:0,this.stroke_=void 0!==t.stroke?t.stroke:null,this.size_=null,this.renderOptions_=null,this.render()}clone(){const t=this.getScale(),e=new N({fill:this.getFill()?this.getFill().clone():void 0,points:this.getPoints(),radius:this.getRadius(),radius2:this.getRadius2(),angle:this.getAngle(),stroke:this.getStroke()?this.getStroke().clone():void 0,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),scale:Array.isArray(t)?t.slice():t,displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()});return e.setOpacity(this.getOpacity()),e}getAnchor(){const t=this.size_;if(!t)return null;const e=this.getDisplacement(),i=this.getScaleArray();return[t[0]/2-e[0]/i[0],t[1]/2+e[1]/i[1]]}getAngle(){return this.angle_}getFill(){return this.fill_}setFill(t){this.fill_=t,this.render()}getHitDetectionImage(){return this.hitDetectionCanvas_||this.createHitDetectionCanvas_(this.renderOptions_),this.hitDetectionCanvas_}getImage(t){let e=this.canvas_[t];if(!e){const i=this.renderOptions_,s=w(i.size*t,i.size*t);this.draw_(i,s,t),e=s.canvas,this.canvas_[t]=e}return e}getPixelRatio(t){return t}getImageSize(){return this.size_}getImageState(){return 2}getOrigin(){return this.origin_}getPoints(){return this.points_}getRadius(){return this.radius_}getRadius2(){return this.radius2_}getSize(){return this.size_}getStroke(){return this.stroke_}setStroke(t){this.stroke_=t,this.render()}listenImageChange(t){}load(){}unlistenImageChange(t){}calculateLineJoinSize_(t,e,i){if(0===e||Infinity===this.points_||"bevel"!==t&&"miter"!==t)return e;let s=this.radius_,o=void 0===this.radius2_?s:this.radius2_;if(s<o){const t=s;s=o,o=t}const n=2*Math.PI/(void 0===this.radius2_?this.points_:2*this.points_),r=o*Math.sin(n),a=s-Math.sqrt(o*o-r*r),l=Math.sqrt(r*r+a*a),h=l/r;if("miter"===t&&h<=i)return h*e;const c=e/2/h,d=e/2*(a/l),g=Math.sqrt((s+c)*(s+c)+d*d)-s;if(void 0===this.radius2_||"bevel"===t)return 2*g;const u=s*Math.sin(n),p=o-Math.sqrt(s*s-u*u),y=Math.sqrt(u*u+p*p)/u;return y<=i?2*Math.max(g,y*e/2-o-s):2*g}createRenderOptions(){let t,e=B,i=0,s=null,o=0,n=0;this.stroke_&&(t=this.stroke_.getColor(),null===t&&(t="#000"),t=S(t),n=this.stroke_.getWidth(),void 0===n&&(n=1),s=this.stroke_.getLineDash(),o=this.stroke_.getLineDashOffset(),e=this.stroke_.getLineJoin(),void 0===e&&(e=B),i=this.stroke_.getMiterLimit(),void 0===i&&(i=10));const r=this.calculateLineJoinSize_(e,n,i),a=Math.max(this.radius_,this.radius2_||0);return{strokeStyle:t,strokeWidth:n,size:Math.ceil(2*a+r),lineDash:s,lineDashOffset:o,lineJoin:e,miterLimit:i}}render(){this.renderOptions_=this.createRenderOptions();const t=this.renderOptions_.size;this.canvas_={},this.size_=[t,t]}draw_(t,e,i){if(e.scale(i,i),e.translate(t.size/2,t.size/2),this.createPath_(e),this.fill_){let t=this.fill_.getColor();null===t&&(t=G),e.fillStyle=S(t),e.fill()}this.stroke_&&(e.strokeStyle=t.strokeStyle,e.lineWidth=t.strokeWidth,t.lineDash&&(e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset),e.lineJoin=t.lineJoin,e.miterLimit=t.miterLimit,e.stroke())}createHitDetectionCanvas_(t){if(this.fill_){let e=this.fill_.getColor(),i=0;if("string"==typeof e&&(e=function(t){return Array.isArray(t)?t:C(t)}(e)),null===e?i=1:Array.isArray(e)&&(i=4===e.length?e[3]:1),0===i){const e=w(t.size,t.size);this.hitDetectionCanvas_=e.canvas,this.drawHitDetectionCanvas_(t,e)}}this.hitDetectionCanvas_||(this.hitDetectionCanvas_=this.getImage(1))}createPath_(t){let e=this.points_;const i=this.radius_;if(Infinity===e)t.arc(0,0,i,0,2*Math.PI);else{const s=void 0===this.radius2_?i:this.radius2_;void 0!==this.radius2_&&(e*=2);const o=this.angle_-Math.PI/2,n=2*Math.PI/e;for(let r=0;r<e;r++){const e=o+r*n,a=r%2==0?i:s;t.lineTo(a*Math.cos(e),a*Math.sin(e))}t.closePath()}}drawHitDetectionCanvas_(t,e){e.translate(t.size/2,t.size/2),this.createPath_(e),e.fillStyle=G,e.fill(),this.stroke_&&(e.strokeStyle=t.strokeStyle,e.lineWidth=t.strokeWidth,t.lineDash&&(e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset),e.lineJoin=t.lineJoin,e.miterLimit=t.miterLimit,e.stroke())}}var V=N;class j extends V{constructor(t){super({points:Infinity,fill:(t=t||{radius:5}).fill,radius:t.radius,stroke:t.stroke,scale:void 0!==t.scale?t.scale:1,rotation:void 0!==t.rotation?t.rotation:0,rotateWithView:void 0!==t.rotateWithView&&t.rotateWithView,displacement:void 0!==t.displacement?t.displacement:[0,0],declutterMode:t.declutterMode})}clone(){const t=this.getScale(),e=new j({fill:this.getFill()?this.getFill().clone():void 0,stroke:this.getStroke()?this.getStroke().clone():void 0,radius:this.getRadius(),scale:Array.isArray(t)?t.slice():t,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()});return e.setOpacity(this.getOpacity()),e}setRadius(t){this.radius_=t,this.render()}}var R=j;class T{constructor(t){this.color_=void 0!==(t=t||{}).color?t.color:null}clone(){const t=this.getColor();return new T({color:Array.isArray(t)?t.slice():t||void 0})}getColor(){return this.color_}setColor(t){this.color_=t}}var U=T;class X{constructor(t){this.color_=void 0!==(t=t||{}).color?t.color:null,this.lineCap_=t.lineCap,this.lineDash_=void 0!==t.lineDash?t.lineDash:null,this.lineDashOffset_=t.lineDashOffset,this.lineJoin_=t.lineJoin,this.miterLimit_=t.miterLimit,this.width_=t.width}clone(){const t=this.getColor();return new X({color:Array.isArray(t)?t.slice():t||void 0,lineCap:this.getLineCap(),lineDash:this.getLineDash()?this.getLineDash().slice():void 0,lineDashOffset:this.getLineDashOffset(),lineJoin:this.getLineJoin(),miterLimit:this.getMiterLimit(),width:this.getWidth()})}getColor(){return this.color_}getLineCap(){return this.lineCap_}getLineDash(){return this.lineDash_}getLineDashOffset(){return this.lineDashOffset_}getLineJoin(){return this.lineJoin_}getMiterLimit(){return this.miterLimit_}getWidth(){return this.width_}setColor(t){this.color_=t}setLineCap(t){this.lineCap_=t}setLineDash(t){this.lineDash_=t}setLineDashOffset(t){this.lineDashOffset_=t}setLineJoin(t){this.lineJoin_=t}setMiterLimit(t){this.miterLimit_=t}setWidth(t){this.width_=t}}var Y=X;class z{constructor(t){t=t||{},this.geometry_=null,this.geometryFunction_=H,void 0!==t.geometry&&this.setGeometry(t.geometry),this.fill_=void 0!==t.fill?t.fill:null,this.image_=void 0!==t.image?t.image:null,this.renderer_=void 0!==t.renderer?t.renderer:null,this.hitDetectionRenderer_=void 0!==t.hitDetectionRenderer?t.hitDetectionRenderer:null,this.stroke_=void 0!==t.stroke?t.stroke:null,this.text_=void 0!==t.text?t.text:null,this.zIndex_=t.zIndex}clone(){let t=this.getGeometry();return t&&"object"==typeof t&&(t=t.clone()),new z({geometry:t,fill:this.getFill()?this.getFill().clone():void 0,image:this.getImage()?this.getImage().clone():void 0,renderer:this.getRenderer(),stroke:this.getStroke()?this.getStroke().clone():void 0,text:this.getText()?this.getText().clone():void 0,zIndex:this.getZIndex()})}getRenderer(){return this.renderer_}setRenderer(t){this.renderer_=t}setHitDetectionRenderer(t){this.hitDetectionRenderer_=t}getHitDetectionRenderer(){return this.hitDetectionRenderer_}getGeometry(){return this.geometry_}getGeometryFunction(){return this.geometryFunction_}getFill(){return this.fill_}setFill(t){this.fill_=t}getImage(){return this.image_}setImage(t){this.image_=t}getStroke(){return this.stroke_}setStroke(t){this.stroke_=t}getText(){return this.text_}setText(t){this.text_=t}getZIndex(){return this.zIndex_}setGeometry(t){"function"==typeof t?this.geometryFunction_=t:"string"==typeof t?this.geometryFunction_=function(e){return e.get(t)}:t?void 0!==t&&(this.geometryFunction_=function(){return t}):this.geometryFunction_=H,this.geometry_=t}setZIndex(t){this.zIndex_=t}}function H(t){return t.getGeometry()}var J=z;const K={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var $=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_||K[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 q=6378137,Z=Math.PI*q,Q=[-Z,-Z,Z,Z],tt=[-180,-85,180,85],et=q*Math.log(Math.tan(Math.PI/2));class it extends ${constructor(t){super({code:t,units:"m",extent:Q,global:!0,worldExtent:tt,getPointResolution:function(t,e){return t/Math.cosh(e[1]/q)}})}}const st=[new it("EPSG:3857"),new it("EPSG:102100"),new it("EPSG:102113"),new it("EPSG:900913"),new it("http://www.opengis.net/def/crs/EPSG/0/3857"),new it("http://www.opengis.net/gml/srs/epsg.xml#3857")],ot=[-180,-90,180,90],nt=6378137*Math.PI/180;class rt extends ${constructor(t,e){super({code:t,units:"degrees",extent:ot,axisOrientation:e,global:!0,metersPerUnit:nt,worldExtent:ot})}}const at=[new rt("CRS:84"),new rt("EPSG:4326","neu"),new rt("urn:ogc:def:crs:OGC:1.3:CRS84"),new rt("urn:ogc:def:crs:OGC:2:84"),new rt("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new rt("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new rt("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let lt={},ht={};function ct(t,e,i){const s=t.getCode(),o=e.getCode();s in ht||(ht[s]={}),ht[s][o]=i}function dt(t,e,i){if(void 0!==e)for(let i=0,s=t.length;i<s;++i)e[i]=t[i];else e=t.slice();return e}function gt(t,e,i){if(void 0!==e&&t!==e){for(let i=0,s=t.length;i<s;++i)e[i]=t[i];t=e}return t}function ut(t){!function(t,e){lt[t]=e}(t.getCode(),t),ct(t,t,dt)}function pt(t){return"string"==typeof t?lt[e=t]||lt[e.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/,"EPSG:$3")]||null:t||null;var e}function yt(t){!function(t){t.forEach(ut)}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&ct(e,t,dt)})})}function mt(t,e,i){const s=function(t,e){return function(t,e){let i=function(t,e){let i;return t in ht&&e in ht[t]&&(i=ht[t][e]),i}(t.getCode(),e.getCode());return i||(i=gt),i}(pt(t),pt(e))}(e,i);return s(t,void 0,t.length)}var ft,vt,_t;yt(st),yt(at),ft=st,vt=function(t,e,i){const s=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(s));for(let o=0;o<s;o+=i){e[o]=Z*t[o]/180;let i=q*Math.log(Math.tan(Math.PI*(+t[o+1]+90)/360));i>et?i=et:i<-et&&(i=-et),e[o+1]=i}return e},_t=function(t,e,i){const s=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(s));for(let o=0;o<s;o+=i)e[o]=180*t[o]/Z,e[o+1]=360*Math.atan(Math.exp(t[o+1]/q))/Math.PI-90;return e},at.forEach(function(t){ft.forEach(function(e){ct(t,e,vt),ct(e,t,_t)})});class Ct extends o{constructor(t){super(t),this.stylingFunction=()=>({}),this._lib=void 0,this._map=void 0,this._container=void 0,this._projection="EPSG:3857",this._vectorSource=void 0,this._geoJSONReader=void 0,this._map=t.map,this._lib=t.lib,this._geoJSONReader=new this._lib.GeoJSON,this._container=this._map.getViewport(),this._container.setAttribute("tabindex","0");const e=new this._lib.VectorSource({features:[]});this._vectorSource=e;const i=new this._lib.VectorLayer({source:e,style:t=>this.getStyles(t,this.stylingFunction())});this._map.addLayer(i)}hexToRGB(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}getStyles(t,e){const i=t.getGeometry();if(i)return{Point:t=>{const i=t.getProperties(),s=e[i.mode]({type:"Feature",geometry:{type:"Point",coordinates:[]},properties:i});return new this._lib.Style({image:new R({radius:s.pointWidth,fill:new U({color:s.pointColor}),stroke:new Y({color:s.pointOutlineColor,width:s.pointOutlineWidth})})})},LineString:t=>{const i=t.getProperties(),s=e[i.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:i});return new this._lib.Style({stroke:new this._lib.Stroke({color:s.lineStringColor,width:s.lineStringWidth})})},Polygon:t=>{const i=t.getProperties(),s=e[i.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:i}),{r:o,g:n,b:r}=this.hexToRGB(s.polygonFillColor);return new J({stroke:new Y({color:s.polygonOutlineColor,width:s.polygonOutlineWidth}),fill:new U({color:`rgba(${o},${n},${r},${s.polygonFillOpacity})`})})}}[i.getType()](t)}clearLayers(){this._vectorSource&&this._vectorSource.clear()}addFeature(t){if(!this._vectorSource||!this._geoJSONReader)throw new Error("Vector Source not initalised");{const e=this._geoJSONReader.readFeature(t,{featureProjection:this._projection});this._vectorSource.addFeature(e)}}removeFeature(t){if(!this._vectorSource)throw new Error("Vector Source not initalised");{const e=this._vectorSource.getFeatureById(t);if(!e)return;this._vectorSource.removeFeature(e)}}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t);try{return this.unproject(e,i)}catch(t){return null}}getMapEventElement(){const t=this._container.querySelectorAll("canvas");if(t.length>1)throw Error("Terra Draw currently only supports 1 canvas with OpenLayers");return t[0]}setDraggability(t){this._map.getInteractions().forEach(e=>{"DragPan"===e.constructor.name&&e.setActive(t)})}project(t,e){const[i,s]=this._map.getPixelFromCoordinate(mt([t,e],"EPSG:4326","EPSG:3857"));return{x:i,y:s}}unproject(t,e){const[i,s]=function(t,e){const i=mt(t,"EPSG:3857","EPSG:4326"),s=i[0];return(s<-180||s>180)&&(i[0]=function(t,e){const i=t%360;return 360*i<0?i+360:i}(s+180)-180),i}(this._map.getCoordinateFromPixel([t,e]));return{lng:i,lat:s}}setCursor(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t}setDoubleClickToZoom(t){this._map.getInteractions().forEach(function(e){"DoubleClickZoom"===e.constructor.name&&e.setActive(t)})}render(t,e){if(this.stylingFunction=()=>e,!this._vectorSource)throw new Error("Vector Layer source has disappeared");t.deletedIds.forEach(t=>{this.removeFeature(t)}),t.updated.forEach(t=>{this.removeFeature(t.id),this.addFeature(t)}),t.created.forEach(t=>{this.addFeature(t)})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}}class Pt extends o{constructor(t){super(t),this._lib=void 0,this._mapView=void 0,this._container=void 0,this._featureIdAttributeName="__tdId",this._featureLayerName="__terraDrawFeatures",this._featureLayer=void 0,this._dragEnabled=!0,this._zoomEnabled=!0,this._dragHandler=void 0,this._doubleClickHandler=void 0,this._mapView=t.map,this._lib=t.lib,this._container=this._mapView.container,this._featureLayer=new this._lib.GraphicsLayer({id:this._featureLayerName}),this._mapView.map.add(this._featureLayer)}register(t){super.register(t),this._dragHandler=this._mapView.on("drag",t=>{this._dragEnabled||t.stopPropagation()}),this._doubleClickHandler=this._mapView.on("double-click",t=>{this._zoomEnabled||t.stopPropagation()})}unregister(){super.unregister(),this._dragHandler&&this._dragHandler.remove(),this._doubleClickHandler&&this._doubleClickHandler.remove()}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t);return this.unproject(e,i)}getMapEventElement(){return this._container.querySelector(".esri-view-surface")}setDraggability(t){this._dragEnabled=t}project(t,e){const i=new this._lib.Point({longitude:t,latitude:e}),{x:s,y:o}=this._mapView.toScreen(i);return{x:s,y:o}}unproject(t,e){const{latitude:i,longitude:s}=this._mapView.toMap({x:t,y:e});return{lng:s,lat:i}}setCursor(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t}setDoubleClickToZoom(t){this._zoomEnabled=t}render(t,e){t.created.forEach(t=>{this.addFeature(t,e)}),t.updated.forEach(t=>{this.removeFeatureById(t.id),this.addFeature(t,e)}),t.deletedIds.forEach(t=>{this.removeFeatureById(t)})}clear(){this._featureLayer.graphics.removeAll()}removeFeatureById(t){const e=this._featureLayer.graphics.find(e=>e.attributes[this._featureIdAttributeName]===t);this._featureLayer.remove(e)}addFeature(t,e){const{coordinates:i,type:s}=t.geometry,o=e[t.properties.mode](t);let n,r;switch(s){case"Point":r=new this._lib.Point({latitude:i[1],longitude:i[0]}),n=new this._lib.SimpleMarkerSymbol({color:this.getColorFromHex(o.pointColor),size:2*o.pointWidth+"px",outline:{color:this.getColorFromHex(o.pointOutlineColor),width:o.pointOutlineWidth+"px"}});break;case"LineString":r=new this._lib.Polyline({paths:[i]}),n=new this._lib.SimpleLineSymbol({color:this.getColorFromHex(o.lineStringColor),width:o.lineStringWidth+"px"});break;case"Polygon":r=new this._lib.Polygon({rings:i}),n=new this._lib.SimpleFillSymbol({color:this.getColorFromHex(o.polygonFillColor,o.polygonFillOpacity),outline:{color:this.getColorFromHex(o.polygonOutlineColor),width:o.polygonOutlineWidth+"px"}})}const a=new this._lib.Graphic({geometry:r,symbol:n,attributes:{[this._featureIdAttributeName]:t.id}});"Point"===s?this._featureLayer.graphics.add(a):this._featureLayer.graphics.add(a,0)}getColorFromHex(t,e){const i=this._lib.Color.fromHex(t);return e&&(i.a=e),i}}const St="selected",xt="midPoint",Et="closingPoint";function wt(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function bt(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 Mt;!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(Mt||(Mt={}));class It{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.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.type=Mt.Drawing,this.mode="base",this._state="unregistered",this._styles=e&&e.styles?t({},e.styles):{},this.pointerDistance=e&&e.pointerDistance||40}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})}validateFeature(t){if("unregistered"===this._state)throw new Error("Mode must be registered");return function(t,e){let i;if(wt(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(wt(t.geometry))if(wt(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)}onFinish(t){}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}}function Dt(t,e){const i=t=>t*Math.PI/180,s=i(t[1]),o=i(t[0]),n=i(e[1]),r=n-s,a=i(e[0])-o,l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(s)*Math.cos(n)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}function kt(t){return t%360*Math.PI/180}function Ot(t){return t%(2*Math.PI)*180/Math.PI}function Ft(t,e,i){const s=kt(t[0]),o=kt(t[1]),n=kt(i),r=function(t){return t/6371.0088}(e),a=Math.asin(Math.sin(o)*Math.cos(r)+Math.cos(o)*Math.sin(r)*Math.cos(n));return[Ot(s+Math.atan2(Math.sin(n)*Math.sin(r)*Math.cos(o),Math.cos(r)-Math.sin(o)*Math.sin(a))),Ot(a)]}function Lt(t){const{center:i,radiusKilometers:s,coordinatePrecision:o}=t,n=t.steps?t.steps:64,r=[];for(let t=0;t<n;t++){const a=Ft(i,s,-360*t/n);r.push([e(a[0],o),e(a[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function Wt(t){let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}const i=[];for(let t=0;t<e.length;t++)for(let i=0;i<e[t].length-1;i++)for(let s=0;s<e.length;s++)for(let n=0;n<e[s].length-1;n++)o(t,i,s,n);return i.length>0;function s(t){return t<0||t>1}function o(t,o,n,r){const a=e[t][o],l=e[t][o+1],h=e[n][r],c=e[n][r+1],d=function(t,e,i,s){if(At(t,i)||At(t,s)||At(e,i)||At(s,i))return null;const o=t[0],n=t[1],r=e[0],a=e[1],l=i[0],h=i[1],c=s[0],d=s[1],g=(o-r)*(h-d)-(n-a)*(l-c);return 0===g?null:[((o*a-n*r)*(l-c)-(o-r)*(l*d-h*c))/g,((o*a-n*r)*(h-d)-(n-a)*(l*d-h*c))/g]}(a,l,h,c);if(null===d)return;let g,u;g=l[0]!==a[0]?(d[0]-a[0])/(l[0]-a[0]):(d[1]-a[1])/(l[1]-a[1]),u=c[0]!==h[0]?(d[0]-h[0])/(c[0]-h[0]):(d[1]-h[1])/(c[1]-h[1]),s(g)||s(u)||(d.toString(),i.push(d))}}function At(t,e){return t[0]===e[0]&&t[1]===e[1]}function Gt(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(s=t[0])>=-180&&s<=180&&(i=t[1])>=-90&&i<=90&&Bt(t[0])<=e&&Bt(t[1])<=e;var i,s}function Bt(t){let e=1,i=0;for(;Math.round(t*e)/e!==t;)e*=10,i++;return i}function Nt(t,e){return"Polygon"===t.geometry.type&&1===t.geometry.coordinates.length&&t.geometry.coordinates[0].length>=4&&t.geometry.coordinates[0].every(t=>Gt(t,e))&&(i=t.geometry.coordinates[0][0])[0]===(s=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]&&i[1]===s[1];var i,s}function Vt(t,e){return Nt(t,e)&&!Wt(t)}class jt extends It{constructor(e){super(e),this.mode="circle",this.center=void 0,this.clickCount=0,this.currentCircleId=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}}close(){if(void 0===this.currentCircleId)return;const t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(t)}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=Lt({center:this.center,radiusKilometers:1e-5,coordinatePrecision:this.coordinatePrecision}),[i]=this.store.create([{geometry:e.geometry,properties:{mode:this.mode}}]);this.currentCircleId=i,this.clickCount++,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.createCircle(t),this.close()}onMouseMove(t){this.createCircle(t)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{void 0!==this.currentCircleId&&this.store.delete([this.currentCircleId])}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted()}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):i}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&Vt(t,this.coordinatePrecision)}createCircle(t){if(1===this.clickCount&&this.center&&this.currentCircleId){const e=Dt(this.center,[t.lng,t.lat]),i=Lt({center:this.center,radiusKilometers:e,coordinatePrecision:this.coordinatePrecision});this.store.updateGeometry([{id:this.currentCircleId,geometry:i.geometry}])}}}class Rt extends It{constructor(e){super(e),this.mode="freehand",this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=void 0,this.keyEvents=void 0,this.cursors=void 0,this.preventPointsNearClose=void 0;const i={start:"crosshair",close:"pointer"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.preventPointsNearClose=e&&e.preventPointsNearClose||!0,this.minDistance=e&&e.minDistance||20,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.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(void 0===this.currentId||!1===this.startingClick)return;const e=this.store.getGeometryCopy(this.currentId),[s,o]=e.coordinates[0][e.coordinates[0].length-2],{x:n,y:r}=this.project(s,o),a=i({x:n,y:r},{x:t.containerX,y:t.containerY}),[l,h]=e.coordinates[0][0],{x:c,y:d}=this.project(l,h);if(i({x:c,y:d},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.setCursor(this.cursors.start);a<this.minDistance||(e.coordinates[0].pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[...e.coordinates[0],[t.lng,t.lat],e.coordinates[0][0]]]}}]))}onClick(t){if(!1===this.startingClick){const[e,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}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);return this.currentId=e,this.closingPointId=i,this.startingClick=!0,void this.setDrawing()}this.close()}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1,"drawing"===this.state&&this.setStarted()}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):"Feature"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode?(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):i}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&Nt(t,this.coordinatePrecision)}}const Tt=Math.PI/180,Ut=180/Math.PI;class Xt{constructor(t){this.coordinatePrecision=void 0,this.coords=void 0,this.length=void 0,this.coordinatePrecision=t,this.coords=[],this.length=0}moveTo(t){this.length++,this.coords.push([e(t[0],this.coordinatePrecision),e(t[1],this.coordinatePrecision)])}}class Yt{constructor({properties:t}){this.geometries=void 0,this.properties=void 0,this.properties=t||{},this.geometries=[]}toJSON(){if(1===this.geometries.length){const t=this.geometries[0].coords;if(t[0][0]&&!isNaN(t[0][0])&&t[0][1]&&!isNaN(t[0][1]))return{geometry:{type:"LineString",coordinates:t},type:"Feature",properties:this.properties}}return null}}class zt{constructor(t,e,i){if(this.g=void 0,this.start=void 0,this.end=void 0,this.properties=void 0,!t||void 0===t[0]||void 0===t[1])throw new Error("GreatCircle constructor expects two args: start and end objects with x and y properties");if(!e||void 0===e[0]||void 0===e[1])throw new Error("GreatCircle constructor expects two args: start and end objects with x and y properties");this.start={lng:t[0],lat:t[1],x:Tt*t[0],y:Tt*t[1]},this.end={lng:e[0],lat:e[1],x:Tt*e[0],y:Tt*e[1]},this.properties=i||{};const s=this.start.x-this.end.x,o=Math.pow(Math.sin((this.start.y-this.end.y)/2),2)+Math.cos(this.start.y)*Math.cos(this.end.y)*Math.pow(Math.sin(s/2),2);if(this.g=2*Math.asin(Math.sqrt(o)),this.g===Math.PI)throw new Error(`it appears ${t} and ${e} are 'antipodal', e.g diametrically opposite, thus there is no single route but rather infinite`);if(isNaN(this.g))throw new Error(`could not calculate great circle between ${t} and ${e}`)}interpolate(t){const e=Math.sin((1-t)*this.g)/Math.sin(this.g),i=Math.sin(t*this.g)/Math.sin(this.g),s=e*Math.cos(this.start.y)*Math.cos(this.start.x)+i*Math.cos(this.end.y)*Math.cos(this.end.x),o=e*Math.cos(this.start.y)*Math.sin(this.start.x)+i*Math.cos(this.end.y)*Math.sin(this.end.x),n=e*Math.sin(this.start.y)+i*Math.sin(this.end.y),r=Ut*Math.atan2(n,Math.sqrt(Math.pow(s,2)+Math.pow(o,2)));return[Ut*Math.atan2(o,s),r]}arc(t,e){const i=[];if(!t||t<=2)i.push([this.start.lng,this.start.lat]),i.push([this.end.lng,this.end.lat]);else{const e=1/(t-1);for(let s=0;s<t;++s){const t=this.interpolate(e*s);i.push(t)}}let s=!1,o=0;const n=e&&e.offset?e.offset:10,r=180-n,a=-180+n,l=360-n;for(let t=1;t<i.length;++t){const e=i[t-1][0],n=i[t][0],h=Math.abs(n-e);h>l&&(n>r&&e<a||e>r&&n<a)?s=!0:h>o&&(o=h)}const h=[];if(s&&o<n){let t=[];h.push(t);for(let e=0;e<i.length;++e){const s=i[e][0];if(e>0&&Math.abs(s-i[e-1][0])>l){let o=i[e-1][0],n=i[e-1][1],l=i[e][0],c=i[e][1];if(o>-180&&o<a&&180===l&&e+1<i.length&&i[e-1][0]>-180&&i[e-1][0]<a){t.push([-180,i[e][1]]),e++,t.push([i[e][0],i[e][1]]);continue}if(o>r&&o<180&&-180===l&&e+1<i.length&&i[e-1][0]>r&&i[e-1][0]<180){t.push([180,i[e][1]]),e++,t.push([i[e][0],i[e][1]]);continue}if(o<a&&l>r){const t=o;o=l,l=t;const e=n;n=c,c=e}if(o>r&&l<a&&(l+=360),o<=180&&l>=180&&o<l){const s=(180-o)/(l-o),a=s*c+(1-s)*n;t.push([i[e-1][0]>r?180:-180,a]),t=[],t.push([i[e-1][0]>r?-180:180,a]),h.push(t)}else t=[],h.push(t);t.push([s,i[e][1]])}else t.push([i[e][0],i[e][1]])}}else{const t=[];h.push(t);for(let e=0;e<i.length;++e)t.push([i[e][0],i[e][1]])}const c=new Yt({properties:this.properties});for(let t=0;t<h.length;++t){const i=new Xt(e.coordinatePrecision);c.geometries.push(i);const s=h[t];for(let t=0;t<s.length;++t)i.moveTo(s[t])}return c}}class Ht{constructor({store:t,mode:e,project:i,unproject:s,pointerDistance:o,coordinatePrecision: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.store=t,this.mode=e,this.project=i,this.unproject=s,this.pointerDistance=o,this.coordinatePrecision=n}}class Jt extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinate=(t,e)=>this.getSnappableEnds(t,t=>Boolean(!t.properties||t.properties.mode!==this.mode||!e||t.id!==e)),this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappableEnds(t,e){const i=this.clickBoundingBox.create(t),s=this.store.search(i,e),o={coord:void 0,minDist:Infinity};return s.forEach(e=>{let i;if("LineString"!==e.geometry.type)return;i=e.geometry.coordinates;const s=i[0],n=this.pixelDistance.measure(t,s);n<o.minDist&&n<this.pointerDistance&&(o.coord=s);const r=i[i.length-1],a=this.pixelDistance.measure(t,r);a<o.minDist&&a<this.pointerDistance&&(o.coord=r)}),o.coord}}class Kt extends Ht{constructor(t){super(t)}measure(t,e){const{x:s,y:o}=this.project(e[0],e[1]);return i({x:s,y:o},{x:t.containerX,y:t.containerY})}}function $t({unproject:t,point:e,pointerDistance:i}){const s=i/2,{x:o,y:n}=e;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[t(o-s,n-s),t(o+s,n-s),t(o+s,n+s),t(o-s,n+s),t(o-s,n-s)].map(t=>[t.lng,t.lat])]}}}class qt extends Ht{constructor(t){super(t)}create(t){const{containerX:e,containerY:i}=t;return $t({unproject:this.unproject,point:{x:e,y:i},pointerDistance:this.pointerDistance})}}class Zt extends It{constructor(e){super(e),this.mode="greatcircle",this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.cursors=void 0,this.snapping=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}}close(){if(void 0===this.currentId)return;const t=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t)}registerBehaviors(t){this.snapping=new Jt(t,new Kt(t),new qt(t))}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(this.setCursor(this.cursors.start),(void 0!==this.currentId||0!==this.currentCoordinate)&&this.currentId&&1===this.currentCoordinate&&this.closingPointId){const e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];this.store.updateGeometry([{id:this.closingPointId,geometry:{type:"Point",coordinates:e}}]);const i=this.store.getGeometryCopy(this.currentId);i.coordinates.pop();const s=function({start:t,end:e,options:i}){const s=i||{};if("object"!=typeof s)throw new Error("options argument is invalid, must be of type object");const{properties:o={},numberOfPoints:n=100,offset:r=10,coordinatePrecision:a=9}=s;return new zt(t,e,o).arc(n,{offset:r,coordinatePrecision:a}).toJSON()}({start:i.coordinates[0],end:e,options:{coordinatePrecision:this.coordinatePrecision}});s&&this.store.updateGeometry([{id:this.currentId,geometry:s.geometry}])}}onClick(t){if(0===this.currentCoordinate){const e=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t)||[t.lng,t.lat],[i]=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=i;const[s]=this.store.create([{geometry:{type:"Point",coordinates:e},properties:{mode:this.mode}}]);this.closingPointId=s,this.currentCoordinate++,this.setDrawing()}else 1===this.currentCoordinate&&this.currentId&&(this.setCursor("pointer"),this.close())}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}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):"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):i}validateFeature(t){return!!super.validateFeature(t)&&"LineString"===t.geometry.type&&t.properties.mode===this.mode&&t.geometry.coordinates.length>=2}}class Qt extends Ht{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),s=this.store.search(i,e),o={coord:void 0,minDist:Infinity};return s.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<o.minDist&&i<this.pointerDistance&&(o.coord=e)})}),o.coord}}class te extends It{constructor(e){super(e),this.mode="linestring",this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.allowSelfIntersections=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.cursors=void 0,this.mouseMove=!1,this.snapping=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,this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,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);t.coordinates.pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[...t.coordinates]}}]);const e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e)}registerBehaviors(t){this.snapping=new Qt(t,new Kt(t),new qt(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);e.coordinates.pop();const s=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(this.closingPointId){const[s,o]=e.coordinates[e.coordinates.length-1],{x:n,y:r}=this.project(s,o);i({x:n,y:r},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[...e.coordinates,s]}}])}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];if(0===this.currentCoordinate){const[t]=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=t,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const t=this.store.getGeometryCopy(this.currentId),[i]=this.store.create([{geometry:{type:"Point",coordinates:[...e]},properties:{mode:this.mode}}]);this.closingPointId=i,this.setCursor(this.cursors.close),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[t.coordinates[0],e,e]}}]),this.currentCoordinate++}else if(this.currentId){const s=this.store.getGeometryCopy(this.currentId),[o,n]=s.coordinates[s.coordinates.length-2],{x:r,y:a}=this.project(o,n);if(i({x:r,y:a},{x:t.containerX,y:t.containerY})<this.pointerDistance)this.close();else{const t={type:"LineString",coordinates:[...s.coordinates,e]};if(!this.allowSelfIntersections&&Wt({type:"Feature",geometry:t,properties:{}}))return;this.closingPointId&&(this.setCursor(this.cursors.close),this.store.updateGeometry([{id:this.currentId,geometry:t},{id:this.closingPointId,geometry:{type:"Point",coordinates:s.coordinates[s.coordinates.length-1]}}]),this.currentCoordinate++)}}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}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):"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):i}validateFeature(t){return!!super.validateFeature(t)&&"LineString"===t.geometry.type&&t.properties.mode===this.mode&&t.geometry.coordinates.length>=2}}function ee(t,e){return"Point"===t.geometry.type&&Gt(t.geometry.coordinates,e)}class ie extends It{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]=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.onFinish(e)}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}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&ee(t,this.coordinatePrecision)}}function se(t,e){return t[0]===e[0]&&t[1]===e[1]}class oe extends Ht{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 creating");if(t.length<=3)throw new Error("Requires at least 4 cooridnates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:{mode:e,[Et]:!0}},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:{mode:e,[Et]:!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]),s=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:s<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}}}class ne extends It{constructor(e){super(e),this.mode="polygon",this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=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,this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,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;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[...t.slice(0,-2),t[0]]]}}]);const e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e)}registerBehaviors(t){this.pixelDistance=new Kt(t),this.snapping=new Qt(t,this.pixelDistance,new qt(t)),this.closingPoints=new oe(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 s;if(e&&(t.lng=e[0],t.lat=e[1]),1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),o=Math.max(1e-6,e);s=[i[0],[t.lng,t.lat],[t.lng,t.lat-o],i[0]]}else if(2===this.currentCoordinate)s=[i[0],i[1],[t.lng,t.lat],i[0]];else{const{isClosing:e,isPreviousClosing:o}=this.closingPoints.isClosingPoint(t);o||e?(this.setCursor(this.cursors.close),s=[...i.slice(0,-2),i[0],i[0]]):s=[...i.slice(0,-2),[t.lng,t.lat],i[0]]}this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[s]}}])}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(se([t.lng,t.lat],i.coordinates[0][0]))return;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]]]}}]),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(se([t.lng,t.lat],i[1]))return;2===this.currentCoordinate&&this.closingPoints.create(i,"polygon"),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[i[0],i[1],[t.lng,t.lat],[t.lng,t.lat],i[0]]]}}]),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:s,isPreviousClosing:o}=this.closingPoints.isClosingPoint(t);if(o||s)this.close();else{if(e&&(t.lng=e[0],t.lat=e[1]),se([t.lng,t.lat],i[this.currentCoordinate-1]))return;const s=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.currentCoordinate>2&&!this.allowSelfIntersections&&Wt(s))return;this.store.updateGeometry([{id:this.currentId,geometry:s.geometry}]),this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(s.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(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}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&&Nt(t,this.coordinatePrecision)}}class re extends It{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){if(1===this.clickCount&&this.center&&this.currentRectangleId){const e=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0];this.store.updateGeometry([{id:this.currentRectangleId,geometry:{type:"Polygon",coordinates:[[e,[t.lng,e[1]],[t.lng,t.lat],[e[0],t.lat],e]]}}])}}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)}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),this.close()}onMouseMove(t){this.updateRectangle(t)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){this.currentRectangleId&&this.store.delete([this.currentRectangleId]),this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted()}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):i}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&Vt(t,this.coordinatePrecision)}}class ae extends It{constructor(t){super({styles:t.styles}),this.type=Mt.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)&&(ee(t,this.coordinatePrecision)||Nt(t,this.coordinatePrecision)||function(t,e){return"LineString"===t.geometry.type&&t.geometry.coordinates.length>=2&&t.geometry.coordinates.every(t=>Gt(t,e))}(t,this.coordinatePrecision))}}function le(t,i,s,o,n){const r=o(t[0],t[1]),a=o(i[0],i[1]),{lng:l,lat:h}=n((r.x+a.x)/2,(r.y+a.y)/2);return[e(l,s),e(h,s)]}function he(t,e,i,s){const o=[];for(let n=0;n<t.length-1;n++){const r=le(t[n],t[n+1],e,i,s);o.push(r)}return o}class ce extends Ht{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:s,midPointSegment:o}=this.store.getPropertiesCopy(t),n=this.store.getGeometryCopy(s),r="Polygon"===n.type?n.coordinates[0]:n.coordinates;r.splice(o+1,0,i.coordinates),n.coordinates="Polygon"===n.type?[r]:r,this.store.updateGeometry([{id:s,geometry:n}]),this.store.delete([...this._midPoints,...this.selectionPointBehavior.ids]),this.create(r,s,e),this.selectionPointBehavior.create(r,n.type,s)}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,s,o){return he(t,i,s,o).map((t,i)=>({geometry:{type:"Point",coordinates:t},properties:e(i)}))}(t,t=>({mode:this.mode,[xt]:!0,midPointSegment:t,midPointFeatureId:e}),i,this.config.project,this.config.unproject))}delete(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])}getUpdated(t){if(0!==this._midPoints.length)return he(t,this.coordinatePrecision,this.config.project,this.config.unproject).map((t,e)=>({id:this._midPoints[e],geometry:{type:"Point",coordinates:t}}))}}class de extends Ht{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 s=[],o="Polygon"===e?t.length-1:t.length;for(let e=0;e<o;e++)s.push({geometry:{type:"Point",coordinates:t[e]},properties:i(e)});return s}(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 ge(t,e){let i=!1;for(let r=0,a=e.length;r<a;r++){const a=e[r];for(let e=0,r=a.length,l=r-1;e<r;l=e++)(o=a[e])[1]>(s=t)[1]!=(n=a[l])[1]>s[1]&&s[0]<(n[0]-o[0])*(s[1]-o[1])/(n[1]-o[1])+o[0]&&(i=!i)}var s,o,n;return i}const ue=(t,e,i)=>{const s=t=>t*t,o=(t,e)=>s(t.x-e.x)+s(t.y-e.y);return Math.sqrt(((t,e,i)=>{const s=o(e,i);if(0===s)return o(t,e);let n=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/s;return n=Math.max(0,Math.min(1,n)),o(t,{x:e.x+n*(i.x-e.x),y:e.y+n*(i.y-e.y)})})(t,e,i))};class pe extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=t,this.createClickBoundingBox=e,this.pixelDistance=i}find(t,e){let i,s,o=Infinity,n=Infinity;const r=this.createClickBoundingBox.create(t),a=this.store.search(r);for(let r=0;r<a.length;r++){const l=a[r],h=l.geometry;if("Point"===h.type){if(l.properties.selectionPoint||!e&&l.properties[xt])continue;const r=this.pixelDistance.measure(t,h.coordinates);l.properties[xt]&&r<this.pointerDistance&&r<n?(n=r,s=l):!l.properties[xt]&&r<this.pointerDistance&&r<o&&(o=r,i=l)}else if("LineString"===h.type)for(let e=0;e<h.coordinates.length-1;e++){const s=h.coordinates[e],n=h.coordinates[e+1],r=ue({x:t.containerX,y:t.containerY},this.project(s[0],s[1]),this.project(n[0],n[1]));r<this.pointerDistance&&r<o&&(o=r,i=l)}else"Polygon"===h.type&&ge([t.lng,t.lat],h.coordinates)&&(o=0,i=l)}return{clickedFeature:i,clickedMidPoint:s}}}class ye extends Ht{constructor(t,e,i,s){super(t),this.config=void 0,this.featuresAtMouseEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=t,this.featuresAtMouseEvent=e,this.selectionPoints=i,this.midPoints=s}startDragging(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return null!==this.draggedFeatureId}canDrag(t,e){const{clickedFeature:i}=this.featuresAtMouseEvent.find(t,!0);return!(!i||i.id!==e)}drag(t){if(!this.draggedFeatureId)return;const i=this.store.getGeometryCopy(this.draggedFeatureId),s=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){let o,n;if("Polygon"===i.type?(o=i.coordinates[0],n=o.length-1):(o=i.coordinates,n=o.length),!this.dragPosition)return!1;for(let t=0;t<n;t++){const i=o[t],n=[this.dragPosition[0]-s[0],this.dragPosition[1]-s[1]],r=e(i[0]-n[0],this.config.coordinatePrecision),a=e(i[1]-n[1],this.config.coordinatePrecision);if(r>180||r<-180||a>90||a<-90)return!1;o[t]=[r,a]}"Polygon"===i.type&&(o[o.length-1]=[o[0][0],o[0][1]]);const r=this.selectionPoints.getUpdated(o)||[],a=this.midPoints.getUpdated(o)||[];this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i},...r,...a]),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:s}}]),this.dragPosition=[t.lng,t.lat])}}class me extends Ht{constructor(t,e,i,s){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedCoordinate={id:null,index:-1},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=s}getClosestCoordinate(t,e){const i={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};let s;if("LineString"===e.type)s=e.coordinates;else{if("Polygon"!==e.type)return i;s=e.coordinates[0]}for(let o=0;o<s.length;o++){const n=this.pixelDistance.measure(t,s[o]);if(n<this.pointerDistance&&n<i.dist){const t="Polygon"===e.type&&(o===s.length-1||0===o);i.dist=n,i.index=t?0:o,i.isFirstOrLastPolygonCoord=t}}return i}getDraggableIndex(t,e){const i=this.store.getGeometryCopy(e),s=this.getClosestCoordinate(t,i);return-1===s.index?-1:s.index}drag(t,e){if(!this.draggedCoordinate.id)return!1;const i=this.draggedCoordinate.index,s=this.store.getGeometryCopy(this.draggedCoordinate.id),o="LineString"===s.type?s.coordinates:s.coordinates[0],n=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==s.type||i!==o.length-1&&0!==i)o[i]=n;else{const t=o.length-1;o[0]=n,o[t]=n}const r=this.selectionPoints.getOneUpdated(i,n),a=r?[r]:[],l=this.midPoints.getUpdated(o)||[];return!("Point"!==s.type&&!e&&Wt({type:"Feature",geometry:s,properties:{}})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:s},...a,...l]),0))}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}}function fe(t){let e=0,i=0,s=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(t=>{e+=t[0],i+=t[1],s++},!0),[e/s,i/s]}function ve(t,e){const i=t,s=e,o=kt(i[1]),n=kt(s[1]);let r=kt(s[0]-i[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);const a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=(Ot(Math.atan2(r,a))+360)%360;return l>180?-(360-l):l}function _e(t,e,i){let s=e;e<0&&(s=-Math.abs(s));const o=s/6371008.8,n=t[0]*Math.PI/180,r=kt(t[1]),a=kt(i),l=o*Math.cos(a);let h=r+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(r/2+Math.PI/4)),d=Math.abs(c)>1e-11?l/c:Math.cos(r),g=[(180*(n+o*Math.sin(a)/d)/Math.PI+540)%360-180,180*h/Math.PI];return g[0]+=g[0]-t[0]>180?-360:t[0]-g[0]>180?360:0,g}function Ce(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;const i=e[1]*Math.PI/180,s=t[1]*Math.PI/180,o=s-i;let n=Math.abs(t[0]-e[0])*Math.PI/180;n>Math.PI&&(n-=2*Math.PI);const r=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(r)>1e-11?o/r:Math.cos(i);return 6371008.8*Math.sqrt(o*o+a*a*n*n)}class Pe extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastBearing=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastBearing=void 0}rotate(t,i){const s=this.store.getGeometryCopy(i);if("Polygon"!==s.type&&"LineString"!==s.type)return;const o=[t.lng,t.lat],n=ve(fe({type:"Feature",geometry:s,properties:{}}),o);if(!this.lastBearing)return void(this.lastBearing=n+180);!function(t,e){if(0===e)return t;const i=fe(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const s=ve(i,t)+e,o=Ce(i,t),n=_e(i,o,s);t[0]=n[0],t[1]=n[1]})}({type:"Feature",geometry:s,properties:{}},-(this.lastBearing-(n+180)));const r="Polygon"===s.type?s.coordinates[0]:s.coordinates;r.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const a=this.midPoints.getUpdated(r)||[],l=this.selectionPoints.getUpdated(r)||[];this.store.updateGeometry([{id:i,geometry:s},...l,...a]),this.lastBearing=n+180}}function Se(t,e,i){return 1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const s=Ce(i,t),o=ve(i,t),n=_e(i,s*e,o);t[0]=n[0],t[1]=n[1]}),t}class xe extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastDistance=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastDistance=void 0}scale(t,i){const s=this.store.getGeometryCopy(i);if("Polygon"!==s.type&&"LineString"!==s.type)return;const o=[t.lng,t.lat],n=Dt(fe({type:"Feature",geometry:s,properties:{}}),o);if(!this.lastDistance)return void(this.lastDistance=n);const r={type:"Feature",geometry:s,properties:{}};Se(r,1-(this.lastDistance-n)/n,fe(r));const a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const l=this.midPoints.getUpdated(a)||[],h=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:i,geometry:s},...h,...l]),this.lastDistance=n}}class Ee extends Ht{constructor(t,e,i,s){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedCoordinate={id:null,index:-1},this.lastDistance=void 0,this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=s}getClosestCoordinate(t,e){const i={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};let s;if("LineString"===e.type)s=e.coordinates;else{if("Polygon"!==e.type)return i;s=e.coordinates[0]}for(let o=0;o<s.length;o++){const n=this.pixelDistance.measure(t,s[o]);if(n<this.pointerDistance&&n<i.dist){const t="Polygon"===e.type&&(o===s.length-1||0===o);i.dist=n,i.index=t?0:o,i.isFirstOrLastPolygonCoord=t}}return i}getDraggableIndex(t,e){const i=this.store.getGeometryCopy(e),s=this.getClosestCoordinate(t,i);return-1===s.index?-1:s.index}drag(t,i){if(!this.draggedCoordinate.id)return!1;const s=this.draggedCoordinate.index,o=this.store.getGeometryCopy(this.draggedCoordinate.id);if("Polygon"!==o.type&&"LineString"!==o.type)return!1;const n=[t.lng,t.lat],r="Polygon"===o.type?o.coordinates[0]:o.coordinates,a=r[s],l={type:"Feature",geometry:o,properties:{}};let h;"center"===i?h=this.getCenterOrigin(l):"opposite"===i&&(h=this.getOppositeOrigin(l,a));const c=Dt(h,n);if(!this.lastDistance)return this.lastDistance=c,!1;Se(l,1-(this.lastDistance-c)/c,h),r.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const d=this.midPoints.getUpdated(r)||[],g=this.selectionPoints.getUpdated(r)||[];return this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:o},...g,...d]),this.lastDistance=c,!0}getCenterOrigin(t){return fe(t)}getOppositeOrigin(t,e){const i=[Infinity,Infinity,-Infinity,-Infinity];("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{i[0]>t[0]&&(i[0]=t[0]),i[1]>t[1]&&(i[1]=t[1]),i[2]<t[0]&&(i[2]=t[0]),i[3]<t[1]&&(i[3]=t[1])});const[s,o,n,r]=i,a=[[s,r],[(s+n)/2,r],[n,r],[n,(o+r)/2],[n,o],[(s+n)/2,o],[s,o],[s,(o+r)/2]];let l,h=Infinity;for(let t=0;t<a.length;t++){const i=Dt(e,a[t]);i<h&&(l=t,h=i)}return a[{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}[l]]}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.lastDistance=void 0,this.draggedCoordinate={id:null,index:-1}}}class we extends It{constructor(e){super(e),this.type=Mt.Select,this.mode="select",this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags=void 0,this.keyEvents=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.maintainShape=void 0,this.cursors=void 0,this.flags=e&&e.flags?e.flags:{};const i={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,null===(null==e?void 0:e.keyEvents))this.keyEvents={deselect:null,delete:null,rotate:null,scale:null};else{const i={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5}setSelecting(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"}registerBehaviors(t){this.pixelDistance=new Kt(t),this.clickBoundingBox=new qt(t),this.featuresAtMouseEvent=new pe(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new de(t),this.midPoints=new ce(t,this.selectionPoints),this.rotateFeature=new Pe(t,this.selectionPoints,this.midPoints),this.scaleFeature=new xe(t,this.selectionPoints,this.midPoints),this.dragFeature=new ye(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new me(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.maintainShape=new Ee(t,this.pixelDistance,this.selectionPoints,this.midPoints)}deselect(){const t=this.selected.filter(t=>this.store.has(t)).map(t=>({id:t,property:St,value:!1}));this.store.updateProperty(t),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()}deleteSelected(){this.store.delete(this.selected),this.selected=[]}onRightClick(t){if(!this.selectionPoints.ids.length)return;let e,i=Infinity;if(this.selectionPoints.ids.forEach(s=>{const o=this.store.getGeometryCopy(s),n=this.pixelDistance.measure(t,o.coordinates);n<this.pointerDistance&&n<i&&(i=n,e=this.store.getPropertiesCopy(s))}),!e)return;const s=e.selectionPointFeatureId,o=e.index,n=this.store.getPropertiesCopy(s),r=this.flags[n.mode];if(!(r&&r.feature&&r.feature.coordinates&&r.feature.coordinates.deletable))return;const a=this.store.getGeometryCopy(s);let l;if("Polygon"===a.type){if(l=a.coordinates[0],l.length<=4)return}else if("LineString"===a.type&&(l=a.coordinates,l.length<=3))return;l&&("Polygon"===a.type&&0===o||o===l.length-1?(l.shift(),l.pop(),l.push([l[0][0],l[0][1]])):l.splice(o,1),this.store.delete([...this.midPoints.ids,...this.selectionPoints.ids]),this.store.updateGeometry([{id:s,geometry:a}]),this.selectionPoints.create(l,a.type,s),r&&r.feature&&r.feature.coordinates&&r.feature.coordinates.midpoints&&this.midPoints.create(l,s,this.coordinatePrecision))}onLeftClick(t){const{clickedFeature:e,clickedMidPoint:i}=this.featuresAtMouseEvent.find(t,this.selected.length>0);if(this.selected.length&&i)this.midPoints.insert(i.id,this.coordinatePrecision);else if(e){const{mode:t}=this.store.getPropertiesCopy(e.id),i=this.flags[t];if(!i||!i.feature)return;const s=this.selected[0];if(s){if(s===e.id)return;this.deselect()}this.setCursor(this.cursors.pointerOver),this.selected=[e.id],this.store.updateProperty([{id:e.id,property:"selected",value:!0}]),this.onSelect(e.id);const{type:o,coordinates:n}=this.store.getGeometryCopy(e.id);if("LineString"!==o&&"Polygon"!==o)return;const r="LineString"===o?n:n[0];r&&i&&i.feature.coordinates&&(this.selectionPoints.create(r,o,e.id),i.feature.coordinates.midpoints&&this.midPoints.create(r,e.id,this.coordinatePrecision))}else if(this.selected.length)return void this.deselect()}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)}canScale(t){return this.keyEvents.scale&&this.keyEvents.scale.every(e=>t.heldKeys.includes(e))}canRotate(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(e=>t.heldKeys.includes(e))}preventDefaultKeyEvent(t){const e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()}onKeyDown(t){this.preventDefaultKeyEvent(t)}onKeyUp(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect()}onDragStart(t,e){if(!this.selected.length)return;const i=this.store.getPropertiesCopy(this.selected[0]),s=this.flags[i.mode];if(!(s&&s.feature&&(s.feature.draggable||s.feature.coordinates&&s.feature.coordinates.draggable)))return;this.dragEventCount=0;const o=this.selected[0],n=this.dragCoordinate.getDraggableIndex(t,o);return s&&s.feature&&s.feature.coordinates&&s.feature.coordinates.draggable&&-1!==n?(this.setCursor(this.cursors.dragStart),s.feature.coordinates.maintainShapeFrom?this.maintainShape.startDragging(o,n):this.dragCoordinate.startDragging(o,n),void e(!1)):s&&s.feature&&s.feature.draggable&&this.dragFeature.canDrag(t,o)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,o),void e(!1)):void 0}onDrag(t,e){const i=this.selected[0];if(!i)return;const s=this.store.getPropertiesCopy(i),o=this.flags[s.mode],n=!0===(o&&o.feature&&o.feature.selfIntersectable);return this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0?o&&o.feature&&o.feature.rotateable&&this.canRotate(t)?(e(!1),void this.rotateFeature.rotate(t,i)):o&&o.feature&&o.feature.scaleable&&this.canScale(t)?(e(!1),void this.scaleFeature.scale(t,i)):this.maintainShape.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.maintainShapeFrom?(e(!1),void this.maintainShape.drag(t,o.feature.coordinates.maintainShapeFrom)):void(this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,n):this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)):void 0}onDragEnd(t,e){this.setCursor(this.cursors.dragEnd),(this.dragCoordinate.isDragging()||this.dragFeature.isDragging())&&this.onFinish(this.selected[0]),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.maintainShape.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)}onMouseMove(t){if(!this.selected.length)return void this.setCursor("unset");if(this.dragFeature.isDragging())return;let e=!1;this.midPoints.ids.forEach(i=>{if(e)return;const s=this.store.getGeometryCopy(i);this.pixelDistance.measure(t,s.coordinates)<this.pointerDistance&&(e=!0)});let i=!1;if(this.selectionPoints.ids.forEach(s=>{const o=this.store.getGeometryCopy(s);this.pixelDistance.measure(t,o.coordinates)<this.pointerDistance&&(e=!1,i=!0)}),e)return void this.setCursor(this.cursors.insertMidpoint);const{clickedFeature:s}=this.featuresAtMouseEvent.find(t,!0);this.setCursor(this.selected.length>0&&(s&&s.id===this.selected[0]||i)?this.cursors.pointerOver:"unset")}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&&"Point"===e.geometry.type){if(e.properties.selectionPoint)return i.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,i.pointOutlineColor,e),i.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,i.pointWidth,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,e),i.zIndex=30,i;if(e.properties.midPoint)return i.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,i.pointOutlineColor,e),i.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,e),i.zIndex=40,i}else if(e.properties[St]){if("Polygon"===e.geometry.type)return i.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,i.polygonFillColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,i.polygonOutlineWidth,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,i.polygonOutlineColor,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i;if("LineString"===e.geometry.type)return i.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,i.lineStringColor,e),i.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,i.lineStringWidth,e),i.zIndex=10,i;if("Point"===e.geometry.type)return i.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,i.pointOutlineWidth,e),i.zIndex=10,i}return i}}class be extends It{constructor(...t){super(...t),this.type=Mt.Static,this.mode="static"}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0})}}function Me(t,e,i,s,o){for(;s>i;){if(s-i>600){const n=s-i+1,r=e-i+1,a=Math.log(n),l=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*l*(n-l)/n)*(r-n/2<0?-1:1);Me(t,e,Math.max(i,Math.floor(e-r*l/n+h)),Math.min(s,Math.floor(e+(n-r)*l/n+h)),o)}const n=t[e];let r=i,a=s;for(Ie(t,i,e),o(t[s],n)>0&&Ie(t,i,s);r<a;){for(Ie(t,r,a),r++,a--;o(t[r],n)<0;)r++;for(;o(t[a],n)>0;)a--}0===o(t[i],n)?Ie(t,i,a):(a++,Ie(t,a,s)),a<=e&&(i=a+1),e<=a&&(s=a-1)}}function Ie(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}function De(t,e){ke(t,0,t.children.length,e,t)}function ke(t,e,i,s,o){o||(o=Ve([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(let n=e;n<i;n++){const e=t.children[n];Oe(o,t.leaf?s(e):e)}return o}function Oe(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Fe(t,e){return t.minX-e.minX}function Le(t,e){return t.minY-e.minY}function We(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Ae(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Ge(t,e){const i=Math.max(t.minX,e.minX),s=Math.max(t.minY,e.minY),o=Math.min(t.maxX,e.maxX),n=Math.min(t.maxY,e.maxY);return Math.max(0,o-i)*Math.max(0,n-s)}function Be(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Ne(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Ve(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function je(t,e,i,s,o){const n=[e,i];for(;n.length;){if((i=n.pop())-(e=n.pop())<=s)continue;const r=e+Math.ceil((i-e)/s/2)*s;Me(t,r,e,i,o),n.push(e,r,r,i)}}class Re{constructor(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(t){let e=this.data;const i=[];if(!Ne(t,e))return i;const s=this.toBBox,o=[];for(;e;){for(let n=0;n<e.children.length;n++){const r=e.children[n],a=e.leaf?s(r):r;Ne(t,a)&&(e.leaf?i.push(r):Be(t,a)?this._all(r,i):o.push(r))}e=o.pop()}return i}collides(t){let e=this.data;if(Ne(t,e)){const i=[];for(;e;){for(let s=0;s<e.children.length;s++){const o=e.children[s],n=e.leaf?this.toBBox(o):o;if(Ne(t,n)){if(e.leaf||Be(t,n))return!0;i.push(o)}}e=i.pop()}}return!1}load(t){if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e}insert(t){this._insert(t,this.data.height-1)}clear(){this.data=Ve([])}remove(t){let e=this.data;const i=this.toBBox(t),s=[],o=[];let n,r,a=!1;for(;e||s.length;){if(e||(e=s.pop(),r=s[s.length-1],n=o.pop(),a=!0),e.leaf){const i=e.children.indexOf(t);-1!==i&&(e.children.splice(i,1),s.push(e),this._condense(s))}a||e.leaf||!Be(e,i)?r?(n++,e=r.children[n],a=!1):e=null:(s.push(e),o.push(n),n=0,r=e,e=e.children[0])}}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,s){const o=i-e+1;let n,r=this._maxEntries;if(o<=r)return n=Ve(t.slice(e,i+1)),De(n,this.toBBox),n;s||(s=Math.ceil(Math.log(o)/Math.log(r)),r=Math.ceil(o/Math.pow(r,s-1))),n=Ve([]),n.leaf=!1,n.height=s;const a=Math.ceil(o/r),l=a*Math.ceil(Math.sqrt(r));je(t,e,i,l,this.compareMinX);for(let o=e;o<=i;o+=l){const e=Math.min(o+l-1,i);je(t,o,e,a,this.compareMinY);for(let i=o;i<=e;i+=a){const o=Math.min(i+a-1,e);n.children.push(this._build(t,i,o,s-1))}}return De(n,this.toBBox),n}_chooseSubtree(t,e,i,s){for(;s.push(e),!e.leaf&&s.length-1!==i;){let i,s=Infinity,r=Infinity;for(let a=0;a<e.children.length;a++){const l=e.children[a],h=We(l),c=(o=t,n=l,(Math.max(n.maxX,o.maxX)-Math.min(n.minX,o.minX))*(Math.max(n.maxY,o.maxY)-Math.min(n.minY,o.minY))-h);c<r?(r=c,s=h<s?h:s,i=l):c===r&&h<s&&(s=h,i=l)}e=i||e.children[0]}var o,n;return e}_insert(t,e,i){const s=i?t:this.toBBox(t),o=[],n=this._chooseSubtree(s,this.data,e,o);for(n.children.push(t),Oe(n,s);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(s,o,e)}_split(t,e){const i=t[e],s=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,s);const n=this._chooseSplitIndex(i,o,s),r=Ve(i.children.splice(n,i.children.length-n));r.height=i.height,r.leaf=i.leaf,De(i,this.toBBox),De(r,this.toBBox),e?t[e-1].children.push(r):this._splitRoot(i,r)}_splitRoot(t,e){this.data=Ve([t,e]),this.data.height=t.height+1,this.data.leaf=!1,De(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let s,o=Infinity,n=Infinity;for(let r=e;r<=i-e;r++){const e=ke(t,0,r,this.toBBox),a=ke(t,r,i,this.toBBox),l=Ge(e,a),h=We(e)+We(a);l<o?(o=l,s=r,n=h<n?h:n):l===o&&h<n&&(n=h,s=r)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:Fe,o=t.leaf?this.compareMinY:Le;this._allDistMargin(t,e,i,s)<this._allDistMargin(t,e,i,o)&&t.children.sort(s)}_allDistMargin(t,e,i,s){t.children.sort(s);const o=this.toBBox,n=ke(t,0,e,o),r=ke(t,i-e,i,o);let a=Ae(n)+Ae(r);for(let s=e;s<i-e;s++){const e=t.children[s];Oe(n,t.leaf?o(e):e),a+=Ae(n)}for(let s=i-e-1;s>=e;s--){const e=t.children[s];Oe(r,t.leaf?o(e):e),a+=Ae(r)}return a}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)Oe(e[s],t)}_condense(t){for(let e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children,e.splice(e.indexOf(t[i]),1)):this.clear():De(t[i],this.toBBox)}}class Te{constructor(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Re(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)}toBBox(t){const e=[],i=[];let s;if("Polygon"===t.geometry.type)s=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)s=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");s=[t.geometry.coordinates]}for(let t=0;t<s.length;t++)i.push(s[t][1]),e.push(s[t][0]);const o=Math.min(...i),n=Math.max(...i);return{minX:Math.min(...e),minY:o,maxX:Math.max(...e),maxY:n}}insert(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}load(t){const e=[],i=new Set;t.forEach(t=>{const s=this.toBBox(t);if(this.setMaps(t,s),i.has(String(t.id)))throw new Error(`Duplicate feature ID found ${t.id}`);i.add(String(t.id)),e.push(s)}),this.tree.load(e)}update(t){this.remove(t.id);const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}remove(t){const e=this.idToNode.get(t);if(!e)throw new Error(`${t} not inserted into the spatial index`);this.tree.remove(e)}clear(){this.tree.clear()}search(t){return this.tree.search(this.toBBox(t)).map(t=>this.nodeToId.get(t))}collides(t){return this.tree.collides(this.toBBox(t))}}const Ue={getId:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}),isValidId:t=>"string"==typeof t&&36===t.length};class Xe{constructor(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new Te,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ue}clone(t){return JSON.parse(JSON.stringify(t))}getId(){return this.idStrategy.getId()}has(t){return Boolean(this.store[t])}load(t,e){if(0===t.length)return;const i=this.clone(t);i.forEach(t=>{null==t.id&&(t.id=this.idStrategy.getId()),this.tracked&&(t.properties.createdAt?bt(t.properties.createdAt):t.properties.createdAt=+new Date,t.properties.updatedAt?bt(t.properties.updatedAt):t.properties.updatedAt=+new Date)});const s=[];i.forEach(t=>{const i=t.id;if(e&&!e(t))throw new Error(`Feature is not ${i} valid: ${JSON.stringify(t)}`);if(this.has(i))throw new Error(`Feature already exists with this id: ${i}`);this.store[i]=t,s.push(i)}),this.spatialIndex.load(i),this._onChange(s,"create")}search(t,e){const i=this.spatialIndex.search(t).map(t=>this.store[t]);return this.clone(e?i.filter(e):i)}registerOnChange(t){this._onChange=(e,i)=>{t(e,i)}}getGeometryCopy(t){const e=this.store[t];if(!e)throw new Error(`No feature with this id (${t}), can not get geometry copy`);return this.clone(e.geometry)}getPropertiesCopy(t){const e=this.store[t];if(!e)throw new Error(`No feature with this id (${t}), can not get properties copy`);return this.clone(e.properties)}updateProperty(t){const e=[];t.forEach(({id:t,property:i,value:s})=>{const o=this.store[t];if(!o)throw new Error(`No feature with this (${t}), can not update geometry`);e.push(t),o.properties[i]=s,this.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,"update")}updateGeometry(t){const e=[];t.forEach(({id:t,geometry:i})=>{e.push(t);const s=this.store[t];if(!s)throw new Error(`No feature with this (${t}), can not update geometry`);s.geometry=this.clone(i),this.spatialIndex.update(s),this.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,"update")}create(e){const i=[];return e.forEach(({geometry:e,properties:s})=>{let o,n=t({},s);this.tracked&&(o=+new Date,s?(n.createdAt="number"==typeof s.createdAt?s.createdAt:o,n.updatedAt="number"==typeof s.updatedAt?s.updatedAt:o):n={createdAt:o,updatedAt:o});const r=this.getId(),a={id:r,type:"Feature",geometry:e,properties:n};this.store[r]=a,this.spatialIndex.insert(a),i.push(r)}),this._onChange&&this._onChange([...i],"create"),i}delete(t){t.forEach(t=>{if(!this.store[t])throw new Error("No feature with this id, can not delete");delete this.store[t],this.spatialIndex.remove(t)}),this._onChange&&this._onChange([...t],"delete")}copyAll(){return this.clone(Object.keys(this.store).map(t=>this.store[t]))}clear(){this.store={},this.spatialIndex.clear()}size(){return Object.keys(this.store).length}}class Ye{constructor(e){this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectMode=void 0,this._adapter=e.adapter,this._mode=new be;const i=new Set,s=e.modes.reduce((t,e)=>{if(i.has(e.mode))throw new Error(`There is already a ${e.mode} mode provided`);return i.add(e.mode),t[e.mode]=e,t},{}),o=Object.keys(s);if(0===o.length)throw new Error("No modes provided");o.forEach(t=>{if(s[t].type===Mt.Select){if(this._instanceSelectMode)throw new Error("only one type of select mode can be provided");this._instanceSelectMode=t}}),this._modes=t({},s,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[]},this._store=new Xe({tracked:!!e.tracked,idStrategy:e.idStrategy?e.idStrategy:void 0});const n=t=>{const e=[],i=this._store.copyAll().filter(i=>!t.includes(i.id)||(e.push(i),!1));return{changed:e,unchanged:i}},r=t=>{this._enabled&&this._eventListeners.finish.forEach(e=>{e(t)})},a=(t,e)=>{if(!this._enabled)return;this._eventListeners.change.forEach(i=>{i(t,e)});const{changed:i,unchanged:s}=n(t);"create"===e?this._adapter.render({created:i,deletedIds:[],unchanged:s,updated:[]},this.getModeStyles()):"update"===e?this._adapter.render({created:[],deletedIds:[],unchanged:s,updated:i},this.getModeStyles()):"delete"===e?this._adapter.render({created:[],deletedIds:t,unchanged:s,updated:[]},this.getModeStyles()):"styling"===e&&this._adapter.render({created:[],deletedIds:[],unchanged:s,updated:[]},this.getModeStyles())},l=t=>{if(!this._enabled)return;this._eventListeners.select.forEach(e=>{e(t)});const{changed:e,unchanged:i}=n([t]);this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())},h=t=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t()});const{changed:e,unchanged:i}=n([t]);e&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())};Object.keys(this._modes).forEach(t=>{this._modes[t].register({mode:t,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:a,onSelect:l,onDeselect:h,onFinish:r,coordinatePrecision:this._adapter.getCoordinatePrecision()})})}checkEnabled(){if(!this._enabled)throw new Error("Terra Draw is not enabled")}getModeStyles(){const t={};return Object.keys(this._modes).forEach(e=>{t[e]=t=>this._instanceSelectMode&&t.properties[St]?this._modes[this._instanceSelectMode].styleFeature.bind(this._modes[this._instanceSelectMode])(t):this._modes[e].styleFeature.bind(this._modes[e])(t)}),t}featuresAtLocation({lng:t,lat:e},s){const o=s&&void 0!==s.pointerDistance?s.pointerDistance:30,n=!s||void 0===s.ignoreSelectFeatures||s.ignoreSelectFeatures,r=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),l=a(t,e),h=$t({unproject:r,point:l,pointerDistance:o});return this._store.search(h).filter(s=>{if(n&&(s.properties[xt]||s.properties.selectionPoint))return!1;if("Point"===s.geometry.type){const t=s.geometry.coordinates,e=a(t[0],t[1]);return i(l,e)<o}if("LineString"===s.geometry.type){const t=s.geometry.coordinates;for(let e=0;e<t.length-1;e++){const i=t[e],s=t[e+1];if(ue(l,a(i[0],i[1]),a(s[0],s[1]))<o)return!0}return!1}return!!ge([t,e],s.geometry.coordinates)||void 0})}setModeStyles(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e}getSnapshot(){return this._store.copyAll()}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(t){throw new Error("Enabled is read only")}getMode(){return this._mode.mode}setMode(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()}removeFeatures(t){this.checkEnabled(),this._store.delete(t)}getFeatureId(){return this._store.getId()}hasFeature(t){return this._store.has(t)}addFeatures(t){this.checkEnabled(),0!==t.length&&this._store.load(t,t=>{if(Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)){const e=this._modes[t.properties.mode];return!!e&&e.validateFeature.bind(e)(t)}return!1})}start(){this._enabled=!0,this._adapter.register({getState:()=>this._mode.state,onClick:t=>{this._mode.onClick(t)},onMouseMove:t=>{this._mode.onMouseMove(t)},onKeyDown:t=>{this._mode.onKeyDown(t)},onKeyUp:t=>{this._mode.onKeyUp(t)},onDragStart:(t,e)=>{this._mode.onDragStart(t,e)},onDrag:(t,e)=>{this._mode.onDrag(t,e)},onDragEnd:(t,e)=>{this._mode.onDragEnd(t,e)},onClear:()=>{this._mode.cleanUp(),this._store.clear()}})}getFeaturesAtLngLat(t,e){const{lng:i,lat:s}=t;return this.featuresAtLocation({lng:i,lat:s},e)}getFeaturesAtPointerEvent(t,e){const i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)}stop(){this._enabled=!1,this._adapter.unregister()}on(t,e){const i=this._eventListeners[t];i.includes(e)||i.push(e)}off(t,e){const i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)}}const ze={TerraDrawBaseDrawMode:It,TerraDrawBaseAdapter:o};export{Ye as TerraDraw,Pt as TerraDrawArcGISMapsSDKAdapter,jt as TerraDrawCircleMode,ze as TerraDrawExtend,Rt as TerraDrawFreehandMode,n as TerraDrawGoogleMapsAdapter,Zt as TerraDrawGreatCircleMode,r as TerraDrawLeafletAdapter,te as TerraDrawLineStringMode,l as TerraDrawMapLibreGLAdapter,a as TerraDrawMapboxGLAdapter,Ct as TerraDrawOpenLayersAdapter,ie as TerraDrawPointMode,ne as TerraDrawPolygonMode,re as TerraDrawRectangleMode,ae as TerraDrawRenderMode,we as TerraDrawSelectMode};
|
|
1
|
+
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 s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},t.apply(this,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:s}=t,{x:o,y:n}=e,r=o-i,a=n-s;return Math.sqrt(a*a+r*r)};class s{constructor({name:t,callback:e,unregister:i,register:s}){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,s(e))},this.unregister=()=>{this.register&&(this.registered=!1,i(e))},this.callback=e}}class o{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:s}=e.getBoundingClientRect();return{containerX:t.clientX-i,containerY:t.clientY-s}}getDrawEventFromEvent(t){const i=this.getLngLatFromEvent(t);if(!i)return null;const{lng:s,lat:o}=i,{containerX:n,containerY:r}=this.getMapElementXYPosition(t),a=this.getButton(t),l=Array.from(this._heldKeys);return{lng:e(s,this._coordinatePrecision),lat:e(o,this._coordinatePrecision),containerX:n,containerY:r,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 s({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 s({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},s={x:e.containerX,y:e.containerY},o=this._currentModeCallbacks.getState(),n=i(t,s);let r=!1;if(r="drawing"===o?n<this._minPixelDragDistanceDrawing:"selecting"===o?n<this._minPixelDragDistanceSelecting:n<this._minPixelDragDistance,r)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 s({name:"contextmenu",callback:t=>{if(this._currentModeCallbacks&&(t.preventDefault(),"not-dragging"===this._dragState||"pre-dragging"===this._dragState)){const e=this.getDrawEventFromEvent(t);if(!e)return;"neither"!==e.button&&this._currentModeCallbacks.onClick(e)}},register:t=>{this.getMapEventElement().addEventListener("contextmenu",t)},unregister:t=>{this.getMapEventElement().removeEventListener("contextmenu",t)}}),new s({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 s({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 s({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 o{constructor(t){if(super(t),this._cursor=void 0,this._cursorStyleSheet=void 0,this._lib=void 0,this._map=void 0,this._overlay=void 0,this._clickEventListener=void 0,this._mouseMoveEventListener=void 0,this.renderedFeatureIds=new Set,this._lib=t.lib,this._map=t.map,!this._map.getDiv().id)throw new Error("Google Map container div requires and id to be set");this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this._overlay=new this._lib.OverlayView,this._overlay.draw=function(){},this._overlay.setMap(this._map)}get _layers(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}circlePath(t,e,i){const s=2*i;return`M ${t} ${e} m -${i}, 0 a ${i},${i} 0 1,0 ${s},0 a ${i},${i} 0 1,0 -${s},0`}register(t){super.register(t),this._clickEventListener=this._map.data.addListener("click",t=>{const e=this._listeners.find(({name:t})=>"click"===t);e&&e.callback(t)}),this._mouseMoveEventListener=this._map.data.addListener("mousemove",t=>{const e=this._listeners.find(({name:t})=>"mousemove"===t);e&&e.callback(t)})}unregister(){var t,e;super.unregister(),null==(t=this._clickEventListener)||t.remove(),null==(e=this._mouseMoveEventListener)||e.remove()}getLngLatFromEvent(t){const e=this._map.getBounds();if(!e)return null;const i=e.getNorthEast(),s=e.getSouthWest(),o=new this._lib.LatLngBounds(s,i),n=this._map.getDiv(),r=t.clientX-n.getBoundingClientRect().left,a=t.clientY-n.getBoundingClientRect().top,l=new this._lib.Point(r,a),h=this._overlay.getProjection();if(!h)return null;const d=h.fromContainerPixelToLatLng(l);return d&&o.contains(d)?{lng:d.lng(),lat:d.lat()}:null}getMapEventElement(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')}project(t,e){if(void 0===this._map.getBounds())throw new Error("cannot get bounds");const i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");const s=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===s)throw new Error("cannot project coordinates");return{x:s.x,y:s.y}}unproject(t,e){const i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");const s=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===s)throw new Error("cannot unproject coordinates");return{lng:s.lng(),lat:s.lat()}}setCursor(t){if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),"unset"!==t){const e=this._map.getDiv(),i=document.querySelector(`#${e.id} .gm-style > div`);if(i){i.classList.add("terra-draw-google-maps");const e=document.createElement("style");e.innerHTML=`.terra-draw-google-maps { cursor: ${t} !important; }`,document.getElementsByTagName("head")[0].appendChild(e),this._cursorStyleSheet=e}}this._cursor=t}}setDoubleClickToZoom(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})}setDraggability(t){this._map.setOptions({draggable:t})}render(t,e){this._layers&&(t.deletedIds.forEach(t=>{const e=this._map.data.getFeatureById(t);e&&(this._map.data.remove(e),this.renderedFeatureIds.delete(t))}),t.updated.forEach(t=>{if(!t||!t.id)throw new Error("Feature is not valid");const e=this._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty((t,i)=>{e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(i=>{e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":{const i=t.geometry.coordinates;e.setGeometry(new this._lib.Data.Point(new this._lib.LatLng(i[1],i[0])))}break;case"LineString":{const i=t.geometry.coordinates,s=[];for(let t=0;t<i.length;t++){const e=i[t],o=new this._lib.LatLng(e[1],e[0]);s.push(o)}e.setGeometry(new this._lib.Data.LineString(s))}break;case"Polygon":{const i=t.geometry.coordinates,s=[];for(let t=0;t<i.length;t++){const e=[];for(let s=0;s<i[t].length;s++){const o=new this._lib.LatLng(i[t][s][1],i[t][s][0]);e.push(o)}s.push(e)}e.setGeometry(new this._lib.Data.Polygon(s))}}}),t.created.forEach(t=>{this.renderedFeatureIds.add(t.id),this._map.data.addGeoJson(t)})),t.created.forEach(t=>{this.renderedFeatureIds.add(t.id)});const i={type:"FeatureCollection",features:[...t.created]};this._map.data.addGeoJson(i),this._map.data.setStyle(t=>{const i=t.getProperty("mode"),s=t.getGeometry();if(!s)throw new Error("Google Maps geometry not found");const o=s.getType(),n={};t.forEachProperty((t,e)=>{n[e]=t});const r=e[i]({type:"Feature",geometry:{type:o,coordinates:[]},properties:n});switch(o){case"Point":return{clickable:!1,icon:{path:this.circlePath(0,0,r.pointWidth),fillColor:r.pointColor,fillOpacity:1,strokeColor:r.pointOutlineColor,strokeWeight:r.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:r.lineStringColor,strokeWeight:r.lineStringWidth};case"Polygon":return{strokeColor:r.polygonOutlineColor,strokeWeight:r.polygonOutlineWidth,fillOpacity:r.polygonFillOpacity,fillColor:r.polygonFillColor}}throw Error("Unknown feature type")})}clearLayers(){this._layers&&(this._map.data.forEach(t=>{const e=t.getId();this.renderedFeatureIds.has(e)&&this._map.data.remove(t)}),this.renderedFeatureIds=new Set)}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}}class r extends o{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} {z-index: ${e};}`,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 s=(0,t[e.properties.mode])(e),o=String(s.zIndex);return this._panes[o]||(this._panes[o]=this.createPaneStyleSheet(o,s.zIndex)),this._lib.circleMarker(i,{radius:s.pointWidth,stroke:s.pointOutlineWidth||!1,color:s.pointOutlineColor,weight:s.pointOutlineWidth,fillOpacity:.8,fillColor:s.pointColor,pane:o,interactive:!1})},style:e=>{if(!e||!e.properties)return{};const i=e,s=(0,t[i.properties.mode])(i),o=String(s.zIndex);return this._panes[o]||(this._panes[o]=this.createPaneStyleSheet(o,s.zIndex)),"LineString"===i.geometry.type?{interactive:!1,color:s.lineStringColor,weight:s.lineStringWidth,pane:o}:"Polygon"===i.geometry.type?{interactive:!1,fillOpacity:s.polygonFillOpacity,fillColor:s.polygonFillColor,weight:s.polygonOutlineWidth,stroke:!0,color:s.polygonFillColor,pane:o}:{}}}}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t),s={x:e,y:i};if(isNaN(s.x)||isNaN(s.y))return null;const o=this._map.containerPointToLatLng(s);return isNaN(o.lng)||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:s}=this._map.latLngToContainerPoint({lng:t,lat:e});return{x:i,y:s}}unproject(t,e){const{lng:i,lat:s}=this._map.containerPointToLatLng({x:t,y:e});return{lng:i,lat:s}}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())}}class a extends o{constructor(t){super(t),this._nextRender=void 0,this._map=void 0,this._container=void 0,this._rendered=!1,this.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},this._map=t.map,this._container=this._map.getContainer()}clearLayers(){this._rendered&&(["point","linestring","polygon"].forEach(t=>{const e=`td-${t.toLowerCase()}`;this._map.removeLayer(e),"polygon"===t&&this._map.removeLayer(e+"-outline"),this._map.removeSource(e)}),this._rendered=!1,this._nextRender&&(cancelAnimationFrame(this._nextRender),this._nextRender=void 0))}_addGeoJSONSource(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e},tolerance:0})}_addFillLayer(t){return this._map.addLayer({id:t,source:t,type:"fill",paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})}_addFillOutlineLayer(t,e){const i=this._map.addLayer({id:t+"-outline",source:t,type:"line",paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}});return e&&this._map.moveLayer(t,e),i}_addLineLayer(t,e){const i=this._map.addLayer({id:t,source:t,type:"line",paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}});return e&&this._map.moveLayer(t,e),i}_addPointLayer(t,e){const i=this._map.addLayer({id:t,source:t,type:"circle",paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return e&&this._map.moveLayer(t,e),i}_addLayer(t,e,i){"Point"===e&&this._addPointLayer(t,i),"LineString"===e&&this._addLineLayer(t,i),"Polygon"===e&&(this._addFillLayer(t),this._addFillOutlineLayer(t,i))}_addGeoJSONLayer(t,e){const i=`td-${t.toLowerCase()}`;return this._addGeoJSONSource(i,e),this._addLayer(i,t),i}_setGeoJSONLayerData(t,e){const i=`td-${t.toLowerCase()}`;return this._map.getSource(i).setData({type:"FeatureCollection",features:e}),i}getEmptyGeometries(){return{points:[],linestrings:[],polygons:[]}}updateChangedIds(t){[...t.updated,...t.created].forEach(t=>{"Point"===t.geometry.type?this.changedIds.points=!0:"LineString"===t.geometry.type?this.changedIds.linestrings=!0:"Polygon"===t.geometry.type&&(this.changedIds.polygons=!0)}),t.deletedIds.length>0&&(this.changedIds.deletion=!0),0===t.created.length&&0===t.updated.length&&0===t.deletedIds.length&&(this.changedIds.styling=!0)}getLngLatFromEvent(t){const{left:e,top:i}=this._container.getBoundingClientRect();return this.unproject(t.clientX-e,t.clientY-i)}getMapEventElement(){return this._map.getCanvas()}setDraggability(t){t?(this._map.dragRotate.enable(),this._map.dragPan.enable()):(this._map.dragRotate.disable(),this._map.dragPan.disable())}project(t,e){const{x:i,y:s}=this._map.project({lng:t,lat:e});return{x:i,y:s}}unproject(t,e){const{lng:i,lat:s}=this._map.unproject({x:t,y:e});return{lng:i,lat:s}}setCursor(t){const e=this._map.getCanvas();"unset"===t?e.style.removeProperty("cursor"):e.style.cursor=t}setDoubleClickToZoom(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(t,e){this.updateChangedIds(t),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(()=>{const i=[...t.created,...t.updated,...t.unchanged],s=this.getEmptyGeometries();for(let t=0;t<i.length;t++){const o=i[t];Object.keys(e).forEach(t=>{const{properties:i}=o;if(i.mode!==t)return;const n=e[t](o);"Point"===o.geometry.type?(i.pointColor=n.pointColor,i.pointOutlineColor=n.pointOutlineColor,i.pointOutlineWidth=n.pointOutlineWidth,i.pointWidth=n.pointWidth,s.points.push(o)):"LineString"===o.geometry.type?(i.lineStringColor=n.lineStringColor,i.lineStringWidth=n.lineStringWidth,s.linestrings.push(o)):"Polygon"===o.geometry.type&&(i.polygonFillColor=n.polygonFillColor,i.polygonFillOpacity=n.polygonFillOpacity,i.polygonOutlineColor=n.polygonOutlineColor,i.polygonOutlineWidth=n.polygonOutlineWidth,s.polygons.push(o))})}const{points:o,linestrings:n,polygons:r}=s;if(this._rendered){const t=this.changedIds.deletion||this.changedIds.styling,e=t||this.changedIds.linestrings,i=t||this.changedIds.polygons;let s;(t||this.changedIds.points)&&(s=this._setGeoJSONLayerData("Point",o)),e&&this._setGeoJSONLayerData("LineString",n),i&&this._setGeoJSONLayerData("Polygon",r),s&&this._map.moveLayer(s)}else this._addGeoJSONLayer("Point",o),this._addGeoJSONLayer("LineString",n),this._addGeoJSONLayer("Polygon",r),this._rendered=!0;this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}}class l extends o{constructor(t){super(t),this.mapboxglAdapter=void 0,this.mapboxglAdapter=new a(t)}register(t){this.mapboxglAdapter.register(t)}unregister(){this.mapboxglAdapter.unregister()}getLngLatFromEvent(t){return this.mapboxglAdapter.getLngLatFromEvent(t)}getMapEventElement(){return this.mapboxglAdapter.getMapEventElement()}setDraggability(t){this.mapboxglAdapter.setDraggability(t)}project(t,e){return this.mapboxglAdapter.project(t,e)}unproject(t,e){return this.mapboxglAdapter.unproject(t,e)}setCursor(t){this.mapboxglAdapter.setCursor(t)}setDoubleClickToZoom(t){this.mapboxglAdapter.setDoubleClickToZoom(t)}render(t,e){this.mapboxglAdapter.render(t,e)}clear(){this.mapboxglAdapter.clear()}}function h(){throw new Error("Unimplemented abstract method.")}let d=0;function c(t,e){return Array.isArray(t)?t:(void 0===e?e=[t,t]:(e[0]=t,e[1]=t),e)}class g{constructor(t){this.opacity_=t.opacity,this.rotateWithView_=t.rotateWithView,this.rotation_=t.rotation,this.scale_=t.scale,this.scaleArray_=c(t.scale),this.displacement_=t.displacement,this.declutterMode_=t.declutterMode}clone(){const t=this.getScale();return new g({opacity:this.getOpacity(),scale:Array.isArray(t)?t.slice():t,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()})}getOpacity(){return this.opacity_}getRotateWithView(){return this.rotateWithView_}getRotation(){return this.rotation_}getScale(){return this.scale_}getScaleArray(){return this.scaleArray_}getDisplacement(){return this.displacement_}getDeclutterMode(){return this.declutterMode_}getAnchor(){return h()}getImage(t){return h()}getHitDetectionImage(){return h()}getPixelRatio(t){return 1}getImageState(){return h()}getImageSize(){return h()}getOrigin(){return h()}getSize(){return h()}setDisplacement(t){this.displacement_=t}setOpacity(t){this.opacity_=t}setRotateWithView(t){this.rotateWithView_=t}setRotation(t){this.rotation_=t}setScale(t){this.scale_=t,this.scaleArray_=c(t)}listenImageChange(t){h()}load(){h()}unlistenImageChange(t){h()}}var u=g;const p={1:"The view center is not defined",2:"The view resolution is not defined",3:"The view rotation is not defined",4:"`image` and `src` cannot be provided at the same time",5:"`imgSize` must be set when `image` is provided",7:"`format` must be set when `url` is set",8:"Unknown `serverType` configured",9:"`url` must be configured or set using `#setUrl()`",10:"The default `geometryFunction` can only handle `Point` geometries",11:"`options.featureTypes` must be an Array",12:"`options.geometryName` must also be provided when `options.bbox` is set",13:"Invalid corner",14:"Invalid color",15:"Tried to get a value for a key that does not exist in the cache",16:"Tried to set a value for a key that is used already",17:"`resolutions` must be sorted in descending order",18:"Either `origin` or `origins` must be configured, never both",19:"Number of `tileSizes` and `resolutions` must be equal",20:"Number of `origins` and `resolutions` must be equal",22:"Either `tileSize` or `tileSizes` must be configured, never both",24:"Invalid extent or geometry provided as `geometry`",25:"Cannot fit empty extent provided as `geometry`",26:"Features must have an id set",27:"Features must have an id set",28:'`renderMode` must be `"hybrid"` or `"vector"`',30:"The passed `feature` was already added to the source",31:"Tried to enqueue an `element` that was already added to the queue",32:"Transformation matrix cannot be inverted",33:"Invalid units",34:"Invalid geometry layout",36:"Unknown SRS type",37:"Unknown geometry type found",38:"`styleMapValue` has an unknown type",39:"Unknown geometry type",40:"Expected `feature` to have a geometry",41:"Expected an `ol/style/Style` or an array of `ol/style/Style.js`",42:"Question unknown, the answer is 42",43:"Expected `layers` to be an array or a `Collection`",47:"Expected `controls` to be an array or an `ol/Collection`",48:"Expected `interactions` to be an array or an `ol/Collection`",49:"Expected `overlays` to be an array or an `ol/Collection`",50:"`options.featureTypes` should be an Array",51:"Either `url` or `tileJSON` options must be provided",52:"Unknown `serverType` configured",53:"Unknown `tierSizeCalculation` configured",55:"The {-y} placeholder requires a tile grid with extent",56:"mapBrowserEvent must originate from a pointer event",57:"At least 2 conditions are required",59:"Invalid command found in the PBF",60:"Missing or invalid `size`",61:"Cannot determine IIIF Image API version from provided image information JSON",62:"A `WebGLArrayBuffer` must either be of type `ELEMENT_ARRAY_BUFFER` or `ARRAY_BUFFER`",64:"Layer opacity must be a number",66:"`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has not been enabled. This is done by providing adequate shaders using the `hitVertexShader` and `hitFragmentShader` properties of `WebGLPointsLayerRenderer`",67:"A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both",68:"A VectorTile source can only be rendered if it has a projection compatible with the view projection"};class y extends Error{constructor(t){const e=p[t];super(e),this.code=t,this.name="AssertionError",this.message=e}}var m=y;function f(t,e,i){return Math.min(Math.max(t,e),i)}const v=/^#([a-f0-9]{3}|[a-f0-9]{4}(?:[a-f0-9]{2}){0,2})$/i,_=/^([a-z]*)$|^hsla?\(.*\)$/i,C=function(){const t={};let e=0;return function(i){let s;if(t.hasOwnProperty(i))s=t[i];else{if(e>=1024){let i=0;for(const s in t)0==(3&i++)&&(delete t[s],--e)}s=function(t){let e,i,s,o,n;if(_.exec(t)&&(t=function(t){const e=document.createElement("div");if(e.style.color=t,""!==e.style.color){document.body.appendChild(e);const t=getComputedStyle(e).color;return document.body.removeChild(e),t}return""}(t)),v.exec(t)){const r=t.length-1;let a;a=r<=4?1:2;const l=4===r||8===r;e=parseInt(t.substr(1+0*a,a),16),i=parseInt(t.substr(1+1*a,a),16),s=parseInt(t.substr(1+2*a,a),16),o=l?parseInt(t.substr(1+3*a,a),16):255,1==a&&(e=(e<<4)+e,i=(i<<4)+i,s=(s<<4)+s,l&&(o=(o<<4)+o)),n=[e,i,s,o/255]}else t.startsWith("rgba(")?(n=t.slice(5,-1).split(",").map(Number),P(n)):t.startsWith("rgb(")?(n=t.slice(4,-1).split(",").map(Number),n.push(1),P(n)):function(t,e){throw new m(14)}();return n}(i),t[i]=s,++e}return s}}();function P(t){return t[0]=f(t[0]+.5|0,0,255),t[1]=f(t[1]+.5|0,0,255),t[2]=f(t[2]+.5|0,0,255),t[3]=f(t[3],0,1),t}function x(t){return Array.isArray(t)?function(t){let e=t[0];e!=(0|e)&&(e=e+.5|0);let i=t[1];i!=(0|i)&&(i=i+.5|0);let s=t[2];return s!=(0|s)&&(s=s+.5|0),"rgba("+e+","+i+","+s+","+(void 0===t[3]?1:Math.round(100*t[3])/100)+")"}(t):t}const S="undefined"!=typeof navigator&&void 0!==navigator.userAgent?navigator.userAgent.toLowerCase():"";S.includes("firefox"),S.includes("safari")&&!S.includes("chrom")&&(S.includes("version/15.4")||/cpu (os|iphone os) 15_4 like mac os x/.test(S)),S.includes("webkit")&&S.includes("edge"),S.includes("macintosh");const E="undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof OffscreenCanvas&&self instanceof WorkerGlobalScope;function w(t,e,i,s){let o;return o=i&&i.length?i.shift():E?new OffscreenCanvas(t||300,e||300):document.createElement("canvas"),t&&(o.width=t),e&&(o.height=e),o.getContext("2d",s)}!function(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("_",null,e),window.removeEventListener("_",null,e)}catch(t){}}();var b=class{constructor(t){this.type=t,this.target=null}preventDefault(){this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0}},M=class{constructor(){this.disposed=!1}dispose(){this.disposed||(this.disposed=!0,this.disposeInternal())}disposeInternal(){}};function D(){}function I(t){for(const e in t)delete t[e]}var k=class extends M{constructor(t){super(),this.eventTarget_=t,this.pendingRemovals_=null,this.dispatching_=null,this.listeners_=null}addEventListener(t,e){if(!t||!e)return;const i=this.listeners_||(this.listeners_={}),s=i[t]||(i[t]=[]);s.includes(e)||s.push(e)}dispatchEvent(t){const e="string"==typeof t,i=e?t:t.type,s=this.listeners_&&this.listeners_[i];if(!s)return;const o=e?new b(t):t;o.target||(o.target=this.eventTarget_||this);const n=this.dispatching_||(this.dispatching_={}),r=this.pendingRemovals_||(this.pendingRemovals_={});let a;i in n||(n[i]=0,r[i]=0),++n[i];for(let t=0,e=s.length;t<e;++t)if(a="handleEvent"in s[t]?s[t].handleEvent(o):s[t].call(this,o),!1===a||o.propagationStopped){a=!1;break}if(0==--n[i]){let t=r[i];for(delete r[i];t--;)this.removeEventListener(i,D);delete n[i]}return a}disposeInternal(){this.listeners_&&I(this.listeners_)}getListeners(t){return this.listeners_&&this.listeners_[t]||void 0}hasListener(t){return!!this.listeners_&&(t?t in this.listeners_:Object.keys(this.listeners_).length>0)}removeEventListener(t,e){const i=this.listeners_&&this.listeners_[t];if(i){const s=i.indexOf(e);-1!==s&&(this.pendingRemovals_&&t in this.pendingRemovals_?(i[s]=D,++this.pendingRemovals_[t]):(i.splice(s,1),0===i.length&&delete this.listeners_[t]))}}};function O(t,e,i,s,o){if(s&&s!==t&&(i=i.bind(s)),o){const s=i;i=function(){t.removeEventListener(e,i),s.apply(this,arguments)}}const n={target:t,type:e,listener:i};return t.addEventListener(e,i),n}function F(t,e,i,s){return O(t,e,i,s,!0)}function L(t){t&&t.target&&(t.target.removeEventListener(t.type,t.listener),I(t))}var W=class extends k{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(t,e){if(Array.isArray(t)){const i=t.length,s=new Array(i);for(let o=0;o<i;++o)s[o]=O(this,t[o],e);return s}return O(this,t,e)}onceInternal(t,e){let i;if(Array.isArray(t)){const s=t.length;i=new Array(s);for(let o=0;o<s;++o)i[o]=F(this,t[o],e)}else i=F(this,t,e);return e.ol_key=i,i}unInternal(t,e){const i=e.ol_key;if(i)!function(t){if(Array.isArray(t))for(let e=0,i=t.length;e<i;++e)L(t[e]);else L(t)}(i);else if(Array.isArray(t))for(let i=0,s=t.length;i<s;++i)this.removeEventListener(t[i],e);else this.removeEventListener(t,e)}};class A extends b{constructor(t,e,i){super(t),this.key=e,this.oldValue=i}}const G="#000",B="round";new class extends W{constructor(t){super(),this.ol_uid||(this.ol_uid=String(++d)),this.values_=null,void 0!==t&&this.setProperties(t)}get(t){let e;return this.values_&&this.values_.hasOwnProperty(t)&&(e=this.values_[t]),e}getKeys(){return this.values_&&Object.keys(this.values_)||[]}getProperties(){return this.values_&&Object.assign({},this.values_)||{}}hasProperties(){return!!this.values_}notify(t,e){let i;i=`change:${t}`,this.hasListener(i)&&this.dispatchEvent(new A(i,t,e)),i="propertychange",this.hasListener(i)&&this.dispatchEvent(new A(i,t,e))}addChangeListener(t,e){this.addEventListener(`change:${t}`,e)}removeChangeListener(t,e){this.removeEventListener(`change:${t}`,e)}set(t,e,i){const s=this.values_||(this.values_={});if(i)s[t]=e;else{const i=s[t];s[t]=e,i!==e&&this.notify(t,i)}}setProperties(t,e){for(const i in t)this.set(i,t[i],e)}applyProperties(t){t.values_&&Object.assign(this.values_||(this.values_={}),t.values_)}unset(t,e){if(this.values_&&t in this.values_){const i=this.values_[t];delete this.values_[t],function(t){let e;for(e in t)return!1;return!e}(this.values_)&&(this.values_=null),e||this.notify(t,i)}}};class N extends u{constructor(t){super({opacity:1,rotateWithView:void 0!==t.rotateWithView&&t.rotateWithView,rotation:void 0!==t.rotation?t.rotation:0,scale:void 0!==t.scale?t.scale:1,displacement:void 0!==t.displacement?t.displacement:[0,0],declutterMode:t.declutterMode}),this.canvas_=void 0,this.hitDetectionCanvas_=null,this.fill_=void 0!==t.fill?t.fill:null,this.origin_=[0,0],this.points_=t.points,this.radius_=void 0!==t.radius?t.radius:t.radius1,this.radius2_=t.radius2,this.angle_=void 0!==t.angle?t.angle:0,this.stroke_=void 0!==t.stroke?t.stroke:null,this.size_=null,this.renderOptions_=null,this.render()}clone(){const t=this.getScale(),e=new N({fill:this.getFill()?this.getFill().clone():void 0,points:this.getPoints(),radius:this.getRadius(),radius2:this.getRadius2(),angle:this.getAngle(),stroke:this.getStroke()?this.getStroke().clone():void 0,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),scale:Array.isArray(t)?t.slice():t,displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()});return e.setOpacity(this.getOpacity()),e}getAnchor(){const t=this.size_;if(!t)return null;const e=this.getDisplacement(),i=this.getScaleArray();return[t[0]/2-e[0]/i[0],t[1]/2+e[1]/i[1]]}getAngle(){return this.angle_}getFill(){return this.fill_}setFill(t){this.fill_=t,this.render()}getHitDetectionImage(){return this.hitDetectionCanvas_||this.createHitDetectionCanvas_(this.renderOptions_),this.hitDetectionCanvas_}getImage(t){let e=this.canvas_[t];if(!e){const i=this.renderOptions_,s=w(i.size*t,i.size*t);this.draw_(i,s,t),e=s.canvas,this.canvas_[t]=e}return e}getPixelRatio(t){return t}getImageSize(){return this.size_}getImageState(){return 2}getOrigin(){return this.origin_}getPoints(){return this.points_}getRadius(){return this.radius_}getRadius2(){return this.radius2_}getSize(){return this.size_}getStroke(){return this.stroke_}setStroke(t){this.stroke_=t,this.render()}listenImageChange(t){}load(){}unlistenImageChange(t){}calculateLineJoinSize_(t,e,i){if(0===e||Infinity===this.points_||"bevel"!==t&&"miter"!==t)return e;let s=this.radius_,o=void 0===this.radius2_?s:this.radius2_;if(s<o){const t=s;s=o,o=t}const n=2*Math.PI/(void 0===this.radius2_?this.points_:2*this.points_),r=o*Math.sin(n),a=s-Math.sqrt(o*o-r*r),l=Math.sqrt(r*r+a*a),h=l/r;if("miter"===t&&h<=i)return h*e;const d=e/2/h,c=e/2*(a/l),g=Math.sqrt((s+d)*(s+d)+c*c)-s;if(void 0===this.radius2_||"bevel"===t)return 2*g;const u=s*Math.sin(n),p=o-Math.sqrt(s*s-u*u),y=Math.sqrt(u*u+p*p)/u;return y<=i?2*Math.max(g,y*e/2-o-s):2*g}createRenderOptions(){let t,e=B,i=0,s=null,o=0,n=0;this.stroke_&&(t=this.stroke_.getColor(),null===t&&(t="#000"),t=x(t),n=this.stroke_.getWidth(),void 0===n&&(n=1),s=this.stroke_.getLineDash(),o=this.stroke_.getLineDashOffset(),e=this.stroke_.getLineJoin(),void 0===e&&(e=B),i=this.stroke_.getMiterLimit(),void 0===i&&(i=10));const r=this.calculateLineJoinSize_(e,n,i),a=Math.max(this.radius_,this.radius2_||0);return{strokeStyle:t,strokeWidth:n,size:Math.ceil(2*a+r),lineDash:s,lineDashOffset:o,lineJoin:e,miterLimit:i}}render(){this.renderOptions_=this.createRenderOptions();const t=this.renderOptions_.size;this.canvas_={},this.size_=[t,t]}draw_(t,e,i){if(e.scale(i,i),e.translate(t.size/2,t.size/2),this.createPath_(e),this.fill_){let t=this.fill_.getColor();null===t&&(t=G),e.fillStyle=x(t),e.fill()}this.stroke_&&(e.strokeStyle=t.strokeStyle,e.lineWidth=t.strokeWidth,t.lineDash&&(e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset),e.lineJoin=t.lineJoin,e.miterLimit=t.miterLimit,e.stroke())}createHitDetectionCanvas_(t){if(this.fill_){let e=this.fill_.getColor(),i=0;if("string"==typeof e&&(e=function(t){return Array.isArray(t)?t:C(t)}(e)),null===e?i=1:Array.isArray(e)&&(i=4===e.length?e[3]:1),0===i){const e=w(t.size,t.size);this.hitDetectionCanvas_=e.canvas,this.drawHitDetectionCanvas_(t,e)}}this.hitDetectionCanvas_||(this.hitDetectionCanvas_=this.getImage(1))}createPath_(t){let e=this.points_;const i=this.radius_;if(Infinity===e)t.arc(0,0,i,0,2*Math.PI);else{const s=void 0===this.radius2_?i:this.radius2_;void 0!==this.radius2_&&(e*=2);const o=this.angle_-Math.PI/2,n=2*Math.PI/e;for(let r=0;r<e;r++){const e=o+r*n,a=r%2==0?i:s;t.lineTo(a*Math.cos(e),a*Math.sin(e))}t.closePath()}}drawHitDetectionCanvas_(t,e){e.translate(t.size/2,t.size/2),this.createPath_(e),e.fillStyle=G,e.fill(),this.stroke_&&(e.strokeStyle=t.strokeStyle,e.lineWidth=t.strokeWidth,t.lineDash&&(e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset),e.lineJoin=t.lineJoin,e.miterLimit=t.miterLimit,e.stroke())}}var V=N;class R extends V{constructor(t){super({points:Infinity,fill:(t=t||{radius:5}).fill,radius:t.radius,stroke:t.stroke,scale:void 0!==t.scale?t.scale:1,rotation:void 0!==t.rotation?t.rotation:0,rotateWithView:void 0!==t.rotateWithView&&t.rotateWithView,displacement:void 0!==t.displacement?t.displacement:[0,0],declutterMode:t.declutterMode})}clone(){const t=this.getScale(),e=new R({fill:this.getFill()?this.getFill().clone():void 0,stroke:this.getStroke()?this.getStroke().clone():void 0,radius:this.getRadius(),scale:Array.isArray(t)?t.slice():t,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()});return e.setOpacity(this.getOpacity()),e}setRadius(t){this.radius_=t,this.render()}}var j=R;class T{constructor(t){this.color_=void 0!==(t=t||{}).color?t.color:null}clone(){const t=this.getColor();return new T({color:Array.isArray(t)?t.slice():t||void 0})}getColor(){return this.color_}setColor(t){this.color_=t}}var U=T;class z{constructor(t){this.color_=void 0!==(t=t||{}).color?t.color:null,this.lineCap_=t.lineCap,this.lineDash_=void 0!==t.lineDash?t.lineDash:null,this.lineDashOffset_=t.lineDashOffset,this.lineJoin_=t.lineJoin,this.miterLimit_=t.miterLimit,this.width_=t.width}clone(){const t=this.getColor();return new z({color:Array.isArray(t)?t.slice():t||void 0,lineCap:this.getLineCap(),lineDash:this.getLineDash()?this.getLineDash().slice():void 0,lineDashOffset:this.getLineDashOffset(),lineJoin:this.getLineJoin(),miterLimit:this.getMiterLimit(),width:this.getWidth()})}getColor(){return this.color_}getLineCap(){return this.lineCap_}getLineDash(){return this.lineDash_}getLineDashOffset(){return this.lineDashOffset_}getLineJoin(){return this.lineJoin_}getMiterLimit(){return this.miterLimit_}getWidth(){return this.width_}setColor(t){this.color_=t}setLineCap(t){this.lineCap_=t}setLineDash(t){this.lineDash_=t}setLineDashOffset(t){this.lineDashOffset_=t}setLineJoin(t){this.lineJoin_=t}setMiterLimit(t){this.miterLimit_=t}setWidth(t){this.width_=t}}var X=z;class Y{constructor(t){t=t||{},this.geometry_=null,this.geometryFunction_=H,void 0!==t.geometry&&this.setGeometry(t.geometry),this.fill_=void 0!==t.fill?t.fill:null,this.image_=void 0!==t.image?t.image:null,this.renderer_=void 0!==t.renderer?t.renderer:null,this.hitDetectionRenderer_=void 0!==t.hitDetectionRenderer?t.hitDetectionRenderer:null,this.stroke_=void 0!==t.stroke?t.stroke:null,this.text_=void 0!==t.text?t.text:null,this.zIndex_=t.zIndex}clone(){let t=this.getGeometry();return t&&"object"==typeof t&&(t=t.clone()),new Y({geometry:t,fill:this.getFill()?this.getFill().clone():void 0,image:this.getImage()?this.getImage().clone():void 0,renderer:this.getRenderer(),stroke:this.getStroke()?this.getStroke().clone():void 0,text:this.getText()?this.getText().clone():void 0,zIndex:this.getZIndex()})}getRenderer(){return this.renderer_}setRenderer(t){this.renderer_=t}setHitDetectionRenderer(t){this.hitDetectionRenderer_=t}getHitDetectionRenderer(){return this.hitDetectionRenderer_}getGeometry(){return this.geometry_}getGeometryFunction(){return this.geometryFunction_}getFill(){return this.fill_}setFill(t){this.fill_=t}getImage(){return this.image_}setImage(t){this.image_=t}getStroke(){return this.stroke_}setStroke(t){this.stroke_=t}getText(){return this.text_}setText(t){this.text_=t}getZIndex(){return this.zIndex_}setGeometry(t){"function"==typeof t?this.geometryFunction_=t:"string"==typeof t?this.geometryFunction_=function(e){return e.get(t)}:t?void 0!==t&&(this.geometryFunction_=function(){return t}):this.geometryFunction_=H,this.geometry_=t}setZIndex(t){this.zIndex_=t}}function H(t){return t.getGeometry()}var J=Y;const K={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var $=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_||K[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 q=6378137,Z=Math.PI*q,Q=[-Z,-Z,Z,Z],tt=[-180,-85,180,85],et=q*Math.log(Math.tan(Math.PI/2));class it extends ${constructor(t){super({code:t,units:"m",extent:Q,global:!0,worldExtent:tt,getPointResolution:function(t,e){return t/Math.cosh(e[1]/q)}})}}const st=[new it("EPSG:3857"),new it("EPSG:102100"),new it("EPSG:102113"),new it("EPSG:900913"),new it("http://www.opengis.net/def/crs/EPSG/0/3857"),new it("http://www.opengis.net/gml/srs/epsg.xml#3857")],ot=[-180,-90,180,90],nt=6378137*Math.PI/180;class rt extends ${constructor(t,e){super({code:t,units:"degrees",extent:ot,axisOrientation:e,global:!0,metersPerUnit:nt,worldExtent:ot})}}const at=[new rt("CRS:84"),new rt("EPSG:4326","neu"),new rt("urn:ogc:def:crs:OGC:1.3:CRS84"),new rt("urn:ogc:def:crs:OGC:2:84"),new rt("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new rt("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new rt("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let lt={},ht={};function dt(t,e,i){const s=t.getCode(),o=e.getCode();s in ht||(ht[s]={}),ht[s][o]=i}function ct(t,e,i){if(void 0!==e)for(let i=0,s=t.length;i<s;++i)e[i]=t[i];else e=t.slice();return e}function gt(t,e,i){if(void 0!==e&&t!==e){for(let i=0,s=t.length;i<s;++i)e[i]=t[i];t=e}return t}function ut(t){!function(t,e){lt[t]=e}(t.getCode(),t),dt(t,t,ct)}function pt(t){return"string"==typeof t?lt[e=t]||lt[e.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/,"EPSG:$3")]||null:t||null;var e}function yt(t){!function(t){t.forEach(ut)}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&dt(e,t,ct)})})}function mt(t,e,i){const s=function(t,e){return function(t,e){let i=function(t,e){let i;return t in ht&&e in ht[t]&&(i=ht[t][e]),i}(t.getCode(),e.getCode());return i||(i=gt),i}(pt(t),pt(e))}(e,i);return s(t,void 0,t.length)}var ft,vt,_t;yt(st),yt(at),ft=st,vt=function(t,e,i){const s=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(s));for(let o=0;o<s;o+=i){e[o]=Z*t[o]/180;let i=q*Math.log(Math.tan(Math.PI*(+t[o+1]+90)/360));i>et?i=et:i<-et&&(i=-et),e[o+1]=i}return e},_t=function(t,e,i){const s=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(s));for(let o=0;o<s;o+=i)e[o]=180*t[o]/Z,e[o+1]=360*Math.atan(Math.exp(t[o+1]/q))/Math.PI-90;return e},at.forEach(function(t){ft.forEach(function(e){dt(t,e,vt),dt(e,t,_t)})});class Ct extends o{constructor(t){super(t),this.stylingFunction=()=>({}),this._lib=void 0,this._map=void 0,this._container=void 0,this._projection="EPSG:3857",this._vectorSource=void 0,this._geoJSONReader=void 0,this._map=t.map,this._lib=t.lib,this._geoJSONReader=new this._lib.GeoJSON,this._container=this._map.getViewport(),this._container.setAttribute("tabindex","0");const e=new this._lib.VectorSource({features:[]});this._vectorSource=e;const i=new this._lib.VectorLayer({source:e,style:t=>this.getStyles(t,this.stylingFunction())});this._map.addLayer(i)}hexToRGB(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}getStyles(t,e){const i=t.getGeometry();if(i)return{Point:t=>{const i=t.getProperties(),s=e[i.mode]({type:"Feature",geometry:{type:"Point",coordinates:[]},properties:i});return new this._lib.Style({image:new j({radius:s.pointWidth,fill:new U({color:s.pointColor}),stroke:new X({color:s.pointOutlineColor,width:s.pointOutlineWidth})})})},LineString:t=>{const i=t.getProperties(),s=e[i.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:i});return new this._lib.Style({stroke:new this._lib.Stroke({color:s.lineStringColor,width:s.lineStringWidth})})},Polygon:t=>{const i=t.getProperties(),s=e[i.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:i}),{r:o,g:n,b:r}=this.hexToRGB(s.polygonFillColor);return new J({stroke:new X({color:s.polygonOutlineColor,width:s.polygonOutlineWidth}),fill:new U({color:`rgba(${o},${n},${r},${s.polygonFillOpacity})`})})}}[i.getType()](t)}clearLayers(){this._vectorSource&&this._vectorSource.clear()}addFeature(t){if(!this._vectorSource||!this._geoJSONReader)throw new Error("Vector Source not initalised");{const e=this._geoJSONReader.readFeature(t,{featureProjection:this._projection});this._vectorSource.addFeature(e)}}removeFeature(t){if(!this._vectorSource)throw new Error("Vector Source not initalised");{const e=this._vectorSource.getFeatureById(t);if(!e)return;this._vectorSource.removeFeature(e)}}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t);try{return this.unproject(e,i)}catch(t){return null}}getMapEventElement(){const t=this._container.querySelectorAll("canvas");if(t.length>1)throw Error("Terra Draw currently only supports 1 canvas with OpenLayers");return t[0]}setDraggability(t){this._map.getInteractions().forEach(e=>{"DragPan"===e.constructor.name&&e.setActive(t)})}project(t,e){const[i,s]=this._map.getPixelFromCoordinate(mt([t,e],"EPSG:4326","EPSG:3857"));return{x:i,y:s}}unproject(t,e){const[i,s]=function(t,e){const i=mt(t,"EPSG:3857","EPSG:4326"),s=i[0];return(s<-180||s>180)&&(i[0]=function(t,e){const i=t%360;return 360*i<0?i+360:i}(s+180)-180),i}(this._map.getCoordinateFromPixel([t,e]));return{lng:i,lat:s}}setCursor(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t}setDoubleClickToZoom(t){this._map.getInteractions().forEach(function(e){"DoubleClickZoom"===e.constructor.name&&e.setActive(t)})}render(t,e){if(this.stylingFunction=()=>e,!this._vectorSource)throw new Error("Vector Layer source has disappeared");t.deletedIds.forEach(t=>{this.removeFeature(t)}),t.updated.forEach(t=>{this.removeFeature(t.id),this.addFeature(t)}),t.created.forEach(t=>{this.addFeature(t)})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())}}class Pt extends o{constructor(t){super(t),this._lib=void 0,this._mapView=void 0,this._container=void 0,this._featureIdAttributeName="__tdId",this._featureLayerName="__terraDrawFeatures",this._featureLayer=void 0,this._dragEnabled=!0,this._zoomEnabled=!0,this._dragHandler=void 0,this._doubleClickHandler=void 0,this._mapView=t.map,this._lib=t.lib,this._container=this._mapView.container,this._featureLayer=new this._lib.GraphicsLayer({id:this._featureLayerName}),this._mapView.map.add(this._featureLayer)}register(t){super.register(t),this._dragHandler=this._mapView.on("drag",t=>{this._dragEnabled||t.stopPropagation()}),this._doubleClickHandler=this._mapView.on("double-click",t=>{this._zoomEnabled||t.stopPropagation()})}unregister(){super.unregister(),this._dragHandler&&this._dragHandler.remove(),this._doubleClickHandler&&this._doubleClickHandler.remove()}getLngLatFromEvent(t){const{containerX:e,containerY:i}=this.getMapElementXYPosition(t);return this.unproject(e,i)}getMapEventElement(){return this._container.querySelector(".esri-view-surface")}setDraggability(t){this._dragEnabled=t}project(t,e){const i=new this._lib.Point({longitude:t,latitude:e}),{x:s,y:o}=this._mapView.toScreen(i);return{x:s,y:o}}unproject(t,e){const{latitude:i,longitude:s}=this._mapView.toMap({x:t,y:e});return{lng:s,lat:i}}setCursor(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t}setDoubleClickToZoom(t){this._zoomEnabled=t}render(t,e){t.created.forEach(t=>{this.addFeature(t,e)}),t.updated.forEach(t=>{this.removeFeatureById(t.id),this.addFeature(t,e)}),t.deletedIds.forEach(t=>{this.removeFeatureById(t)})}clear(){this._featureLayer.graphics.removeAll()}removeFeatureById(t){const e=this._featureLayer.graphics.find(e=>e.attributes[this._featureIdAttributeName]===t);this._featureLayer.remove(e)}addFeature(t,e){const{coordinates:i,type:s}=t.geometry,o=e[t.properties.mode](t);let n,r;switch(s){case"Point":r=new this._lib.Point({latitude:i[1],longitude:i[0]}),n=new this._lib.SimpleMarkerSymbol({color:this.getColorFromHex(o.pointColor),size:2*o.pointWidth+"px",outline:{color:this.getColorFromHex(o.pointOutlineColor),width:o.pointOutlineWidth+"px"}});break;case"LineString":r=new this._lib.Polyline({paths:[i]}),n=new this._lib.SimpleLineSymbol({color:this.getColorFromHex(o.lineStringColor),width:o.lineStringWidth+"px"});break;case"Polygon":r=new this._lib.Polygon({rings:i}),n=new this._lib.SimpleFillSymbol({color:this.getColorFromHex(o.polygonFillColor,o.polygonFillOpacity),outline:{color:this.getColorFromHex(o.polygonOutlineColor),width:o.polygonOutlineWidth+"px"}})}const a=new this._lib.Graphic({geometry:r,symbol:n,attributes:{[this._featureIdAttributeName]:t.id}});"Point"===s?this._featureLayer.graphics.add(a):this._featureLayer.graphics.add(a,0)}getColorFromHex(t,e){const i=this._lib.Color.fromHex(t);return e&&(i.a=e),i}}const xt="selected",St="midPoint",Et="closingPoint";function wt(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function bt(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 Mt;!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(Mt||(Mt={}));class Dt{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.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.type=Mt.Drawing,this.mode="base",this._state="unregistered",this._styles=e&&e.styles?t({},e.styles):{},this.pointerDistance=e&&e.pointerDistance||40}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})}validateFeature(t){if("unregistered"===this._state)throw new Error("Mode must be registered");return function(t,e){let i;if(wt(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(wt(t.geometry))if(wt(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)}onFinish(t){}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}}function It(t,e){const i=t=>t*Math.PI/180,s=i(t[1]),o=i(t[0]),n=i(e[1]),r=n-s,a=i(e[0])-o,l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(s)*Math.cos(n)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}function kt(t){return t%360*Math.PI/180}function Ot(t){return t%(2*Math.PI)*180/Math.PI}function Ft(t,e,i){const s=kt(t[0]),o=kt(t[1]),n=kt(i),r=function(t){return t/6371.0088}(e),a=Math.asin(Math.sin(o)*Math.cos(r)+Math.cos(o)*Math.sin(r)*Math.cos(n));return[Ot(s+Math.atan2(Math.sin(n)*Math.sin(r)*Math.cos(o),Math.cos(r)-Math.sin(o)*Math.sin(a))),Ot(a)]}function Lt(t){const{center:i,radiusKilometers:s,coordinatePrecision:o}=t,n=t.steps?t.steps:64,r=[];for(let t=0;t<n;t++){const a=Ft(i,s,-360*t/n);r.push([e(a[0],o),e(a[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function Wt(t){let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}const i=[];for(let t=0;t<e.length;t++)for(let i=0;i<e[t].length-1;i++)for(let s=0;s<e.length;s++)for(let n=0;n<e[s].length-1;n++)o(t,i,s,n);return i.length>0;function s(t){return t<0||t>1}function o(t,o,n,r){const a=e[t][o],l=e[t][o+1],h=e[n][r],d=e[n][r+1],c=function(t,e,i,s){if(At(t,i)||At(t,s)||At(e,i)||At(s,i))return null;const o=t[0],n=t[1],r=e[0],a=e[1],l=i[0],h=i[1],d=s[0],c=s[1],g=(o-r)*(h-c)-(n-a)*(l-d);return 0===g?null:[((o*a-n*r)*(l-d)-(o-r)*(l*c-h*d))/g,((o*a-n*r)*(h-c)-(n-a)*(l*c-h*d))/g]}(a,l,h,d);if(null===c)return;let g,u;g=l[0]!==a[0]?(c[0]-a[0])/(l[0]-a[0]):(c[1]-a[1])/(l[1]-a[1]),u=d[0]!==h[0]?(c[0]-h[0])/(d[0]-h[0]):(c[1]-h[1])/(d[1]-h[1]),s(g)||s(u)||(c.toString(),i.push(c))}}function At(t,e){return t[0]===e[0]&&t[1]===e[1]}function Gt(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(s=t[0])>=-180&&s<=180&&(i=t[1])>=-90&&i<=90&&Bt(t[0])<=e&&Bt(t[1])<=e;var i,s}function Bt(t){let e=1,i=0;for(;Math.round(t*e)/e!==t;)e*=10,i++;return i}function Nt(t,e){return"Polygon"===t.geometry.type&&1===t.geometry.coordinates.length&&t.geometry.coordinates[0].length>=4&&t.geometry.coordinates[0].every(t=>Gt(t,e))&&(i=t.geometry.coordinates[0][0])[0]===(s=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]&&i[1]===s[1];var i,s}function Vt(t,e){return Nt(t,e)&&!Wt(t)}class Rt extends Dt{constructor(e){super(e),this.mode="circle",this.center=void 0,this.clickCount=0,this.currentCircleId=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}}close(){if(void 0===this.currentCircleId)return;const t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(t)}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=Lt({center:this.center,radiusKilometers:1e-5,coordinatePrecision:this.coordinatePrecision}),[i]=this.store.create([{geometry:e.geometry,properties:{mode:this.mode}}]);this.currentCircleId=i,this.clickCount++,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.createCircle(t),this.close()}onMouseMove(t){this.createCircle(t)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{void 0!==this.currentCircleId&&this.store.delete([this.currentCircleId])}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted()}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):i}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&Vt(t,this.coordinatePrecision)}createCircle(t){if(1===this.clickCount&&this.center&&this.currentCircleId){const e=It(this.center,[t.lng,t.lat]),i=Lt({center:this.center,radiusKilometers:e,coordinatePrecision:this.coordinatePrecision});this.store.updateGeometry([{id:this.currentCircleId,geometry:i.geometry}])}}}class jt extends Dt{constructor(e){super(e),this.mode="freehand",this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=void 0,this.keyEvents=void 0,this.cursors=void 0,this.preventPointsNearClose=void 0;const i={start:"crosshair",close:"pointer"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.preventPointsNearClose=e&&e.preventPointsNearClose||!0,this.minDistance=e&&e.minDistance||20,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.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(void 0===this.currentId||!1===this.startingClick)return;const e=this.store.getGeometryCopy(this.currentId),[s,o]=e.coordinates[0][e.coordinates[0].length-2],{x:n,y:r}=this.project(s,o),a=i({x:n,y:r},{x:t.containerX,y:t.containerY}),[l,h]=e.coordinates[0][0],{x:d,y:c}=this.project(l,h);if(i({x:d,y:c},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.setCursor(this.cursors.start);a<this.minDistance||(e.coordinates[0].pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[...e.coordinates[0],[t.lng,t.lat],e.coordinates[0][0]]]}}]))}onClick(t){if(!1===this.startingClick){const[e,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}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);return this.currentId=e,this.closingPointId=i,this.startingClick=!0,void this.setDrawing()}this.close()}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1,"drawing"===this.state&&this.setStarted()}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):"Feature"===e.type&&"Point"===e.geometry.type&&e.properties.mode===this.mode?(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):i}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&Nt(t,this.coordinatePrecision)}}const Tt=Math.PI/180,Ut=180/Math.PI;class zt{constructor(t){this.coordinatePrecision=void 0,this.coords=void 0,this.length=void 0,this.coordinatePrecision=t,this.coords=[],this.length=0}moveTo(t){this.length++,this.coords.push([e(t[0],this.coordinatePrecision),e(t[1],this.coordinatePrecision)])}}class Xt{constructor({properties:t}){this.geometries=void 0,this.properties=void 0,this.properties=t||{},this.geometries=[]}toJSON(){if(1===this.geometries.length){const t=this.geometries[0].coords;if(t[0][0]&&!isNaN(t[0][0])&&t[0][1]&&!isNaN(t[0][1]))return{geometry:{type:"LineString",coordinates:t},type:"Feature",properties:this.properties}}return null}}class Yt{constructor(t,e,i){if(this.g=void 0,this.start=void 0,this.end=void 0,this.properties=void 0,!t||void 0===t[0]||void 0===t[1])throw new Error("GreatCircle constructor expects two args: start and end objects with x and y properties");if(!e||void 0===e[0]||void 0===e[1])throw new Error("GreatCircle constructor expects two args: start and end objects with x and y properties");this.start={lng:t[0],lat:t[1],x:Tt*t[0],y:Tt*t[1]},this.end={lng:e[0],lat:e[1],x:Tt*e[0],y:Tt*e[1]},this.properties=i||{};const s=this.start.x-this.end.x,o=Math.pow(Math.sin((this.start.y-this.end.y)/2),2)+Math.cos(this.start.y)*Math.cos(this.end.y)*Math.pow(Math.sin(s/2),2);if(this.g=2*Math.asin(Math.sqrt(o)),this.g===Math.PI)throw new Error(`it appears ${t} and ${e} are 'antipodal', e.g diametrically opposite, thus there is no single route but rather infinite`);if(isNaN(this.g))throw new Error(`could not calculate great circle between ${t} and ${e}`)}interpolate(t){const e=Math.sin((1-t)*this.g)/Math.sin(this.g),i=Math.sin(t*this.g)/Math.sin(this.g),s=e*Math.cos(this.start.y)*Math.cos(this.start.x)+i*Math.cos(this.end.y)*Math.cos(this.end.x),o=e*Math.cos(this.start.y)*Math.sin(this.start.x)+i*Math.cos(this.end.y)*Math.sin(this.end.x),n=e*Math.sin(this.start.y)+i*Math.sin(this.end.y),r=Ut*Math.atan2(n,Math.sqrt(Math.pow(s,2)+Math.pow(o,2)));return[Ut*Math.atan2(o,s),r]}arc(t,e){const i=[];if(!t||t<=2)i.push([this.start.lng,this.start.lat]),i.push([this.end.lng,this.end.lat]);else{const e=1/(t-1);for(let s=0;s<t;++s){const t=this.interpolate(e*s);i.push(t)}}let s=!1,o=0;const n=e&&e.offset?e.offset:10,r=180-n,a=-180+n,l=360-n;for(let t=1;t<i.length;++t){const e=i[t-1][0],n=i[t][0],h=Math.abs(n-e);h>l&&(n>r&&e<a||e>r&&n<a)?s=!0:h>o&&(o=h)}const h=[];if(s&&o<n){let t=[];h.push(t);for(let e=0;e<i.length;++e){const s=i[e][0];if(e>0&&Math.abs(s-i[e-1][0])>l){let o=i[e-1][0],n=i[e-1][1],l=i[e][0],d=i[e][1];if(o>-180&&o<a&&180===l&&e+1<i.length&&i[e-1][0]>-180&&i[e-1][0]<a){t.push([-180,i[e][1]]),e++,t.push([i[e][0],i[e][1]]);continue}if(o>r&&o<180&&-180===l&&e+1<i.length&&i[e-1][0]>r&&i[e-1][0]<180){t.push([180,i[e][1]]),e++,t.push([i[e][0],i[e][1]]);continue}if(o<a&&l>r){const t=o;o=l,l=t;const e=n;n=d,d=e}if(o>r&&l<a&&(l+=360),o<=180&&l>=180&&o<l){const s=(180-o)/(l-o),a=s*d+(1-s)*n;t.push([i[e-1][0]>r?180:-180,a]),t=[],t.push([i[e-1][0]>r?-180:180,a]),h.push(t)}else t=[],h.push(t);t.push([s,i[e][1]])}else t.push([i[e][0],i[e][1]])}}else{const t=[];h.push(t);for(let e=0;e<i.length;++e)t.push([i[e][0],i[e][1]])}const d=new Xt({properties:this.properties});for(let t=0;t<h.length;++t){const i=new zt(e.coordinatePrecision);d.geometries.push(i);const s=h[t];for(let t=0;t<s.length;++t)i.moveTo(s[t])}return d}}class Ht{constructor({store:t,mode:e,project:i,unproject:s,pointerDistance:o,coordinatePrecision: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.store=t,this.mode=e,this.project=i,this.unproject=s,this.pointerDistance=o,this.coordinatePrecision=n}}class Jt extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinate=(t,e)=>this.getSnappableEnds(t,t=>Boolean(!t.properties||t.properties.mode!==this.mode||!e||t.id!==e)),this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappableEnds(t,e){const i=this.clickBoundingBox.create(t),s=this.store.search(i,e),o={coord:void 0,minDist:Infinity};return s.forEach(e=>{let i;if("LineString"!==e.geometry.type)return;i=e.geometry.coordinates;const s=i[0],n=this.pixelDistance.measure(t,s);n<o.minDist&&n<this.pointerDistance&&(o.coord=s);const r=i[i.length-1],a=this.pixelDistance.measure(t,r);a<o.minDist&&a<this.pointerDistance&&(o.coord=r)}),o.coord}}class Kt extends Ht{constructor(t){super(t)}measure(t,e){const{x:s,y:o}=this.project(e[0],e[1]);return i({x:s,y:o},{x:t.containerX,y:t.containerY})}}function $t({unproject:t,point:e,pointerDistance:i}){const s=i/2,{x:o,y:n}=e;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[t(o-s,n-s),t(o+s,n-s),t(o+s,n+s),t(o-s,n+s),t(o-s,n-s)].map(t=>[t.lng,t.lat])]}}}class qt extends Ht{constructor(t){super(t)}create(t){const{containerX:e,containerY:i}=t;return $t({unproject:this.unproject,point:{x:e,y:i},pointerDistance:this.pointerDistance})}}class Zt extends Dt{constructor(e){super(e),this.mode="greatcircle",this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.cursors=void 0,this.snapping=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}}close(){if(void 0===this.currentId)return;const t=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t)}registerBehaviors(t){this.snapping=new Jt(t,new Kt(t),new qt(t))}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(this.setCursor(this.cursors.start),(void 0!==this.currentId||0!==this.currentCoordinate)&&this.currentId&&1===this.currentCoordinate&&this.closingPointId){const e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];this.store.updateGeometry([{id:this.closingPointId,geometry:{type:"Point",coordinates:e}}]);const i=this.store.getGeometryCopy(this.currentId);i.coordinates.pop();const s=function({start:t,end:e,options:i}){const s=i||{};if("object"!=typeof s)throw new Error("options argument is invalid, must be of type object");const{properties:o={},numberOfPoints:n=100,offset:r=10,coordinatePrecision:a=9}=s;return new Yt(t,e,o).arc(n,{offset:r,coordinatePrecision:a}).toJSON()}({start:i.coordinates[0],end:e,options:{coordinatePrecision:this.coordinatePrecision}});s&&this.store.updateGeometry([{id:this.currentId,geometry:s.geometry}])}}onClick(t){if(0===this.currentCoordinate){const e=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t)||[t.lng,t.lat],[i]=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=i;const[s]=this.store.create([{geometry:{type:"Point",coordinates:e},properties:{mode:this.mode}}]);this.closingPointId=s,this.currentCoordinate++,this.setDrawing()}else 1===this.currentCoordinate&&this.currentId&&(this.setCursor("pointer"),this.close())}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}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):"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):i}validateFeature(t){return!!super.validateFeature(t)&&"LineString"===t.geometry.type&&t.properties.mode===this.mode&&t.geometry.coordinates.length>=2}}class Qt extends Ht{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),s=this.store.search(i,e),o={coord:void 0,minDist:Infinity};return s.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<o.minDist&&i<this.pointerDistance&&(o.coord=e)})}),o.coord}}class te extends Dt{constructor(e){super(e),this.mode="linestring",this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.allowSelfIntersections=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.cursors=void 0,this.mouseMove=!1,this.snapping=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,this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,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);t.coordinates.pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[...t.coordinates]}}]);const e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e)}registerBehaviors(t){this.snapping=new Qt(t,new Kt(t),new qt(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);e.coordinates.pop();const s=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(this.closingPointId){const[s,o]=e.coordinates[e.coordinates.length-1],{x:n,y:r}=this.project(s,o);i({x:n,y:r},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[...e.coordinates,s]}}])}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];if(0===this.currentCoordinate){const[t]=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=t,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const t=this.store.getGeometryCopy(this.currentId),[i]=this.store.create([{geometry:{type:"Point",coordinates:[...e]},properties:{mode:this.mode}}]);this.closingPointId=i,this.setCursor(this.cursors.close),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[t.coordinates[0],e,e]}}]),this.currentCoordinate++}else if(this.currentId){const s=this.store.getGeometryCopy(this.currentId),[o,n]=s.coordinates[s.coordinates.length-2],{x:r,y:a}=this.project(o,n);if(i({x:r,y:a},{x:t.containerX,y:t.containerY})<this.pointerDistance)this.close();else{const t={type:"LineString",coordinates:[...s.coordinates,e]};if(!this.allowSelfIntersections&&Wt({type:"Feature",geometry:t,properties:{}}))return;this.closingPointId&&(this.setCursor(this.cursors.close),this.store.updateGeometry([{id:this.currentId,geometry:t},{id:this.closingPointId,geometry:{type:"Point",coordinates:s.coordinates[s.coordinates.length-1]}}]),this.currentCoordinate++)}}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}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):"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):i}validateFeature(t){return!!super.validateFeature(t)&&"LineString"===t.geometry.type&&t.properties.mode===this.mode&&t.geometry.coordinates.length>=2}}function ee(t,e){return"Point"===t.geometry.type&&Gt(t.geometry.coordinates,e)}class ie extends Dt{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]=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.onFinish(e)}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}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&ee(t,this.coordinatePrecision)}}function se(t,e){return t[0]===e[0]&&t[1]===e[1]}class oe extends Ht{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 creating");if(t.length<=3)throw new Error("Requires at least 4 cooridnates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:{mode:e,[Et]:!0}},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:{mode:e,[Et]:!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]),s=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:s<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}}}class ne extends Dt{constructor(e){super(e),this.mode="polygon",this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=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,this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,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;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[...t.slice(0,-2),t[0]]]}}]);const e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e)}registerBehaviors(t){this.pixelDistance=new Kt(t),this.snapping=new Qt(t,this.pixelDistance,new qt(t)),this.closingPoints=new oe(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 s;if(e&&(t.lng=e[0],t.lat=e[1]),1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),o=Math.max(1e-6,e);s=[i[0],[t.lng,t.lat],[t.lng,t.lat-o],i[0]]}else if(2===this.currentCoordinate)s=[i[0],i[1],[t.lng,t.lat],i[0]];else{const{isClosing:e,isPreviousClosing:o}=this.closingPoints.isClosingPoint(t);o||e?(this.setCursor(this.cursors.close),s=[...i.slice(0,-2),i[0],i[0]]):s=[...i.slice(0,-2),[t.lng,t.lat],i[0]]}this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[s]}}])}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(se([t.lng,t.lat],i.coordinates[0][0]))return;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]]]}}]),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(se([t.lng,t.lat],i[1]))return;2===this.currentCoordinate&&this.closingPoints.create(i,"polygon"),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[i[0],i[1],[t.lng,t.lat],[t.lng,t.lat],i[0]]]}}]),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:s,isPreviousClosing:o}=this.closingPoints.isClosingPoint(t);if(o||s)this.close();else{if(e&&(t.lng=e[0],t.lat=e[1]),se([t.lng,t.lat],i[this.currentCoordinate-1]))return;const s=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.currentCoordinate>2&&!this.allowSelfIntersections&&Wt(s))return;this.store.updateGeometry([{id:this.currentId,geometry:s.geometry}]),this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(s.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(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}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&&Nt(t,this.coordinatePrecision)}}class re extends Dt{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){if(1===this.clickCount&&this.center&&this.currentRectangleId){const e=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0];this.store.updateGeometry([{id:this.currentRectangleId,geometry:{type:"Polygon",coordinates:[[e,[t.lng,e[1]],[t.lng,t.lat],[e[0],t.lat],e]]}}])}}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)}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),this.close()}onMouseMove(t){this.updateRectangle(t)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){this.currentRectangleId&&this.store.delete([this.currentRectangleId]),this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted()}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):i}validateFeature(t){return!!super.validateFeature(t)&&t.properties.mode===this.mode&&Vt(t,this.coordinatePrecision)}}class ae extends Dt{constructor(t){super({styles:t.styles}),this.type=Mt.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)&&(ee(t,this.coordinatePrecision)||Nt(t,this.coordinatePrecision)||function(t,e){return"LineString"===t.geometry.type&&t.geometry.coordinates.length>=2&&t.geometry.coordinates.every(t=>Gt(t,e))}(t,this.coordinatePrecision))}}function le(t,i,s,o,n){const r=o(t[0],t[1]),a=o(i[0],i[1]),{lng:l,lat:h}=n((r.x+a.x)/2,(r.y+a.y)/2);return[e(l,s),e(h,s)]}function he(t,e,i,s){const o=[];for(let n=0;n<t.length-1;n++){const r=le(t[n],t[n+1],e,i,s);o.push(r)}return o}class de extends Ht{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:s,midPointSegment:o}=this.store.getPropertiesCopy(t),n=this.store.getGeometryCopy(s),r="Polygon"===n.type?n.coordinates[0]:n.coordinates;r.splice(o+1,0,i.coordinates),n.coordinates="Polygon"===n.type?[r]:r,this.store.updateGeometry([{id:s,geometry:n}]),this.store.delete([...this._midPoints,...this.selectionPointBehavior.ids]),this.create(r,s,e),this.selectionPointBehavior.create(r,n.type,s)}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,s,o){return he(t,i,s,o).map((t,i)=>({geometry:{type:"Point",coordinates:t},properties:e(i)}))}(t,t=>({mode:this.mode,[St]:!0,midPointSegment:t,midPointFeatureId:e}),i,this.config.project,this.config.unproject))}delete(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])}getUpdated(t){if(0!==this._midPoints.length)return he(t,this.coordinatePrecision,this.config.project,this.config.unproject).map((t,e)=>({id:this._midPoints[e],geometry:{type:"Point",coordinates:t}}))}}class ce extends Ht{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 s=[],o="Polygon"===e?t.length-1:t.length;for(let e=0;e<o;e++)s.push({geometry:{type:"Point",coordinates:t[e]},properties:i(e)});return s}(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 ge(t,e){let i=!1;for(let r=0,a=e.length;r<a;r++){const a=e[r];for(let e=0,r=a.length,l=r-1;e<r;l=e++)(o=a[e])[1]>(s=t)[1]!=(n=a[l])[1]>s[1]&&s[0]<(n[0]-o[0])*(s[1]-o[1])/(n[1]-o[1])+o[0]&&(i=!i)}var s,o,n;return i}const ue=(t,e,i)=>{const s=t=>t*t,o=(t,e)=>s(t.x-e.x)+s(t.y-e.y);return Math.sqrt(((t,e,i)=>{const s=o(e,i);if(0===s)return o(t,e);let n=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/s;return n=Math.max(0,Math.min(1,n)),o(t,{x:e.x+n*(i.x-e.x),y:e.y+n*(i.y-e.y)})})(t,e,i))};class pe extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=t,this.createClickBoundingBox=e,this.pixelDistance=i}find(t,e){let i,s,o=Infinity,n=Infinity;const r=this.createClickBoundingBox.create(t),a=this.store.search(r);for(let r=0;r<a.length;r++){const l=a[r],h=l.geometry;if("Point"===h.type){if(l.properties.selectionPoint||!e&&l.properties[St])continue;const r=this.pixelDistance.measure(t,h.coordinates);l.properties[St]&&r<this.pointerDistance&&r<n?(n=r,s=l):!l.properties[St]&&r<this.pointerDistance&&r<o&&(o=r,i=l)}else if("LineString"===h.type)for(let e=0;e<h.coordinates.length-1;e++){const s=h.coordinates[e],n=h.coordinates[e+1],r=ue({x:t.containerX,y:t.containerY},this.project(s[0],s[1]),this.project(n[0],n[1]));r<this.pointerDistance&&r<o&&(o=r,i=l)}else"Polygon"===h.type&&ge([t.lng,t.lat],h.coordinates)&&(o=0,i=l)}return{clickedFeature:i,clickedMidPoint:s}}}class ye extends Ht{constructor(t,e,i,s){super(t),this.config=void 0,this.featuresAtMouseEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=t,this.featuresAtMouseEvent=e,this.selectionPoints=i,this.midPoints=s}startDragging(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return null!==this.draggedFeatureId}canDrag(t,e){const{clickedFeature:i}=this.featuresAtMouseEvent.find(t,!0);return!(!i||i.id!==e)}drag(t){if(!this.draggedFeatureId)return;const i=this.store.getGeometryCopy(this.draggedFeatureId),s=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){let o,n;if("Polygon"===i.type?(o=i.coordinates[0],n=o.length-1):(o=i.coordinates,n=o.length),!this.dragPosition)return!1;for(let t=0;t<n;t++){const i=o[t],n=[this.dragPosition[0]-s[0],this.dragPosition[1]-s[1]],r=e(i[0]-n[0],this.config.coordinatePrecision),a=e(i[1]-n[1],this.config.coordinatePrecision);if(r>180||r<-180||a>90||a<-90)return!1;o[t]=[r,a]}"Polygon"===i.type&&(o[o.length-1]=[o[0][0],o[0][1]]);const r=this.selectionPoints.getUpdated(o)||[],a=this.midPoints.getUpdated(o)||[];this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i},...r,...a]),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:s}}]),this.dragPosition=[t.lng,t.lat])}}class me extends Ht{constructor(t,e,i,s){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedCoordinate={id:null,index:-1},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=s}getClosestCoordinate(t,e){const i={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};let s;if("LineString"===e.type)s=e.coordinates;else{if("Polygon"!==e.type)return i;s=e.coordinates[0]}for(let o=0;o<s.length;o++){const n=this.pixelDistance.measure(t,s[o]);if(n<this.pointerDistance&&n<i.dist){const t="Polygon"===e.type&&(o===s.length-1||0===o);i.dist=n,i.index=t?0:o,i.isFirstOrLastPolygonCoord=t}}return i}getDraggableIndex(t,e){const i=this.store.getGeometryCopy(e),s=this.getClosestCoordinate(t,i);return-1===s.index?-1:s.index}drag(t,e){if(!this.draggedCoordinate.id)return!1;const i=this.draggedCoordinate.index,s=this.store.getGeometryCopy(this.draggedCoordinate.id),o="LineString"===s.type?s.coordinates:s.coordinates[0],n=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==s.type||i!==o.length-1&&0!==i)o[i]=n;else{const t=o.length-1;o[0]=n,o[t]=n}const r=this.selectionPoints.getOneUpdated(i,n),a=r?[r]:[],l=this.midPoints.getUpdated(o)||[];return!("Point"!==s.type&&!e&&Wt({type:"Feature",geometry:s,properties:{}})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:s},...a,...l]),0))}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}}function fe(t){let e=0,i=0,s=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(t=>{e+=t[0],i+=t[1],s++},!0),[e/s,i/s]}function ve(t,e){const i=t,s=e,o=kt(i[1]),n=kt(s[1]);let r=kt(s[0]-i[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);const a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=(Ot(Math.atan2(r,a))+360)%360;return l>180?-(360-l):l}function _e(t,e,i){let s=e;e<0&&(s=-Math.abs(s));const o=s/6371008.8,n=t[0]*Math.PI/180,r=kt(t[1]),a=kt(i),l=o*Math.cos(a);let h=r+l;Math.abs(h)>Math.PI/2&&(h=h>0?Math.PI-h:-Math.PI-h);const d=Math.log(Math.tan(h/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(d)>1e-11?l/d:Math.cos(r),g=[(180*(n+o*Math.sin(a)/c)/Math.PI+540)%360-180,180*h/Math.PI];return g[0]+=g[0]-t[0]>180?-360:t[0]-g[0]>180?360:0,g}function Ce(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;const i=e[1]*Math.PI/180,s=t[1]*Math.PI/180,o=s-i;let n=Math.abs(t[0]-e[0])*Math.PI/180;n>Math.PI&&(n-=2*Math.PI);const r=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(r)>1e-11?o/r:Math.cos(i);return 6371008.8*Math.sqrt(o*o+a*a*n*n)}class Pe extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastBearing=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastBearing=void 0}rotate(t,i){const s=this.store.getGeometryCopy(i);if("Polygon"!==s.type&&"LineString"!==s.type)return;const o=[t.lng,t.lat],n=ve(fe({type:"Feature",geometry:s,properties:{}}),o);if(!this.lastBearing)return void(this.lastBearing=n+180);!function(t,e){if(0===e)return t;const i=fe(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const s=ve(i,t)+e,o=Ce(i,t),n=_e(i,o,s);t[0]=n[0],t[1]=n[1]})}({type:"Feature",geometry:s,properties:{}},-(this.lastBearing-(n+180)));const r="Polygon"===s.type?s.coordinates[0]:s.coordinates;r.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const a=this.midPoints.getUpdated(r)||[],l=this.selectionPoints.getUpdated(r)||[];this.store.updateGeometry([{id:i,geometry:s},...l,...a]),this.lastBearing=n+180}}function xe(t,e,i,s="xy"){return 1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const o=Ce(i,t),n=ve(i,t),r=_e(i,o*e,n);"x"!==s&&"xy"!==s||(t[0]=r[0]),"y"!==s&&"xy"!==s||(t[1]=r[1])}),t}class Se extends Ht{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastDistance=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastDistance=void 0}scale(t,i){const s=this.store.getGeometryCopy(i);if("Polygon"!==s.type&&"LineString"!==s.type)return;const o=[t.lng,t.lat],n=It(fe({type:"Feature",geometry:s,properties:{}}),o);if(!this.lastDistance)return void(this.lastDistance=n);const r={type:"Feature",geometry:s,properties:{}};xe(r,1-(this.lastDistance-n)/n,fe(r));const a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const l=this.midPoints.getUpdated(a)||[],h=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:i,geometry:s},...h,...l]),this.lastDistance=n}}class Ee extends Ht{constructor(t,e,i,s){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedCoordinate={id:null,index:-1},this.lastDistance=void 0,this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=s}getClosestCoordinate(t,e){const i={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};let s;if("LineString"===e.type)s=e.coordinates;else{if("Polygon"!==e.type)return i;s=e.coordinates[0]}for(let o=0;o<s.length;o++){const n=this.pixelDistance.measure(t,s[o]);if(n<this.pointerDistance&&n<i.dist){const t="Polygon"===e.type&&(o===s.length-1||0===o);i.dist=n,i.index=t?0:o,i.isFirstOrLastPolygonCoord=t}}return i}getDraggableIndex(t,e){const i=this.store.getGeometryCopy(e),s=this.getClosestCoordinate(t,i);return-1===s.index?-1:s.index}drag(t,i){if(!this.draggedCoordinate.id)return!1;const s=this.draggedCoordinate.index,o=this.store.getGeometryCopy(this.draggedCoordinate.id);if("Polygon"!==o.type&&"LineString"!==o.type)return!1;const n=[t.lng,t.lat],r="Polygon"===o.type?o.coordinates[0]:o.coordinates,a=r[s],l={type:"Feature",geometry:o,properties:{}};let h;"center-fixed"===i?h=this.getCenterOrigin(l):"opposite-corner-fixed"===i&&(h=this.getOppositeOrigin(l,a));const d=It(h,n);if(!this.lastDistance)return this.lastDistance=d,!1;xe(l,1-(this.lastDistance-d)/d,h),r.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const c=this.midPoints.getUpdated(r)||[],g=this.selectionPoints.getUpdated(r)||[];return this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:o},...g,...c]),this.lastDistance=d,!0}getCenterOrigin(t){return fe(t)}getOppositeOrigin(t,e){const i=[Infinity,Infinity,-Infinity,-Infinity];("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{i[0]>t[0]&&(i[0]=t[0]),i[1]>t[1]&&(i[1]=t[1]),i[2]<t[0]&&(i[2]=t[0]),i[3]<t[1]&&(i[3]=t[1])});const[s,o,n,r]=i,a=[[s,r],[(s+n)/2,r],[n,r],[n,(o+r)/2],[n,o],[(s+n)/2,o],[s,o],[s,(o+r)/2]];let l,h=Infinity;for(let t=0;t<a.length;t++){const i=It(e,a[t]);i<h&&(l=t,h=i)}if(void 0===l)throw new Error("No closest coordinate found");return a[this.boundingBoxMaps.opposite[l]]}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.lastDistance=void 0,this.draggedCoordinate={id:null,index:-1}}}class we extends Dt{constructor(e){var i;super(e),this.type=Mt.Select,this.mode="select",this.allowManualDeselection=!0,this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags=void 0,this.keyEvents=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.dragCoordinateResizeFeature=void 0,this.cursors=void 0,this.flags=e&&e.flags?e.flags:{};const s={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"};if(this.cursors=e&&e.cursors?t({},s,e.cursors):s,null===(null==e?void 0:e.keyEvents))this.keyEvents={deselect:null,delete:null,rotate:null,scale:null};else{const i={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,this.allowManualDeselection=null==(i=null==e?void 0:e.allowManualDeselection)||i}setSelecting(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"}registerBehaviors(t){this.pixelDistance=new Kt(t),this.clickBoundingBox=new qt(t),this.featuresAtMouseEvent=new pe(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new ce(t),this.midPoints=new de(t,this.selectionPoints),this.rotateFeature=new Pe(t,this.selectionPoints,this.midPoints),this.scaleFeature=new Se(t,this.selectionPoints,this.midPoints),this.dragFeature=new ye(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new me(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new Ee(t,this.pixelDistance,this.selectionPoints,this.midPoints)}deselect(){const t=this.selected.filter(t=>this.store.has(t)).map(t=>({id:t,property:xt,value:!1}));this.store.updateProperty(t),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()}deleteSelected(){this.store.delete(this.selected),this.selected=[]}onRightClick(t){if(!this.selectionPoints.ids.length)return;let e,i=Infinity;if(this.selectionPoints.ids.forEach(s=>{const o=this.store.getGeometryCopy(s),n=this.pixelDistance.measure(t,o.coordinates);n<this.pointerDistance&&n<i&&(i=n,e=this.store.getPropertiesCopy(s))}),!e)return;const s=e.selectionPointFeatureId,o=e.index,n=this.store.getPropertiesCopy(s),r=this.flags[n.mode];if(!(r&&r.feature&&r.feature.coordinates&&r.feature.coordinates.deletable))return;const a=this.store.getGeometryCopy(s);let l;if("Polygon"===a.type){if(l=a.coordinates[0],l.length<=4)return}else if("LineString"===a.type&&(l=a.coordinates,l.length<=3))return;l&&("Polygon"===a.type&&0===o||o===l.length-1?(l.shift(),l.pop(),l.push([l[0][0],l[0][1]])):l.splice(o,1),this.store.delete([...this.midPoints.ids,...this.selectionPoints.ids]),this.store.updateGeometry([{id:s,geometry:a}]),this.selectionPoints.create(l,a.type,s),r&&r.feature&&r.feature.coordinates&&r.feature.coordinates.midpoints&&this.midPoints.create(l,s,this.coordinatePrecision))}onLeftClick(t){const{clickedFeature:e,clickedMidPoint:i}=this.featuresAtMouseEvent.find(t,this.selected.length>0);if(this.selected.length&&i)this.midPoints.insert(i.id,this.coordinatePrecision);else if(e){const{mode:t}=this.store.getPropertiesCopy(e.id),i=this.flags[t];if(!i||!i.feature)return;const s=this.selected[0];if(s){if(s===e.id)return;this.deselect()}this.setCursor(this.cursors.pointerOver),this.selected=[e.id],this.store.updateProperty([{id:e.id,property:"selected",value:!0}]),this.onSelect(e.id);const{type:o,coordinates:n}=this.store.getGeometryCopy(e.id);if("LineString"!==o&&"Polygon"!==o)return;const r="LineString"===o?n:n[0];r&&i&&i.feature.coordinates&&(this.selectionPoints.create(r,o,e.id),i.feature.coordinates.midpoints&&this.midPoints.create(r,e.id,this.coordinatePrecision))}else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)}canScale(t){return this.keyEvents.scale&&this.keyEvents.scale.every(e=>t.heldKeys.includes(e))}canRotate(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(e=>t.heldKeys.includes(e))}preventDefaultKeyEvent(t){const e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()}onKeyDown(t){this.preventDefaultKeyEvent(t)}onKeyUp(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect()}onDragStart(t,e){if(!this.selected.length)return;const i=this.store.getPropertiesCopy(this.selected[0]),s=this.flags[i.mode];if(!(s&&s.feature&&(s.feature.draggable||s.feature.coordinates&&s.feature.coordinates.draggable)))return;this.dragEventCount=0;const o=this.selected[0],n=this.dragCoordinate.getDraggableIndex(t,o);return s&&s.feature&&s.feature.coordinates&&s.feature.coordinates.draggable&&-1!==n?(this.setCursor(this.cursors.dragStart),s.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(o,n):this.dragCoordinate.startDragging(o,n),void e(!1)):s&&s.feature&&s.feature.draggable&&this.dragFeature.canDrag(t,o)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,o),void e(!1)):void 0}onDrag(t,e){const i=this.selected[0];if(!i)return;const s=this.store.getPropertiesCopy(i),o=this.flags[s.mode],n=!0===(o&&o.feature&&o.feature.selfIntersectable);return this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0?o&&o.feature&&o.feature.rotateable&&this.canRotate(t)?(e(!1),void this.rotateFeature.rotate(t,i)):o&&o.feature&&o.feature.scaleable&&this.canScale(t)?(e(!1),void this.scaleFeature.scale(t,i)):this.dragCoordinateResizeFeature.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.resizable?(e(!1),void this.dragCoordinateResizeFeature.drag(t,o.feature.coordinates.resizable)):void(this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,n):this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)):void 0}onDragEnd(t,e){this.setCursor(this.cursors.dragEnd),(this.dragCoordinate.isDragging()||this.dragFeature.isDragging())&&this.onFinish(this.selected[0]),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)}onMouseMove(t){if(!this.selected.length)return void this.setCursor("unset");if(this.dragFeature.isDragging())return;let e=!1;this.midPoints.ids.forEach(i=>{if(e)return;const s=this.store.getGeometryCopy(i);this.pixelDistance.measure(t,s.coordinates)<this.pointerDistance&&(e=!0)});let i=!1;if(this.selectionPoints.ids.forEach(s=>{const o=this.store.getGeometryCopy(s);this.pixelDistance.measure(t,o.coordinates)<this.pointerDistance&&(e=!1,i=!0)}),e)return void this.setCursor(this.cursors.insertMidpoint);const{clickedFeature:s}=this.featuresAtMouseEvent.find(t,!0);this.setCursor(this.selected.length>0&&(s&&s.id===this.selected[0]||i)?this.cursors.pointerOver:"unset")}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&&"Point"===e.geometry.type){if(e.properties.selectionPoint)return i.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,i.pointOutlineColor,e),i.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,i.pointWidth,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,e),i.zIndex=30,i;if(e.properties.midPoint)return i.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,i.pointOutlineColor,e),i.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,e),i.zIndex=40,i}else if(e.properties[xt]){if("Polygon"===e.geometry.type)return i.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,i.polygonFillColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,i.polygonOutlineWidth,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,i.polygonOutlineColor,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i;if("LineString"===e.geometry.type)return i.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,i.lineStringColor,e),i.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,i.lineStringWidth,e),i.zIndex=10,i;if("Point"===e.geometry.type)return i.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,i.pointOutlineWidth,e),i.zIndex=10,i}return i}}class be extends Dt{constructor(...t){super(...t),this.type=Mt.Static,this.mode="static"}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0})}}function Me(t,e,i,s,o){for(;s>i;){if(s-i>600){const n=s-i+1,r=e-i+1,a=Math.log(n),l=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*l*(n-l)/n)*(r-n/2<0?-1:1);Me(t,e,Math.max(i,Math.floor(e-r*l/n+h)),Math.min(s,Math.floor(e+(n-r)*l/n+h)),o)}const n=t[e];let r=i,a=s;for(De(t,i,e),o(t[s],n)>0&&De(t,i,s);r<a;){for(De(t,r,a),r++,a--;o(t[r],n)<0;)r++;for(;o(t[a],n)>0;)a--}0===o(t[i],n)?De(t,i,a):(a++,De(t,a,s)),a<=e&&(i=a+1),e<=a&&(s=a-1)}}function De(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}function Ie(t,e){ke(t,0,t.children.length,e,t)}function ke(t,e,i,s,o){o||(o=Ve([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(let n=e;n<i;n++){const e=t.children[n];Oe(o,t.leaf?s(e):e)}return o}function Oe(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Fe(t,e){return t.minX-e.minX}function Le(t,e){return t.minY-e.minY}function We(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Ae(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Ge(t,e){const i=Math.max(t.minX,e.minX),s=Math.max(t.minY,e.minY),o=Math.min(t.maxX,e.maxX),n=Math.min(t.maxY,e.maxY);return Math.max(0,o-i)*Math.max(0,n-s)}function Be(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Ne(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Ve(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function Re(t,e,i,s,o){const n=[e,i];for(;n.length;){if((i=n.pop())-(e=n.pop())<=s)continue;const r=e+Math.ceil((i-e)/s/2)*s;Me(t,r,e,i,o),n.push(e,r,r,i)}}class je{constructor(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(t){let e=this.data;const i=[];if(!Ne(t,e))return i;const s=this.toBBox,o=[];for(;e;){for(let n=0;n<e.children.length;n++){const r=e.children[n],a=e.leaf?s(r):r;Ne(t,a)&&(e.leaf?i.push(r):Be(t,a)?this._all(r,i):o.push(r))}e=o.pop()}return i}collides(t){let e=this.data;if(Ne(t,e)){const i=[];for(;e;){for(let s=0;s<e.children.length;s++){const o=e.children[s],n=e.leaf?this.toBBox(o):o;if(Ne(t,n)){if(e.leaf||Be(t,n))return!0;i.push(o)}}e=i.pop()}}return!1}load(t){if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e}insert(t){this._insert(t,this.data.height-1)}clear(){this.data=Ve([])}remove(t){let e=this.data;const i=this.toBBox(t),s=[],o=[];let n,r,a=!1;for(;e||s.length;){if(e||(e=s.pop(),r=s[s.length-1],n=o.pop(),a=!0),e.leaf){const i=e.children.indexOf(t);-1!==i&&(e.children.splice(i,1),s.push(e),this._condense(s))}a||e.leaf||!Be(e,i)?r?(n++,e=r.children[n],a=!1):e=null:(s.push(e),o.push(n),n=0,r=e,e=e.children[0])}}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,s){const o=i-e+1;let n,r=this._maxEntries;if(o<=r)return n=Ve(t.slice(e,i+1)),Ie(n,this.toBBox),n;s||(s=Math.ceil(Math.log(o)/Math.log(r)),r=Math.ceil(o/Math.pow(r,s-1))),n=Ve([]),n.leaf=!1,n.height=s;const a=Math.ceil(o/r),l=a*Math.ceil(Math.sqrt(r));Re(t,e,i,l,this.compareMinX);for(let o=e;o<=i;o+=l){const e=Math.min(o+l-1,i);Re(t,o,e,a,this.compareMinY);for(let i=o;i<=e;i+=a){const o=Math.min(i+a-1,e);n.children.push(this._build(t,i,o,s-1))}}return Ie(n,this.toBBox),n}_chooseSubtree(t,e,i,s){for(;s.push(e),!e.leaf&&s.length-1!==i;){let i,s=Infinity,r=Infinity;for(let a=0;a<e.children.length;a++){const l=e.children[a],h=We(l),d=(o=t,n=l,(Math.max(n.maxX,o.maxX)-Math.min(n.minX,o.minX))*(Math.max(n.maxY,o.maxY)-Math.min(n.minY,o.minY))-h);d<r?(r=d,s=h<s?h:s,i=l):d===r&&h<s&&(s=h,i=l)}e=i||e.children[0]}var o,n;return e}_insert(t,e,i){const s=i?t:this.toBBox(t),o=[],n=this._chooseSubtree(s,this.data,e,o);for(n.children.push(t),Oe(n,s);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(s,o,e)}_split(t,e){const i=t[e],s=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,s);const n=this._chooseSplitIndex(i,o,s),r=Ve(i.children.splice(n,i.children.length-n));r.height=i.height,r.leaf=i.leaf,Ie(i,this.toBBox),Ie(r,this.toBBox),e?t[e-1].children.push(r):this._splitRoot(i,r)}_splitRoot(t,e){this.data=Ve([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Ie(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let s,o=Infinity,n=Infinity;for(let r=e;r<=i-e;r++){const e=ke(t,0,r,this.toBBox),a=ke(t,r,i,this.toBBox),l=Ge(e,a),h=We(e)+We(a);l<o?(o=l,s=r,n=h<n?h:n):l===o&&h<n&&(n=h,s=r)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:Fe,o=t.leaf?this.compareMinY:Le;this._allDistMargin(t,e,i,s)<this._allDistMargin(t,e,i,o)&&t.children.sort(s)}_allDistMargin(t,e,i,s){t.children.sort(s);const o=this.toBBox,n=ke(t,0,e,o),r=ke(t,i-e,i,o);let a=Ae(n)+Ae(r);for(let s=e;s<i-e;s++){const e=t.children[s];Oe(n,t.leaf?o(e):e),a+=Ae(n)}for(let s=i-e-1;s>=e;s--){const e=t.children[s];Oe(r,t.leaf?o(e):e),a+=Ae(r)}return a}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)Oe(e[s],t)}_condense(t){for(let e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children,e.splice(e.indexOf(t[i]),1)):this.clear():Ie(t[i],this.toBBox)}}class Te{constructor(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new je(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)}toBBox(t){const e=[],i=[];let s;if("Polygon"===t.geometry.type)s=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)s=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");s=[t.geometry.coordinates]}for(let t=0;t<s.length;t++)i.push(s[t][1]),e.push(s[t][0]);const o=Math.min(...i),n=Math.max(...i);return{minX:Math.min(...e),minY:o,maxX:Math.max(...e),maxY:n}}insert(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}load(t){const e=[],i=new Set;t.forEach(t=>{const s=this.toBBox(t);if(this.setMaps(t,s),i.has(String(t.id)))throw new Error(`Duplicate feature ID found ${t.id}`);i.add(String(t.id)),e.push(s)}),this.tree.load(e)}update(t){this.remove(t.id);const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}remove(t){const e=this.idToNode.get(t);if(!e)throw new Error(`${t} not inserted into the spatial index`);this.tree.remove(e)}clear(){this.tree.clear()}search(t){return this.tree.search(this.toBBox(t)).map(t=>this.nodeToId.get(t))}collides(t){return this.tree.collides(this.toBBox(t))}}const Ue={getId:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}),isValidId:t=>"string"==typeof t&&36===t.length};class ze{constructor(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new Te,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ue}clone(t){return JSON.parse(JSON.stringify(t))}getId(){return this.idStrategy.getId()}has(t){return Boolean(this.store[t])}load(t,e){if(0===t.length)return;const i=this.clone(t);i.forEach(t=>{null==t.id&&(t.id=this.idStrategy.getId()),this.tracked&&(t.properties.createdAt?bt(t.properties.createdAt):t.properties.createdAt=+new Date,t.properties.updatedAt?bt(t.properties.updatedAt):t.properties.updatedAt=+new Date)});const s=[];i.forEach(t=>{const i=t.id;if(e&&!e(t))throw new Error(`Feature is not ${i} valid: ${JSON.stringify(t)}`);if(this.has(i))throw new Error(`Feature already exists with this id: ${i}`);this.store[i]=t,s.push(i)}),this.spatialIndex.load(i),this._onChange(s,"create")}search(t,e){const i=this.spatialIndex.search(t).map(t=>this.store[t]);return this.clone(e?i.filter(e):i)}registerOnChange(t){this._onChange=(e,i)=>{t(e,i)}}getGeometryCopy(t){const e=this.store[t];if(!e)throw new Error(`No feature with this id (${t}), can not get geometry copy`);return this.clone(e.geometry)}getPropertiesCopy(t){const e=this.store[t];if(!e)throw new Error(`No feature with this id (${t}), can not get properties copy`);return this.clone(e.properties)}updateProperty(t){const e=[];t.forEach(({id:t,property:i,value:s})=>{const o=this.store[t];if(!o)throw new Error(`No feature with this (${t}), can not update geometry`);e.push(t),o.properties[i]=s,this.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,"update")}updateGeometry(t){const e=[];t.forEach(({id:t,geometry:i})=>{e.push(t);const s=this.store[t];if(!s)throw new Error(`No feature with this (${t}), can not update geometry`);s.geometry=this.clone(i),this.spatialIndex.update(s),this.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,"update")}create(e){const i=[];return e.forEach(({geometry:e,properties:s})=>{let o,n=t({},s);this.tracked&&(o=+new Date,s?(n.createdAt="number"==typeof s.createdAt?s.createdAt:o,n.updatedAt="number"==typeof s.updatedAt?s.updatedAt:o):n={createdAt:o,updatedAt:o});const r=this.getId(),a={id:r,type:"Feature",geometry:e,properties:n};this.store[r]=a,this.spatialIndex.insert(a),i.push(r)}),this._onChange&&this._onChange([...i],"create"),i}delete(t){t.forEach(t=>{if(!this.store[t])throw new Error("No feature with this id, can not delete");delete this.store[t],this.spatialIndex.remove(t)}),this._onChange&&this._onChange([...t],"delete")}copyAll(){return this.clone(Object.keys(this.store).map(t=>this.store[t]))}clear(){this.store={},this.spatialIndex.clear()}size(){return Object.keys(this.store).length}}class Xe{constructor(e){this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectMode=void 0,this._adapter=e.adapter,this._mode=new be;const i=new Set,s=e.modes.reduce((t,e)=>{if(i.has(e.mode))throw new Error(`There is already a ${e.mode} mode provided`);return i.add(e.mode),t[e.mode]=e,t},{}),o=Object.keys(s);if(0===o.length)throw new Error("No modes provided");o.forEach(t=>{if(s[t].type===Mt.Select){if(this._instanceSelectMode)throw new Error("only one type of select mode can be provided");this._instanceSelectMode=t}}),this._modes=t({},s,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[]},this._store=new ze({tracked:!!e.tracked,idStrategy:e.idStrategy?e.idStrategy:void 0});const n=t=>{const e=[],i=this._store.copyAll().filter(i=>!t.includes(i.id)||(e.push(i),!1));return{changed:e,unchanged:i}},r=t=>{this._enabled&&this._eventListeners.finish.forEach(e=>{e(t)})},a=(t,e)=>{if(!this._enabled)return;this._eventListeners.change.forEach(i=>{i(t,e)});const{changed:i,unchanged:s}=n(t);"create"===e?this._adapter.render({created:i,deletedIds:[],unchanged:s,updated:[]},this.getModeStyles()):"update"===e?this._adapter.render({created:[],deletedIds:[],unchanged:s,updated:i},this.getModeStyles()):"delete"===e?this._adapter.render({created:[],deletedIds:t,unchanged:s,updated:[]},this.getModeStyles()):"styling"===e&&this._adapter.render({created:[],deletedIds:[],unchanged:s,updated:[]},this.getModeStyles())},l=t=>{if(!this._enabled)return;this._eventListeners.select.forEach(e=>{e(t)});const{changed:e,unchanged:i}=n([t]);this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())},h=t=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t()});const{changed:e,unchanged:i}=n([t]);e&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())};Object.keys(this._modes).forEach(t=>{this._modes[t].register({mode:t,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:a,onSelect:l,onDeselect:h,onFinish:r,coordinatePrecision:this._adapter.getCoordinatePrecision()})})}checkEnabled(){if(!this._enabled)throw new Error("Terra Draw is not enabled")}getModeStyles(){const t={};return Object.keys(this._modes).forEach(e=>{t[e]=t=>this._instanceSelectMode&&t.properties[xt]?this._modes[this._instanceSelectMode].styleFeature.bind(this._modes[this._instanceSelectMode])(t):this._modes[e].styleFeature.bind(this._modes[e])(t)}),t}featuresAtLocation({lng:t,lat:e},s){const o=s&&void 0!==s.pointerDistance?s.pointerDistance:30,n=!s||void 0===s.ignoreSelectFeatures||s.ignoreSelectFeatures,r=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),l=a(t,e),h=$t({unproject:r,point:l,pointerDistance:o});return this._store.search(h).filter(s=>{if(n&&(s.properties[St]||s.properties.selectionPoint))return!1;if("Point"===s.geometry.type){const t=s.geometry.coordinates,e=a(t[0],t[1]);return i(l,e)<o}if("LineString"===s.geometry.type){const t=s.geometry.coordinates;for(let e=0;e<t.length-1;e++){const i=t[e],s=t[e+1];if(ue(l,a(i[0],i[1]),a(s[0],s[1]))<o)return!0}return!1}return!!ge([t,e],s.geometry.coordinates)||void 0})}setModeStyles(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e}getSnapshot(){return this._store.copyAll()}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(t){throw new Error("Enabled is read only")}getMode(){return this._mode.mode}setMode(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()}removeFeatures(t){this.checkEnabled(),this._store.delete(t)}getFeatureId(){return this._store.getId()}hasFeature(t){return this._store.has(t)}addFeatures(t){this.checkEnabled(),0!==t.length&&this._store.load(t,t=>{if(Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)){const e=this._modes[t.properties.mode];return!!e&&e.validateFeature.bind(e)(t)}return!1})}start(){this._enabled=!0,this._adapter.register({getState:()=>this._mode.state,onClick:t=>{this._mode.onClick(t)},onMouseMove:t=>{this._mode.onMouseMove(t)},onKeyDown:t=>{this._mode.onKeyDown(t)},onKeyUp:t=>{this._mode.onKeyUp(t)},onDragStart:(t,e)=>{this._mode.onDragStart(t,e)},onDrag:(t,e)=>{this._mode.onDrag(t,e)},onDragEnd:(t,e)=>{this._mode.onDragEnd(t,e)},onClear:()=>{this._mode.cleanUp(),this._store.clear()}})}getFeaturesAtLngLat(t,e){const{lng:i,lat:s}=t;return this.featuresAtLocation({lng:i,lat:s},e)}getFeaturesAtPointerEvent(t,e){const i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)}stop(){this._enabled=!1,this._adapter.unregister()}on(t,e){const i=this._eventListeners[t];i.includes(e)||i.push(e)}off(t,e){const i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)}}const Ye={TerraDrawBaseDrawMode:Dt,TerraDrawBaseAdapter:o};export{Xe as TerraDraw,Pt as TerraDrawArcGISMapsSDKAdapter,Rt as TerraDrawCircleMode,Ye as TerraDrawExtend,jt as TerraDrawFreehandMode,n as TerraDrawGoogleMapsAdapter,Zt as TerraDrawGreatCircleMode,r as TerraDrawLeafletAdapter,te as TerraDrawLineStringMode,l as TerraDrawMapLibreGLAdapter,a as TerraDrawMapboxGLAdapter,Ct as TerraDrawOpenLayersAdapter,ie as TerraDrawPointMode,ne as TerraDrawPolygonMode,re as TerraDrawRectangleMode,ae as TerraDrawRenderMode,we as TerraDrawSelectMode};
|
|
2
2
|
//# sourceMappingURL=terra-draw.modern.js.map
|