diff --git a/dist/samples/map-drawing-terradraw/app/package.json b/dist/samples/map-drawing-terradraw/app/package.json index f22e90905..b0723a9a3 100644 --- a/dist/samples/map-drawing-terradraw/app/package.json +++ b/dist/samples/map-drawing-terradraw/app/package.json @@ -11,12 +11,12 @@ }, "dependencies": { "terra-draw": "^1.32.3", - "terra-draw-google-maps-adapter": "*" + "terra-draw-google-maps-adapter": "^1.6.2" }, "devDependencies": { "@types/google.maps": "*", "typescript": "^5.9.3", - "vite": "^8.2.0" + "vite": "^8.3.0" }, "author": "Google LLC" } diff --git a/dist/samples/map-drawing-terradraw/dist/assets/index-CDuhlBlN.css b/dist/samples/map-drawing-terradraw/dist/assets/index-CDuhlBlN.css deleted file mode 100644 index cf8ed49d1..000000000 --- a/dist/samples/map-drawing-terradraw/dist/assets/index-CDuhlBlN.css +++ /dev/null @@ -1 +0,0 @@ -html,body{height:100%;margin:0;padding:0;font-family:Arial,sans-serif}#map{height:100%;width:100%}#mode-ui{position:absolute;top:10px;right:10px;background:#fff;padding:10px;border-radius:5px;box-shadow:0 0 10px #0003;z-index:1000;display:flex;flex-direction:column}#mode-ui button{margin:5px 0;cursor:pointer}.mode-button{width:30px;height:30px;border:1px solid #ccc;background-color:#fff;padding:2px;box-sizing:border-box}.mode-button img{width:100%;height:100%;display:block;-webkit-user-select:none;user-select:none}.mode-button.active{background-color:#e0e0e0}#select-mode,#clear-mode,#delete-selected-button,#undo-button,#redo-button,#export-button,#upload-button,#resize-button{background-color:#000}#select-mode img,#clear-mode img,#delete-selected-button img,#undo-button img,#redo-button img,#export-button img,#upload-button img,#resize-button img{filter:brightness(0) invert(1)}#select-mode.active,#clear-mode:active,#delete-selected-button:active,#undo-button:active,#redo-button:active,#export-button:active,#upload-button:active,#resize-button.active{background-color:#a9a9a9} diff --git a/dist/samples/map-drawing-terradraw/dist/assets/index-CMfcP0GD.js b/dist/samples/map-drawing-terradraw/dist/assets/index-CMfcP0GD.js deleted file mode 100644 index 1610d85f7..000000000 --- a/dist/samples/map-drawing-terradraw/dist/assets/index-CMfcP0GD.js +++ /dev/null @@ -1 +0,0 @@ -(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))i(o);new MutationObserver(o=>{for(const n of o)if(n.type==="childList")for(const r of n.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function e(o){const n={};return o.integrity&&(n.integrity=o.integrity),o.referrerPolicy&&(n.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?n.credentials="include":o.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function i(o){if(o.ep)return;o.ep=!0;const n=e(o);fetch(o.href,n)}})();function S(){return S=Object.assign?Object.assign.bind():function(s){for(var t=1;th*Math.PI/180,i=e(s[1]),o=e(s[0]),n=e(t[1]),r=n-i,a=e(t[0])-o,d=Math.sin(r/2)*Math.sin(r/2)+Math.cos(i)*Math.cos(n)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371e3/1e3}const Ce=63710088e-1;function R(s){return s%360*Math.PI/180}function Pe(s){return s/6371.0088}function V(s){return s%(2*Math.PI)*180/Math.PI}function O(s,t=9){const e=Math.pow(10,t);return Math.round(s*e)/e}const ee=57.29577951308232,ie=.017453292519943295,xt=6378137,_=(s,t)=>({x:s===0?0:s*ie*xt,y:t===0?0:Math.log(Math.tan(Math.PI/4+t*ie/2))*xt}),tt=(s,t)=>({lng:s===0?0:ee*(s/xt),lat:t===0?0:(2*Math.atan(Math.exp(t/xt))-Math.PI/2)*ee});function Re(s,t,e){const i=R(s[0]),o=R(s[1]),n=R(e),r=Pe(t),a=Math.asin(Math.sin(o)*Math.cos(r)+Math.cos(o)*Math.sin(r)*Math.cos(n));return[V(i+Math.atan2(Math.sin(n)*Math.sin(r)*Math.cos(o),Math.cos(r)-Math.sin(o)*Math.sin(a))),V(a)]}function oe(s){const{center:t,radiusKilometers:e,coordinatePrecision:i}=s,o=s.steps?s.steps:64,n=[];for(let r=0;r0;function i(n){return n<0||n>1}function o(n,r,a,d){const h=t[n][r],l=t[n][r+1],c=t[a][d],u=t[a][d+1],p=(function(C,v,y,I){if(vt(C,y)||vt(C,I)||vt(v,y)||vt(I,y))return null;const F=C[0],x=C[1],w=v[0],M=v[1],D=y[0],B=y[1],k=I[0],z=I[1],K=(F-w)*(B-z)-(x-M)*(D-k);return K===0?null:[((F*M-x*w)*(D-k)-(F-w)*(D*z-B*k))/K,((F*M-x*w)*(B-z)-(x-M)*(D*z-B*k))/K]})(h,l,c,u);if(p===null)return;let g,f;g=l[0]!==h[0]?(p[0]-h[0])/(l[0]-h[0]):(p[1]-h[1])/(l[1]-h[1]),f=u[0]!==c[0]?(p[0]-c[0])/(u[0]-c[0]):(p[1]-c[1])/(u[1]-c[1]),i(g)||i(f)||(p.toString(),e.push(p))}}function vt(s,t){return s[0]===t[0]&&s[1]===t[1]}function wt(s,t){return ne(s[0])<=t&&ne(s[1])<=t}function Gt(s){return s.length===2&&typeof s[0]=="number"&&typeof s[1]=="number"&&s[0]!==1/0&&s[1]!==1/0&&(e=s[0])>=-180&&e<=180&&(t=s[1])>=-90&&t<=90;var t,e}function ne(s){let t=1,e=0;for(;Math.round(s*t)/t!==s;)t*=10,e++;return e}const Be="Feature has holes",Ae="Feature has less than 4 coordinates",Ue="Feature has invalid coordinates",We="Feature coordinates are not closed";function zt(s,t){if(s.geometry.type!=="Polygon")return{valid:!1,reason:"Feature is not a Polygon"};if(s.geometry.coordinates.length!==1)return{valid:!1,reason:Be};if(s.geometry.coordinates[0].length<4)return{valid:!1,reason:Ae};for(let o=0;o({type:"Feature",geometry:{type:"Point",coordinates:n},properties:S({mode:this.mode,[e]:!0},i?i(r):{})}));return this.createFeatures(o)}updatePoint({featureId:t,coordinateMutations:e,propertyMutations:i,context:o}){return this.handleMutateFeature({type:"Point",featureId:t,coordinateMutations:e,propertyMutations:i,context:o})}updatePolygon({featureId:t,coordinateMutations:e,context:i,propertyMutations:o}){return this.handleMutateFeature({type:"Polygon",featureId:t,coordinateMutations:e,propertyMutations:o,context:i})}updateLineString({featureId:t,coordinateMutations:e,context:i,propertyMutations:o}){return this.handleMutateFeature({type:"LineString",featureId:t,coordinateMutations:e,propertyMutations:o,context:i})}deleteFeatureIfPresent(t){t&&this.store.has(t)&&this.store.delete([t])}deleteFeaturesIfPresent(t){if(t.length===0)return;const e=t.filter(i=>this.store.has(i));e.length&&this.store.delete(e)}setDeselected(t){const e=t.filter(i=>this.store.has(i)).map(i=>({featureId:i,properties:{[b.SELECTED]:!1}}));this.updateFeatureProperties(e)}setSelected(t){const{type:e}=this.store.getGeometryCopy(t),i={featureId:t,propertyMutations:{[b.SELECTED]:!0},context:{updateType:P.Commit}};e==="Polygon"?this.updatePolygon(i):e==="LineString"?this.updateLineString(i):e==="Point"&&this.updatePoint(i)}updateGuidancePoints(t){this.updateFeatureGeometries(t.map(({featureId:e,coordinate:i})=>({id:e,geometry:{type:"Point",coordinates:i}})))}handleCreateFeature({geometry:t,properties:e}){return this.createFeatureWithGeometry({geometry:t,properties:e})}handleMutateFeature({type:t,featureId:e,coordinateMutations:i,propertyMutations:o,context:n}){if(!this.mutateFeature({type:t,featureId:e,coordinateMutations:i,propertyMutations:o,context:n.updateType===P.Finish?S({},n,{correctRightHandRule:!0}):S({},n)}))return null;const r=this.buildFeatureWithGeometry(e);return n.updateType!==P.Finish||i||this.validateGeometryWithUpdateType({geometry:r.geometry,properties:r.properties,updateType:n.updateType})?r:null}mutateFeature({type:t,featureId:e,coordinateMutations:i,propertyMutations:o,context:n}){if(!e)return!1;const r=this.store.getGeometryCopy(e),a=this.store.getPropertiesCopy(e);if(r.type!==t)throw new Error(`${t} geometries cannot be updated on features with ${r.type} geometries`);if(i){let d=this.applyCoordinateMutations(r,i);if(n.correctRightHandRule&&d.type==="Polygon"){const h=re(d);h&&(d=h)}if(!this.validateGeometryWithUpdateType({geometry:d,properties:a,updateType:n.updateType}))return!1;this.updateFeatureGeometries([{id:e,geometry:d}])}return o&&this.updateFeatureProperties([{featureId:e,properties:o}]),!0}applyCoordinateMutations(t,e){if(this.isReplaceMutation(e))return S({},t,{coordinates:e.coordinates});if(t.type==="Point")throw new Error("Coordinate mutations are not supported for Point geometries");const i=t.type==="Polygon",o=i?t.coordinates[0].slice():t.coordinates.slice(),n=o.length,r=u=>{const p=u<0?n+u:u;if(p<0||p>=n)throw new RangeError(`Index ${u} (normalized to ${p}) is out of bounds`);return p},a=new Array(n).fill(void 0),d=Array.from({length:n},()=>[]),h=Array.from({length:n},()=>[]),l=[];for(const u of e){if(u.type===pt||u.type===at){const g=u.index,f=g<0?n+g:g;if(f<0||f>n)throw new RangeError(`Index ${u.index} (normalized to ${f}) is out of bounds`);if(u.type===pt){if(f>=n)throw new RangeError(`INSERT_BEFORE index ${u.index} (normalized to ${f}) is out of bounds for length ${n}`);d[f].push(u)}else f===n?l.push(u):h[f].push(u);continue}const p=r(u.index);a[p]=S({},u,{index:p})}const c=[];for(let u=0;uObject.entries(o).map(([n,r])=>({id:i,property:n,value:r}))).flat();this.store.updateProperty(e)}}const Ge={cancel:"Escape",finish:"Enter"},ze={start:"crosshair"};class je extends Y{constructor(t){super(t,!0),this.mode="circle",this.center=void 0,this.endPosition=void 0,this.segments=64,this.currentCircleId=void 0,this.keyEvents=Ge,this.cursors=ze,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1,this.drawInteraction="click-move",this.drawType=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=S({},this.cursors,t.cursors)),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=S({},this.keyEvents,t.keyEvents)),t!=null&&t.startingRadiusKilometers&&(this.startingRadiusKilometers=t.startingRadiusKilometers),t!=null&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction),t!=null&&t.segments&&(this.segments=t.segments<3?3:t.segments)}close(){if(this.currentCircleId===void 0||this.endPosition===void 0||!this.updateCircle(this.endPosition,P.Finish))return;const t=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state==="drawing"&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:U})}beginDrawing(t,e="click"){this.center=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];const i=oe({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.mutateFeature.createPolygon({coordinates:i.geometry.coordinates[0],properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers,[m.CURRENTLY_DRAWING]:!0}});o&&(this.currentCircleId=o.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=e,this.setDrawing())}dragDrawAllowed(){return this.drawInteraction==="click-drag"||this.drawInteraction==="click-move-or-drag"}moveDrawAllowed(){return this.drawInteraction==="click-move"||this.drawInteraction==="click-move-or-drag"}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){this.moveDrawAllowed()&&(t.button==="right"&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.button==="left"&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.center?this.center&&this.currentCircleId!==void 0&&(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))}onMouseMove(t){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,P.Provisional)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(t,e){this.state!=="drawing"&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&this.drawType==="drag"&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,P.Provisional))}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&this.drawType==="drag"&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))}cleanUp(){const t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state==="drawing"&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});return t.type==="Feature"&&t.geometry.type==="Polygon"&&t.properties.mode===this.mode&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=H),e}validateFeature(t){return this.validateModeFeature(t,e=>Fe(e,this.coordinatePrecision))}updateCircle(t,e){if(this.currentCircleId===void 0||this.center===void 0)return;const i=e===P.Finish;let o,n;if(this.cursorMovedAfterInitialCursorDown)if(n=W(this.center,t),this.projection==="web-mercator"){const a=(function(d,h){const l=1e3*W(d,h);if(l===0)return 1;const{x:c,y:u}=_(d[0],d[1]),{x:p,y:g}=_(h[0],h[1]);return Math.sqrt(Math.pow(p-c,2)+Math.pow(g-u,2))/l})(this.center,t);o=(function(d){const{center:h,radiusKilometers:l,coordinatePrecision:c}=d,u=d.steps?d.steps:64,p=1e3*l,[g,f]=h,{x:C,y:v}=_(g,f),y=[];for(let I=0;I{const{x:e,y:i}=s,{x:o,y:n}=t,r=o-e,a=n-i;return Math.sqrt(a*a+r*r)};function Se(s,t){return s[0]===t[0]&&s[1]===t[1]}class gt extends L{constructor(t){super(t)}getGeometryType(t){return this.store.getGeometryCopy(t).type}coordinateAtIndexIsIdentical({featureId:t,newCoordinate:e,index:i}){const o=this.store.getGeometryCopy(t);let n;if(o.type==="Polygon")n=o.coordinates[0][i];else if(o.type==="LineString")n=o.coordinates[i];else{if(i!==0)throw new Error("Point geometries only have one coordinate at index 0");n=o.coordinates}return Se(e,n)}getGeometry(t){return this.store.getGeometryCopy(t)}getCoordinates(t){const{type:e,coordinates:i}=this.store.getGeometryCopy(t);return e==="Polygon"?i[0]:i}getCoordinate(t,e){const i=this.getCoordinates(t),o=e<0?i.length+e:e;if(o<0||o>=i.length)throw new RangeError(`Index ${e} (normalized to ${o}) is out of bounds`);return i[o]}getProperties(t){return this.store.getPropertiesCopy(t)}hasFeature(t){return this.store.has(t)}getAllFeatureIdsWhere(t){return this.store.copyAllWhere(t).map(({id:e})=>e)}}const He={cancel:"Escape",finish:"Enter"},Ve={start:"crosshair",close:"pointer"};class Ye extends Y{constructor(t){super(t,!0),this.mode="freehand",this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=20,this.keyEvents=He,this.cursors=Ve,this.preventPointsNearClose=!0,this.autoClose=!1,this.autoCloseTimeout=500,this.hasLeftStartingPoint=!1,this.preventNewFeature=!1,this.drawInteraction="click-move",this.drawType=void 0,this.smoothing=0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),t!=null&&t.minDistance&&(this.minDistance=t.minDistance),t?.smoothing!==void 0&&(this.smoothing=Math.min(Math.max(t.smoothing,0),.999)),t?.preventPointsNearClose!==void 0&&(this.preventPointsNearClose=t.preventPointsNearClose),t?.autoClose!==void 0&&(this.autoClose=t.autoClose),t!=null&&t.autoCloseTimeout&&(this.autoCloseTimeout=t.autoCloseTimeout),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=S({},this.keyEvents,t.keyEvents)),t!=null&&t.cursors&&(this.cursors=S({},this.cursors,t.cursors)),t!=null&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction)}moveDrawAllowed(){return this.drawInteraction==="click-move"||this.drawInteraction==="click-move-or-drag"}dragDrawAllowed(){return this.drawInteraction==="click-drag"||this.drawInteraction==="click-move-or-drag"}beginDrawing(t,e="click"){const{id:i}=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[m.CURRENTLY_DRAWING]:!0}});this.currentId=i,this.drawType=e,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[t.lng,t.lat],type:m.CLOSING_POINT}),this.canClose=!0,this.state!=="drawing"&&this.setDrawing()}addCoordinate(t){if(this.currentId===void 0||this.canClose===!1)return void this.setCursor(this.cursors.start);const[e,i]=this.readFeature.getCoordinate(this.currentId,-2),{x:o,y:n}=this.project(e,i),r=G({x:o,y:n},{x:t.containerX,y:t.containerY}),[a,d]=this.readFeature.getCoordinate(this.currentId,0),{x:h,y:l}=this.project(a,d);if(G({x:h,y:l},{x:t.containerX,y:t.containerY}){this.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(r{this.preventNewFeature=!1},this.autoCloseTimeout),this.close(),e(!0))}cleanUp(){const t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,this.state==="drawing"&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});return t.type==="Feature"&&t.geometry.type==="Polygon"&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=H,e):(t.type==="Feature"&&t.geometry.type==="Point"&&t.properties.mode===this.mode&&(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,e.pointOpacity===void 0?1:e.pointOpacity,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,e.pointOutlineOpacity===void 0?1:e.pointOutlineOpacity,t),e.zIndex=50),e)}validateFeature(t){return this.validateModeFeature(t,e=>zt(e,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)}registerBehaviors(t){this.readFeature=new gt(t),this.mutateFeature=new et(t,{validate:this.validate})}}function xe({unproject:s,point:t,pointerDistance:e}){const i=e/2,{x:o,y:n}=t;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[s(o-i,n-i),s(o+i,n-i),s(o+i,n+i),s(o-i,n+i),s(o-i,n-i)].map(r=>[r.lng,r.lat])]}}}class Et extends L{constructor(t){super(t)}create(t){const{containerX:e,containerY:i}=t;return xe({unproject:this.unproject,point:{x:e,y:i},pointerDistance:this.pointerDistance})}}class Ot extends L{constructor(t){super(t)}measure(t,e){const{x:i,y:o}=this.project(e[0],e[1]);return G({x:i,y:o},{x:t.containerX,y:t.containerY})}}class jt extends L{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappableCoordinateFirstClick(t){return this.getSnappable(t,e=>!!(e.properties&&e.properties.mode===this.mode)).coordinate}getSnappableCoordinate(t,e){return this.getSnappable(t,i=>!!(i.properties&&i.properties.mode===this.mode&&i.id!==e)).coordinate}getSnappable(t,e){const i=this.clickBoundingBox.create(t),o=this.store.search(i,e),n={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return o.forEach(r=>{let a;if(r.geometry.type==="Polygon")a=r.geometry.coordinates[0];else if(r.geometry.type==="LineString")a=r.geometry.coordinates;else{if(r.geometry.type!=="Point")return;var d,h,l,c,u,p;if((d=r.properties)!=null&&d[m.EDITED]||(h=r.properties)!=null&&h[m.CLOSING_POINT]||(l=r.properties)!=null&&l[m.SNAPPING_POINT]||(c=r.properties)!=null&&c[m.COORDINATE_POINT]||(u=r.properties)!=null&&u[b.SELECTION_POINT]||(p=r.properties)!=null&&p[b.MID_POINT])return;a=[r.geometry.coordinates]}a.forEach((g,f)=>{const C=this.pixelDistance.measure(t,g);C180?r-=360:r<-180&&(r+=360),r}function Xe(s,t,e){const i=[],o=s.length;let n,r,a,d=0;for(let l=0;l=d&&l===s.length-1);l++){if(d>t&&i.length===0){if(n=t-d,!n)return i.push(s[l]),i;r=ae(s[l],s[l-1])-180,a=se(s[l],n,r),i.push(a)}if(d>=e)return n=e-d,n?(r=ae(s[l],s[l-1])-180,a=se(s[l],n,r),i.push(a),i):(i.push(s[l]),i);if(d>=t&&i.push(s[l]),l===s.length-1)return i;d+=W(s[l],s[l+1])}if(d[O(e[0],this.config.coordinatePrecision),O(e[1],this.config.coordinatePrecision)])}}function qe(s,t){if(s.geometry.type!=="LineString")return{valid:!1,reason:"Feature is not a LineString"};if(s.geometry.coordinates.length<2)return{valid:!1,reason:"Feature has less than 2 coordinates"};for(let e=0;ex||X(o,k)>x?W($(k),$(i))<=W($(k),$(o))?[$(i),!0,!1]:[$(o),!1,!0]:[$(k),!1,!1]}function Ze(s,t,e){const i=t.x-s.x,o=t.y-s.y,n=Math.max(0,Math.min(1,((e.x-s.x)*i+(e.y-s.y)*o)/(i*i+o*o)));return{x:s.x+n*i,y:s.y+n*o}}class Ht extends L{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=o=>{const n=this.getSnappable(o,r=>!!(r.properties&&r.properties.mode===this.mode));return n.coordinate?[O(n.coordinate[0],this.config.coordinatePrecision),O(n.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappableCoordinate=(o,n)=>{const r=this.getSnappable(o,a=>!!(a.properties&&a.properties.mode===this.mode&&a.id!==n));return r.coordinate?[O(r.coordinate[0],this.config.coordinatePrecision),O(r.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappable=(o,n)=>{const r=this.clickBoundingBox.create(o),a=this.store.search(r,n),d={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return a.forEach(h=>{let l;if(h.geometry.type==="Polygon")l=h.geometry.coordinates[0];else{if(h.geometry.type!=="LineString")return;l=h.geometry.coordinates}const c=[];for(let f=0;f(e===void 0||d.id!==e)&&(!i||i(d));let a={coordinate:void 0,featureId:void 0,featureCoordinateIndex:void 0,minDistance:1/0};if(o?.toCoordinate!==!1){const d=this.coordinateSnapping.getSnappable(t,r);d.coordinate&&d.minDistance0&&Array.isArray(s[0])&&Array.isArray(s[0][0])}const Mt=s=>Yt(s)?s[0].slice(0,-1):s,ct=s=>Yt(s)?s[0]:s;class Me extends L{constructor(t,e,i,o){super(t),this.config=void 0,this.pixelDistance=void 0,this.mutateFeatureBehavior=void 0,this.readFeatureBehavior=void 0,this._startEndPoints=[],this.config=t,this.pixelDistance=e,this.mutateFeatureBehavior=i,this.readFeatureBehavior=o}get ids(){return this._startEndPoints.concat()}set ids(t){}create(t){if(this.ids.length)throw new Error("Opening and closing points already created");const e=Yt(t),i=ct(t);if(e){if(i.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[i[0],i[i.length-2]],type:m.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:i[i.length-2],type:m.CLOSING_POINT})]}delete(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])}updateOne(t,e){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[t],coordinate:e}])}update(t){const e=ct(t);this.ids.length!==1?this.ids.length===2&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[0]},{featureId:this.ids[1],coordinate:e[e.length-3]}]):this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[e.length-2]}])}isLineStringClosingPoint(t){if(this.ids.length!==1)return{isClosing:!1};const e=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(t,e.coordinates)this.readFeature.hasFeature(r))){const r=o.coordinatePointIds,a=r.map(d=>this.readFeature.getGeometry(d).coordinates);if(r.length!==i.length){this.deleteCoordinatePoints(r);const d=this.createPoints(i,o.mode,t);this.setFeatureCoordinatePoints(t,d)}else{const d=[];i.forEach((h,l)=>{h[0]===a[l][0]&&h[1]===a[l][1]||d.push({featureId:r[l],coordinate:h})}),this.mutateFeature.updateGuidancePoints(d)}}else{const r=n.filter(d=>this.readFeature.hasFeature(d));r.length&&this.deleteCoordinatePoints(r);const a=this.createPoints(i,o.mode,t);this.setFeatureCoordinatePoints(t,a)}else{const r=this.createPoints(i,o.mode,t);this.setFeatureCoordinatePoints(t,r)}}deletePointsByFeatureIds(t){for(const e of t)this.deleteIfPresent(e)}updateOneAtIndex(t,e,i){const o=this.readFeature.getProperties(t).coordinatePointIds;o&&o.length!==0&&o[e]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:o[e],coordinate:i}])}updateAllInPlace({featureId:t,featureCoordinates:e}){const i=this.readFeature.getProperties(t);if(!i.coordinatePointIds)return;const o=Mt(e);o.length===i.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(i.coordinatePointIds.map((n,r)=>({featureId:n,coordinate:o[r]})))}createPoints(t,e,i){return this.mutateFeature.createGuidancePoints({coordinates:t,type:m.COORDINATE_POINT,additionalProperties:o=>({mode:e,[m.COORDINATE_POINT]:!0,[m.COORDINATE_POINT_FEATURE_ID]:i,index:o})})}setFeatureCoordinatePoints(t,e,i=P.Commit){const o=this.readFeature.getGeometryType(t),n={featureId:t,propertyMutations:{[m.COORDINATE_POINT_IDS]:e},context:{updateType:i}};if(o==="Polygon")this.mutateFeature.updatePolygon(n);else{if(o!=="LineString")throw new Error("Unsupported geometry type for coordinate points");this.mutateFeature.updateLineString(n)}}deleteCoordinatePoints(t){this.mutateFeature.deleteFeaturesIfPresent(t)}deleteIfPresent(t){if(!this.readFeature.hasFeature(t))return;const e=this.readFeature.getProperties(t).coordinatePointIds;e&&(this.deleteCoordinatePoints(e),this.setFeatureCoordinatePoints(t,null))}deleteOrphanedPoints(t){const e=this.readFeature.getAllFeatureIdsWhere(i=>i[m.COORDINATE_POINT_FEATURE_ID]===t);this.mutateFeature.deleteFeaturesIfPresent(e)}}class we{constructor(t){this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=i=>this.cloneRecursively(i);const e=t?.maxStackSize;this.maxStackSize=e!==void 0&&Number.isFinite(e)?Math.max(0,Math.floor(e)):Number.POSITIVE_INFINITY}setMaxStackSize(t){Number.isFinite(t)?(this.maxStackSize=Math.max(0,Math.floor(t)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=Number.POSITIVE_INFINITY}trimHistoryToMax(t){if(Number.isFinite(this.maxStackSize))for(;t.length>this.maxStackSize;)t.shift()}pushUndoEntry(t){this.maxStackSize!==0&&(this.undoHistory.push(t),this.trimHistoryToMax(this.undoHistory))}pushRedoEntry(t){this.maxStackSize!==0&&(this.redoHistory.push(t),this.trimHistoryToMax(this.redoHistory))}cloneRecursively(t){return Array.isArray(t)?t.map(e=>this.cloneRecursively(e)):t!==null&&typeof t=="object"?S({},t):t}cloneCoordinates(t){return this.cloneCoordinatesFunction(t)}cloneEntry(t){return{featureCoordinates:this.cloneCoordinates(t.featureCoordinates),currentCoordinate:t.currentCoordinate}}clear(){this.undoHistory=[],this.redoHistory=[]}undoSize(){return this.undoHistory.length}redoSize(){return this.redoHistory.length}recordSnapshot(t){this.pushUndoEntry(this.cloneEntry(t)),this.redoHistory=[]}beginUndo(){const t=this.undoHistory.pop();if(!t)return;const e=this.cloneEntry(t);this.pushRedoEntry(e);const i=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:e,previousEntry:i?this.cloneEntry(i):void 0}}takeRedo(){const t=this.redoHistory.pop();if(t)return this.cloneEntry(t)}commitRedo(t){this.pushUndoEntry(this.cloneEntry(t))}}const Qe={cancel:"Escape",finish:"Enter"},ti={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"};class ei extends Y{constructor(t){super(t,!0),this.mode="linestring",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=Qe,this.snapping=void 0,this.cursors=ti,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommittedCoordinates=void 0,this.snappedPointId=void 0,this.lastMouseMoveEvent=void 0,this.showCoordinatePoints=!1,this.finishOnNthCoordinate=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0,this.lineSnapping=void 0,this.featureSnapping=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.closingPoints=void 0,this.coordinatePoints=void 0,this.undoRedo=void 0,this.updateOptions(t)}updateOptions(t){if(super.updateOptions(t),t?.finishOnNthCoordinate!==void 0&&Number.isInteger(t.finishOnNthCoordinate)&&t.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(t.finishOnNthCoordinate)),t!=null&&t.cursors&&(this.cursors=S({},this.cursors,t.cursors)),t!=null&&t.snapping&&(this.snapping=t.snapping),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=S({},this.keyEvents,t.keyEvents)),t!=null&&t.insertCoordinates&&(this.insertCoordinates=t.insertCoordinates),t&&t.editable&&(this.editable=t.editable),t?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=t.showCoordinatePoints,this.coordinatePoints&&t.showCoordinatePoints===!0)this.store.copyAllWhere(e=>e.mode===this.mode).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&this.showCoordinatePoints===!1){const e=this.store.copyAllWhere(i=>{var o;return i.mode===this.mode&&!!((o=i[m.COORDINATE_POINT_IDS])!=null&&o.length)});this.coordinatePoints.deletePointsByFeatureIds(e.map(i=>i.id))}}}shouldFinishOnCommit(t){return!!this.finishOnNthCoordinate&&Math.max(0,t.coordinates.length-1)>=this.finishOnNthCoordinate}updateSnappedCoordinate(t){const e=this.snapCoordinate(t);return e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:m.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),e}close(){if(this.currentId===void 0)return;const t=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:P.Finish,action:U},coordinateMutations:[{type:Q,index:-1}],propertyMutations:{[m.CURRENTLY_DRAWING]:void 0}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates});const e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state==="drawing"&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(e,{mode:this.mode,action:U})}generateInsertCoordinates(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw new Error("Not able to insert coordinates");if(this.insertCoordinates.strategy!=="amount")throw new Error("Strategy does not exist");const i=W(t,e)/(this.insertCoordinates.value+1);let o=[];return this.projection==="globe"?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):this.projection==="web-mercator"&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o}createLine(t){const e=this.mutateFeature.createLineString({coordinates:[t,t],properties:{mode:this.mode,[m.CURRENTLY_DRAWING]:!0}});this.lastCommittedCoordinates=e.geometry.coordinates,this.currentId=e.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates})}firstUpdateToLine(t){if(!this.currentId)return;this.setCursor(this.cursors.close);const e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:P.Commit},coordinateMutations:[{type:at,index:-1,coordinate:t}]});e&&(this.closingPoints.create(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.lastCommittedCoordinates=e.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(e.geometry)&&this.close())}updateToLine(t,e){if(!this.currentId)return;const{isClosing:i}=this.closingPoints.isLineStringClosingPoint(t);if(i)return void this.close();this.setCursor(this.cursors.close);const o=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:P.Commit},coordinateMutations:[{type:at,index:-1,coordinate:e}]});o&&(this.closingPoints.update(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.lastCommittedCoordinates=o.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(o.geometry)&&this.close())}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(t,e){const i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}syncClosingPoints(t){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()}undo(){if(this.state!=="drawing"||!this.currentId)return;const t=this.undoRedo.beginUndo();if(!t)return;const{previousEntry:e}=t;if(!e){const o=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),this.state==="drawing"&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([o]),this.mutateFeature.deleteFeatureIfPresent(o),void this.updateSnappedGuidancePointFromLastMouseMove()}const i=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:N,coordinates:e.featureCoordinates},propertyMutations:{[m.CURRENTLY_DRAWING]:!0},context:{updateType:P.Commit}});i&&(this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=i.geometry.coordinates,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){const t=this.undoRedo.takeRedo();if(t){if(this.currentId){const e=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:N,coordinates:t.featureCoordinates},propertyMutations:{[m.CURRENTLY_DRAWING]:!0},context:{updateType:P.Commit}});if(!e)return;this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=e.geometry.coordinates,this.syncClosingPoints(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates})}else{const{id:e,geometry:i}=this.mutateFeature.createLineString({coordinates:t.featureCoordinates,properties:{mode:this.mode,[m.CURRENTLY_DRAWING]:!0}});this.currentId=e,this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=i.coordinates,this.state==="started"&&this.setDrawing(),this.syncClosingPoints(i.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:i.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}}registerBehaviors(t){this.insertPoint=new $e(t),this.clickBoundingBox=new Et(t),this.pixelDistance=new Ot(t),this.lineSnapping=new Ht(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new jt(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Vt(this.coordinateSnapping,this.lineSnapping),this.readFeature=new gt(t),this.mutateFeature=new et(t,{validate:this.validate}),this.closingPoints=new Me(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Kt(t,this.readFeature,this.mutateFeature),this.undoRedo=new we({maxStackSize:t.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t;const e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(this.currentId===void 0||this.currentCoordinate===0)return;const{isClosing:i}=this.closingPoints.isLineStringClosingPoint(t);i&&this.setCursor(this.cursors.close);let o=[{type:T,index:-1,coordinate:e}];if(this.insertCoordinates){const r=this.getInsertCoordinates(e);r&&(o={type:N,coordinates:r})}const n=this.mutateFeature.updateLineString({coordinateMutations:o,featureId:this.currentId,context:{updateType:P.Provisional}});n&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates})}getInsertCoordinates(t){if(!this.lastCommittedCoordinates)return;const e=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(Se(e,t))return;const i=this.generateInsertCoordinates(e,t);return[...this.lastCommittedCoordinates.slice(0,-1),...i,t]}onRightClick(t){if(!this.editable||this.state!=="started")return;const{featureId:e,featureCoordinateIndex:i}=this.coordinateSnapping.getSnappable(t,a=>this.lineStringFilter(a));if(!e||i===void 0)return;const o=this.readFeature.getGeometry(e);let n;if(o.type!=="LineString"||(n=o.coordinates,n.length<=2))return;const r=this.mutateFeature.updateLineString({featureId:e,coordinateMutations:[{type:Q,index:i}],context:{updateType:P.Finish,action:Z}});r&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:r.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(e,{mode:this.mode,action:ve})}onLeftClick(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);const e=this.snapCoordinate(t)||[t.lng,t.lat];this.currentCoordinate===0?this.createLine(e):this.currentCoordinate===1&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(t,e)}onClick(t){this.currentId===void 0||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),(t.button==="right"&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.button==="left"&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,t.button==="right"?this.onRightClick(t):t.button==="left"&&this.onLeftClick(t))}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,t)||!this.editable)return;let i;if(this.state==="started"){const o=this.lineSnapping.getSnappable(t,r=>this.lineStringFilter(r));o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,i=o.coordinate);const n=this.coordinateSnapping.getSnappable(t,r=>this.lineStringFilter(r));n.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=n.featureCoordinateIndex,this.editedFeatureId=n.featureId,i=n.coordinate)}this.editedFeatureId&&i&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:m.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}onDrag(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.editedFeatureId!==void 0&&this.editedFeatureCoordinateIndex!==void 0){if(this.editedSnapType==="coordinate"||this.editedSnapType==="line"&&this.editedInsertIndex!==void 0){const i=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:P.Provisional},coordinateMutations:[{type:T,index:this.editedFeatureCoordinateIndex,coordinate:[t.lng,t.lat]}]});if(!i)return;this.showCoordinatePoints&&(this.editedInsertIndex!==void 0?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:i.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[t.lng,t.lat]))}else if(this.editedSnapType==="line"&&this.editedInsertIndex===void 0){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;const i=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:P.Provisional}});if(!i)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:i.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[t.lng,t.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:P.Provisional},propertyMutations:{[m.EDITED]:!0}})}}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:{[m.EDITED]:!1},context:{updateType:P.Finish,action:Z}})))return;const i=this.editedFeatureId;e(!0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(i,{mode:this.mode,action:Z})}cleanUp(){const t=this.currentId,e=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state==="drawing"&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.delete()}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.type==="Feature"&&t.geometry.type==="LineString"&&t.properties.mode===this.mode)return e.lineStringDash=this.getDashArrayStylingValue(this.styles.lineStringDash,void 0,t),e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,e.lineStringOpacity===void 0?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=H,e;if(t.type==="Feature"&&t.geometry.type==="Point"&&t.properties.mode===this.mode){const i=t.properties[m.COORDINATE_POINT],o=t.properties[m.CLOSING_POINT]?"closingPoint":t.properties[m.SNAPPING_POINT]?"snappingPoint":i?"coordinatePoint":void 0;if(!o)return e;const n={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(n[o].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(n[o].opacity,1,t),e.pointColor=this.getHexColorStylingValue(n[o].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(n[o].outlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(n[o].outlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(n[o].outlineOpacity,1,t),e.zIndex=i?20:50,e}return e}validateFeature(t){return this.validateModeFeature(t,e=>qe(e,this.coordinatePrecision))}lineStringFilter(t){return!!(t.geometry.type==="LineString"&&t.properties&&t.properties.mode===this.mode)}snapCoordinate(t){var e,i,o,n;let r;if((e=this.snapping)!=null&&e.toLine){let a;a=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t),a&&(r=a)}if((i=this.snapping)!=null&&i.toCoordinate){let a;a=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t),a&&(r=a)}if((o=this.snapping)!=null&&o.toCustom){const a=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});a&&(r=a)}if((n=this.snapping)!=null&&n.toFeature){const a=this.featureSnapping.getSnappable(t,this.currentId,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});a.coordinate&&(r=a.coordinate)}return r}afterFeatureUpdated(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state==="drawing"&&this.setStarted())}afterFeatureAdded(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})}}const ii="Feature is not a Point",oi="Feature has invalid coordinates",ni="Feature has coordinates with excessive precision";function ri(s,t){return s.geometry.type!=="Point"?{valid:!1,reason:ii}:Gt(s.geometry.coordinates)?wt(s.geometry.coordinates,t)?{valid:!0}:{valid:!1,reason:ni}:{valid:!1,reason:oi}}class si extends L{constructor(t,e,i){super(t),this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pixelDistance=e,this.clickBoundingBox=i}getNearestPointFeature(t){const e=this.clickBoundingBox.create(t),i=this.store.search(e);let o,n=1/0;for(let r=0;rn||d>this.pointerDistance||(n=d,o=a)}return o}}const ai={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"};class di extends Y{constructor(t){super(t,!0),this.mode="point",this.cursors=ai,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=S({},this.cursors,t.cursors)),t!=null&&t.editable&&(this.editable=t.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){t.button==="right"&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):t.button==="left"&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){const i=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=i?.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:N,coordinates:[t.lng,t.lat]},propertyMutations:{[m.EDITED]:!0},context:{updateType:P.Provisional}})}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[m.EDITED]:!1},context:{updateType:P.Finish,action:"edit"}}))return;const i=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(i,{mode:this.mode,action:U})}registerBehaviors(t){this.pixelDistance=new Ot(t),this.clickBoundingBox=new Et(t),this.pointSearch=new si(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new et(t,{validate:this.validate})}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.type==="Feature"&&t.geometry.type==="Point"&&t.properties.mode===this.mode){const i=!!(t.id&&this.editedFeatureId===t.id);e.pointWidth=this.getNumericStylingValue(i?this.styles.editedPointWidth:this.styles.pointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,e.pointOpacity===void 0?1:e.pointOpacity,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.editedPointColor:this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,e.pointOutlineOpacity===void 0?1:e.pointOutlineOpacity,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),e.zIndex=30}return e}validateFeature(t){return this.validateModeFeature(t,e=>ri(e,this.coordinatePrecision))}onLeftClick(t){const e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode},context:{updateType:P.Finish,action:U}});e&&this.onFinish(e.id,{mode:this.mode,action:U})}onRightClick(t){if(!this.editable)return;const e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}afterFeatureUpdated(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}}const hi={cancel:"Escape",finish:"Enter"},li={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"};class ui extends Y{constructor(t){super(t,!0),this.mode="polygon",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=hi,this.cursors=li,this.mouseMove=!1,this.showCoordinatePoints=!1,this.lastMouseMoveEvent=void 0,this.snapping=void 0,this.snappedPointId=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinatePoints=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.featureSnapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.undoRedo=void 0,this.updateOptions(t)}updateOptions(t){if(super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=S({},this.cursors,t.cursors)),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=S({},this.keyEvents,t.keyEvents)),t!=null&&t.snapping&&(this.snapping=t.snapping),t?.editable!==void 0&&(this.editable=t.editable),t?.pointerEvents!==void 0&&(this.pointerEvents=t.pointerEvents),t?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=t.showCoordinatePoints,this.coordinatePoints&&t.showCoordinatePoints===!0)this.store.copyAllWhere(e=>e.mode===this.mode).filter(e=>e.geometry.type==="Polygon").forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&this.showCoordinatePoints===!1){const e=this.store.copyAllWhere(i=>i.mode===this.mode&&!!i[m.COORDINATE_POINT_IDS]).filter(i=>i.geometry.type==="Polygon");this.coordinatePoints.deletePointsByFeatureIds(e.map(i=>i.id))}}}close(){if(this.currentId===void 0||this.readFeature.getCoordinates(this.currentId).length<5)return;const t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:Q,index:-2}],propertyMutations:{[m.CURRENTLY_DRAWING]:void 0,[m.COMMITTED_COORDINATE_COUNT]:void 0,[m.PROVISIONAL_COORDINATE_COUNT]:void 0},context:{updateType:P.Finish,action:U}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.state==="drawing"&&this.setStarted(),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.closingPoints.delete();const e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(e,{mode:this.mode,action:U})}registerBehaviors(t){this.readFeature=new gt(t),this.mutateFeature=new et(t,{validate:this.validate}),this.clickBoundingBox=new Et(t),this.pixelDistance=new Ot(t),this.lineSnapping=new Ht(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new jt(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Vt(this.coordinateSnapping,this.lineSnapping),this.closingPoints=new Me(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Kt(t,this.readFeature,this.mutateFeature),this.undoRedo=new we({maxStackSize:t.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}updateSnappedCoordinate(t){const e=this.snapCoordinate(t);e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:m.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(t,e){const i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}syncClosingPoints(t){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()}undo(){if(this.state!=="drawing"||!this.currentId)return;const t=this.undoRedo.beginUndo();if(!t)return;const{previousEntry:e}=t;if(!e){const o=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),this.state==="drawing"&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([o]),this.mutateFeature.deleteFeatureIfPresent(o),void this.updateSnappedGuidancePointFromLastMouseMove()}const i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:N,coordinates:e.featureCoordinates},propertyMutations:{[m.CURRENTLY_DRAWING]:!0,[m.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[m.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate},context:{updateType:P.Commit}});i&&(this.currentCoordinate=e.currentCoordinate,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){const t=this.undoRedo.takeRedo();if(t){if(this.currentId){const e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:N,coordinates:t.featureCoordinates},propertyMutations:{[m.CURRENTLY_DRAWING]:!0,[m.COMMITTED_COORDINATE_COUNT]:t.currentCoordinate,[m.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate},context:{updateType:P.Commit}});if(!e)return;this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates})}else{const e=this.undoRedo.cloneCoordinates(t.featureCoordinates)[0],{id:i,geometry:o}=this.mutateFeature.createPolygon({coordinates:e,properties:{mode:this.mode,[m.CURRENTLY_DRAWING]:!0,[m.COMMITTED_COORDINATE_COUNT]:t.currentCoordinate,[m.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate}});this.currentId=i,this.currentCoordinate=t.currentCoordinate,this.state==="started"&&this.setDrawing(),this.syncClosingPoints(o.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:i,featureCoordinates:o.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),this.currentId===void 0||this.currentCoordinate===0)return;const e=this.readFeature.getCoordinate(this.currentId,0),i=[t.lng,t.lat];let o;if(this.currentCoordinate===1)o=[{type:T,index:1,coordinate:i},{type:T,index:2,coordinate:[t.lng,t.lat]}];else if(this.currentCoordinate===2)o=[{type:T,index:2,coordinate:i}];else{const{isClosing:r,isPreviousClosing:a}=this.closingPoints.isPolygonClosingPoints(t);a||r?(this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.setCursor(this.cursors.close),o=[{type:T,index:-1,coordinate:e},{type:T,index:-2,coordinate:e}]):o=[{type:T,index:-2,coordinate:i},{type:T,index:-1,coordinate:e}]}const n=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:o,propertyMutations:{[m.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:P.Provisional}});n&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates})}snapCoordinate(t){var e,i,o,n;let r;if((e=this.snapping)!=null&&e.toLine){let d;d=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t),d&&(r=d)}if((i=this.snapping)!=null&&i.toCoordinate){let d;d=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t),d&&(r=d)}if((o=this.snapping)!=null&&o.toFeature){var a;const d=this.featureSnapping.getSnappable(t,this.currentId,(a=this.snapping)==null?void 0:a.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});d.coordinate&&(r=d.coordinate)}if((n=this.snapping)!=null&&n.toCustom){const d=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});d&&(r=d)}return r}polygonFilter(t){return!!(t.geometry.type==="Polygon"&&t.properties&&t.properties.mode===this.mode)}onRightClick(t){if(!this.editable||this.state!=="started")return;const{featureId:e,featureCoordinateIndex:i}=this.coordinateSnapping.getSnappable(t,d=>this.polygonFilter(d));if(!e||i===void 0)return;const o=this.readFeature.getGeometry(e);if(o.type!=="Polygon")return;const n=o.coordinates[0];if(n.length<=4)return;let r;r=i===0||i===n.length-1?[{type:Q,index:0},{type:Q,index:-1},{type:at,index:-1,coordinate:n[1]}]:[{type:Q,index:i}];const a=this.mutateFeature.updatePolygon({featureId:e,coordinateMutations:r,context:{updateType:P.Finish,action:Z}});if(a){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){const d=this.snapCoordinate(t);if(d){const[h]=this.mutateFeature.createGuidancePoints({type:m.SNAPPING_POINT,coordinates:[d]});this.snappedPointId=h}}this.onFinish(e,{mode:this.mode,action:Z})}}onLeftClick(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);let e=this.snapCoordinate(t)||[t.lng,t.lat];if(this.currentCoordinate===0){const{id:i,geometry:o}=this.mutateFeature.createPolygon({coordinates:[e,e,e,e],properties:{mode:this.mode,[m.CURRENTLY_DRAWING]:!0,[m.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1,[m.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1}});this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:i,featureCoordinates:o.coordinates}),this.currentId=i,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(this.currentCoordinate===1&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:0}))return;const i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:T,index:1,coordinate:e},{type:T,index:2,coordinate:e}],propertyMutations:{[m.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:P.Commit}});if(!i)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentCoordinate===2&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:1}))return;const i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:T,index:2,coordinate:e},{type:at,index:2,coordinate:e}],propertyMutations:{[m.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:P.Commit}});if(!i)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.currentCoordinate===2&&this.closingPoints.create(i.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){const{isClosing:i,isPreviousClosing:o}=this.closingPoints.isPolygonClosingPoints(t);if(o||i)this.close();else{if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:this.currentCoordinate-1}))return;const n=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:pt,index:-1,coordinate:e}],propertyMutations:{[m.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:P.Commit}});if(!n)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(n.geometry.coordinates)}}}onClick(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,t.button==="right"&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):t.button==="left"&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,t)||!this.editable)return;let i;if(this.state==="started"){const o=this.lineSnapping.getSnappable(t,r=>this.polygonFilter(r));o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,i=o.coordinate);const n=this.coordinateSnapping.getSnappable(t,r=>this.polygonFilter(r));n.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=n.featureCoordinateIndex,this.editedFeatureId=n.featureId,i=n.coordinate)}this.editedFeatureId&&i&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:m.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}onDrag(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDrag,t)||this.editedFeatureId===void 0||this.editedFeatureCoordinateIndex===void 0)return;const i=this.readFeature.getGeometry(this.editedFeatureId),o=[t.lng,t.lat];let n=[];if(this.editedSnapType==="coordinate"||this.editedSnapType==="line"&&this.editedInsertIndex!==void 0?n=this.editedFeatureCoordinateIndex===0||this.editedFeatureCoordinateIndex===i.coordinates[0].length-1?[{type:T,index:0,coordinate:o},{type:T,index:-1,coordinate:o}]:[{type:T,index:this.editedFeatureCoordinateIndex,coordinate:o}]:this.editedSnapType==="line"&&this.editedInsertIndex===void 0&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,n=[{type:pt,index:this.editedInsertIndex,coordinate:o}],this.editedFeatureCoordinateIndex++),n.length===0)return;const r=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:n,propertyMutations:{[m.EDITED]:!0},context:{updateType:P.Provisional}});r&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:r.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,r.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:o}]))}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:{[m.EDITED]:!1},context:{updateType:P.Finish,action:Z}})))return;const i=this.editedFeatureId;this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,e(!0),this.onFinish(i,{mode:this.mode,action:Z})}cleanUp(){const t=this.currentId,e=this.snappedPointId,i=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),this.state==="drawing"&&this.setStarted(),t&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(i),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.ids.length&&this.closingPoints.delete()}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.properties.mode===this.mode){if(t.geometry.type==="Polygon")return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.zIndex=H,e;if(t.geometry.type==="Point"){const i=t.properties[m.EDITED],o=t.properties[m.COORDINATE_POINT],n=i?"editedPoint":t.properties[m.CLOSING_POINT]?"closingPoint":t.properties[m.SNAPPING_POINT]?"snappingPoint":o?"coordinatePoint":void 0;if(!n)return e;const r={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(r[n].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(r[n].opacity,1,t),e.pointColor=this.getHexColorStylingValue(r[n].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(r[n].outlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(r[n].outlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(r[n].outlineWidth,2,t),e.zIndex=i?40:o?20:30,e}}return e}afterFeatureAdded(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})}afterFeatureUpdated(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),this.state==="drawing"&&this.setStarted())}validateFeature(t){return this.validateModeFeature(t,e=>zt(e,this.coordinatePrecision))}}const ci={cancel:"Escape",finish:"Enter"},pi={start:"crosshair"};class gi extends Y{constructor(t){super(t,!0),this.mode="rectangle",this.startPosition=void 0,this.endPosition=void 0,this.currentRectangleId=void 0,this.keyEvents=ci,this.cursors=pi,this.drawInteraction="click-move",this.drawType=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=S({},this.cursors,t.cursors)),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=S({},this.keyEvents,t.keyEvents)),t!=null&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction)}updateRectangle(t,e){if(!this.startPosition||!this.currentRectangleId)return;const i=e===P.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:T,index:1,coordinate:[t[0],this.startPosition[1]]},{type:T,index:2,coordinate:t},{type:T,index:3,coordinate:[this.startPosition[0],t[1]]}],propertyMutations:i?{[m.CURRENTLY_DRAWING]:void 0}:{},context:i?{updateType:e,action:U}:{updateType:e}})}close(){if(!this.currentRectangleId||!this.endPosition||!this.updateRectangle(this.endPosition,P.Finish))return;const t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state==="drawing"&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:U})}beginDrawing(t,e="click"){this.startPosition=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];const i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[m.CURRENTLY_DRAWING]:!0}});this.currentRectangleId=i.id,this.drawType=e,this.setDrawing()}moveDrawAllowed(){return this.drawInteraction==="click-move"||this.drawInteraction==="click-move-or-drag"}dragDrawAllowed(){return this.drawInteraction==="click-drag"||this.drawInteraction==="click-move-or-drag"}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){this.moveDrawAllowed()&&(t.button==="right"&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.button==="left"&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.startPosition?(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))}onMouseMove(t){this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,P.Provisional)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(t,e){this.state!=="drawing"&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&this.drawType==="drag"&&(this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,P.Provisional))}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&this.drawType==="drag"&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))}cleanUp(){const t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state==="drawing"&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});return t.type==="Feature"&&t.geometry.type==="Polygon"&&t.properties.mode===this.mode&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=H),e}validateFeature(t){return this.validateModeFeature(t,e=>Fe(e,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentRectangleId===t.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state==="drawing"&&this.setStarted())}registerBehaviors(t){this.readFeature=new gt(t),this.mutateFeature=new et(t,{validate:this.validate})}}function Rt(s,t){const e=s,i=t,o=R(e[1]),n=R(i[1]);let r=R(i[0]-e[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)),d=(V(Math.atan2(r,a))+360)%360;return d>180?-(360-d):d}function Ee(s,t,e){let i=t;t<0&&(i=-Math.abs(i));const o=i/Ce,n=s[0]*Math.PI/180,r=R(s[1]),a=R(e),d=o*Math.cos(a);let h=r+d;Math.abs(h)>Math.PI/2&&(h=h>0?Math.PI-h:-Math.PI-h);const l=Math.log(Math.tan(h/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(l)>1e-11?d/l:Math.cos(r),u=[(180*(n+o*Math.sin(a)/c)/Math.PI+540)%360-180,180*h/Math.PI];return u[0]+=u[0]-s[0]>180?-360:s[0]-u[0]>180?360:0,u}function yi(s,t,e,i,o){const n=i(s[0],s[1]),r=i(t[0],t[1]),{lng:a,lat:d}=o((n.x+r.x)/2,(n.y+r.y)/2);return[O(a,e),O(d,e)]}function fi(s,t,e){const i=Ee(s,1e3*W(s,t)/2,Rt(s,t));return[O(i[0],e),O(i[1],e)]}function bt({featureCoords:s,precision:t,unproject:e,project:i,projection:o}){const n=[];for(let r=0;r{const n=this.readFeature.getGeometry(o),r=this.pixelDistance.measure(t,n.coordinates);r({mode:this.mode,midPointSegment:n,midPointFeatureId:e,[b.MID_POINT]:!0}),coordinates:o,type:b.MID_POINT})}delete(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])}updateAllInPlace({featureCoordinates:t}){if(this._midPoints.length===0)return;const e=ct(t),i=bt(this.getMidpointConfig(e));this.mutateFeature.updateGuidancePoints(this._midPoints.map((o,n)=>({featureId:o,coordinate:i[n]})))}updateOneAtIndex(t,e){if(t<0&&(t=this._midPoints.length+t),this._midPoints[t]===void 0)return;const i=ct(e),o=bt(this.getMidpointConfig(i));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[t],coordinate:o[t]}])}}class vi extends L{constructor(t,e){super(t),this.mutateFeature=void 0,this._selectionPoints=[],this.mutateFeature=e}get ids(){return this._selectionPoints.concat()}set ids(t){}create({featureId:t,featureCoordinates:e}){const i=Mt(e);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:i,type:b.SELECTION_POINT,additionalProperties:o=>({[b.SELECTION_POINT_FEATURE_ID]:t,index:o})})}delete(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])}updateAllInPlace({featureCoordinates:t}){if(this._selectionPoints.length===0)return;const e=Mt(t);e.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map((i,o)=>({featureId:i,coordinate:e[o]})))}updateOneAtIndex(t,e){this._selectionPoints[t]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[t],coordinate:e}])}}function Oe(s,t){let e=!1;for(let r=0,a=t.length;r(i=s)[1]!=(n=d[c])[1]>i[1]&&i[0]<(n[0]-o[0])*(i[1]-o[1])/(n[1]-o[1])+o[0]&&(e=!e)}var i,o,n;return e}const Bt=(s,t,e)=>{const i=n=>n*n,o=(n,r)=>i(n.x-r.x)+i(n.y-r.y);return Math.sqrt(((n,r,a)=>{const d=o(r,a);if(d===0)return o(n,r);let h=((n.x-r.x)*(a.x-r.x)+(n.y-r.y)*(a.y-r.y))/d;return h=Math.max(0,Math.min(1,h)),o(n,{x:r.x+h*(a.x-r.x),y:r.y+h*(a.y-r.y)})})(s,t,e))};class Ci extends L{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,o,n,r=1/0,a=1/0;const d=this.createClickBoundingBox.create(t),h=this.store.search(d);for(let l=0;l180||c<-180||u>90||u<-90)return!1;o[h]=[c,u]}e.type==="Polygon"&&(o[o.length-1]=[o[0][0],o[0][1]]);const r=this.draggedFeatureId;let a=null;if(e.type==="Polygon")a=this.mutateFeature.updatePolygon({featureId:r,coordinateMutations:{type:N,coordinates:[o]},context:{updateType:P.Provisional}});else{if(e.type!=="LineString")return;a=this.mutateFeature.updateLineString({featureId:r,coordinateMutations:{type:N,coordinates:o},context:{updateType:P.Provisional}})}if(!a)return!1;const d=a.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:d}),this.selectionPoints.updateAllInPlace({featureCoordinates:d}),this.coordinatePoints.updateAllInPlace({featureId:r,featureCoordinates:d}),this.dragPosition=[t.lng,t.lat]}else e.type==="Point"&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:N,coordinates:i},context:{updateType:P.Provisional}}),this.dragPosition=[t.lng,t.lat])}}class Ii extends L{constructor(t,e,i,o,n,r,a,d,h){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.featureSnapping=void 0,this.draggedCoordinate={id:null,index:-1},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=o,this.coordinatePoints=n,this.coordinateSnapping=r,this.lineSnapping=a,this.readFeature=d,this.mutateFeature=h,this.featureSnapping=new Vt(this.coordinateSnapping,this.lineSnapping)}getClosestCoordinate(t,e){const i={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1};let o;if(e.type==="LineString")o=e.coordinates;else{if(e.type!=="Polygon")return i;o=e.coordinates[0]}for(let n=0;n!!(r.properties&&r.properties.mode===i.properties.mode&&r.id!==this.draggedCoordinate.id);if(e!=null&&e.toLine){let r;r=this.lineSnapping.getSnappable(t,n).coordinate,r&&(o=r)}if(e.toCoordinate){let r;r=this.coordinateSnapping.getSnappable(t,n).coordinate,r&&(o=r)}if(e!=null&&e.toFeature){const r=this.featureSnapping.getSnappable(t,i.id,e.toFeature.filter,{toLine:e.toFeature.toLine,toCoordinate:e.toFeature.toCoordinate});r.coordinate&&(o=r.coordinate)}if(e!=null&&e.toCustom){let r;r=e.toCustom(t,{currentCoordinate:this.draggedCoordinate.index,currentId:i.id,getCurrentGeometrySnapshot:i.id?()=>this.readFeature.getGeometry(i.id):()=>null,project:this.project,unproject:this.unproject}),r&&(o=r)}return o}drag(t,e,i){const o=this.draggedCoordinate.id;if(o===null)return!1;if(this.readFeature.hasFeature(o)===!1)return this.stopDragging(),!1;const n=this.draggedCoordinate.index,r=this.readFeature.getGeometry(o),a=this.readFeature.getProperties(o),d=r.type==="LineString"?r.coordinates:r.coordinates[0],h=r.type==="Polygon"&&(n===d.length-1||n===0),l=this.snapCoordinate(t,i,{type:"Feature",id:o,geometry:r,properties:a});if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(h){const p=d.length-1;d[0]=l,d[p]=l}else d[n]=l;if(r.type!=="Point"&&!e&&Ie({geometry:r}))return!1;const c=o;let u=null;return r.type==="Polygon"?u=this.mutateFeature.updatePolygon({featureId:c,coordinateMutations:{type:N,coordinates:[d]},context:{updateType:P.Provisional}}):r.type==="LineString"&&(u=this.mutateFeature.updateLineString({featureId:c,coordinateMutations:{type:N,coordinates:d},context:{updateType:P.Provisional}})),!!u&&(this.midPoints.updateOneAtIndex(n>0?n-1:-1,d),this.midPoints.updateOneAtIndex(n,d),this.selectionPoints.updateOneAtIndex(n,l),this.coordinatePoints.updateOneAtIndex(c,n,l),!0)}isDragging(){return this.draggedCoordinate.id!==null}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}}function le(s){let t=0,e=0,i=0;return(s.geometry.type==="Polygon"?s.geometry.coordinates[0].slice(0,-1):s.geometry.coordinates).forEach(o=>{t+=o[0],e+=o[1],i++},!0),[t/i,e/i]}const _e=(s,t)=>{if(t===0||t===360||t===-360)return s;const e=.017453292519943295*t,i=(s.geometry.type==="Polygon"?s.geometry.coordinates[0]:s.geometry.coordinates).map(([r,a])=>_(r,a)),o=i.reduce((r,a)=>({x:r.x+a.x,y:r.y+a.y}),{x:0,y:0});o.x/=i.length,o.y/=i.length;const n=i.map(r=>({x:o.x+(r.x-o.x)*Math.cos(e)-(r.y-o.y)*Math.sin(e),y:o.y+(r.x-o.x)*Math.sin(e)+(r.y-o.y)*Math.cos(e)})).map(({x:r,y:a})=>[tt(r,a).lng,tt(r,a).lat]);return s.geometry.type==="Polygon"?s.geometry.coordinates[0]=n:s.geometry.coordinates=n,s};function At(s){const t=(s.geometry.type==="Polygon"?s.geometry.coordinates[0]:s.geometry.coordinates).map(e=>{const{x:i,y:o}=_(e[0],e[1]);return[i,o]});return s.geometry.type==="Polygon"?(function(e){let i=0,o=0,n=0;const r=e.length;for(let a=0;a{const f=Rt(p,g)+u,C=(function(y,I){y[0]+=y[0]-I[0]>180?-360:I[0]-y[0]>180?360:0;const F=Ce,x=I[1]*Math.PI/180,w=y[1]*Math.PI/180,M=w-x;let D=Math.abs(y[0]-I[0])*Math.PI/180;D>Math.PI&&(D-=2*Math.PI);const B=Math.log(Math.tan(w/2+Math.PI/4)/Math.tan(x/2+Math.PI/4)),k=Math.abs(B)>1e-11?M/B:Math.cos(x);return Math.sqrt(M*M+k*k*D*D)*F})(p,g),v=Ee(p,C,f);g[0]=v[0],g[1]=v[1]})})(r,-(this.lastBearing-(n+180)))}const a=i.type==="Polygon"?i.coordinates[0]:i.coordinates;a.forEach(c=>{c[0]=O(c[0],this.coordinatePrecision),c[1]=O(c[1],this.coordinatePrecision)});const d={featureId:e,coordinateMutations:{type:N,coordinates:i.type==="Polygon"?[a]:a},context:{updateType:P.Provisional}};let h=null;if(r.geometry.type==="Polygon")h=this.mutateFeature.updatePolygon(d);else{if(r.geometry.type!=="LineString")return;h=this.mutateFeature.updateLineString(d)}if(!h)return!1;const l=h.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:l}),this.selectionPoints.updateAllInPlace({featureCoordinates:l}),this.coordinatePoints.updateAllInPlace({featureId:e,featureCoordinates:l}),this.projection==="web-mercator"?this.lastBearing=n:this.projection==="globe"&&(this.lastBearing=n+180)}}class Si extends L{constructor(t,e){super(t),this.config=void 0,this.dragCoordinateResizeBehavior=void 0,this.config=t,this.dragCoordinateResizeBehavior=e}scale(t,e){if(!this.dragCoordinateResizeBehavior.isDragging()){const i=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,i)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed")}reset(){this.dragCoordinateResizeBehavior.stopDragging()}}function De({coordinates:s,originX:t,originY:e,xScale:i,yScale:o}){i===1&&o===1||s.forEach(n=>{const{x:r,y:a}=_(n[0],n[1]),d=t+(r-t)*i,h=e+(a-e)*o,{lng:l,lat:c}=tt(d,h);n[0]=l,n[1]=c})}class xi extends L{constructor(t,e,i,o,n,r,a){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},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=o,this.coordinatePoints=n,this.readFeature=r,this.mutateFeature=a}getClosestCoordinate(t,e){const i={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1};let o;if(e.type==="LineString")o=e.coordinates;else{if(e.type!=="Polygon")return i;o=e.coordinates[0]}for(let n=0;n=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||this.draggedCoordinate.index===-1)return null;const t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;const e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}}centerWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{feature:i,boundingBox:o,updatedCoords:n,selectedCoordinate:r}=e,a=At(i);if(!a)return null;const d=_(r[0],r[1]),{closestBBoxIndex:h}=this.getIndexesWebMercator(o,d),l=_(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:h,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:d,webMercatorOrigin:a}),n}centerFixedWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{feature:i,boundingBox:o,updatedCoords:n,selectedCoordinate:r}=e,a=At(i);if(!a)return null;const d=_(r[0],r[1]),{closestBBoxIndex:h}=this.getIndexesWebMercator(o,d),l=_(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:h,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:d,webMercatorOrigin:a}),n}scaleFixedWebMercator({closestBBoxIndex:t,webMercatorOrigin:e,webMercatorSelected:i,webMercatorCursor:o,updatedCoords:n}){if(!this.isValidDragWebMercator(t,e.x-o.x,e.y-o.y))return null;let r=G(e,o)/G(e,i);return r<0&&(r=this.minimumScale),De({coordinates:n,originX:e.x,originY:e.y,xScale:r,yScale:r}),n}oppositeFixedWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{boundingBox:i,updatedCoords:o,selectedCoordinate:n}=e,r=_(n[0],n[1]),{oppositeBboxIndex:a,closestBBoxIndex:d}=this.getIndexesWebMercator(i,r),h={x:i[a][0],y:i[a][1]},l=_(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:l,webMercatorSelected:r,webMercatorOrigin:h}),o}oppositeWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{boundingBox:i,updatedCoords:o,selectedCoordinate:n}=e,r=_(n[0],n[1]),{oppositeBboxIndex:a,closestBBoxIndex:d}=this.getIndexesWebMercator(i,r),h={x:i[a][0],y:i[a][1]},l=_(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:l,webMercatorSelected:r,webMercatorOrigin:h}),o}scaleWebMercator({closestBBoxIndex:t,webMercatorOrigin:e,webMercatorSelected:i,webMercatorCursor:o,updatedCoords:n}){const r=e.x-o.x,a=e.y-o.y;if(!this.isValidDragWebMercator(t,r,a))return null;let d=1;r!==0&&t!==1&&t!==5&&(d=1-(e.x-i.x-r)/r);let h=1;return a!==0&&t!==3&&t!==7&&(h=1-(e.y-i.y-a)/a),this.validateScale(d,h)?(d<0&&(d=this.minimumScale),h<0&&(h=this.minimumScale),this.performWebMercatorScale(n,e.x,e.y,d,h),n):null}getFeature(t){if(this.draggedCoordinate.id===null)return null;const e=this.readFeature.getGeometry(t);return e.type!=="Polygon"&&e.type!=="LineString"?null:{id:t,type:"Feature",geometry:e,properties:{}}}getNormalisedCoordinates(t){return t.type==="Polygon"?t.coordinates[0]:t.coordinates}validateScale(t,e){const i=!isNaN(t)&&e{const{x:a,y:d}=_(r[0],r[1]),h=e+(a-e)*o,l=i+(d-i)*n,{lng:c,lat:u}=tt(h,l);r[0]=c,r[1]=u})}getBBoxWebMercator(t){const e=[1/0,1/0,-1/0,-1/0];(t=t.map(a=>{const{x:d,y:h}=_(a[0],a[1]);return[d,h]})).forEach(([a,d])=>{ae[2]&&(e[2]=a),d>e[3]&&(e[3]=d)});const[i,o,n,r]=e;return[[i,r],[(i+n)/2,r],[n,r],[n,r+(o-r)/2],[n,o],[(i+n)/2,o],[i,o],[i,r+(o-r)/2]]}getIndexesWebMercator(t,e){let i,o=1/0;for(let n=0;n{const o=e.properties.mode;return this.validations&&this.validations[o]?this.validations[o](e,i):{valid:!0}}}),this.pixelDistance=new Ot(t),this.clickBoundingBox=new Et(t),this.featuresAtMouseEvent=new Ci(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new vi(t,this.mutateFeature),this.coordinatePoints=new Kt(t,this.readFeature,this.mutateFeature),this.midPoints=new mi(t,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new jt(t,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new Ht(t,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new Fi(t,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new Pi(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new Ii(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new xi(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new Si(t,this.dragCoordinateResizeFeature)}deselectFeature(t){this.deselect(t)}deselect(t){this.selected.includes(t)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:"none"})}deleteSelected(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:"none"}}clearDragTargetAndCursor(){this.dragTarget={type:"none"},this.setCursor("unset")}getSelectedFlags(t){const e=this.readFeature.getProperties(t),i=this.flags[e.mode],o=i?.feature,n=o?.coordinates;return{featureFlags:o,coordinatesFlags:n,hasDraggableFlags:o&&(o.draggable||n?.draggable||n?.resizable||typeof n?.midpoints=="object"&&n.midpoints.draggable)}}onRightClick(t){if(!this.selectionPoints.ids.length)return;let e,i=1/0;if(this.selectionPoints.ids.forEach(u=>{const p=this.readFeature.getGeometry(u),g=this.pixelDistance.measure(t,p.coordinates);g0),i=this.midPoints.getNearestMidPoint(t),o=this.selected[0];if(o){var n;const{featureFlags:r}=this.getSelectedFlags(o);if(r!=null&&(n=r.coordinates)!=null&&n.midpoints&&i){if(r.coordinates.draggable){const a=this.pixelDistance.measure(t,this.readFeature.getGeometry(i).coordinates),{dist:d}=this.dragCoordinate.getDraggable(t,o);if(d!==void 0&&a>d)return}return this.midPoints.insert({featureId:o,midPointId:i}),void this.onFinish(this.selected[0],{action:Zt,mode:this.mode})}}if(e!=null&&e.id)this.allowManualSelection&&this.select(e.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(t){t.button==="right"&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):t.button==="left"&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(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;const e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),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(this.selected[0])}onDragStart(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,t))return;const i=this.selected[0];if(!i)return;const{featureFlags:o,coordinatesFlags:n,hasDraggableFlags:r}=this.getSelectedFlags(i);if(!r)return;this.dragEventCount=0;const a=this.dragTarget.type!=="none"&&this.dragTarget.featureId===i?this.dragTarget:{type:"none"},d=a.type==="coordinate"?a.coordinateIndex:this.dragCoordinate.getDraggableIndex(t,i),h=a.type==="resize"?a.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(t,i),l=n?.resizable&&h!==-1,c=n?.draggable&&d!==-1,u=n&&typeof n.midpoints=="object"&&n.midpoints.draggable,p=o?.draggable&&(a.type==="feature"||this.dragFeature.canDrag(t,i));if(l)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(i,h),void e(!1);if(c)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(i,d),void e(!1);if(u){const g=a.type==="midpoint"?a.midPointId:this.midPoints.getNearestMidPoint(t);if(this.selected.length&&g){this.midPoints.insert({featureId:i,midPointId:g}),this.onFinish(this.selected[0],{action:Zt,mode:this.mode});const f=this.dragCoordinate.getDraggableIndex(t,i);return this.dragCoordinate.startDragging(i,f),void e(!1)}}if(p)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,i),void e(!1);this.setCursor("unset")}onDrag(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDrag,t))return;const i=this.selected[0];if(!i)return;const o=this.readFeature.getProperties(i),n=this.flags[o.mode],r=(n&&n.feature&&n.feature.selfIntersectable)===!0;if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(n&&n.feature&&n.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i);if(n&&n.feature&&n.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i);if(this.dragCoordinateResizeFeature.isDragging()&&n.feature&&n.feature.coordinates&&n.feature.coordinates.resizable){if(this.projection==="globe")throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,n.feature.coordinates.resizable)}if(this.dragCoordinate.isDragging()){var a;const d=(a=n.feature)==null||(a=a.coordinates)==null?void 0:a.snappable;let h={toCoordinate:!1};return d===!0?h={toCoordinate:!0}:typeof d=="object"&&(h=d),void this.dragCoordinate.drag(t,r,h)}this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)}}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0))}onMouseMove(t){const e=this.selected[0];if(!e)return void this.clearDragTargetAndCursor();if(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())return;const{featureFlags:i}=this.getSelectedFlags(e);if(!i)return void this.clearDragTargetAndCursor();let o;const n=i.coordinates;if(n!=null&&n.midpoints&&(o=this.midPoints.getNearestMidPoint(t),o&&(this.dragTarget={type:"midpoint",featureId:e,midPointId:o},this.setCursor(this.cursors.insertMidpoint))),n&&n.draggable){const{index:r,dist:a}=this.dragCoordinate.getDraggable(t,e);if(r>-1)return o&&this.pixelDistance.measure(t,this.readFeature.getGeometry(o).coordinates)-1)return this.dragTarget={type:"resize",featureId:e,coordinateIndex:r},void this.setCursor(this.getPointerOverResizeHandleCursor())}if(i.draggable&&this.dragFeature.canDrag(t,e))return o?void 0:(this.dragTarget={type:"feature",featureId:e},void this.setCursor(this.getPointerOverFeatureCursor()));o||this.clearDragTargetAndCursor()}styleFeature(t){const e=S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.properties.mode===this.mode&&t.geometry.type==="Point"){if(t.properties[b.SELECTION_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties[b.MID_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=50,e}else if(t.properties[b.SELECTED]){if(t.geometry.type==="Point"&&t.properties[m.MARKER])return e.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,ke,t),e.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),e.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),e;if(t.geometry.type==="Polygon")return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=H,e;if(t.geometry.type==="LineString")return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.selectedLineStringOpacity,1,t),e.lineStringDash=this.getDashArrayStylingValue(this.styles.selectedLineStringDash,void 0,t),e.zIndex=H,e;if(t.geometry.type==="Point")return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=H,e}return e}afterFeatureUpdated(t){if(this.selected.length&&t.id===this.selected[0]){var e,i;const o=this.flags[t.properties.mode];if(o==null||(e=o.feature)==null||!e.coordinates)return;const n=t.geometry.type,r=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),n!=="LineString"&&n!=="Polygon")return;const a=t.geometry.coordinates;this.selectionPoints.create({featureCoordinates:a,featureId:r}),o!=null&&(i=o.feature)!=null&&(i=i.coordinates)!=null&&i.midpoints&&this.midPoints.create({featureCoordinates:a,featureId:r})}}}class Ei extends Y{constructor(...t){super(...t),this.type=st.Static,this.mode="static"}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return S({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0})}}function be(s,t,e,i,o){for(;i>e;){if(i-e>600){const d=i-e+1,h=t-e+1,l=Math.log(d),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(d-c)/d)*(h-d/2<0?-1:1);be(s,t,Math.max(e,Math.floor(t-h*c/d+u)),Math.min(i,Math.floor(t+(d-h)*c/d+u)),o)}const n=s[t];let r=e,a=i;for(dt(s,e,t),o(s[i],n)>0&&dt(s,e,i);r0;)a--}o(s[e],n)===0?dt(s,e,a):(a++,dt(s,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function dt(s,t,e){const i=s[t];s[t]=s[e],s[e]=i}function it(s,t){lt(s,0,s.children.length,t,s)}function lt(s,t,e,i,o){o||(o=rt([])),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let n=t;n=s.minX&&t.maxY>=s.minY}function rt(s){return{children:s,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ce(s,t,e,i,o){const n=[t,e];for(;n.length;){if((e=n.pop())-(t=n.pop())<=i)continue;const r=t+Math.ceil((e-t)/i/2)*i;be(s,r,t,e,o),n.push(t,r,r,e)}}class bi{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(!It(t,e))return i;const o=this.toBBox,n=[];for(;e;){for(let r=0;r=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)}_split(t,e){const i=t[e],o=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,o);const r=this._chooseSplitIndex(i,n,o),a=rt(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,it(i,this.toBBox),it(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=rt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,it(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let o,n=1/0,r=1/0;for(let a=e;a<=i-e;a++){const d=lt(t,0,a,this.toBBox),h=lt(t,a,i,this.toBBox),l=Di(d,h),c=kt(d)+kt(h);l=e;h--){const l=t.children[h];ut(a,t.leaf?n(l):l),d+=Pt(a)}return d}_adjustParentBBoxes(t,e,i){for(let o=i;o>=0;o--)ut(e[o],t)}_condense(t){for(let e,i=t.length-1;i>=0;i--)t[i].children.length===0?i>0?(e=t[i-1].children,e.splice(e.indexOf(t[i]),1)):this.clear():it(t[i],this.toBBox)}}class ki{constructor(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new bi(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 o;if(t.geometry.type==="Polygon")o=t.geometry.coordinates[0];else if(t.geometry.type==="LineString")o=t.geometry.coordinates;else{if(t.geometry.type!=="Point")throw new Error("Not a valid feature to turn into a bounding box");o=[t.geometry.coordinates]}for(let a=0;a{const n=this.toBBox(o);if(this.setMaps(o,n),i.has(String(o.id)))throw new Error(`Duplicate feature ID found ${o.id}`);i.add(String(o.id)),e.push(n)}),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(e=>this.nodeToId.get(e))}collides(t){return this.tree.collides(this.toBBox(t))}}const Ti={getId:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(s){const t=16*Math.random()|0;return(s=="x"?t:3&t|8).toString(16)}),isValidId:s=>typeof s=="string"&&s.length===36},pe={target:"geometry"},ge={target:"properties"};class Ni{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 ki,this.tracked=!t||t.tracked!==!1,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ti}clone(t){return JSON.parse(JSON.stringify(t))}getId(){return this.idStrategy.getId()}has(t){return!!this.store[t]}load(t,e,i,o){if(t.length===0)return[];let n=this.clone(t);const r=[],a=[];n=n.filter(h=>{h.id==null&&(h.id=this.idStrategy.getId());const l=h.id;if(e){const c=e(h);if(!c.valid)return r.push({id:l,valid:!1,reason:c.reason}),!1}if(this.tracked){if(h.properties.createdAt){if(!te(h.properties.createdAt))return r.push({id:h.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else h.properties.createdAt=+new Date;if(h.properties.updatedAt){if(!te(h.properties.updatedAt))return r.push({id:h.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else h.properties.updatedAt=+new Date}return this.has(l)?(r.push({id:l,valid:!1,reason:`Feature already exists with this id: ${l}`}),!1):(this.store[l]=h,a.push(h),r.push({id:l,valid:!0}),!0)}),this.spatialIndex.load(n);const d=a.map(({id:h})=>h);return d.length>0&&(this._onChange(d,"create",o),i&&a.forEach(h=>{i(h)})),r}search(t,e){const i=this.spatialIndex.search(t).map(o=>this.store[o]);return this.clone(e?i.filter(e):i)}registerOnChange(t){this._onChange=(e,i,o)=>{t(e,i,o)}}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,e){const i=new Set;t.forEach(({id:o,property:n,value:r})=>{const a=this.store[o];if(!a)throw new Error(`No feature with this (${o}), can not update geometry`);a.properties[n]!==r&&(i.add(o),r===void 0?delete a.properties[n]:a.properties[n]=r,this.tracked&&(a.properties.updatedAt=+new Date))}),this._onChange&&i.size>0&&this._onChange(Array.from(i),"update",e?S({},e,ge):ge)}updateGeometry(t,e){const i=new Set;t.forEach(({id:o,geometry:n})=>{i.add(o);const r=this.store[o];if(!r)throw new Error(`No feature with this (${o}), can not update geometry`);r.geometry=this.clone(n),this.spatialIndex.update(r),this.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&i.size>0&&this._onChange(Array.from(i),"update",e?S({},e,pe):pe)}create(t,e){const i=[];return t.forEach(({geometry:o,properties:n})=>{let r,a=S({},n);this.tracked&&(r=+new Date,n?(a.createdAt=typeof n.createdAt=="number"?n.createdAt:r,a.updatedAt=typeof n.updatedAt=="number"?n.updatedAt:r):a={createdAt:r,updatedAt:r});const d=this.getId(),h={id:d,type:"Feature",geometry:o,properties:a};this.store[d]=h,this.spatialIndex.insert(h),i.push(d)}),this._onChange&&this._onChange([...i],"create",e),i}delete(t,e){t.forEach(i=>{if(!this.store[i])throw new Error(`No feature with id ${i}, can not delete`);delete this.store[i],this.spatialIndex.remove(i)}),this._onChange&&this._onChange([...t],"delete",e)}copy(t){return this.clone(this.store[t])}copyAll(){return this.clone(Object.keys(this.store).map(t=>this.store[t]))}copyAllWhere(t){return this.clone(Object.keys(this.store).map(e=>this.store[e]).filter(e=>e.properties&&t(e.properties)))}clear(t){const e=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(e,"delete",t)}size(){return Object.keys(this.store).length}}class ot{constructor({name:t,callback:e,unregister:i,register:o}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=t,this.register=()=>{this.registered||(this.registered=!0,o(e))},this.unregister=()=>{this.register&&(this.registered=!1,i(e))},this.callback=e}}var Li={__proto__:null,TerraDrawBaseAdapter:class{constructor(s){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,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._ignoreMismatchedPointerEvents=typeof s.ignoreMismatchedPointerEvents=="boolean"&&s.ignoreMismatchedPointerEvents,this._minPixelDragDistance=typeof s.minPixelDragDistance=="number"?s.minPixelDragDistance:1,this._minPixelDragDistanceSelecting=typeof s.minPixelDragDistanceSelecting=="number"?s.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing=typeof s.minPixelDragDistanceDrawing=="number"?s.minPixelDragDistanceDrawing:8,this._coordinatePrecision=typeof s.coordinatePrecision=="number"?s.coordinatePrecision:9}getButton(s){return s.button===-1?"neither":s.button===0?"left":s.button===1?"middle":s.button===2?"right":"neither"}getMapElementXYPosition(s){const t=this.getMapEventElement(s.type),{left:e,top:i}=t.getBoundingClientRect();return{containerX:s.clientX-e,containerY:s.clientY-i}}getDrawEventFromEvent(s,t=!1){const e=this.getLngLatFromEvent(s);if(!e)return null;const{lng:i,lat:o}=e,{containerX:n,containerY:r}=this.getMapElementXYPosition(s),a=this.getButton(s),d=Array.from(this._heldKeys);return{lng:O(i,this._coordinatePrecision),lat:O(o,this._coordinatePrecision),containerX:n,containerY:r,button:a,heldKeys:d,isContextMenu:t}}register(s){this._currentModeCallbacks=s,this._listeners=this.getAdapterListeners(),this._listeners.forEach(t=>{t.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new ot({name:"pointerdown",callback:s=>{if(!this._currentModeCallbacks||!s.isPrimary)return;const t=this.getDrawEventFromEvent(s);t&&(this._dragState="pre-dragging",this._lastDrawEvent=t,this._lastPointerDownEventTarget=s.target?s.target:void 0)},register:s=>{this.getMapEventElement("pointerdown").addEventListener("pointerdown",s)},unregister:s=>{this.getMapEventElement("pointerdown").removeEventListener("pointerdown",s)}}),new ot({name:"pointermove",callback:s=>{if(!this._currentModeCallbacks||!s.isPrimary)return;s.preventDefault();const t=this.getDrawEventFromEvent(s);if(t)if(this._dragState==="not-dragging")this._currentModeCallbacks.onMouseMove(t),this._lastDrawEvent=t;else if(this._dragState==="pre-dragging"){if(!this._lastDrawEvent)return;const e={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},i={x:t.containerX,y:t.containerY},o=this._currentModeCallbacks.getState(),n=G(e,i);let r=!1;if(r=o==="drawing"?n{this.setDraggability.bind(this)(a)})}else this._dragState==="dragging"&&this._currentModeCallbacks.onDrag(t,e=>{this.setDraggability.bind(this)(e)})},register:s=>{this.getMapEventElement("pointermove").addEventListener("pointermove",s)},unregister:s=>{this.getMapEventElement("pointermove").removeEventListener("pointermove",s)}}),new ot({name:"contextmenu",callback:s=>{this._currentModeCallbacks&&(s.preventDefault(),this._nextKeyUpIsContextMenu=!0)},register:s=>{this.getMapEventElement("contextmenu").addEventListener("contextmenu",s)},unregister:s=>{this.getMapEventElement("contextmenu").removeEventListener("contextmenu",s)}}),new ot({name:"pointerup",callback:s=>{if(!this._currentModeCallbacks||s.target!==this.getMapEventElement("pointerup")||this._ignoreMismatchedPointerEvents&&this._lastPointerDownEventTarget!==s.target||(this._lastPointerDownEventTarget=void 0,!s.isPrimary))return;const t=this.getDrawEventFromEvent(s);t&&(this._dragState==="dragging"?this._currentModeCallbacks.onDragEnd(t,e=>{this.setDraggability.bind(this)(e)}):this._dragState!=="not-dragging"&&this._dragState!=="pre-dragging"||(this._nextKeyUpIsContextMenu&&(t.isContextMenu=!0,this._nextKeyUpIsContextMenu=!1),this._currentModeCallbacks.onClick(t)),this._dragState="not-dragging",this.setDraggability(!0))},register:s=>{this.getMapEventElement("pointerup").addEventListener("pointerup",s)},unregister:s=>{this.getMapEventElement("pointerup").removeEventListener("pointerup",s)}}),new ot({name:"keyup",callback:s=>{this._currentModeCallbacks&&(this._heldKeys.delete(s.key),this._currentModeCallbacks.onKeyUp({key:s.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>s.preventDefault()}))},register:s=>{this.getMapEventElement("keyup").addEventListener("keyup",s)},unregister:s=>{this.getMapEventElement("keyup").removeEventListener("keyup",s)}}),new ot({name:"keydown",callback:s=>{this._currentModeCallbacks&&(this._heldKeys.add(s.key),this._currentModeCallbacks.onKeyDown({key:s.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>s.preventDefault()}))},register:s=>{this.getMapEventElement("keydown").addEventListener("keydown",s)},unregister:s=>{this.getMapEventElement("keydown").removeEventListener("keydown",s)}})]}unregister(){this._listeners.forEach(s=>{s.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1}}};function Ut(s){if(s===null||typeof s=="boolean"||typeof s=="string")return!0;if(s===void 0)return!1;if(typeof s=="number")return Number.isFinite(s);if(typeof s=="bigint"||typeof s=="symbol"||typeof s=="function"||s instanceof RegExp||s instanceof Map||s instanceof Set||s instanceof Date)return!1;if(typeof s=="object"&&s!==null&&!Array.isArray(s)){const t=Object.getPrototypeOf(s);if(t!==Object.prototype&&t!==null)return!1}if(ArrayBuffer.isView(s)&&!(s instanceof DataView))return!1;if(Array.isArray(s)){for(const t of s)if(!Ut(t))return!1}return typeof s=="object"&&Object.keys(s).every(t=>typeof t=="string"&&Ut(s[t]))}const ye="push",q="mode",Nt="session";class Ri{constructor(t){var e;this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=t.modeLevel,this.sessionLevel=t.sessionLevel,this.shouldPreferMode=t.shouldPreferMode,this.onHistoryChange=t.onHistoryChange,this.shouldEmitHistoryChange=(e=t.shouldEmitHistoryChange)!=null?e:()=>!0}emitStackHistoryChange(t){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:t.cause,stack:t.stack,undoSize:t.undoStackSize,redoSize:t.redoStackSize})}hasSessionUndo(){return!!(this.sessionLevel&&this.sessionLevel.canUndo())}hasSessionRedo(){return!!(this.sessionLevel&&this.sessionLevel.canRedo())}activeStackForUndo(){var t,e;return this.shouldPreferMode()&&(t=this.modeLevel)!=null&&t.canUndo()?q:this.hasSessionUndo()?Nt:(e=this.modeLevel)!=null&&e.canUndo()?q:void 0}activeStackForRedo(){var t,e;return this.shouldPreferMode()&&(t=this.modeLevel)!=null&&t.canRedo()?q:this.hasSessionRedo()?Nt:(e=this.modeLevel)!=null&&e.canRedo()?q:void 0}canUndo(){return this.activeStackForUndo()!==void 0}canRedo(){return this.activeStackForRedo()!==void 0}undo(){const t=this.activeStackForUndo();return!!t&&(t===q?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){const t=this.activeStackForRedo();return!!t&&(t===q?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())}clearHistory(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()}emitHistoryPushForCompletedAction(){this.sessionLevel?this.emitStackHistoryChange({cause:ye,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:Nt}):this.modeLevel&&this.emitStackHistoryChange({cause:ye,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:q})}}class Bi{constructor(t){var e,i,o,n;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=t.adapter,this._instanceSelectModes=[];const r=t==null||(e=t.undoRedo)==null?void 0:e.modeLevel;r&&(this.drawingUndoRedo=r);const a=t==null||(i=t.undoRedo)==null?void 0:i.keyboardShortcuts;a&&(this.keyboardShortcutsMatcher=a),this.sessionUndoRedoEnabled=!!(!(t==null||(o=t.undoRedo)==null)&&o.sessionLevel);const d=t==null||(n=t.undoRedo)==null?void 0:n.sessionLevel;this._mode=new Ei;const h=new Set,l=t.modes.reduce((v,y)=>{if(h.has(y.mode))throw new Error(`There is already a ${y.mode} mode provided`);return h.add(y.mode),v[y.mode]=y,v},{}),c=Object.keys(l);if(c.length===0)throw new Error("No modes provided");c.forEach(v=>{l[v].type===st.Select&&this._instanceSelectModes.push(v)}),this._modes=S({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new Ni({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});const u=v=>{const y=[],I=this._store.copyAll().filter(F=>!v.includes(F.id)||(y.push(F),!1));return{changed:y,unchanged:I}},p=(v,y)=>{var I;this._enabled&&(this._eventListeners.finish.forEach(F=>{F(v,y)}),(I=this.undoRedoCoordinator)==null||I.emitHistoryPushForCompletedAction())},g=(v,y,I)=>{if(!this._enabled)return;this._eventListeners.change.forEach(w=>{w(v,y,I)}),this.emitDrawingPushIfHistoryChangedFromLastSnapshot();const{changed:F,unchanged:x}=u(v);y==="create"?this._adapter.render({created:F,deletedIds:[],unchanged:x,updated:[]},this.getModeStyles()):y==="update"?this._adapter.render({created:[],deletedIds:[],unchanged:x,updated:F},this.getModeStyles()):y==="delete"?this._adapter.render({created:[],deletedIds:v,unchanged:x,updated:[]},this.getModeStyles()):y==="styling"&&this._adapter.render({created:[],deletedIds:[],unchanged:x,updated:[]},this.getModeStyles())},f=v=>{if(!this._enabled)return;this._eventListeners.select.forEach(F=>{F(v)});const{changed:y,unchanged:I}=u([v]);this._adapter.render({created:[],deletedIds:[],unchanged:I,updated:y},this.getModeStyles())},C=v=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(F=>{F(v)});const{changed:y,unchanged:I}=u([v]);y&&this._adapter.render({created:[],deletedIds:[],unchanged:I,updated:y},this.getModeStyles())};Object.keys(this._modes).forEach(v=>{var y;this._modes[v].register({mode:v,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:g,onSelect:f,onDeselect:C,onFinish:p,coordinatePrecision:this._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:(y=this.drawingUndoRedo)==null||y.getMaxStackSize==null?void 0:y.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&d&&(this.sessionUndoRedo=d,d.register({draw:this,onHistoryChange:v=>{var y;(y=this.undoRedoCoordinator)==null||y.emitStackHistoryChange(v)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:()=>this.getModeState(),getModeHistorySizes:()=>this.getDrawingHistorySizes(),undoMode:()=>{this._mode.undo&&this._mode.undo()},redoMode:()=>{this._mode.redo&&this._mode.redo()},clearModeHistory:()=>{const v=this._mode;v.clearHistory&&v.clearHistory()},onHistoryChange:v=>{var y;(y=this.undoRedoCoordinator)==null||y.emitStackHistoryChange(v)}}),this.undoRedoCoordinator=new Ri({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:()=>this.getModeState()==="drawing",onHistoryChange:v=>{this._eventListeners.history.forEach(y=>{y(v)})},shouldEmitHistoryChange:()=>this._enabled})}checkEnabled(){if(!this._enabled)throw new Error("Terra Draw is not enabled")}handleUndoRedoKeyboardShortcut(t){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled||!this.keyboardShortcutsMatcher)return!1;const e=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(t),i=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(t);if(e){if(!this.canUndo())return!1;const o=this.undo();return o&&t.preventDefault(),o}if(i){if(!this.canRedo())return!1;const o=this.redo();return o&&t.preventDefault(),o}return!1}getDrawingHistorySizes(){return{undoSize:this._mode.undoSize&&typeof this._mode.undoSize=="function"?this._mode.undoSize():0,redoSize:this._mode.redoSize&&typeof this._mode.redoSize=="function"?this._mode.redoSize():0}}emitDrawingPushIfHistoryChangedFromLastSnapshot(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()}emitDrawingPushIfHistoryChanged(t){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(t)}getModeStyles(){const t={},e=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(i=>{t[i]=o=>e&&o.properties[b.SELECTED]?this._modes[e].styleFeature.bind(this._modes[e])(o):this._modes[i].styleFeature.bind(this._modes[i])(o)}),t}featuresAtLocation({lng:t,lat:e},i){const o=i&&i.pointerDistance!==void 0?i.pointerDistance:30,n=!i||i.ignoreSelectFeatures===void 0||i.ignoreSelectFeatures,r=!(!i||i.ignoreCoordinatePoints===void 0)&&i.ignoreCoordinatePoints,a=!(!i||i.ignoreCurrentlyDrawing===void 0)&&i.ignoreCurrentlyDrawing,d=!(!i||i.ignoreClosingPoints===void 0)&&i.ignoreClosingPoints,h=!(!i||i.ignoreSnappingPoints===void 0)&&i.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),c=this._adapter.project.bind(this._adapter),u=c(t,e),p=xe({unproject:l,point:u,pointerDistance:o});return this._store.search(p).filter(g=>{if(n&&(g.properties[b.MID_POINT]||g.properties[b.SELECTION_POINT])||r&&g.properties[m.COORDINATE_POINT]||d&&g.properties[m.CLOSING_POINT]||a&&g.properties[m.CURRENTLY_DRAWING]||h&&g.properties[m.SNAPPING_POINT])return!1;if(g.geometry.type==="Point"){const f=g.geometry.coordinates,C=c(f[0],f[1]);return G(u,C){if(i==null||!i.addClosestCoordinateInfoToProperties)return g;let f;if(g.geometry.type==="Polygon")f=g.geometry.coordinates[0].slice(0,-1);else{if(g.geometry.type!=="LineString")return g;f=g.geometry.coordinates}let C,v=-1,y=1/0;for(let I=0;I{if(!this._store.has(n))throw new Error(`No feature with id ${n}, can not delete`);const r=this._store.getPropertiesCopy(n);r[b.SELECTED]&&this.deselectFeature(n),r[m.CURRENTLY_DRAWING]&&this._modes[r.mode]?o=r.mode:(r[m.COORDINATE_POINT_IDS]&&e.push(...r[m.COORDINATE_POINT_IDS]),i.push(n))}),this._store.delete([...i,...e],{origin:"api"}),o&&this._modes[o]&&this._modes[o].cleanUp()&&this._modes[o].cleanUp()}selectFeature(t,e){this.getSelectModeOrThrow(e).selectFeature(t)}deselectFeature(t){this.getSelectModeOrThrow().deselectFeature(t)}getFeatureId(){return this._store.getId()}hasFeature(t){return this._store.has(t)}checkIsReservedProperty(t){return![...Object.values(b),...Object.values(m)].includes(t)}updateFeatureProperties(t,e){var i;if(!this._store.has(t))throw new Error(`No feature with id ${t} present in store`);const o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");const n=o.properties.mode;if(!this._modes[n])throw new Error(`No mode with name ${n} present in instance`);const r=Object.entries(e);r.forEach(([a,d])=>{if(!this.checkIsReservedProperty(a))throw new Error(`You are trying to update a reserved property name: ${a}. Please choose another name.`);if(d!==void 0&&!Ut(d))throw new Error(`Invalid JSON value provided for property ${a}`)}),this._store.updateProperty(r.map(([a,d])=>({id:o.id,property:a,value:d})),{origin:"api"}),(i=this.undoRedoCoordinator)==null||i.emitHistoryPushForCompletedAction()}updateFeatureGeometry(t,e){var i;if(!this._store.has(t))throw new Error(`No feature with id ${t} present in store`);const o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");if(!(o&&e&&e.type&&e.coordinates))throw new Error("Invalid geometry provided");if(e.type!==o.geometry.type)throw new Error(`Geometry type mismatch: expected ${o.geometry.type}, got ${e.type}`);const n=o.properties.mode,r=this._modes[n];if(!r)throw new Error(`No mode with name ${n} present in instance`);const a=S({},o,{geometry:e}),d=r.validateFeature(a);if(!d.valid)throw new Error(`Feature validation failed: ${d.reason||"Unknown reason"}`);if(this._store.updateGeometry([{id:o.id,geometry:e}],{origin:"api"}),r.afterFeatureUpdated){r.afterFeatureUpdated(a);const h=a.properties[b.SELECTED],l=this.getSelectMode({switchToSelectMode:!1});l&&h&&l.afterFeatureUpdated(a)}(i=this.undoRedoCoordinator)==null||i.emitHistoryPushForCompletedAction()}transformFeatureGeometry(t,e){var i;if(!this._store.has(t))throw new Error(`No feature with id ${t} present in store`);let o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");const n=o.properties.mode,r=this._modes[n];if(!r)throw new Error(`No mode with name ${n} present in instance`);let a;if(o.geometry.type==="Polygon")a=o.geometry.coordinates[0];else{if(o.geometry.type!=="LineString")throw new Error(`Feature geometry type ${o.geometry.type} is not supported for transformation`);a=o.geometry.coordinates}if(e.projection!="web-mercator")throw new Error(`Projection ${e.projection} is not currently supported for transformation`);if(e.type==="scale"){const{x:d,y:h}=_(e.origin[0],e.origin[1]);De({coordinates:a,originX:d,originY:h,xScale:e.options.xScale||1,yScale:e.options.yScale||1})}else e.type==="rotate"&&(o=_e(o,e.options.angle||0),a=o.geometry.type==="Polygon"?o.geometry.coordinates[0]:o.geometry.coordinates);if(a=a.map(d=>[O(d[0],this._adapter.getCoordinatePrecision()),O(d[1],this._adapter.getCoordinatePrecision())]),o.geometry.coordinates=o.geometry.type==="Polygon"?[a]:a,this._store.updateGeometry([{id:o.id,geometry:o.geometry}],{origin:"api"}),r.afterFeatureUpdated){r.afterFeatureUpdated(o);const d=o.properties[b.SELECTED],h=this.getSelectMode({switchToSelectMode:!1});h&&d&&h.afterFeatureUpdated(o)}(i=this.undoRedoCoordinator)==null||i.emitHistoryPushForCompletedAction()}undo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()}canUndo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()}canRedo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()}redo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()}clearUndoRedoHistory(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()}addFeatures(t){return this.checkEnabled(),t.length===0?[]:this._store.load(t,e=>{if(Qt(e)){const i=e.properties.mode,o=this._modes[i];if(!o)return{id:e.id,valid:!1,reason:`${i} mode is not in the list of instantiated modes`};const n=o.validateFeature.bind(o)(e);return{id:e.id,valid:n.valid,reason:n.reason?n.reason:n.valid?void 0:"Feature is invalid"}}return{id:e.id,valid:!1,reason:"Mode property does not exist"}},e=>{if(Qt(e)){const i=this._modes[e.properties.mode];i&&i.afterFeatureAdded&&i.afterFeatureAdded(e)}},{origin:"api"})}start(){this._enabled||(this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(t=>{t()})},getState:()=>this._mode.state,onClick:t=>{const e=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onClick(t),this.emitDrawingPushIfHistoryChanged(e)},onMouseMove:t=>{this._mode.onMouseMove(t)},onKeyDown:t=>{this.handleUndoRedoKeyboardShortcut(t)||this._mode.onKeyDown(t)},onKeyUp:t=>{const e=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onKeyUp(t),this.emitDrawingPushIfHistoryChanged(e)},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({origin:"api"})}}))}getFeaturesAtLngLat(t,e){const{lng:i,lat:o}=t;return this.featuresAtLocation({lng:i,lat:o},e)}getFeaturesAtPointerEvent(t,e){const i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return i===null?[]:this.featuresAtLocation(i,e)}stop(){this._enabled&&(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)}}function Wt(){return Wt=Object.assign?Object.assign.bind():function(s){for(var t=1;t0}getPointerTargetElement(t){return t?t instanceof Element?t:t instanceof Node?t.parentElement:null:null}shouldCapturePointer(t){const e=this.getPointerTargetElement(t.target);return!e||!!e.closest(this._advancedMarkerElementTag)||!e.closest(this._interactiveTargetSelector)}circlePath(t,e,i){const o=2*i;return`M ${t} ${e} m -${i}, 0 a ${i},${i} 0 1,0 ${o},0 a ${i},${i} 0 1,0 -${o},0`}register(t){if(super.register(t),this._overlay=new this._lib.OverlayView,this._overlay.draw=function(){},this._overlay.onAdd=()=>{var e;(e=this._currentModeCallbacks)!=null&&e.onReady&&!this._readyCalled&&(this._currentModeCallbacks.onReady(),this._readyCalled=!0)},this._overlay.setMap(this._map),this._overlay.onRemove=()=>{},this._forwardMapElementEvents){const e=this.getMapEventElement();this._pointerCaptureDownListener=i=>{if(i.isPrimary&&this.shouldCapturePointer(i)&&typeof e.setPointerCapture=="function")try{e.setPointerCapture(i.pointerId)}catch{}},this._pointerCaptureUpListener=i=>{if(typeof e.releasePointerCapture=="function"&&typeof e.hasPointerCapture=="function"&&e.hasPointerCapture(i.pointerId))try{e.releasePointerCapture(i.pointerId)}catch{}},e.addEventListener("pointerdown",this._pointerCaptureDownListener),e.addEventListener("pointerup",this._pointerCaptureUpListener),e.addEventListener("pointercancel",this._pointerCaptureUpListener),this._markerClickListener=i=>{const o=i.target;if(o==null||!o.closest(this._advancedMarkerElementTag))return;const n=this.getDrawEventFromEvent(i);n&&t.onClick(n)},e.addEventListener("pointerdown",this._markerClickListener),this._markerMouseMoveListener=i=>{const o=i.target;if(o==null||!o.closest(this._advancedMarkerElementTag))return;const n=this.getDrawEventFromEvent(i);n&&t.onMouseMove(n)},e.addEventListener("pointermove",this._markerMouseMoveListener)}this._clickEventListener=this.data().addListener("click",e=>{const i=this._listeners.find(({name:o})=>o==="click");i&&i.callback(e)}),this._mouseMoveEventListener=this.data().addListener("mousemove",e=>{const i=this._listeners.find(({name:o})=>o==="mousemove");i&&i.callback(e)}),this._isolatedData&&(this._data=new this._lib.Data,this._data.setMap(this._map))}data(){return this._isolatedData&&this._data?this._data:this._map.data}style(t){if(!this.styling)throw new Error("Styling function not defined");const e=String(t.getId());if(!this.renderedFeatureIds.has(e))return{};const i=t.getProperty("mode"),o=t.getGeometry();if(!o)throw new Error("Google Maps geometry not found");const n=o.getType(),r={};t.forEachProperty((d,h)=>{r[h]=d});const a=this.styling[i]({type:"Feature",id:e,geometry:{type:n,coordinates:[]},properties:r});switch(n){case"Point":if(a.markerUrl)return{clickable:!1,icon:{url:a.markerUrl,scaledSize:a.markerWidth&&a.markerHeight?new this._lib.Size(a.markerWidth,a.markerHeight):void 0},zIndex:a.zIndex};const d=this.circlePath(0,0,a.pointWidth),h=a.pointOutlineOpacity,l=a.pointOpacity;return{clickable:!1,icon:{path:d,fillColor:a.pointColor,fillOpacity:l===void 0?1:l,strokeColor:a.pointOutlineColor,strokeWeight:a.pointOutlineWidth,strokeOpacity:h===void 0?1:h,rotation:0,scale:1},zIndex:a.zIndex};case"LineString":const c=a.lineStringOpacity,u=a.lineStringDash;return Wt({strokeColor:a.lineStringColor,strokeWeight:a.lineStringWidth,strokeOpacity:c===void 0?1:c,zIndex:a.zIndex},u?{strokeOpacity:0,icons:[{icon:{path:"M 0,0 0,"+u[0],strokeOpacity:1,strokeWeight:a.lineStringWidth,color:a.lineStringColor,scale:1},offset:"0",repeat:`${u[0]+u[1]}px`,fixedRotation:!1}]}:{});case"Polygon":const p=a.polygonOutlineOpacity;return{strokeColor:a.polygonOutlineColor,strokeWeight:a.polygonOutlineWidth,strokeOpacity:p===void 0?1:p,fillOpacity:a.polygonFillOpacity,fillColor:a.polygonFillColor,zIndex:a.zIndex}}throw Error("Unknown feature type")}unregister(){var t,e;super.unregister(),(t=this._clickEventListener)==null||t.remove(),(e=this._mouseMoveEventListener)==null||e.remove(),this._markerClickListener&&this.getMapEventElement().removeEventListener("pointerdown",this._markerClickListener),this._markerMouseMoveListener&&this.getMapEventElement().removeEventListener("pointermove",this._markerMouseMoveListener),this._pointerCaptureDownListener&&this.getMapEventElement().removeEventListener("pointerdown",this._pointerCaptureDownListener),this._pointerCaptureUpListener&&(this.getMapEventElement().removeEventListener("pointerup",this._pointerCaptureUpListener),this.getMapEventElement().removeEventListener("pointercancel",this._pointerCaptureUpListener)),this._overlay&&this._overlay.getMap()&&this._overlay.setMap(null),this._overlay=void 0,this._readyCalled=!1,this._isolatedData&&this._data&&(this._data.setMap(null),this._data=void 0)}getLngLatFromEvent(t){var e;if(!this._overlay)throw new Error("cannot get overlay");const i=this._map.getBounds();if(!i)return null;const o=i.getNorthEast(),n=i.getSouthWest(),r=new this._lib.LatLngBounds(n,o),a=((e=document.fullscreenElement)!=null?e:this._map.getDiv()).getBoundingClientRect(),d=new this._lib.Point(t.clientX-a.left,t.clientY-a.top),h=this._overlay.getProjection();if(!h)return null;const l=h.fromContainerPixelToLatLng(d);return l&&r.contains(l)?{lng:l.lng(),lat:l.lat()}:null}getMapEventElement(t){return!t||t!=="keyup"&&t!=="keydown"?this._map.getDiv().querySelector('div[style*="z-index: 3;"]'):this._map.getDiv()}project(t,e){if(!this._overlay)throw new Error("cannot get overlay");if(this._map.getBounds()===void 0)throw new Error("cannot get bounds");const i=this._overlay.getProjection();if(i===void 0)throw new Error("cannot get projection");const o=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(o===null)throw new Error("cannot project coordinates");return{x:o.x,y:o.y}}unproject(t,e){if(!this._overlay)throw new Error("cannot get overlay");const i=this._overlay.getProjection();if(i===void 0)throw new Error("cannot get projection");const o=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(o===null)throw new Error("cannot unproject coordinates");return{lng:o.lng(),lat:o.lat()}}setCursor(t){if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),t!=="unset"){const e=this._map.getDiv().querySelector(".gm-style > div");if(e){e.classList.add("terra-draw-google-maps");const i=document.createElement("style");i.innerHTML=`.terra-draw-google-maps { cursor: ${t} !important; }`,document.getElementsByTagName("head")[0].appendChild(i),this._cursorStyleSheet=i}}this._cursor=t}}setDoubleClickToZoom(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})}setDraggability(t){this._map.setOptions({draggable:t})}render(t,e){this.styling=e,this.data().getStyle()||this.data().setStyle(i=>this.style(i)),this._rafState||(this._rafState={rafId:null,pending:{deletedIds:[],updated:[],created:[]},deletedSet:new Set,updatedById:new Map,createdById:new Map});for(const i of t.deletedIds)this._rafState.deletedSet.add(i),this._rafState.updatedById.delete(i),this._rafState.createdById.delete(i);for(const i of t.updated){if(i==null||!i.id)throw new Error("Feature is not valid");const o=String(i.id);this._rafState.deletedSet.has(o)||(this._rafState.createdById.has(o)?this._rafState.createdById.set(o,i):this._rafState.updatedById.set(o,i))}for(const i of t.created){if(i==null||!i.id)throw new Error("Feature is not valid");const o=String(i.id);this._rafState.createdById.set(o,i),this._rafState.updatedById.delete(o)}this._rafState.rafId==null&&(this._rafState.rafId=requestAnimationFrame(()=>{if(!this._rafState)return;this._rafState.rafId=null;const i=Array.from(this._rafState.deletedSet),o=Array.from(this._rafState.updatedById.values()),n=Array.from(this._rafState.createdById.values());if(this._rafState.deletedSet.clear(),this._rafState.updatedById.clear(),this._rafState.createdById.clear(),this._hasRenderedFeatures){for(const r of i){const a=this.data().getFeatureById(r);a&&(this.data().remove(a),this.renderedFeatureIds.delete(r))}for(const r of o){if(r==null||!r.id)throw new Error("Feature is not valid");const a=this.data().getFeatureById(String(r.id));if(!a)throw new Error("Feature could not be found by Google Maps API");switch(a.forEachProperty((d,h)=>{a.setProperty(h,void 0)}),Object.keys(r.properties).forEach(d=>{a.setProperty(d,r.properties[d])}),r.geometry.type){case"Point":{const d=r.geometry.coordinates;a.setGeometry(new this._lib.Data.Point(new this._lib.LatLng(d[1],d[0])));break}case"LineString":{const d=r.geometry.coordinates,h=[];for(let l=0;l{const e=t.getId();this.renderedFeatureIds.has(e)&&this.data().remove(t)}),this.renderedFeatureIds=new Set)}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers()),this.data()&&this.data().setStyle(null)}getCoordinatePrecision(){return super.getCoordinatePrecision()}}const fe=["#E74C3C","#FF0066","#9B59B6","#673AB7","#3F51B5","#3498DB","#03A9F4","#00BCD4","#009688","#27AE60","#8BC34A","#CDDC39","#F1C40F","#FFC107","#F39C12","#FF5722","#795548"],nt=()=>fe[Math.floor(Math.random()*fe.length)];function me(s){return s.map(t=>{const e=JSON.parse(JSON.stringify(t));return e.properties.mode==="rectangle"?(e.geometry.type="Polygon",e.properties.mode="polygon"):e.properties.mode==="circle"&&(e.geometry.type="Polygon",e.properties.mode="circle"),e})}function Ui(){if(!document.getElementById("mode-ui"))return;const t={"select-mode":"select","point-mode":"point","linestring-mode":"linestring","polygon-mode":"polygon","rectangle-mode":"rectangle","circle-mode":"circle","freehand-mode":"freehand","clear-mode":"static"};for(const e in t){const i=document.getElementById(e);i&&(i.onclick=()=>{Xt(e);const o=t[e];E&&(o==="static"?(E.clear(),E.setMode("static")):o&&E.setMode(o))})}}function Xt(s){const t=document.querySelectorAll(".mode-button"),e=document.getElementById("resize-button"),i=e?.classList.contains("active");t.forEach(n=>{n.id!=="resize-button"&&n.classList.remove("active")});const o=document.getElementById(s);o&&o.classList.add("active"),i&&e?.classList.add("active")}function Wi(){Xt("point-mode")}let Ft,E;const J=[];let St=[],j=null,ht=!1,A=!1,Lt;async function Gi(){try{const{Map:s}=await google.maps.importLibrary("maps"),t={center:{lat:48.862,lng:2.342},zoom:12,mapId:"c306b3c6dd3ed8d9",mapTypeId:"roadmap",zoomControl:!1,tilt:45,mapTypeControl:!0,clickableIcons:!1,streetViewControl:!1,fullscreenControl:!1},e=document.getElementById("map");Ft=new s(e,t),Ft.addListener("click",()=>{E&&console.log("Current draw mode on map click:",E.getMode())}),Ft.addListener("projection_changed",()=>{E=new Bi({adapter:new Ai({map:Ft,lib:google.maps,coordinatePrecision:9}),modes:[new wi({flags:{polygon:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},point:{feature:{draggable:!0,rotateable:!0}},rectangle:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},freehand:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}}),new di({editable:!0,styles:{pointColor:nt()}}),new ei({editable:!0,styles:{lineStringColor:nt()}}),new ui({editable:!0,styles:(()=>{const n=nt();return{fillColor:n,outlineColor:n}})()}),new gi({styles:(()=>{const n=nt();return{fillColor:n,outlineColor:n}})()}),new je({styles:(()=>{const n=nt();return{fillColor:n,outlineColor:n}})()}),new Ye({styles:(()=>{const n=nt();return{fillColor:n,outlineColor:n}})()})]}),E.start(),E.on("ready",()=>{console.log("TerraDraw is ready!"),Wi(),Ui(),E.setMode("point"),Xt("point-mode"),E.on("select",u=>{j&&j!==u&&E.deselectFeature(j),j=u}),E.on("deselect",()=>{j=null}),J.push(me(E.getSnapshot())),E.on("change",()=>{ht||(Lt&&clearTimeout(Lt),Lt=window.setTimeout(()=>{const u=E.getSnapshot(),g=me(u).filter(f=>!f.properties.midPoint&&!f.properties.selectionPoint);J.push(g),St=[]},200))});const n=document.getElementById("export-button");n&&(n.onclick=()=>{const p={type:"FeatureCollection",features:E.getSnapshot()},g=JSON.stringify(p,null,2),f=new Blob([g],{type:"text/plain"}),C=URL.createObjectURL(f),v=document.createElement("a");v.href=C,v.download="drawing.geojson",v.click(),URL.revokeObjectURL(C)});const r=document.getElementById("upload-button"),a=document.getElementById("upload-input");r&&a&&(r.onclick=()=>{a.click()},a.onchange=u=>{const p=u.target.files?.[0];if(p){const g=new FileReader;g.onload=f=>{try{const C=JSON.parse(f.target?.result);C.type==="FeatureCollection"?E.addFeatures(C.features):alert("Invalid GeoJSON file: must be a FeatureCollection.")}catch{alert("Error parsing GeoJSON file.")}},g.readAsText(p)}});const d=document.getElementById("resize-button");d&&(d.onclick=()=>{A=!A,d.classList.toggle("active",A);const u={polygon:{feature:{draggable:!0,coordinates:{resizable:A?"center":void 0,draggable:!A}}},linestring:{feature:{draggable:!0,coordinates:{resizable:A?"center":void 0,draggable:!A}}},rectangle:{feature:{draggable:!0,coordinates:{resizable:A?"center":void 0,draggable:!A}}},circle:{feature:{draggable:!0,coordinates:{resizable:A?"center":void 0,draggable:!A}}},freehand:{feature:{draggable:!0,coordinates:{resizable:A?"center":void 0,draggable:!A}}}};console.log("Updating flags:",u),E.updateModeOptions("select",{flags:u})});const h=document.getElementById("delete-selected-button");h&&(h.onclick=()=>{if(j)E.removeFeatures([j]);else{const u=E.getSnapshot();if(u.length>0){const p=u[u.length-1];p.id&&E.removeFeatures([p.id])}}});const l=document.getElementById("undo-button");l&&(l.onclick=()=>{if(J.length>1){const u=J.pop();u&&St.push(u);const p=J[J.length-1];console.log("Restoring snapshot (undo):",p),ht=!0,E.clear(),E.addFeatures(p),setTimeout(()=>{ht=!1},0)}});const c=document.getElementById("redo-button");c&&(c.onclick=()=>{if(St.length>0){const u=St.pop();console.log("Restoring snapshot (redo):",u),J.push(u),ht=!0,E.clear(),E.addFeatures(u),setTimeout(()=>{ht=!1},0)}})});function i(n,r){const a=JSON.parse(JSON.stringify(n)),d=a.geometry.coordinates,h=o(d),l=d.map(c=>c.map(u=>{const p=u[0]-h[0],g=u[1]-h[1],f=p*Math.cos(r*Math.PI/180)-g*Math.sin(r*Math.PI/180),C=p*Math.sin(r*Math.PI/180)+g*Math.cos(r*Math.PI/180);return[f+h[0],C+h[1]]}));return a.geometry.coordinates=l,a}function o(n){let r=0,a=0,d=0;return n.forEach(h=>{h.forEach(l=>{r+=l[0],a+=l[1],d++})}),[r/d,a/d]}document.addEventListener("keydown",n=>{if(n.key==="r"&&j){const a=E.getSnapshot().find(d=>d.id===j);if(a){const d=i(a,15);E.addFeatures([d])}}})})}catch(s){console.error("Error loading Google Maps API:",s)}}Gi(); diff --git a/dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js b/dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js new file mode 100644 index 000000000..0cb338f14 --- /dev/null +++ b/dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js @@ -0,0 +1 @@ +(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;te*Math.PI/180,r=n(e[1]),i=n(e[0]),a=n(t[1]),o=a-r,s=n(t[0])-i,c=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*6371e3/1e3}var y=6371008.8;function b(e){return e%360*Math.PI/180}function x(e){return e/6371.0088}function S(e){return e%(2*Math.PI)*180/Math.PI}function C(e,t=9){let n=10**t;return Math.round(e*n)/n}var w=57.29577951308232,T=.017453292519943295,E=6378137,D=(e,t)=>({x:e===0?0:e*T*E,y:t===0?0:Math.log(Math.tan(Math.PI/4+t*T/2))*E}),O=(e,t)=>({lng:e===0?0:e/E*w,lat:t===0?0:(2*Math.atan(Math.exp(t/E))-Math.PI/2)*w});function ee(e,t,n){let r=b(e[0]),i=b(e[1]),a=b(n),o=x(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[S(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),S(s)]}function te(e){let{center:t,radiusKilometers:n,coordinatePrecision:r}=e,i=e.steps?e.steps:64,a=[];for(let e=0;e0;function r(e){return e<0||e>1}function i(e,i,a,o){let s=t[e][i],c=t[e][i+1],l=t[a][o],u=t[a][o+1],d=function(e,t,n,r){if(re(e,n)||re(e,r)||re(t,n)||re(r,n))return null;let i=e[0],a=e[1],o=t[0],s=t[1],c=n[0],l=n[1],u=r[0],d=r[1],f=(i-o)*(l-d)-(a-s)*(c-u);return f===0?null:[((i*s-a*o)*(c-u)-(i-o)*(c*d-l*u))/f,((i*s-a*o)*(l-d)-(a-s)*(c*d-l*u))/f]}(s,c,l,u);if(d===null)return;let f,p;f=c[0]===s[0]?(d[1]-s[1])/(c[1]-s[1]):(d[0]-s[0])/(c[0]-s[0]),p=u[0]===l[0]?(d[1]-l[1])/(u[1]-l[1]):(d[0]-l[0])/(u[0]-l[0]),r(f)||r(p)||(d.toString(),n.push(d))}}function re(e,t){return e[0]===t[0]&&e[1]===t[1]}function ie(e,t){return oe(e[0])<=t&&oe(e[1])<=t}function ae(e){return e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`&&e[0]!==1/0&&e[1]!==1/0&&(n=e[0])>=-180&&n<=180&&(t=e[1])>=-90&&t<=90;var t,n}function oe(e){let t=1,n=0;for(;Math.round(e*t)/t!==e;)t*=10,n++;return n}var se=`Feature has holes`,ce=`Feature has less than 4 coordinates`,le=`Feature has invalid coordinates`,ue=`Feature coordinates are not closed`;function de(e,t){if(e.geometry.type!==`Polygon`)return{valid:!1,reason:`Feature is not a Polygon`};if(e.geometry.coordinates.length!==1)return{valid:!1,reason:se};if(e.geometry.coordinates[0].length<4)return{valid:!1,reason:ce};for(let n=0;n({type:`Feature`,geometry:{type:`Point`,coordinates:t},properties:e({mode:this.mode,[n]:!0},r?r(i):{})}));return this.createFeatures(i)}updatePoint({featureId:e,coordinateMutations:t,propertyMutations:n,context:r}){return this.handleMutateFeature({type:`Point`,featureId:e,coordinateMutations:t,propertyMutations:n,context:r})}updatePolygon({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`Polygon`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}updateLineString({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`LineString`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}deleteFeatureIfPresent(e){e&&this.store.has(e)&&this.store.delete([e])}deleteFeaturesIfPresent(e){if(e.length===0)return;let t=e.filter(e=>this.store.has(e));t.length&&this.store.delete(t)}setDeselected(e){let t=e.filter(e=>this.store.has(e)).map(e=>({featureId:e,properties:{[s.SELECTED]:!1}}));this.updateFeatureProperties(t)}setSelected(e){let{type:t}=this.store.getGeometryCopy(e),n={featureId:e,propertyMutations:{[s.SELECTED]:!0},context:{updateType:a.Commit}};t===`Polygon`?this.updatePolygon(n):t===`LineString`?this.updateLineString(n):t===`Point`&&this.updatePoint(n)}updateGuidancePoints(e){this.updateFeatureGeometries(e.map(({featureId:e,coordinate:t})=>({id:e,geometry:{type:`Point`,coordinates:t}})))}handleCreateFeature({geometry:e,properties:t}){return this.createFeatureWithGeometry({geometry:e,properties:t})}handleMutateFeature({type:t,featureId:n,coordinateMutations:r,propertyMutations:i,context:o}){if(!this.mutateFeature({type:t,featureId:n,coordinateMutations:r,propertyMutations:i,context:o.updateType===a.Finish?e({},o,{correctRightHandRule:!0}):e({},o)}))return null;let s=this.buildFeatureWithGeometry(n);return o.updateType!==a.Finish||r||this.validateGeometryWithUpdateType({geometry:s.geometry,properties:s.properties,updateType:o.updateType})?s:null}mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!t)return!1;let a=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t);if(a.type!==e)throw Error(`${e} geometries cannot be updated on features with ${a.type} geometries`);if(n){let e=this.applyCoordinateMutations(a,n);if(i.correctRightHandRule&&e.type===`Polygon`){let t=pe(e);t&&(e=t)}if(!this.validateGeometryWithUpdateType({geometry:e,properties:o,updateType:i.updateType}))return!1;this.updateFeatureGeometries([{id:t,geometry:e}])}return r&&this.updateFeatureProperties([{featureId:t,properties:r}]),!0}applyCoordinateMutations(t,n){if(this.isReplaceMutation(n))return e({},t,{coordinates:n.coordinates});if(t.type===`Point`)throw Error(`Coordinate mutations are not supported for Point geometries`);let r=t.type===`Polygon`,i=r?t.coordinates[0].slice():t.coordinates.slice(),a=i.length,o=e=>{let t=e<0?a+e:e;if(t<0||t>=a)throw RangeError(`Index ${e} (normalized to ${t}) is out of bounds`);return t},s=Array(a).fill(void 0),c=Array.from({length:a},()=>[]),l=Array.from({length:a},()=>[]),u=[];for(let t of n){if(t.type===A||t.type===j){let e=t.index,n=e<0?a+e:e;if(n<0||n>a)throw RangeError(`Index ${t.index} (normalized to ${n}) is out of bounds`);if(t.type===A){if(n>=a)throw RangeError(`INSERT_BEFORE index ${t.index} (normalized to ${n}) is out of bounds for length ${a}`);c[n].push(t)}else n===a?u.push(t):l[n].push(t);continue}let n=o(t.index);s[n]=e({},t,{index:n})}let d=[];for(let e=0;eObject.entries(t).map(([t,n])=>({id:e,property:t,value:n}))).flat();this.store.updateProperty(t)}},me={cancel:`Escape`,finish:`Enter`},he={start:`crosshair`},ge=class extends g{constructor(e){super(e,!0),this.mode=`circle`,this.center=void 0,this.endPosition=void 0,this.segments=64,this.currentCircleId=void 0,this.keyEvents=me,this.cursors=he,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(t){super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),t!=null&&t.startingRadiusKilometers&&(this.startingRadiusKilometers=t.startingRadiusKilometers),t!=null&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction),t!=null&&t.segments&&(this.segments=t.segments<3?3:t.segments)}close(){if(this.currentCircleId===void 0||this.endPosition===void 0||!this.updateCircle(this.endPosition,a.Finish))return;let e=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:t})}beginDrawing(e,t=`click`){this.center=[e.lng,e.lat],this.endPosition=[e.lng,e.lat];let n=te({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),r=this.mutateFeature.createPolygon({coordinates:n.geometry.coordinates[0],properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers,[c.CURRENTLY_DRAWING]:!0}});r&&(this.currentCircleId=r.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=t,this.setDrawing())}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.center?this.center&&this.currentCircleId!==void 0&&(this.endPosition=[e.lng,e.lat],this.close()):this.beginDrawing(e))}onMouseMove(e){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[e.lng,e.lat],this.updateCircle(this.endPosition,a.Provisional)}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){this.state!==`drawing`&&this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[e.lng,e.lat],this.updateCircle(this.endPosition,a.Provisional))}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.close(),t(!0))}cleanUp(){let e=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});return t.type===`Feature`&&t.geometry.type===`Polygon`&&t.properties.mode===this.mode?(n.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,n.polygonFillColor,t),n.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,n.polygonOutlineColor,t),n.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,n.polygonOutlineWidth,t),n.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),n.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,n.polygonFillOpacity,t),n.zIndex=l,n):n}validateFeature(e){return this.validateModeFeature(e,e=>fe(e,this.coordinatePrecision))}updateCircle(e,n){if(this.currentCircleId===void 0||this.center===void 0)return;let r=n===a.Finish,i,o;if(this.cursorMovedAfterInitialCursorDown){if(o=v(this.center,e),this.projection===`web-mercator`){let t=function(e,t){let n=1e3*v(e,t);if(n===0)return 1;let{x:r,y:i}=D(e[0],e[1]),{x:a,y:o}=D(t[0],t[1]);return Math.sqrt((a-r)**2+(o-i)**2)/n}(this.center,e);i=function(e){let{center:t,radiusKilometers:n,coordinatePrecision:r}=e,i=e.steps?e.steps:64,a=1e3*n,[o,s]=t,{x:c,y:l}=D(o,s),u=[];for(let e=0;e{let{x:n,y:r}=e,{x:i,y:a}=t,o=i-n,s=a-r;return Math.sqrt(s*s+o*o)};function _e(e,t){return e[0]===t[0]&&e[1]===t[1]}var L=class extends k{constructor(e){super(e)}getGeometryType(e){return this.store.getGeometryCopy(e).type}coordinateAtIndexIsIdentical({featureId:e,newCoordinate:t,index:n}){let r=this.store.getGeometryCopy(e),i;if(r.type===`Polygon`)i=r.coordinates[0][n];else if(r.type===`LineString`)i=r.coordinates[n];else{if(n!==0)throw Error(`Point geometries only have one coordinate at index 0`);i=r.coordinates}return _e(t,i)}getGeometry(e){return this.store.getGeometryCopy(e)}getCoordinates(e){let{type:t,coordinates:n}=this.store.getGeometryCopy(e);return t===`Polygon`?n[0]:n}getCoordinate(e,t){let n=this.getCoordinates(e),r=t<0?n.length+t:t;if(r<0||r>=n.length)throw RangeError(`Index ${t} (normalized to ${r}) is out of bounds`);return n[r]}getProperties(e){return this.store.getPropertiesCopy(e)}hasFeature(e){return this.store.has(e)}getAllFeatureIdsWhere(e){return this.store.copyAllWhere(e).map(({id:e})=>e)}},ve={cancel:`Escape`,finish:`Enter`},ye={start:`crosshair`,close:`pointer`},be=class extends g{constructor(e){super(e,!0),this.mode=`freehand`,this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=20,this.keyEvents=ve,this.cursors=ye,this.preventPointsNearClose=!0,this.autoClose=!1,this.autoCloseTimeout=500,this.hasLeftStartingPoint=!1,this.preventNewFeature=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.smoothing=0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(t){super.updateOptions(t),t!=null&&t.minDistance&&(this.minDistance=t.minDistance),t?.smoothing!==void 0&&(this.smoothing=Math.min(Math.max(t.smoothing,0),.999)),t?.preventPointsNearClose!==void 0&&(this.preventPointsNearClose=t.preventPointsNearClose),t?.autoClose!==void 0&&(this.autoClose=t.autoClose),t!=null&&t.autoCloseTimeout&&(this.autoCloseTimeout=t.autoCloseTimeout),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),t!=null&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),t!=null&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction)}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}beginDrawing(e,t=`click`){let{id:n}=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[c.CURRENTLY_DRAWING]:!0}});this.currentId=n,this.drawType=t,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[e.lng,e.lat],type:c.CLOSING_POINT}),this.canClose=!0,this.state!==`drawing`&&this.setDrawing()}addCoordinate(e){if(this.currentId===void 0||!1===this.canClose)return void this.setCursor(this.cursors.start);let[t,n]=this.readFeature.getCoordinate(this.currentId,-2),{x:r,y:i}=this.project(t,n),o=I({x:r,y:i},{x:e.containerX,y:e.containerY}),[s,c]=this.readFeature.getCoordinate(this.currentId,0),{x:l,y:u}=this.project(s,c);if(I({x:l,y:u},{x:e.containerX,y:e.containerY}){this.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(o{this.preventNewFeature=!1},this.autoCloseTimeout),this.close(),t(!0))}cleanUp(){let e=this.currentId,t=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t)}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});return t.type===`Feature`&&t.geometry.type===`Polygon`&&t.properties.mode===this.mode?(n.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,n.polygonFillColor,t),n.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,n.polygonOutlineColor,t),n.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),n.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,n.polygonOutlineWidth,t),n.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,n.polygonFillOpacity,t),n.zIndex=l,n):t.type===`Feature`&&t.geometry.type===`Point`&&t.properties.mode===this.mode?(n.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,n.pointWidth,t),n.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,n.pointColor,t),n.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,n.pointOpacity===void 0?1:n.pointOpacity,t),n.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,n.pointOutlineColor,t),n.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,n.pointOutlineOpacity===void 0?1:n.pointOutlineOpacity,t),n.zIndex=50,n):n}validateFeature(e){return this.validateModeFeature(e,e=>de(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)}registerBehaviors(e){this.readFeature=new L(e),this.mutateFeature=new F(e,{validate:this.validate})}};function xe({unproject:e,point:t,pointerDistance:n}){let r=n/2,{x:i,y:a}=t;return{type:`Feature`,properties:{},geometry:{type:`Polygon`,coordinates:[[e(i-r,a-r),e(i+r,a-r),e(i+r,a+r),e(i-r,a+r),e(i-r,a-r)].map(e=>[e.lng,e.lat])]}}}var Se=class extends k{constructor(e){super(e)}create(e){let{containerX:t,containerY:n}=e;return xe({unproject:this.unproject,point:{x:t,y:n},pointerDistance:this.pointerDistance})}},Ce=class extends k{constructor(e){super(e)}measure(e,t){let{x:n,y:r}=this.project(t[0],t[1]);return I({x:n,y:r},{x:e.containerX,y:e.containerY})}},we=class extends k{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappableCoordinateFirstClick(e){return this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode)).coordinate}getSnappableCoordinate(e,t){return this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t)).coordinate}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else if(t.geometry.type===`LineString`)n=t.geometry.coordinates;else{if(t.geometry.type!==`Point`)return;var r,a,o,l,u,d;if((r=t.properties)!=null&&r[c.EDITED]||(a=t.properties)!=null&&a[c.CLOSING_POINT]||(o=t.properties)!=null&&o[c.SNAPPING_POINT]||(l=t.properties)!=null&&l[c.COORDINATE_POINT]||(u=t.properties)!=null&&u[s.SELECTION_POINT]||(d=t.properties)!=null&&d[s.MID_POINT])return;n=[t.geometry.coordinates]}n.forEach((n,r)=>{let a=this.pixelDistance.measure(e,n);a180?o-=360:o<-180&&(o+=360),o}function Oe(e,t,n){let r=[],i=e.length,a,o,s,c=0;for(let i=0;i=c&&i===e.length-1);i++){if(c>t&&r.length===0){if(a=t-c,!a)return r.push(e[i]),r;o=Ee(e[i],e[i-1])-180,s=Te(e[i],a,o),r.push(s)}if(c>=n)return a=n-c,a?(o=Ee(e[i],e[i-1])-180,s=Te(e[i],a,o),r.push(s),r):(r.push(e[i]),r);if(c>=t&&r.push(e[i]),i===e.length-1)return r;c+=v(e[i],e[i+1])}if(c[C(e[0],this.config.coordinatePrecision),C(e[1],this.config.coordinatePrecision)])}};function Me(e,t){if(e.geometry.type!==`LineString`)return{valid:!1,reason:`Feature is not a LineString`};if(e.geometry.coordinates.length<2)return{valid:!1,reason:`Feature has less than 2 coordinates`};for(let n=0;nx||R(i,E)>x?v(z(E),z(r))<=v(z(E),z(i))?[z(r),!0,!1]:[z(i),!1,!0]:[z(E),!1,!1]}function Ie(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.max(0,Math.min(1,((n.x-e.x)*r+(n.y-e.y)*i)/(r*r+i*i)));return{x:e.x+a*r,y:e.y+a*i}}var Le=class extends k{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>{let t=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode));return t.coordinate?[C(t.coordinate[0],this.config.coordinatePrecision),C(t.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappableCoordinate=(e,t)=>{let n=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t));return n.coordinate?[C(n.coordinate[0],this.config.coordinatePrecision),C(n.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappable=(e,t)=>{let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}let r=[];for(let e=0;e(t===void 0||e.id!==t)&&(!n||n(e)),o={coordinate:void 0,featureId:void 0,featureCoordinateIndex:void 0,minDistance:1/0};if(!1!==r?.toCoordinate){let t=this.coordinateSnapping.getSnappable(e,a);t.coordinate&&t.minDistance0&&Array.isArray(e[0])&&Array.isArray(e[0][0])}var Be=e=>ze(e)?e[0].slice(0,-1):e,B=e=>ze(e)?e[0]:e,Ve=class extends k{constructor(e,t,n,r){super(e),this.config=void 0,this.pixelDistance=void 0,this.mutateFeatureBehavior=void 0,this.readFeatureBehavior=void 0,this._startEndPoints=[],this.config=e,this.pixelDistance=t,this.mutateFeatureBehavior=n,this.readFeatureBehavior=r}get ids(){return this._startEndPoints.concat()}set ids(e){}create(e){if(this.ids.length)throw Error(`Opening and closing points already created`);let t=ze(e),n=B(e);if(t){if(n.length<=3)throw Error(`Requires at least 4 coordinates`);this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[n[0],n[n.length-2]],type:c.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:n[n.length-2],type:c.CLOSING_POINT})]}delete(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])}updateOne(e,t){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[e],coordinate:t}])}update(e){let t=B(e);this.ids.length===1?this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[t.length-2]}]):this.ids.length===2&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[0]},{featureId:this.ids[1],coordinate:t[t.length-3]}])}isLineStringClosingPoint(e){if(this.ids.length!==1)return{isClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(e,t.coordinates)this.readFeature.hasFeature(e))){let t=r.coordinatePointIds,i=t.map(e=>this.readFeature.getGeometry(e).coordinates);if(t.length!==n.length){this.deleteCoordinatePoints(t);let i=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,i)}else{let e=[];n.forEach((n,r)=>{n[0]===i[r][0]&&n[1]===i[r][1]||e.push({featureId:t[r],coordinate:n})}),this.mutateFeature.updateGuidancePoints(e)}}else{let t=i.filter(e=>this.readFeature.hasFeature(e));t.length&&this.deleteCoordinatePoints(t);let a=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,a)}}else{let t=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,t)}}deletePointsByFeatureIds(e){for(let t of e)this.deleteIfPresent(t)}updateOneAtIndex(e,t,n){let r=this.readFeature.getProperties(e).coordinatePointIds;r&&r.length!==0&&r[t]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:r[t],coordinate:n}])}updateAllInPlace({featureId:e,featureCoordinates:t}){let n=this.readFeature.getProperties(e);if(!n.coordinatePointIds)return;let r=Be(t);r.length===n.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(n.coordinatePointIds.map((e,t)=>({featureId:e,coordinate:r[t]})))}createPoints(e,t,n){return this.mutateFeature.createGuidancePoints({coordinates:e,type:c.COORDINATE_POINT,additionalProperties:e=>({mode:t,[c.COORDINATE_POINT]:!0,[c.COORDINATE_POINT_FEATURE_ID]:n,index:e})})}setFeatureCoordinatePoints(e,t,n=a.Commit){let r=this.readFeature.getGeometryType(e),i={featureId:e,propertyMutations:{[c.COORDINATE_POINT_IDS]:t},context:{updateType:n}};if(r===`Polygon`)this.mutateFeature.updatePolygon(i);else{if(r!==`LineString`)throw Error(`Unsupported geometry type for coordinate points`);this.mutateFeature.updateLineString(i)}}deleteCoordinatePoints(e){this.mutateFeature.deleteFeaturesIfPresent(e)}deleteIfPresent(e){if(!this.readFeature.hasFeature(e))return;let t=this.readFeature.getProperties(e).coordinatePointIds;t&&(this.deleteCoordinatePoints(t),this.setFeatureCoordinatePoints(e,null))}deleteOrphanedPoints(e){let t=this.readFeature.getAllFeatureIdsWhere(t=>t[c.COORDINATE_POINT_FEATURE_ID]===e);this.mutateFeature.deleteFeaturesIfPresent(t)}},Ue=class{constructor(e){this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=e=>this.cloneRecursively(e);let t=e?.maxStackSize;this.maxStackSize=t!==void 0&&Number.isFinite(t)?Math.max(0,Math.floor(t)):1/0}setMaxStackSize(e){Number.isFinite(e)?(this.maxStackSize=Math.max(0,Math.floor(e)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=1/0}trimHistoryToMax(e){if(Number.isFinite(this.maxStackSize))for(;e.length>this.maxStackSize;)e.shift()}pushUndoEntry(e){this.maxStackSize!==0&&(this.undoHistory.push(e),this.trimHistoryToMax(this.undoHistory))}pushRedoEntry(e){this.maxStackSize!==0&&(this.redoHistory.push(e),this.trimHistoryToMax(this.redoHistory))}cloneRecursively(t){return Array.isArray(t)?t.map(e=>this.cloneRecursively(e)):typeof t==`object`&&t?e({},t):t}cloneCoordinates(e){return this.cloneCoordinatesFunction(e)}cloneEntry(e){return{featureCoordinates:this.cloneCoordinates(e.featureCoordinates),currentCoordinate:e.currentCoordinate}}clear(){this.undoHistory=[],this.redoHistory=[]}undoSize(){return this.undoHistory.length}redoSize(){return this.redoHistory.length}recordSnapshot(e){this.pushUndoEntry(this.cloneEntry(e)),this.redoHistory=[]}beginUndo(){let e=this.undoHistory.pop();if(!e)return;let t=this.cloneEntry(e);this.pushRedoEntry(t);let n=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:t,previousEntry:n?this.cloneEntry(n):void 0}}takeRedo(){let e=this.redoHistory.pop();if(e)return this.cloneEntry(e)}commitRedo(e){this.pushUndoEntry(this.cloneEntry(e))}},We={cancel:`Escape`,finish:`Enter`},Ge={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},Ke=class extends g{constructor(e){super(e,!0),this.mode=`linestring`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=We,this.snapping=void 0,this.cursors=Ge,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommittedCoordinates=void 0,this.snappedPointId=void 0,this.lastMouseMoveEvent=void 0,this.showCoordinatePoints=!1,this.finishOnNthCoordinate=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0,this.lineSnapping=void 0,this.featureSnapping=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.closingPoints=void 0,this.coordinatePoints=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(t){if(super.updateOptions(t),t?.finishOnNthCoordinate!==void 0&&Number.isInteger(t.finishOnNthCoordinate)&&t.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(t.finishOnNthCoordinate)),t!=null&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),t!=null&&t.snapping&&(this.snapping=t.snapping),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),t!=null&&t.insertCoordinates&&(this.insertCoordinates=t.insertCoordinates),t&&t.editable&&(this.editable=t.editable),t?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=t.showCoordinatePoints,this.coordinatePoints&&!0===t.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[c.COORDINATE_POINT_IDS]?.length);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}shouldFinishOnCommit(e){return!!this.finishOnNthCoordinate&&Math.max(0,e.coordinates.length-1)>=this.finishOnNthCoordinate}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);return t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:c.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),t}close(){if(this.currentId===void 0)return;let e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:a.Finish,action:t},coordinateMutations:[{type:N,index:-1}],propertyMutations:{[c.CURRENTLY_DRAWING]:void 0}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});let n=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(n,{mode:this.mode,action:t})}generateInsertCoordinates(e,t){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw Error(`Not able to insert coordinates`);if(this.insertCoordinates.strategy!==`amount`)throw Error(`Strategy does not exist`);let n=v(e,t)/(this.insertCoordinates.value+1),r=[];return this.projection===`globe`?r=this.insertPoint.generateInsertionGeodesicCoordinates(e,t,n):this.projection===`web-mercator`&&(r=this.insertPoint.generateInsertionCoordinates(e,t,n)),r}createLine(e){let t=this.mutateFeature.createLineString({coordinates:[e,e],properties:{mode:this.mode,[c.CURRENTLY_DRAWING]:!0}});this.lastCommittedCoordinates=t.geometry.coordinates,this.currentId=t.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}firstUpdateToLine(e){if(!this.currentId)return;this.setCursor(this.cursors.close);let t=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:a.Commit},coordinateMutations:[{type:j,index:-1,coordinate:e}]});t&&(this.closingPoints.create(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.lastCommittedCoordinates=t.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(t.geometry)&&this.close())}updateToLine(e,t){if(!this.currentId)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);if(n)return void this.close();this.setCursor(this.cursors.close);let r=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:a.Commit},coordinateMutations:[{type:j,index:-1,coordinate:t}]});r&&(this.closingPoints.update(r.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates}),this.lastCommittedCoordinates=r.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(r.geometry)&&this.close())}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:P,coordinates:t.featureCoordinates},propertyMutations:{[c.CURRENTLY_DRAWING]:!0},context:{updateType:a.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=n.geometry.coordinates,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:P,coordinates:e.featureCoordinates},propertyMutations:{[c.CURRENTLY_DRAWING]:!0},context:{updateType:a.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=t.geometry.coordinates,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let{id:t,geometry:n}=this.mutateFeature.createLineString({coordinates:e.featureCoordinates,properties:{mode:this.mode,[c.CURRENTLY_DRAWING]:!0}});this.currentId=t,this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=n.coordinates,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(n.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:n.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}registerBehaviors(e){this.insertPoint=new je(e),this.clickBoundingBox=new Se(e),this.pixelDistance=new Ce(e),this.lineSnapping=new Le(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new we(e,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Re(this.coordinateSnapping,this.lineSnapping),this.readFeature=new L(e),this.mutateFeature=new F(e,{validate:this.validate}),this.closingPoints=new Ve(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new He(e,this.readFeature,this.mutateFeature),this.undoRedo=new Ue({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e;let t=this.updateSnappedCoordinate(e)||[e.lng,e.lat];if(this.currentId===void 0||this.currentCoordinate===0)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);n&&this.setCursor(this.cursors.close);let r=[{type:M,index:-1,coordinate:t}];if(this.insertCoordinates){let e=this.getInsertCoordinates(t);e&&(r={type:P,coordinates:e})}let i=this.mutateFeature.updateLineString({coordinateMutations:r,featureId:this.currentId,context:{updateType:a.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}getInsertCoordinates(e){if(!this.lastCommittedCoordinates)return;let t=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(_e(t,e))return;let n=this.generateInsertCoordinates(t,e);return[...this.lastCommittedCoordinates.slice(0,-1),...n,e]}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:i}=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));if(!t||i===void 0)return;let o=this.readFeature.getGeometry(t),s;if(o.type!==`LineString`||(s=o.coordinates,s.length<=2))return;let c=this.mutateFeature.updateLineString({featureId:t,coordinateMutations:[{type:N,index:i}],context:{updateType:a.Finish,action:n}});c&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:c.geometry.coordinates}),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(t,{mode:this.mode,action:r})}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];this.currentCoordinate===0?this.createLine(t):this.currentCoordinate===1&&this.currentId?this.firstUpdateToLine(t):this.currentId&&this.updateToLine(e,t)}onClick(e){this.currentId===void 0||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`?this.onRightClick(e):e.button===`left`&&this.onLeftClick(e))}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel&&this.cleanUp(),e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.lineStringFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:c.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.editedFeatureCoordinateIndex!==void 0){if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0){let t=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:a.Provisional},coordinateMutations:[{type:M,index:this.editedFeatureCoordinateIndex,coordinate:[e.lng,e.lat]}]});if(!t)return;this.showCoordinatePoints&&(this.editedInsertIndex===void 0?this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[e.lng,e.lat]):this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:t.geometry.coordinates}))}else if(this.editedSnapType===`line`&&this.editedInsertIndex===void 0){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;let e=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:a.Provisional}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:e.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[e.lng,e.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:a.Provisional},propertyMutations:{[c.EDITED]:!0}})}}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:{[c.EDITED]:!1},context:{updateType:a.Finish,action:n}})))return;let r=this.editedFeatureId;t(!0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(r,{mode:this.mode,action:n})}cleanUp(){let e=this.currentId,t=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.type===`Feature`&&t.geometry.type===`LineString`&&t.properties.mode===this.mode)return n.lineStringDash=this.getDashArrayStylingValue(this.styles.lineStringDash,void 0,t),n.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,n.lineStringColor,t),n.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,n.lineStringOpacity===void 0?1:n.lineStringOpacity,t),n.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,n.lineStringWidth,t),n.zIndex=l,n;if(t.type===`Feature`&&t.geometry.type===`Point`&&t.properties.mode===this.mode){let e=t.properties[c.COORDINATE_POINT],r=t.properties[c.CLOSING_POINT]?`closingPoint`:t.properties[c.SNAPPING_POINT]?`snappingPoint`:e?`coordinatePoint`:void 0;if(!r)return n;let i={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return n.pointWidth=this.getNumericStylingValue(i[r].width,n.pointWidth,t),n.pointOpacity=this.getNumericStylingValue(i[r].opacity,1,t),n.pointColor=this.getHexColorStylingValue(i[r].color,n.pointColor,t),n.pointOutlineColor=this.getHexColorStylingValue(i[r].outlineColor,`#ffffff`,t),n.pointOutlineWidth=this.getNumericStylingValue(i[r].outlineWidth,2,t),n.pointOutlineOpacity=this.getNumericStylingValue(i[r].outlineOpacity,1,t),n.zIndex=e?20:50,n}return n}validateFeature(e){return this.validateModeFeature(e,e=>Me(e,this.coordinatePrecision))}lineStringFilter(e){return!!(e.geometry.type===`LineString`&&e.properties&&e.properties.mode===this.mode)}snapCoordinate(e){var t,n,r,i;let a;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(a=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(a=t)}if((r=this.snapping)!=null&&r.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(a=t)}if((i=this.snapping)!=null&&i.toFeature){let t=this.featureSnapping.getSnappable(e,this.currentId,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});t.coordinate&&(a=t.coordinate)}return a}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===e.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted())}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}},qe=`Feature is not a Point`,Je=`Feature has invalid coordinates`,Ye=`Feature has coordinates with excessive precision`;function Xe(e,t){return e.geometry.type===`Point`?ae(e.geometry.coordinates)?ie(e.geometry.coordinates,t)?{valid:!0}:{valid:!1,reason:Ye}:{valid:!1,reason:Je}:{valid:!1,reason:qe}}var Ze=class extends k{constructor(e,t,n){super(e),this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pixelDistance=t,this.clickBoundingBox=n}getNearestPointFeature(e){let t=this.clickBoundingBox.create(e),n=this.store.search(t),r,i=1/0;for(let t=0;ti||o>this.pointerDistance||(i=o,r=a)}return r}},Qe={create:`crosshair`,dragStart:`grabbing`,dragEnd:`crosshair`},$e=class extends g{constructor(e){super(e,!0),this.mode=`point`,this.cursors=Qe,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(t){super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),t!=null&&t.editable&&(this.editable=t.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(e,t){if(this.allowPointerEvent(this.pointerEvents.onDragStart,e)){if(this.editable){let t=this.pointSearch.getNearestPointFeature(e);this.editedFeatureId=t?.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),t(!1))}}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:P,coordinates:[e.lng,e.lat]},propertyMutations:{[c.EDITED]:!0},context:{updateType:a.Provisional}})}onDragEnd(e,n){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[c.EDITED]:!1},context:{updateType:a.Finish,action:`edit`}}))return;let r=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,n(!0),this.onFinish(r,{mode:this.mode,action:t})}registerBehaviors(e){this.pixelDistance=new Ce(e),this.clickBoundingBox=new Se(e),this.pointSearch=new Ze(e,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new F(e,{validate:this.validate})}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.type===`Feature`&&t.geometry.type===`Point`&&t.properties.mode===this.mode){let e=!!(t.id&&this.editedFeatureId===t.id);n.pointWidth=this.getNumericStylingValue(e?this.styles.editedPointWidth:this.styles.pointWidth,n.pointWidth,t),n.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,n.pointOpacity===void 0?1:n.pointOpacity,t),n.pointColor=this.getHexColorStylingValue(e?this.styles.editedPointColor:this.styles.pointColor,n.pointColor,t),n.pointOutlineColor=this.getHexColorStylingValue(e?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,n.pointOutlineColor,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,n.pointOutlineOpacity===void 0?1:n.pointOutlineOpacity,t),n.pointOutlineWidth=this.getNumericStylingValue(e?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),n.zIndex=30}return n}validateFeature(e){return this.validateModeFeature(e,e=>Xe(e,this.coordinatePrecision))}onLeftClick(e){let n=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode},context:{updateType:a.Finish,action:t}});n&&this.onFinish(n.id,{mode:this.mode,action:t})}onRightClick(e){if(!this.editable)return;let t=this.pointSearch.getNearestPointFeature(e);t&&this.mutateFeature.deleteFeatureIfPresent(t.id)}afterFeatureUpdated(e){this.editedFeatureId===e.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}},et={cancel:`Escape`,finish:`Enter`},tt={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},nt=class extends g{constructor(e){super(e,!0),this.mode=`polygon`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=et,this.cursors=tt,this.mouseMove=!1,this.showCoordinatePoints=!1,this.lastMouseMoveEvent=void 0,this.snapping=void 0,this.snappedPointId=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinatePoints=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.featureSnapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(t){if(super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),t!=null&&t.snapping&&(this.snapping=t.snapping),t?.editable!==void 0&&(this.editable=t.editable),t?.pointerEvents!==void 0&&(this.pointerEvents=t.pointerEvents),t?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=t.showCoordinatePoints,this.coordinatePoints&&!0===t.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).filter(e=>e.geometry.type===`Polygon`).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[c.COORDINATE_POINT_IDS]).filter(e=>e.geometry.type===`Polygon`);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}close(){if(this.currentId===void 0||this.readFeature.getCoordinates(this.currentId).length<5)return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:N,index:-2}],propertyMutations:{[c.CURRENTLY_DRAWING]:void 0,[c.COMMITTED_COORDINATE_COUNT]:void 0,[c.PROVISIONAL_COORDINATE_COUNT]:void 0},context:{updateType:a.Finish,action:t}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.state===`drawing`&&this.setStarted(),this.editedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),void 0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.closingPoints.delete();let n=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(n,{mode:this.mode,action:t})}registerBehaviors(e){this.readFeature=new L(e),this.mutateFeature=new F(e,{validate:this.validate}),this.clickBoundingBox=new Se(e),this.pixelDistance=new Ce(e),this.lineSnapping=new Le(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new we(e,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Re(this.coordinateSnapping,this.lineSnapping),this.closingPoints=new Ve(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new He(e,this.readFeature,this.mutateFeature),this.undoRedo=new Ue({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:c.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:P,coordinates:t.featureCoordinates},propertyMutations:{[c.CURRENTLY_DRAWING]:!0,[c.COMMITTED_COORDINATE_COUNT]:t.currentCoordinate,[c.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate},context:{updateType:a.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:P,coordinates:e.featureCoordinates},propertyMutations:{[c.CURRENTLY_DRAWING]:!0,[c.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[c.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate},context:{updateType:a.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let t=this.undoRedo.cloneCoordinates(e.featureCoordinates)[0],{id:n,geometry:r}=this.mutateFeature.createPolygon({coordinates:t,properties:{mode:this.mode,[c.CURRENTLY_DRAWING]:!0,[c.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[c.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate}});this.currentId=n,this.currentCoordinate=e.currentCoordinate,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(r.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:r.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e,this.updateSnappedCoordinate(e),this.currentId===void 0||this.currentCoordinate===0)return;let t=this.readFeature.getCoordinate(this.currentId,0),n=[e.lng,e.lat],r;if(this.currentCoordinate===1)r=[{type:M,index:1,coordinate:n},{type:M,index:2,coordinate:[e.lng,e.lat]}];else if(this.currentCoordinate===2)r=[{type:M,index:2,coordinate:n}];else{let{isClosing:i,isPreviousClosing:a}=this.closingPoints.isPolygonClosingPoints(e);a||i?(this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.setCursor(this.cursors.close),r=[{type:M,index:-1,coordinate:t},{type:M,index:-2,coordinate:t}]):r=[{type:M,index:-2,coordinate:n},{type:M,index:-1,coordinate:t}]}let i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:r,propertyMutations:{[c.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:a.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}snapCoordinate(e){var t,n,r,i;let a;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(a=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(a=t)}if((r=this.snapping)!=null&&r.toFeature){let t=this.featureSnapping.getSnappable(e,this.currentId,this.snapping?.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});t.coordinate&&(a=t.coordinate)}if((i=this.snapping)!=null&&i.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(a=t)}return a}polygonFilter(e){return!!(e.geometry.type===`Polygon`&&e.properties&&e.properties.mode===this.mode)}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:r}=this.coordinateSnapping.getSnappable(e,e=>this.polygonFilter(e));if(!t||r===void 0)return;let i=this.readFeature.getGeometry(t);if(i.type!==`Polygon`)return;let o=i.coordinates[0];if(o.length<=4)return;let s;s=r===0||r===o.length-1?[{type:N,index:0},{type:N,index:-1},{type:j,index:-1,coordinate:o[1]}]:[{type:N,index:r}];let l=this.mutateFeature.updatePolygon({featureId:t,coordinateMutations:s,context:{updateType:a.Finish,action:n}});if(l){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:l.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){let t=this.snapCoordinate(e);if(t){let[e]=this.mutateFeature.createGuidancePoints({type:c.SNAPPING_POINT,coordinates:[t]});this.snappedPointId=e}}this.onFinish(t,{mode:this.mode,action:n})}}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];if(this.currentCoordinate===0){let{id:e,geometry:n}=this.mutateFeature.createPolygon({coordinates:[t,t,t,t],properties:{mode:this.mode,[c.CURRENTLY_DRAWING]:!0,[c.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1,[c.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1}});this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:n.coordinates}),this.currentId=e,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(this.currentCoordinate===1&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:0}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:M,index:1,coordinate:t},{type:M,index:2,coordinate:t}],propertyMutations:{[c.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:a.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentCoordinate===2&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:1}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:M,index:2,coordinate:t},{type:j,index:2,coordinate:t}],propertyMutations:{[c.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:a.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate===2&&this.closingPoints.create(e.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){let{isClosing:n,isPreviousClosing:r}=this.closingPoints.isPolygonClosingPoints(e);if(r||n)this.close();else{if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:this.currentCoordinate-1}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:A,index:-1,coordinate:t}],propertyMutations:{[c.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:a.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(e.geometry.coordinates)}}}onClick(e){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.polygonFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.polygonFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:c.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e)||this.editedFeatureId===void 0||this.editedFeatureCoordinateIndex===void 0)return;let n=this.readFeature.getGeometry(this.editedFeatureId),r=[e.lng,e.lat],i=[];if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0?i=this.editedFeatureCoordinateIndex===0||this.editedFeatureCoordinateIndex===n.coordinates[0].length-1?[{type:M,index:0,coordinate:r},{type:M,index:-1,coordinate:r}]:[{type:M,index:this.editedFeatureCoordinateIndex,coordinate:r}]:this.editedSnapType===`line`&&this.editedInsertIndex===void 0&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i=[{type:A,index:this.editedInsertIndex,coordinate:r}],this.editedFeatureCoordinateIndex++),i.length===0)return;let o=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:i,propertyMutations:{[c.EDITED]:!0},context:{updateType:a.Provisional}});o&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:o.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,o.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:r}]))}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:{[c.EDITED]:!1},context:{updateType:a.Finish,action:n}})))return;let r=this.editedFeatureId;this.editedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),void 0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,t(!0),this.onFinish(r,{mode:this.mode,action:n})}cleanUp(){let e=this.currentId,t=this.snappedPointId,n=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(n),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.ids.length&&this.closingPoints.delete()}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.properties.mode===this.mode){if(t.geometry.type===`Polygon`)return n.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,n.polygonFillColor,t),n.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,n.polygonOutlineColor,t),n.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,n.polygonOutlineWidth,t),n.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,n.polygonFillOpacity,t),n.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),n.zIndex=l,n;if(t.geometry.type===`Point`){let e=t.properties[c.EDITED],r=t.properties[c.COORDINATE_POINT],i=e?`editedPoint`:t.properties[c.CLOSING_POINT]?`closingPoint`:t.properties[c.SNAPPING_POINT]?`snappingPoint`:r?`coordinatePoint`:void 0;if(!i)return n;let a={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return n.pointWidth=this.getNumericStylingValue(a[i].width,n.pointWidth,t),n.pointOpacity=this.getNumericStylingValue(a[i].opacity,1,t),n.pointColor=this.getHexColorStylingValue(a[i].color,n.pointColor,t),n.pointOutlineColor=this.getHexColorStylingValue(a[i].outlineColor,n.pointOutlineColor,t),n.pointOutlineOpacity=this.getNumericStylingValue(a[i].outlineOpacity,1,t),n.pointOutlineWidth=this.getNumericStylingValue(a[i].outlineWidth,2,t),n.zIndex=e?40:r?20:30,n}}return n}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===e.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),this.state===`drawing`&&this.setStarted())}validateFeature(e){return this.validateModeFeature(e,e=>de(e,this.coordinatePrecision))}},rt={cancel:`Escape`,finish:`Enter`},it={start:`crosshair`},at=class extends g{constructor(e){super(e,!0),this.mode=`rectangle`,this.startPosition=void 0,this.endPosition=void 0,this.currentRectangleId=void 0,this.keyEvents=rt,this.cursors=it,this.drawInteraction=`click-move`,this.drawType=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(t){super.updateOptions(t),t!=null&&t.cursors&&(this.cursors=e({},this.cursors,t.cursors)),t?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:t!=null&&t.keyEvents&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),t!=null&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction)}updateRectangle(e,n){if(!this.startPosition||!this.currentRectangleId)return;let r=n===a.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:M,index:1,coordinate:[e[0],this.startPosition[1]]},{type:M,index:2,coordinate:e},{type:M,index:3,coordinate:[this.startPosition[0],e[1]]}],propertyMutations:r?{[c.CURRENTLY_DRAWING]:void 0}:{},context:r?{updateType:n,action:t}:{updateType:n}})}close(){if(!this.currentRectangleId||!this.endPosition||!this.updateRectangle(this.endPosition,a.Finish))return;let e=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:t})}beginDrawing(e,t=`click`){this.startPosition=[e.lng,e.lat],this.endPosition=[e.lng,e.lat];let n=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[c.CURRENTLY_DRAWING]:!0}});this.currentRectangleId=n.id,this.drawType=t,this.setDrawing()}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.startPosition?(this.endPosition=[e.lng,e.lat],this.close()):this.beginDrawing(e))}onMouseMove(e){this.endPosition=[e.lng,e.lat],this.updateRectangle(this.endPosition,a.Provisional)}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){this.state!==`drawing`&&this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.updateRectangle(this.endPosition,a.Provisional))}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.close(),t(!0))}cleanUp(){let e=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});return t.type===`Feature`&&t.geometry.type===`Polygon`&&t.properties.mode===this.mode?(n.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,n.polygonFillColor,t),n.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,n.polygonOutlineColor,t),n.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),n.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,n.polygonOutlineWidth,t),n.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,n.polygonFillOpacity,t),n.zIndex=l,n):n}validateFeature(e){return this.validateModeFeature(e,e=>fe(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentRectangleId===e.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new L(e),this.mutateFeature=new F(e,{validate:this.validate})}};function ot(e,t){let n=e,r=t,i=b(n[1]),a=b(r[1]),o=b(r[0]-n[0]);o>Math.PI&&(o-=2*Math.PI),o<-Math.PI&&(o+=2*Math.PI);let s=Math.log(Math.tan(a/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=(S(Math.atan2(o,s))+360)%360;return c>180?-(360-c):c}function st(e,t,n){let r=t;t<0&&(r=-Math.abs(r));let i=r/y,a=e[0]*Math.PI/180,o=b(e[1]),s=b(n),c=i*Math.cos(s),l=o+c;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);let u=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(u)>1e-11?c/u:Math.cos(o),f=[(180*(a+i*Math.sin(s)/d)/Math.PI+540)%360-180,180*l/Math.PI];return f[0]+=f[0]-e[0]>180?-360:e[0]-f[0]>180?360:0,f}function ct(e,t,n,r,i){let a=r(e[0],e[1]),o=r(t[0],t[1]),{lng:s,lat:c}=i((a.x+o.x)/2,(a.y+o.y)/2);return[C(s,n),C(c,n)]}function lt(e,t,n){let r=st(e,1e3*v(e,t)/2,ot(e,t));return[C(r[0],n),C(r[1],n)]}function ut({featureCoords:e,precision:t,unproject:n,project:r,projection:i}){let a=[];for(let o=0;o{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a({mode:this.mode,midPointSegment:e,midPointFeatureId:t,[s.MID_POINT]:!0}),coordinates:r,type:s.MID_POINT})}delete(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._midPoints.length===0)return;let t=B(e),n=ut(this.getMidpointConfig(t));this.mutateFeature.updateGuidancePoints(this._midPoints.map((e,t)=>({featureId:e,coordinate:n[t]})))}updateOneAtIndex(e,t){if(e<0&&(e=this._midPoints.length+e),this._midPoints[e]===void 0)return;let n=B(t),r=ut(this.getMidpointConfig(n));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[e],coordinate:r[e]}])}},ft=class extends k{constructor(e,t){super(e),this.mutateFeature=void 0,this._selectionPoints=[],this.mutateFeature=t}get ids(){return this._selectionPoints.concat()}set ids(e){}create({featureId:e,featureCoordinates:t}){let n=Be(t);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:n,type:s.SELECTION_POINT,additionalProperties:t=>({[s.SELECTION_POINT_FEATURE_ID]:e,index:t})})}delete(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._selectionPoints.length===0)return;let t=Be(e);t.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map((e,n)=>({featureId:e,coordinate:t[n]})))}updateOneAtIndex(e,t){this._selectionPoints[e]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[e],coordinate:t}])}};function pt(e,t){let n=!1;for(let o=0,s=t.length;o(r=e)[1]!=(a=s[c])[1]>r[1]&&r[0]<(a[0]-i[0])*(r[1]-i[1])/(a[1]-i[1])+i[0]&&(n=!n)}var r,i,a;return n}var mt=(e,t,n)=>{let r=e=>e*e,i=(e,t)=>r(e.x-t.x)+r(e.y-t.y);return Math.sqrt(((e,t,n)=>{let r=i(t,n);if(r===0)return i(e,t);let a=((e.x-t.x)*(n.x-t.x)+(e.y-t.y)*(n.y-t.y))/r;return a=Math.max(0,Math.min(1,a)),i(e,{x:t.x+a*(n.x-t.x),y:t.y+a*(n.y-t.y)})})(e,t,n))},ht=class extends k{constructor(e,t,n){super(e),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=e,this.createClickBoundingBox=t,this.pixelDistance=n}find(e,t){let n,r,i,a=1/0,o=1/0,c=this.createClickBoundingBox.create(e),l=this.store.search(c);for(let c=0;c180||i<-180||a>90||a<-90)return!1;r[e]=[i,a]}t.type===`Polygon`&&(r[r.length-1]=[r[0][0],r[0][1]]);let o=this.draggedFeatureId,s=null;if(t.type===`Polygon`)s=this.mutateFeature.updatePolygon({featureId:o,coordinateMutations:{type:P,coordinates:[r]},context:{updateType:a.Provisional}});else{if(t.type!==`LineString`)return;s=this.mutateFeature.updateLineString({featureId:o,coordinateMutations:{type:P,coordinates:r},context:{updateType:a.Provisional}})}if(!s)return!1;let c=s.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:c}),this.selectionPoints.updateAllInPlace({featureCoordinates:c}),this.coordinatePoints.updateAllInPlace({featureId:o,featureCoordinates:c}),this.dragPosition=[e.lng,e.lat]}else t.type===`Point`&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:P,coordinates:n},context:{updateType:a.Provisional}}),this.dragPosition=[e.lng,e.lat])}},_t=class extends k{constructor(e,t,n,r,i,a,o,s,c){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.featureSnapping=void 0,this.draggedCoordinate={id:null,index:-1},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.coordinateSnapping=a,this.lineSnapping=o,this.readFeature=s,this.mutateFeature=c,this.featureSnapping=new Re(this.coordinateSnapping,this.lineSnapping)}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i!!(e.properties&&e.properties.mode===n.properties.mode&&e.id!==this.draggedCoordinate.id);if(t!=null&&t.toLine){let t;t=this.lineSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t.toCoordinate){let t;t=this.coordinateSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t!=null&&t.toFeature){let i=this.featureSnapping.getSnappable(e,n.id,t.toFeature.filter,{toLine:t.toFeature.toLine,toCoordinate:t.toFeature.toCoordinate});i.coordinate&&(r=i.coordinate)}if(t!=null&&t.toCustom){let i;i=t.toCustom(e,{currentCoordinate:this.draggedCoordinate.index,currentId:n.id,getCurrentGeometrySnapshot:n.id?()=>this.readFeature.getGeometry(n.id):()=>null,project:this.project,unproject:this.unproject}),i&&(r=i)}return r}drag(e,t,n){let r=this.draggedCoordinate.id;if(r===null)return!1;if(!1===this.readFeature.hasFeature(r))return this.stopDragging(),!1;let i=this.draggedCoordinate.index,o=this.readFeature.getGeometry(r),s=this.readFeature.getProperties(r),c=o.type===`LineString`?o.coordinates:o.coordinates[0],l=o.type===`Polygon`&&(i===c.length-1||i===0),u=this.snapCoordinate(e,n,{type:`Feature`,id:r,geometry:o,properties:s});if(e.lng>180||e.lng<-180||e.lat>90||e.lat<-90)return!1;if(l){let e=c.length-1;c[0]=u,c[e]=u}else c[i]=u;if(o.type!==`Point`&&!t&&ne({type:`Feature`,geometry:o,properties:{}}))return!1;let d=r,f=null;return o.type===`Polygon`?f=this.mutateFeature.updatePolygon({featureId:d,coordinateMutations:{type:P,coordinates:[c]},context:{updateType:a.Provisional}}):o.type===`LineString`&&(f=this.mutateFeature.updateLineString({featureId:d,coordinateMutations:{type:P,coordinates:c},context:{updateType:a.Provisional}})),!!f&&(this.midPoints.updateOneAtIndex(i>0?i-1:-1,c),this.midPoints.updateOneAtIndex(i,c),this.selectionPoints.updateOneAtIndex(i,u),this.coordinatePoints.updateOneAtIndex(d,i,u),!0)}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}};function vt(e){let t=0,n=0,r=0;return(e.geometry.type===`Polygon`?e.geometry.coordinates[0].slice(0,-1):e.geometry.coordinates).forEach(e=>{t+=e[0],n+=e[1],r++},!0),[t/r,n/r]}var yt=(e,t)=>{if(t===0||t===360||t===-360)return e;let n=.017453292519943295*t,r=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(([e,t])=>D(e,t)),i=r.reduce((e,t)=>({x:e.x+t.x,y:e.y+t.y}),{x:0,y:0});i.x/=r.length,i.y/=r.length;let a=r.map(e=>({x:i.x+(e.x-i.x)*Math.cos(n)-(e.y-i.y)*Math.sin(n),y:i.y+(e.x-i.x)*Math.sin(n)+(e.y-i.y)*Math.cos(n)})).map(({x:e,y:t})=>[O(e,t).lng,O(e,t).lat]);return e.geometry.type===`Polygon`?e.geometry.coordinates[0]=a:e.geometry.coordinates=a,e};function bt(e){let t=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(e=>{let{x:t,y:n}=D(e[0],e[1]);return[t,n]});return e.geometry.type===`Polygon`?function(e){let t=0,n=0,r=0,i=e.length;for(let a=0;a{let r=ot(n,e)+t,i=function(e,t){e[0]+=e[0]-t[0]>180?-360:t[0]-e[0]>180?360:0;let n=y,r=t[1]*Math.PI/180,i=e[1]*Math.PI/180,a=i-r,o=Math.abs(e[0]-t[0])*Math.PI/180;o>Math.PI&&(o-=2*Math.PI);let s=Math.log(Math.tan(i/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(s)>1e-11?a/s:Math.cos(r);return Math.sqrt(a*a+c*c*o*o)*n}(n,e),a=st(n,i,r);e[0]=a[0],e[1]=a[1]})})(o,-(this.lastBearing-(i+180)))}let s=n.type===`Polygon`?n.coordinates[0]:n.coordinates;s.forEach(e=>{e[0]=C(e[0],this.coordinatePrecision),e[1]=C(e[1],this.coordinatePrecision)});let c={featureId:t,coordinateMutations:{type:P,coordinates:n.type===`Polygon`?[s]:s},context:{updateType:a.Provisional}},l=null;if(o.geometry.type===`Polygon`)l=this.mutateFeature.updatePolygon(c);else{if(o.geometry.type!==`LineString`)return;l=this.mutateFeature.updateLineString(c)}if(!l)return!1;let u=l.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:u}),this.selectionPoints.updateAllInPlace({featureCoordinates:u}),this.coordinatePoints.updateAllInPlace({featureId:t,featureCoordinates:u}),this.projection===`web-mercator`?this.lastBearing=i:this.projection===`globe`&&(this.lastBearing=i+180)}},St=class extends k{constructor(e,t){super(e),this.config=void 0,this.dragCoordinateResizeBehavior=void 0,this.config=e,this.dragCoordinateResizeBehavior=t}scale(e,t){if(!this.dragCoordinateResizeBehavior.isDragging()){let n=this.dragCoordinateResizeBehavior.getDraggableIndex(e,t);this.dragCoordinateResizeBehavior.startDragging(t,n)}this.dragCoordinateResizeBehavior.drag(e,`center-fixed`)}reset(){this.dragCoordinateResizeBehavior.stopDragging()}};function Ct({coordinates:e,originX:t,originY:n,xScale:r,yScale:i}){r===1&&i===1||e.forEach(e=>{let{x:a,y:o}=D(e[0],e[1]),{lng:s,lat:c}=O(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}var wt=class extends k{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i=0)return!1;break;case 1:if(n>=0)return!1;break;case 2:if(t>=0||n>=0)return!1;break;case 3:if(t>=0)return!1;break;case 4:if(t>=0||n<=0)return!1;break;case 5:if(n<=0)return!1;break;case 6:if(t<=0||n<=0)return!1;break;case 7:if(t<=0)return!1}return!0}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||this.draggedCoordinate.index===-1)return null;let e=this.getFeature(this.draggedCoordinate.id);if(!e)return null;let t=this.getNormalisedCoordinates(e.geometry);return{boundingBox:this.getBBoxWebMercator(t),feature:e,updatedCoords:t,selectedCoordinate:t[this.draggedCoordinate.index]}}centerWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=bt(n);if(!o)return null;let s=D(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=D(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}centerFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=bt(n);if(!o)return null;let s=D(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=D(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}scaleFixedWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){if(!this.isValidDragWebMercator(e,t.x-r.x,t.y-r.y))return null;let a=I(t,r)/I(t,n);return a<0&&(a=this.minimumScale),Ct({coordinates:i,originX:t.x,originY:t.y,xScale:a,yScale:a}),i}oppositeFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=D(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=D(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}oppositeWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=D(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=D(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}scaleWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){let a=t.x-r.x,o=t.y-r.y;if(!this.isValidDragWebMercator(e,a,o))return null;let s=1;a!==0&&e!==1&&e!==5&&(s=1-(t.x-n.x-a)/a);let c=1;return o!==0&&e!==3&&e!==7&&(c=1-(t.y-n.y-o)/o),this.validateScale(s,c)?(s<0&&(s=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(i,t.x,t.y,s,c),i):null}getFeature(e){if(this.draggedCoordinate.id===null)return null;let t=this.readFeature.getGeometry(e);return t.type!==`Polygon`&&t.type!==`LineString`?null:{id:e,type:`Feature`,geometry:t,properties:{}}}getNormalisedCoordinates(e){return e.type===`Polygon`?e.coordinates[0]:e.coordinates}validateScale(e,t){return!isNaN(e)&&t<2**53-1&&!isNaN(t)&&t<2**53-1}performWebMercatorScale(e,t,n,r,i){e.forEach(e=>{let{x:a,y:o}=D(e[0],e[1]),{lng:s,lat:c}=O(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}getBBoxWebMercator(e){let t=[1/0,1/0,-1/0,-1/0];(e=e.map(e=>{let{x:t,y:n}=D(e[0],e[1]);return[t,n]})).forEach(([e,n])=>{et[2]&&(t[2]=e),n>t[3]&&(t[3]=n)});let[n,r,i,a]=t;return[[n,a],[(n+i)/2,a],[i,a],[i,a+(r-a)/2],[i,r],[(n+i)/2,r],[n,r],[n,a+(r-a)/2]]}getIndexesWebMercator(e,t){let n,r=1/0;for(let i=0;i{let n=e.properties.mode;return this.validations&&this.validations[n]?this.validations[n](e,t):{valid:!0}}}),this.pixelDistance=new Ce(e),this.clickBoundingBox=new Se(e),this.featuresAtMouseEvent=new ht(e,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new ft(e,this.mutateFeature),this.coordinatePoints=new He(e,this.readFeature,this.mutateFeature),this.midPoints=new dt(e,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new we(e,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new Le(e,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new xt(e,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new gt(e,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new _t(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new wt(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new St(e,this.dragCoordinateResizeFeature)}deselectFeature(e){this.deselect(e)}deselect(e){this.selected.includes(e)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:`none`})}deleteSelected(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:`none`}}clearDragTargetAndCursor(){this.dragTarget={type:`none`},this.setCursor(`unset`)}getSelectedFlags(e){let t=this.readFeature.getProperties(e),n=this.flags[t.mode]?.feature,r=n?.coordinates;return{featureFlags:n,coordinatesFlags:r,hasDraggableFlags:n&&(n.draggable||r?.draggable||r?.resizable||typeof r?.midpoints==`object`&&r.midpoints.draggable)}}onRightClick(e){if(!this.selectionPoints.ids.length)return;let t,n=1/0;if(this.selectionPoints.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a0),n=this.midPoints.getNearestMidPoint(e),r=this.selected[0];if(r){var a;let{featureFlags:t}=this.getSelectedFlags(r);if(t!=null&&(a=t.coordinates)!=null&&a.midpoints&&n){if(t.coordinates.draggable){let t=this.pixelDistance.measure(e,this.readFeature.getGeometry(n).coordinates),{dist:i}=this.dragCoordinate.getDraggable(e,r);if(i!==void 0&&t>i)return}this.midPoints.insert({featureId:r,midPointId:n}),this.onFinish(this.selected[0],{action:i,mode:this.mode});return}}if(t!=null&&t.id)this.allowManualSelection&&this.select(t.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}canScale(e){return this.keyEvents.scale&&this.keyEvents.scale.every(t=>e.heldKeys.includes(t))}canRotate(e){return this.keyEvents.rotate&&this.keyEvents.rotate.every(t=>e.heldKeys.includes(t))}preventDefaultKeyEvent(e){let t=this.canRotate(e),n=this.canScale(e);(t||n)&&e.preventDefault()}onKeyDown(e){this.preventDefaultKeyEvent(e)}onKeyUp(e){if(this.preventDefaultKeyEvent(e),this.keyEvents.delete&&e.key===this.keyEvents.delete){if(!this.selected.length)return;let e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&e.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect(this.selected[0])}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e))return;let n=this.selected[0];if(!n)return;let{featureFlags:r,coordinatesFlags:a,hasDraggableFlags:o}=this.getSelectedFlags(n);if(!o)return;this.dragEventCount=0;let s=this.dragTarget.type!==`none`&&this.dragTarget.featureId===n?this.dragTarget:{type:`none`},c=s.type===`coordinate`?s.coordinateIndex:this.dragCoordinate.getDraggableIndex(e,n),l=s.type===`resize`?s.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(e,n),u=a?.resizable&&l!==-1,d=a?.draggable&&c!==-1,f=a&&typeof a.midpoints==`object`&&a.midpoints.draggable,p=r?.draggable&&(s.type===`feature`||this.dragFeature.canDrag(e,n));if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(n,l),void t(!1);if(d)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(n,c),void t(!1);if(f){let r=s.type===`midpoint`?s.midPointId:this.midPoints.getNearestMidPoint(e);if(this.selected.length&&r){this.midPoints.insert({featureId:n,midPointId:r}),this.onFinish(this.selected[0],{action:i,mode:this.mode});let a=this.dragCoordinate.getDraggableIndex(e,n);this.dragCoordinate.startDragging(n,a),t(!1);return}}if(p)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(e,n),void t(!1);this.setCursor(`unset`)}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e))return;let n=this.selected[0];if(!n)return;let r=this.readFeature.getProperties(n),i=this.flags[r.mode],a=!0===(i&&i.feature&&i.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(i&&i.feature&&i.feature.rotateable&&this.canRotate(e))return t(!1),void this.rotateFeature.rotate(e,n);if(i&&i.feature&&i.feature.scaleable&&this.canScale(e))return t(!1),void this.scaleFeature.scale(e,n);if(this.dragCoordinateResizeFeature.isDragging()&&i.feature&&i.feature.coordinates&&i.feature.coordinates.resizable){if(this.projection===`globe`)throw Error(`Globe is currently unsupported projection for resizable`);t(!1),this.dragCoordinateResizeFeature.drag(e,i.feature.coordinates.resizable);return}if(this.dragCoordinate.isDragging()){var o;let t=(o=i.feature)==null||(o=o.coordinates)==null?void 0:o.snappable,n={toCoordinate:!1};!0===t?n={toCoordinate:!0}:typeof t==`object`&&(n=t),this.dragCoordinate.drag(e,a,n);return}this.dragFeature.isDragging()?this.dragFeature.drag(e):t(!0)}}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:`dragCoordinate`}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:`dragFeature`}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:`dragCoordinateResize`}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),t(!0))}onMouseMove(e){let t=this.selected[0];if(!t)return void this.clearDragTargetAndCursor();if(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())return;let{featureFlags:n}=this.getSelectedFlags(t);if(!n)return void this.clearDragTargetAndCursor();let r,i=n.coordinates;if(i!=null&&i.midpoints&&(r=this.midPoints.getNearestMidPoint(e),r&&(this.dragTarget={type:`midpoint`,featureId:t,midPointId:r},this.setCursor(this.cursors.insertMidpoint))),i&&i.draggable){let{index:n,dist:i}=this.dragCoordinate.getDraggable(e,t);if(n>-1){if(r&&this.pixelDistance.measure(e,this.readFeature.getGeometry(r).coordinates)-1)return this.dragTarget={type:`resize`,featureId:t,coordinateIndex:n},void this.setCursor(this.getPointerOverResizeHandleCursor())}if(n.draggable&&this.dragFeature.canDrag(e,t)){if(r)return;this.dragTarget={type:`feature`,featureId:t},this.setCursor(this.getPointerOverFeatureCursor());return}r||this.clearDragTargetAndCursor()}styleFeature(t){let n=e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0});if(t.properties.mode===this.mode&&t.geometry.type===`Point`){if(t.properties[s.SELECTION_POINT])return n.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,n.pointColor,t),n.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,t),n.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,n.pointOutlineColor,t),n.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,n.pointWidth,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,t),n.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),n.zIndex=30,n;if(t.properties[s.MID_POINT])return n.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,n.pointColor,t),n.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,t),n.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,n.pointOutlineColor,t),n.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,t),n.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),n.zIndex=50,n}else if(t.properties[s.SELECTED]){if(t.geometry.type===`Point`&&t.properties[c.MARKER])return n.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,o,t),n.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),n.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),n;if(t.geometry.type===`Polygon`)return n.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,n.polygonFillColor,t),n.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,n.polygonOutlineWidth,t),n.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,n.polygonOutlineColor,t),n.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,t),n.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,n.polygonFillOpacity,t),n.zIndex=l,n;if(t.geometry.type===`LineString`)return n.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,n.lineStringColor,t),n.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,n.lineStringWidth,t),n.lineStringOpacity=this.getNumericStylingValue(this.styles.selectedLineStringOpacity,1,t),n.lineStringDash=this.getDashArrayStylingValue(this.styles.selectedLineStringDash,void 0,t),n.zIndex=l,n;if(t.geometry.type===`Point`)return n.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,n.pointWidth,t),n.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,n.pointColor,t),n.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,t),n.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,n.pointOutlineColor,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,t),n.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,n.pointOutlineWidth,t),n.zIndex=l,n}return n}afterFeatureUpdated(e){if(this.selected.length&&e.id===this.selected[0]){var t,n;let r=this.flags[e.properties.mode];if(r==null||(t=r.feature)==null||!t.coordinates)return;let i=e.geometry.type,a=e.id;if(this.selectionPoints.delete(),this.midPoints.delete(),i!==`LineString`&&i!==`Polygon`)return;let o=e.geometry.coordinates;this.selectionPoints.create({featureCoordinates:o,featureId:a}),r!=null&&(n=r.feature)!=null&&(n=n.coordinates)!=null&&n.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:a})}}},Ot=class extends g{constructor(...e){super(...e),this.type=m.Static,this.mode=`static`}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return e({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0})}};function kt(e,t,n,r,i){for(;r>n;){if(r-n>600){let a=r-n+1,o=t-n+1,s=Math.log(a),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(a-c)/a)*(o-a/2<0?-1:1);kt(e,t,Math.max(n,Math.floor(t-o*c/a+l)),Math.min(r,Math.floor(t+(a-o)*c/a+l)),i)}let a=e[t],o=n,s=r;for(V(e,n,t),i(e[r],a)>0&&V(e,n,r);o0;)s--}i(e[n],a)===0?V(e,n,s):(s++,V(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}}function V(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function H(e,t){U(e,0,e.children.length,t,e)}function U(e,t,n,r,i){i||=G([]),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let a=t;a=e.minX&&t.maxY>=e.minY}function G(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Lt(e,t,n,r,i){let a=[t,n];for(;a.length;){if((n=a.pop())-(t=a.pop())<=r)continue;let o=t+Math.ceil((n-t)/r/2)*r;kt(e,o,t,n,i),a.push(t,o,o,n)}}var Rt=class{constructor(e){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(e){let t=this.data,n=[];if(!It(e,t))return n;let r=this.toBBox,i=[];for(;t;){for(let a=0;a=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)}_split(e,t){let n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);let a=this._chooseSplitIndex(n,i,r),o=G(n.children.splice(a,n.children.length-a));o.height=n.height,o.leaf=n.leaf,H(n,this.toBBox),H(o,this.toBBox),t?e[t-1].children.push(o):this._splitRoot(n,o)}_splitRoot(e,t){this.data=G([e,t]),this.data.height=e.height+1,this.data.leaf=!1,H(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,i=1/0,a=1/0;for(let o=t;o<=n-t;o++){let t=U(e,0,o,this.toBBox),s=U(e,o,n,this.toBBox),c=Pt(t,s),l=Mt(t)+Mt(s);c=t;r--){let t=e.children[r];W(o,e.leaf?i(t):t),s+=Nt(o)}return s}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)W(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)e[n].children.length===0?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():H(e[n],this.toBBox)}},zt=class{constructor(e){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Rt(e&&e.maxEntries?e.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(e,t){this.idToNode.set(e.id,t),this.nodeToId.set(t,e.id)}toBBox(e){let t=[],n=[],r;if(e.geometry.type===`Polygon`)r=e.geometry.coordinates[0];else if(e.geometry.type===`LineString`)r=e.geometry.coordinates;else{if(e.geometry.type!==`Point`)throw Error(`Not a valid feature to turn into a bounding box`);r=[e.geometry.coordinates]}for(let e=0;e{let r=this.toBBox(e);if(this.setMaps(e,r),n.has(String(e.id)))throw Error(`Duplicate feature ID found ${e.id}`);n.add(String(e.id)),t.push(r)}),this.tree.load(t)}update(e){this.remove(e.id);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}remove(e){let t=this.idToNode.get(e);if(!t)throw Error(`${e} not inserted into the spatial index`);this.tree.remove(t)}clear(){this.tree.clear()}search(e){return this.tree.search(this.toBBox(e)).map(e=>this.nodeToId.get(e))}collides(e){return this.tree.collides(this.toBBox(e))}},Bt={getId:()=>`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){let t=16*Math.random()|0;return(e==`x`?t:3&t|8).toString(16)}),isValidId:e=>typeof e==`string`&&e.length===36},Vt={target:`geometry`},Ht={target:`properties`},Ut=class{constructor(e){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new zt,this.tracked=!e||!1!==e.tracked,this.idStrategy=e&&e.idStrategy?e.idStrategy:Bt}clone(e){return JSON.parse(JSON.stringify(e))}getId(){return this.idStrategy.getId()}has(e){return!!this.store[e]}load(e,t,n,r){if(e.length===0)return[];let i=this.clone(e),a=[],o=[];i=i.filter(e=>{e.id??=this.idStrategy.getId();let n=e.id;if(t){let r=t(e);if(!r.valid)return a.push({id:n,valid:!1,reason:r.reason}),!1}if(this.tracked){if(e.properties.createdAt){if(!f(e.properties.createdAt))return a.push({id:e.id,valid:!1,reason:`createdAt is not a valid numeric timestamp`}),!1}else e.properties.createdAt=+new Date;if(e.properties.updatedAt){if(!f(e.properties.updatedAt))return a.push({id:e.id,valid:!1,reason:`updatedAt is not a valid numeric timestamp`}),!1}else e.properties.updatedAt=+new Date}return this.has(n)?(a.push({id:n,valid:!1,reason:`Feature already exists with this id: ${n}`}),!1):(this.store[n]=e,o.push(e),a.push({id:n,valid:!0}),!0)}),this.spatialIndex.load(i);let s=o.map(({id:e})=>e);return s.length>0&&(this._onChange(s,`create`,r),n&&o.forEach(e=>{n(e)})),a}search(e,t){let n=this.spatialIndex.search(e).map(e=>this.store[e]);return this.clone(t?n.filter(t):n)}registerOnChange(e){this._onChange=(t,n,r)=>{e(t,n,r)}}getGeometryCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get geometry copy`);return this.clone(t.geometry)}getPropertiesCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get properties copy`);return this.clone(t.properties)}updateProperty(t,n){let r=new Set;t.forEach(({id:e,property:t,value:n})=>{let i=this.store[e];if(!i)throw Error(`No feature with this (${e}), can not update geometry`);i.properties[t]!==n&&(r.add(e),n===void 0?delete i.properties[t]:i.properties[t]=n,this.tracked&&(i.properties.updatedAt=+new Date))}),this._onChange&&r.size>0&&this._onChange(Array.from(r),`update`,n?e({},n,Ht):Ht)}updateGeometry(t,n){let r=new Set;t.forEach(({id:e,geometry:t})=>{r.add(e);let n=this.store[e];if(!n)throw Error(`No feature with this (${e}), can not update geometry`);n.geometry=this.clone(t),this.spatialIndex.update(n),this.tracked&&(n.properties.updatedAt=+new Date)}),this._onChange&&r.size>0&&this._onChange(Array.from(r),`update`,n?e({},n,Vt):Vt)}create(t,n){let r=[];return t.forEach(({geometry:t,properties:n})=>{let i,a=e({},n);this.tracked&&(i=+new Date,n?(a.createdAt=typeof n.createdAt==`number`?n.createdAt:i,a.updatedAt=typeof n.updatedAt==`number`?n.updatedAt:i):a={createdAt:i,updatedAt:i});let o=this.getId(),s={id:o,type:`Feature`,geometry:t,properties:a};this.store[o]=s,this.spatialIndex.insert(s),r.push(o)}),this._onChange&&this._onChange([...r],`create`,n),r}delete(e,t){e.forEach(e=>{if(!this.store[e])throw Error(`No feature with id ${e}, can not delete`);delete this.store[e],this.spatialIndex.remove(e)}),this._onChange&&this._onChange([...e],`delete`,t)}copy(e){return this.clone(this.store[e])}copyAll(){return this.clone(Object.keys(this.store).map(e=>this.store[e]))}copyAllWhere(e){return this.clone(Object.keys(this.store).map(e=>this.store[e]).filter(t=>t.properties&&e(t.properties)))}clear(e){let t=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(t,`delete`,e)}size(){return Object.keys(this.store).length}};Math.PI/180;var K=class{constructor({name:e,callback:t,unregister:n,register:r}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=e,this.register=()=>{this.registered||(this.registered=!0,r(t))},this.unregister=()=>{this.register&&(this.registered=!1,n(t))},this.callback=t}},Wt={__proto__:null,GeoJSONStore:Ut,TerraDrawBaseDrawMode:g,TerraDrawBaseSelectMode:_,TerraDrawBaseAdapter:class{constructor(e){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,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._ignoreMismatchedPointerEvents=typeof e.ignoreMismatchedPointerEvents==`boolean`&&e.ignoreMismatchedPointerEvents,this._minPixelDragDistance=typeof e.minPixelDragDistance==`number`?e.minPixelDragDistance:1,this._minPixelDragDistanceSelecting=typeof e.minPixelDragDistanceSelecting==`number`?e.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing=typeof e.minPixelDragDistanceDrawing==`number`?e.minPixelDragDistanceDrawing:8,this._coordinatePrecision=typeof e.coordinatePrecision==`number`?e.coordinatePrecision:9}getButton(e){return e.button===-1?`neither`:e.button===0?`left`:e.button===1?`middle`:e.button===2?`right`:`neither`}getMapElementXYPosition(e){let{left:t,top:n}=this.getMapEventElement(e.type).getBoundingClientRect();return{containerX:e.clientX-t,containerY:e.clientY-n}}getDrawEventFromEvent(e,t=!1){let n=this.getLngLatFromEvent(e);if(!n)return null;let{lng:r,lat:i}=n,{containerX:a,containerY:o}=this.getMapElementXYPosition(e),s=this.getButton(e),c=Array.from(this._heldKeys);return{lng:C(r,this._coordinatePrecision),lat:C(i,this._coordinatePrecision),containerX:a,containerY:o,button:s,heldKeys:c,isContextMenu:t}}register(e){this._currentModeCallbacks=e,this._listeners=this.getAdapterListeners(),this._listeners.forEach(e=>{e.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new K({name:`pointerdown`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState=`pre-dragging`,this._lastDrawEvent=t,this._lastPointerDownEventTarget=e.target?e.target:void 0)},register:e=>{this.getMapEventElement(`pointerdown`).addEventListener(`pointerdown`,e)},unregister:e=>{this.getMapEventElement(`pointerdown`).removeEventListener(`pointerdown`,e)}}),new K({name:`pointermove`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;e.preventDefault();let t=this.getDrawEventFromEvent(e);if(t){if(this._dragState===`not-dragging`)this._currentModeCallbacks.onMouseMove(t),this._lastDrawEvent=t;else if(this._dragState===`pre-dragging`){if(!this._lastDrawEvent)return;let e={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},n={x:t.containerX,y:t.containerY},r=this._currentModeCallbacks.getState(),i=I(e,n),a=!1;if(a=r===`drawing`?i{this.setDraggability.bind(this)(e)})}else this._dragState===`dragging`&&this._currentModeCallbacks.onDrag(t,e=>{this.setDraggability.bind(this)(e)})}},register:e=>{this.getMapEventElement(`pointermove`).addEventListener(`pointermove`,e)},unregister:e=>{this.getMapEventElement(`pointermove`).removeEventListener(`pointermove`,e)}}),new K({name:`contextmenu`,callback:e=>{this._currentModeCallbacks&&(e.preventDefault(),this._nextKeyUpIsContextMenu=!0)},register:e=>{this.getMapEventElement(`contextmenu`).addEventListener(`contextmenu`,e)},unregister:e=>{this.getMapEventElement(`contextmenu`).removeEventListener(`contextmenu`,e)}}),new K({name:`pointerup`,callback:e=>{if(!this._currentModeCallbacks||e.target!==this.getMapEventElement(`pointerup`)||this._ignoreMismatchedPointerEvents&&this._lastPointerDownEventTarget!==e.target||(this._lastPointerDownEventTarget=void 0,!e.isPrimary))return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState===`dragging`?this._currentModeCallbacks.onDragEnd(t,e=>{this.setDraggability.bind(this)(e)}):this._dragState!==`not-dragging`&&this._dragState!==`pre-dragging`||(this._nextKeyUpIsContextMenu&&=(t.isContextMenu=!0,!1),this._currentModeCallbacks.onClick(t)),this._dragState=`not-dragging`,this.setDraggability(!0))},register:e=>{this.getMapEventElement(`pointerup`).addEventListener(`pointerup`,e)},unregister:e=>{this.getMapEventElement(`pointerup`).removeEventListener(`pointerup`,e)}}),new K({name:`keyup`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.delete(e.key),this._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keyup`).addEventListener(`keyup`,e)},unregister:e=>{this.getMapEventElement(`keyup`).removeEventListener(`keyup`,e)}}),new K({name:`keydown`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.add(e.key),this._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keydown`).addEventListener(`keydown`,e)},unregister:e=>{this.getMapEventElement(`keydown`).removeEventListener(`keydown`,e)}})]}unregister(){this._listeners.forEach(e=>{e.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1}},getDefaultStyling:()=>({polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0,lineStringDash:void 0}),SELECT_PROPERTIES:s};function Gt(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return!0;if(e===void 0)return!1;if(typeof e==`number`)return Number.isFinite(e);if(typeof e==`bigint`||typeof e==`symbol`||typeof e==`function`||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Date)return!1;if(typeof e==`object`&&e&&!Array.isArray(e)){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return!1}if(ArrayBuffer.isView(e)&&!(e instanceof DataView))return!1;if(Array.isArray(e)){for(let t of e)if(!Gt(t))return!1}return typeof e==`object`&&Object.keys(e).every(t=>typeof t==`string`&&Gt(e[t]))}var Kt=`push`,q=`mode`,qt=`session`,Jt=class{constructor(e){this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=e.modeLevel,this.sessionLevel=e.sessionLevel,this.shouldPreferMode=e.shouldPreferMode,this.onHistoryChange=e.onHistoryChange,this.shouldEmitHistoryChange=e.shouldEmitHistoryChange??(()=>!0)}emitStackHistoryChange(e){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:e.cause,stack:e.stack,undoSize:e.undoStackSize,redoSize:e.redoStackSize})}hasSessionUndo(){return!!(this.sessionLevel&&this.sessionLevel.canUndo())}hasSessionRedo(){return!!(this.sessionLevel&&this.sessionLevel.canRedo())}activeStackForUndo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canUndo()?q:this.hasSessionUndo()?qt:(t=this.modeLevel)!=null&&t.canUndo()?q:void 0}activeStackForRedo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canRedo()?q:this.hasSessionRedo()?qt:(t=this.modeLevel)!=null&&t.canRedo()?q:void 0}canUndo(){return this.activeStackForUndo()!==void 0}canRedo(){return this.activeStackForRedo()!==void 0}undo(){let e=this.activeStackForUndo();return!!e&&(e===q?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){let e=this.activeStackForRedo();return!!e&&(e===q?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())}clearHistory(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()}emitHistoryPushForCompletedAction(){this.sessionLevel?this.emitStackHistoryChange({cause:Kt,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:qt}):this.modeLevel&&this.emitStackHistoryChange({cause:Kt,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:q})}},Yt=class{constructor(t){var n,r,i,a;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=t.adapter,this._instanceSelectModes=[];let o=t==null||(n=t.undoRedo)==null?void 0:n.modeLevel;o&&(this.drawingUndoRedo=o);let s=t==null||(r=t.undoRedo)==null?void 0:r.keyboardShortcuts;s&&(this.keyboardShortcutsMatcher=s),this.sessionUndoRedoEnabled=!!(t!=null&&(i=t.undoRedo)!=null&&i.sessionLevel);let c=t==null||(a=t.undoRedo)==null?void 0:a.sessionLevel;this._mode=new Ot;let l=new Set,u=t.modes.reduce((e,t)=>{if(l.has(t.mode))throw Error(`There is already a ${t.mode} mode provided`);return l.add(t.mode),e[t.mode]=t,e},{}),d=Object.keys(u);if(d.length===0)throw Error(`No modes provided`);d.forEach(e=>{u[e].type===m.Select&&this._instanceSelectModes.push(e)}),this._modes=e({},u,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new Ut({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});let f=e=>{let t=[];return{changed:t,unchanged:this._store.copyAll().filter(n=>!e.includes(n.id)||(t.push(n),!1))}},p=(e,t)=>{var n;this._enabled&&(this._eventListeners.finish.forEach(n=>{n(e,t)}),(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction())},h=(e,t,n)=>{if(!this._enabled)return;this._eventListeners.change.forEach(r=>{r(e,t,n)}),this.emitDrawingPushIfHistoryChangedFromLastSnapshot();let{changed:r,unchanged:i}=f(e);t===`create`?this._adapter.render({created:r,deletedIds:[],unchanged:i,updated:[]},this.getModeStyles()):t===`update`?this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:r},this.getModeStyles()):t===`delete`?this._adapter.render({created:[],deletedIds:e,unchanged:i,updated:[]},this.getModeStyles()):t===`styling`&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:[]},this.getModeStyles())},g=e=>{if(!this._enabled)return;this._eventListeners.select.forEach(t=>{t(e)});let{changed:t,unchanged:n}=f([e]);this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())},_=e=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t(e)});let{changed:t,unchanged:n}=f([e]);t&&this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())};Object.keys(this._modes).forEach(e=>{var t;this._modes[e].register({mode:e,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:h,onSelect:g,onDeselect:_,onFinish:p,coordinatePrecision:this._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:(t=this.drawingUndoRedo)==null||t.getMaxStackSize==null?void 0:t.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&c&&(this.sessionUndoRedo=c,c.register({draw:this,onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:()=>this.getModeState(),getModeHistorySizes:()=>this.getDrawingHistorySizes(),undoMode:()=>{this._mode.undo&&this._mode.undo()},redoMode:()=>{this._mode.redo&&this._mode.redo()},clearModeHistory:()=>{let e=this._mode;e.clearHistory&&e.clearHistory()},onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}}),this.undoRedoCoordinator=new Jt({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:()=>this.getModeState()===`drawing`,onHistoryChange:e=>{this._eventListeners.history.forEach(t=>{t(e)})},shouldEmitHistoryChange:()=>this._enabled})}checkEnabled(){if(!this._enabled)throw Error(`Terra Draw is not enabled`)}handleUndoRedoKeyboardShortcut(e){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled||!this.keyboardShortcutsMatcher)return!1;let t=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(e),n=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(e);if(t){if(!this.canUndo())return!1;let t=this.undo();return t&&e.preventDefault(),t}if(n){if(!this.canRedo())return!1;let t=this.redo();return t&&e.preventDefault(),t}return!1}getDrawingHistorySizes(){return{undoSize:this._mode.undoSize&&typeof this._mode.undoSize==`function`?this._mode.undoSize():0,redoSize:this._mode.redoSize&&typeof this._mode.redoSize==`function`?this._mode.redoSize():0}}emitDrawingPushIfHistoryChangedFromLastSnapshot(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()}emitDrawingPushIfHistoryChanged(e){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(e)}getModeStyles(){let e={},t=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(n=>{e[n]=e=>t&&e.properties[s.SELECTED]?this._modes[t].styleFeature.bind(this._modes[t])(e):this._modes[n].styleFeature.bind(this._modes[n])(e)}),e}featuresAtLocation({lng:e,lat:t},n){let r=n&&n.pointerDistance!==void 0?n.pointerDistance:30,i=!n||n.ignoreSelectFeatures===void 0||n.ignoreSelectFeatures,a=!(!n||n.ignoreCoordinatePoints===void 0)&&n.ignoreCoordinatePoints,o=!(!n||n.ignoreCurrentlyDrawing===void 0)&&n.ignoreCurrentlyDrawing,l=!(!n||n.ignoreClosingPoints===void 0)&&n.ignoreClosingPoints,u=!(!n||n.ignoreSnappingPoints===void 0)&&n.ignoreSnappingPoints,d=this._adapter.unproject.bind(this._adapter),f=this._adapter.project.bind(this._adapter),p=f(e,t),m=xe({unproject:d,point:p,pointerDistance:r});return this._store.search(m).filter(d=>{if(i&&(d.properties[s.MID_POINT]||d.properties[s.SELECTION_POINT])||a&&d.properties[c.COORDINATE_POINT]||l&&d.properties[c.CLOSING_POINT]||o&&d.properties[c.CURRENTLY_DRAWING]||u&&d.properties[c.SNAPPING_POINT])return!1;if(d.geometry.type===`Point`){let e=d.geometry.coordinates,t=f(e[0],e[1]);return I(p,t){if(n==null||!n.addClosestCoordinateInfoToProperties)return r;let i;if(r.geometry.type===`Polygon`)i=r.geometry.coordinates[0].slice(0,-1);else{if(r.geometry.type!==`LineString`)return r;i=r.geometry.coordinates}let a,o=-1,s=1/0;for(let e=0;e{if(!this._store.has(e))throw Error(`No feature with id ${e}, can not delete`);let i=this._store.getPropertiesCopy(e);i[s.SELECTED]&&this.deselectFeature(e),i[c.CURRENTLY_DRAWING]&&this._modes[i.mode]?r=i.mode:(i[c.COORDINATE_POINT_IDS]&&t.push(...i[c.COORDINATE_POINT_IDS]),n.push(e))}),this._store.delete([...n,...t],{origin:`api`}),r&&this._modes[r]&&this._modes[r].cleanUp()&&this._modes[r].cleanUp()}selectFeature(e,t){this.getSelectModeOrThrow(t).selectFeature(e)}deselectFeature(e){this.getSelectModeOrThrow().deselectFeature(e)}getFeatureId(){return this._store.getId()}hasFeature(e){return this._store.has(e)}checkIsReservedProperty(e){return![...Object.values(s),...Object.values(c)].includes(e)}updateFeatureProperties(e,t){var n;if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let r=this._store.copy(e);if(this.isGuidanceFeature(r))throw Error(`Guidance features are not allowed to be updated directly.`);let i=r.properties.mode;if(!this._modes[i])throw Error(`No mode with name ${i} present in instance`);let a=Object.entries(t);a.forEach(([e,t])=>{if(!this.checkIsReservedProperty(e))throw Error(`You are trying to update a reserved property name: ${e}. Please choose another name.`);if(t!==void 0&&!Gt(t))throw Error(`Invalid JSON value provided for property ${e}`)}),this._store.updateProperty(a.map(([e,t])=>({id:r.id,property:e,value:t})),{origin:`api`}),(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction()}updateFeatureGeometry(t,n){var r;if(!this._store.has(t))throw Error(`No feature with id ${t} present in store`);let i=this._store.copy(t);if(this.isGuidanceFeature(i))throw Error(`Guidance features are not allowed to be updated directly.`);if(!(i&&n&&n.type&&n.coordinates))throw Error(`Invalid geometry provided`);if(n.type!==i.geometry.type)throw Error(`Geometry type mismatch: expected ${i.geometry.type}, got ${n.type}`);let a=i.properties.mode,o=this._modes[a];if(!o)throw Error(`No mode with name ${a} present in instance`);let c=e({},i,{geometry:n}),l=o.validateFeature(c);if(!l.valid)throw Error(`Feature validation failed: ${l.reason||`Unknown reason`}`);if(this._store.updateGeometry([{id:i.id,geometry:n}],{origin:`api`}),o.afterFeatureUpdated){o.afterFeatureUpdated(c);let e=c.properties[s.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(c)}(r=this.undoRedoCoordinator)==null||r.emitHistoryPushForCompletedAction()}transformFeatureGeometry(e,t){var n;if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let r=this._store.copy(e);if(this.isGuidanceFeature(r))throw Error(`Guidance features are not allowed to be updated directly.`);let i=r.properties.mode,a=this._modes[i];if(!a)throw Error(`No mode with name ${i} present in instance`);let o;if(r.geometry.type===`Polygon`)o=r.geometry.coordinates[0];else{if(r.geometry.type!==`LineString`)throw Error(`Feature geometry type ${r.geometry.type} is not supported for transformation`);o=r.geometry.coordinates}if(t.projection!=`web-mercator`)throw Error(`Projection ${t.projection} is not currently supported for transformation`);if(t.type===`scale`){let{x:e,y:n}=D(t.origin[0],t.origin[1]);Ct({coordinates:o,originX:e,originY:n,xScale:t.options.xScale||1,yScale:t.options.yScale||1})}else t.type===`rotate`&&(r=yt(r,t.options.angle||0),o=r.geometry.type===`Polygon`?r.geometry.coordinates[0]:r.geometry.coordinates);if(o=o.map(e=>[C(e[0],this._adapter.getCoordinatePrecision()),C(e[1],this._adapter.getCoordinatePrecision())]),r.geometry.coordinates=r.geometry.type===`Polygon`?[o]:o,this._store.updateGeometry([{id:r.id,geometry:r.geometry}],{origin:`api`}),a.afterFeatureUpdated){a.afterFeatureUpdated(r);let e=r.properties[s.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(r)}(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction()}undo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()}canUndo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()}canRedo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()}redo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()}clearUndoRedoHistory(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()}addFeatures(e){return this.checkEnabled(),e.length===0?[]:this._store.load(e,e=>{if(d(e)){let t=e.properties.mode,n=this._modes[t];if(!n)return{id:e.id,valid:!1,reason:`${t} mode is not in the list of instantiated modes`};let r=n.validateFeature.bind(n)(e);return{id:e.id,valid:r.valid,reason:r.reason?r.reason:r.valid?void 0:`Feature is invalid`}}return{id:e.id,valid:!1,reason:`Mode property does not exist`}},e=>{if(d(e)){let t=this._modes[e.properties.mode];t&&t.afterFeatureAdded&&t.afterFeatureAdded(e)}},{origin:`api`})}start(){this._enabled||(this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(e=>{e()})},getState:()=>this._mode.state,onClick:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onClick(e),this.emitDrawingPushIfHistoryChanged(t)},onMouseMove:e=>{this._mode.onMouseMove(e)},onKeyDown:e=>{this.handleUndoRedoKeyboardShortcut(e)||this._mode.onKeyDown(e)},onKeyUp:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onKeyUp(e),this.emitDrawingPushIfHistoryChanged(t)},onDragStart:(e,t)=>{this._mode.onDragStart(e,t)},onDrag:(e,t)=>{this._mode.onDrag(e,t)},onDragEnd:(e,t)=>{this._mode.onDragEnd(e,t)},onClear:()=>{this._mode.cleanUp(),this._store.clear({origin:`api`})}}))}getFeaturesAtLngLat(e,t){let{lng:n,lat:r}=e;return this.featuresAtLocation({lng:n,lat:r},t)}getFeaturesAtPointerEvent(e,t){let n=this._adapter.getLngLatFromEvent.bind(this._adapter)(e);return n===null?[]:this.featuresAtLocation(n,t)}stop(){this._enabled&&(this._enabled=!1,this._adapter.unregister())}on(e,t){let n=this._eventListeners[e];n.includes(t)||n.push(t)}off(e,t){let n=this._eventListeners[e];n.includes(t)&&n.splice(n.indexOf(t),1)}};function Xt(){return Xt=Object.assign?Object.assign.bind():function(e){for(var t=1;t0}getPointerTargetElement(e){return e?e instanceof Element?e:e instanceof Node?e.parentElement:null:null}shouldCapturePointer(e){let t=this.getPointerTargetElement(e.target);return!t||!!t.closest(this._advancedMarkerElementTag)||!t.closest(this._interactiveTargetSelector)}circlePath(e,t,n){let r=2*n;return`M ${e} ${t} m -${n}, 0 a ${n},${n} 0 1,0 ${r},0 a ${n},${n} 0 1,0 -${r},0`}register(e){if(super.register(e),this._overlay=new this._lib.OverlayView,this._overlay.draw=function(){},this._overlay.onAdd=()=>{var e;(e=this._currentModeCallbacks)!=null&&e.onReady&&!this._readyCalled&&(this._currentModeCallbacks.onReady(),this._readyCalled=!0)},this._overlay.setMap(this._map),this._overlay.onRemove=()=>{},this._forwardMapElementEvents){let t=this.getMapEventElement();this._pointerCaptureDownListener=e=>{if(e.isPrimary&&this.shouldCapturePointer(e)&&typeof t.setPointerCapture==`function`)try{t.setPointerCapture(e.pointerId)}catch{}},this._pointerCaptureUpListener=e=>{if(typeof t.releasePointerCapture==`function`&&typeof t.hasPointerCapture==`function`&&t.hasPointerCapture(e.pointerId))try{t.releasePointerCapture(e.pointerId)}catch{}},t.addEventListener(`pointerdown`,this._pointerCaptureDownListener),t.addEventListener(`pointerup`,this._pointerCaptureUpListener),t.addEventListener(`pointercancel`,this._pointerCaptureUpListener),this._markerClickListener=t=>{let n=t.target;if(n==null||!n.closest(this._advancedMarkerElementTag))return;let r=this.getDrawEventFromEvent(t);r&&e.onClick(r)},t.addEventListener(`pointerdown`,this._markerClickListener),this._markerMouseMoveListener=t=>{let n=t.target;if(n==null||!n.closest(this._advancedMarkerElementTag))return;let r=this.getDrawEventFromEvent(t);r&&e.onMouseMove(r)},t.addEventListener(`pointermove`,this._markerMouseMoveListener)}this._clickEventListener=this.data().addListener(`click`,e=>{let t=this._listeners.find(({name:e})=>e===`click`);t&&t.callback(e)}),this._mouseMoveEventListener=this.data().addListener(`mousemove`,e=>{let t=this._listeners.find(({name:e})=>e===`mousemove`);t&&t.callback(e)}),this._isolatedData&&(this._data=new this._lib.Data,this._data.setMap(this._map))}data(){return this._isolatedData&&this._data?this._data:this._map.data}style(e){if(!this.styling)throw Error(`Styling function not defined`);let t=String(e.getId());if(!this.renderedFeatureIds.has(t))return{};let n=e.getProperty(`mode`),r=e.getGeometry();if(!r)throw Error(`Google Maps geometry not found`);let i=r.getType(),a={};e.forEachProperty((e,t)=>{a[t]=e});let o=this.styling[n]({type:`Feature`,id:t,geometry:{type:i,coordinates:[]},properties:a});switch(i){case`Point`:if(o.markerUrl)return{clickable:!1,icon:{url:o.markerUrl,scaledSize:o.markerWidth&&o.markerHeight?new this._lib.Size(o.markerWidth,o.markerHeight):void 0},zIndex:o.zIndex};let e=this.circlePath(0,0,o.pointWidth),t=o.pointOutlineOpacity,n=o.pointOpacity;return{clickable:!1,icon:{path:e,fillColor:o.pointColor,fillOpacity:n===void 0?1:n,strokeColor:o.pointOutlineColor,strokeWeight:o.pointOutlineWidth,strokeOpacity:t===void 0?1:t,rotation:0,scale:1},zIndex:o.zIndex};case`LineString`:let r=o.lineStringOpacity,i=o.lineStringDash;return Xt({strokeColor:o.lineStringColor,strokeWeight:o.lineStringWidth,strokeOpacity:r===void 0?1:r,zIndex:o.zIndex},i?{strokeOpacity:0,icons:[{icon:{path:`M 0,0 0,`+i[0],strokeOpacity:1,strokeWeight:o.lineStringWidth,color:o.lineStringColor,scale:1},offset:`0`,repeat:`${i[0]+i[1]}px`,fixedRotation:!1}]}:{});case`Polygon`:let a=o.polygonOutlineOpacity;return{strokeColor:o.polygonOutlineColor,strokeWeight:o.polygonOutlineWidth,strokeOpacity:a===void 0?1:a,fillOpacity:o.polygonFillOpacity,fillColor:o.polygonFillColor,zIndex:o.zIndex}}throw Error(`Unknown feature type`)}unregister(){var e,t;super.unregister(),(e=this._clickEventListener)==null||e.remove(),(t=this._mouseMoveEventListener)==null||t.remove(),this._markerClickListener&&this.getMapEventElement().removeEventListener(`pointerdown`,this._markerClickListener),this._markerMouseMoveListener&&this.getMapEventElement().removeEventListener(`pointermove`,this._markerMouseMoveListener),this._pointerCaptureDownListener&&this.getMapEventElement().removeEventListener(`pointerdown`,this._pointerCaptureDownListener),this._pointerCaptureUpListener&&(this.getMapEventElement().removeEventListener(`pointerup`,this._pointerCaptureUpListener),this.getMapEventElement().removeEventListener(`pointercancel`,this._pointerCaptureUpListener)),this._overlay&&this._overlay.getMap()&&this._overlay.setMap(null),this._overlay=void 0,this._readyCalled=!1,this._mapEventElement=void 0,this._isolatedData&&this._data&&(this._data.setMap(null),this._data=void 0)}getLngLatFromEvent(e){if(!this._overlay)throw Error(`cannot get overlay`);let t=this._map.getBounds();if(!t)return null;let n=t.getNorthEast(),r=t.getSouthWest(),i=new this._lib.LatLngBounds(r,n),a=(document.fullscreenElement??this._map.getDiv()).getBoundingClientRect(),o=new this._lib.Point(e.clientX-a.left,e.clientY-a.top),s=this._overlay.getProjection();if(!s)return null;let c=s.fromContainerPixelToLatLng(o);return c&&i.contains(c)?{lng:c.lng(),lat:c.lat()}:null}getMapEventElement(e){return e&&(e===`keyup`||e===`keydown`)?this._map.getDiv():(this._mapEventElement||=this._map.getDiv().querySelector(`div[style*="z-index: 3;"]`),this._mapEventElement)}project(e,t){if(!this._overlay)throw Error(`cannot get overlay`);if(this._map.getBounds()===void 0)throw Error(`cannot get bounds`);let n=this._overlay.getProjection();if(n===void 0)throw Error(`cannot get projection`);let r=n.fromLatLngToContainerPixel(new this._lib.LatLng(t,e));if(r===null)throw Error(`cannot project coordinates`);return{x:r.x,y:r.y}}unproject(e,t){if(!this._overlay)throw Error(`cannot get overlay`);let n=this._overlay.getProjection();if(n===void 0)throw Error(`cannot get projection`);let r=n.fromContainerPixelToLatLng(new this._lib.Point(e,t));if(r===null)throw Error(`cannot unproject coordinates`);return{lng:r.lng(),lat:r.lat()}}setCursor(e){if(e!==this._cursor){if(this._cursorStyleSheet&&=(this._cursorStyleSheet.remove(),void 0),e!==`unset`){let t=this._map.getDiv().querySelector(`.gm-style > div`);if(t){t.classList.add(`terra-draw-google-maps`);let n=document.createElement(`style`);n.innerHTML=`.terra-draw-google-maps { cursor: ${e} !important; }`,document.getElementsByTagName(`head`)[0].appendChild(n),this._cursorStyleSheet=n}}this._cursor=e}}setDoubleClickToZoom(e){this._map.setOptions(e?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})}setDraggability(e){this._map.setOptions({draggable:e})}render(e,t){this.styling=t,this.data().getStyle()||this.data().setStyle(e=>this.style(e)),this._rafState||={rafId:null,pending:{deletedIds:[],updated:[],created:[]},deletedSet:new Set,updatedById:new Map,createdById:new Map};for(let t of e.deletedIds)this._rafState.deletedSet.add(t),this._rafState.updatedById.delete(t),this._rafState.createdById.delete(t);for(let t of e.updated){if(t==null||!t.id)throw Error(`Feature is not valid`);let e=String(t.id);this._rafState.deletedSet.has(e)||(this._rafState.createdById.has(e)?this._rafState.createdById.set(e,t):this._rafState.updatedById.set(e,t))}for(let t of e.created){if(t==null||!t.id)throw Error(`Feature is not valid`);let e=String(t.id);this._rafState.createdById.set(e,t),this._rafState.updatedById.delete(e)}this._rafState.rafId??(this._rafState.rafId=requestAnimationFrame(()=>{if(!this._rafState)return;this._rafState.rafId=null;let e=Array.from(this._rafState.deletedSet),t=Array.from(this._rafState.updatedById.values()),n=Array.from(this._rafState.createdById.values());if(this._rafState.deletedSet.clear(),this._rafState.updatedById.clear(),this._rafState.createdById.clear(),this._hasRenderedFeatures){for(let t of e){let e=this.data().getFeatureById(t);e&&(this.data().remove(e),this.renderedFeatureIds.delete(t))}for(let e of t){if(e==null||!e.id)throw Error(`Feature is not valid`);let t=this.data().getFeatureById(String(e.id));if(!t)throw Error(`Feature could not be found by Google Maps API`);switch(t.forEachProperty((e,n)=>{t.setProperty(n,void 0)}),Object.keys(e.properties).forEach(n=>{t.setProperty(n,e.properties[n])}),e.geometry.type){case`Point`:{let n=e.geometry.coordinates;t.setGeometry(new this._lib.Data.Point(new this._lib.LatLng(n[1],n[0])));break}case`LineString`:{let n=e.geometry.coordinates,r=[];for(let e=0;e{let t=e.getId();this.renderedFeatureIds.has(t)&&this.data().remove(e)}),this.renderedFeatureIds=new Set)}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers()),this.data()&&this.data().setStyle(null)}getCoordinatePrecision(){return super.getCoordinatePrecision()}},Qt=[`#E74C3C`,`#FF0066`,`#9B59B6`,`#673AB7`,`#3F51B5`,`#3498DB`,`#03A9F4`,`#00BCD4`,`#009688`,`#27AE60`,`#8BC34A`,`#CDDC39`,`#F1C40F`,`#FFC107`,`#F39C12`,`#FF5722`,`#795548`],J=()=>Qt[Math.floor(Math.random()*Qt.length)];function $t(e){return e.map(e=>{let t=JSON.parse(JSON.stringify(e));return t.properties.mode===`rectangle`?(t.geometry.type=`Polygon`,t.properties.mode=`polygon`):t.properties.mode===`circle`&&(t.geometry.type=`Polygon`,t.properties.mode=`circle`),t})}function en(){if(!document.getElementById(`mode-ui`))return;let e={"select-mode":`select`,"point-mode":`point`,"linestring-mode":`linestring`,"polygon-mode":`polygon`,"rectangle-mode":`rectangle`,"circle-mode":`circle`,"freehand-mode":`freehand`,"clear-mode":`static`};for(let t in e){let n=document.getElementById(t);n&&(n.onclick=()=>{tn(t);let n=e[t];Y&&(n===`static`?(Y.clear(),Y.setMode(`static`)):n&&Y.setMode(n))})}}function tn(e){let t=document.querySelectorAll(`.mode-button`),n=document.getElementById(`resize-button`),r=n?.classList.contains(`active`);t.forEach(e=>{e.id!==`resize-button`&&e.classList.remove(`active`)});let i=document.getElementById(e);i&&i.classList.add(`active`),r&&n?.classList.add(`active`)}function nn(){tn(`point-mode`)}var rn,Y,X=[],an=[],Z=null,Q=!1,$=!1,on;async function sn(){try{let{Map:e}=await google.maps.importLibrary(`maps`);rn=new e(document.getElementById(`map`),{center:{lat:48.862,lng:2.342},zoom:12,mapId:`c306b3c6dd3ed8d9`,mapTypeId:`roadmap`,zoomControl:!1,tilt:45,mapTypeControl:!0,clickableIcons:!1,streetViewControl:!1,fullscreenControl:!1}),rn.addListener(`click`,()=>{Y&&console.log(`Current draw mode on map click:`,Y.getMode())}),rn.addListener(`projection_changed`,()=>{Y=new Yt({adapter:new Zt({map:rn,lib:google.maps,coordinatePrecision:9}),modes:[new Dt({flags:{polygon:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},point:{feature:{draggable:!0,rotateable:!0}},rectangle:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},freehand:{feature:{draggable:!0,rotateable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}}),new $e({editable:!0,styles:{pointColor:J()}}),new Ke({editable:!0,styles:{lineStringColor:J()}}),new nt({editable:!0,styles:(()=>{let e=J();return{fillColor:e,outlineColor:e}})()}),new at({styles:(()=>{let e=J();return{fillColor:e,outlineColor:e}})()}),new ge({styles:(()=>{let e=J();return{fillColor:e,outlineColor:e}})()}),new be({styles:(()=>{let e=J();return{fillColor:e,outlineColor:e}})()})]}),Y.start(),Y.on(`ready`,()=>{console.log(`TerraDraw is ready!`),nn(),en(),Y.setMode(`point`),tn(`point-mode`),Y.on(`select`,e=>{Z&&Z!==e&&Y.deselectFeature(Z),Z=e}),Y.on(`deselect`,()=>{Z=null}),X.push($t(Y.getSnapshot())),Y.on(`change`,()=>{Q||(on&&clearTimeout(on),on=window.setTimeout(()=>{let e=$t(Y.getSnapshot()).filter(e=>!e.properties.midPoint&&!e.properties.selectionPoint);X.push(e),an=[]},200))});let e=document.getElementById(`export-button`);e&&(e.onclick=()=>{let e={type:`FeatureCollection`,features:Y.getSnapshot()},t=JSON.stringify(e,null,2),n=new Blob([t],{type:`text/plain`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`drawing.geojson`,i.click(),URL.revokeObjectURL(r)});let t=document.getElementById(`upload-button`),n=document.getElementById(`upload-input`);t&&n&&(t.onclick=()=>{n.click()},n.onchange=e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result);t.type===`FeatureCollection`?Y.addFeatures(t.features):alert(`Invalid GeoJSON file: must be a FeatureCollection.`)}catch{alert(`Error parsing GeoJSON file.`)}},e.readAsText(t)}});let r=document.getElementById(`resize-button`);r&&(r.onclick=()=>{$=!$,r.classList.toggle(`active`,$);let e={polygon:{feature:{draggable:!0,coordinates:{resizable:$?`center`:void 0,draggable:!$}}},linestring:{feature:{draggable:!0,coordinates:{resizable:$?`center`:void 0,draggable:!$}}},rectangle:{feature:{draggable:!0,coordinates:{resizable:$?`center`:void 0,draggable:!$}}},circle:{feature:{draggable:!0,coordinates:{resizable:$?`center`:void 0,draggable:!$}}},freehand:{feature:{draggable:!0,coordinates:{resizable:$?`center`:void 0,draggable:!$}}}};console.log(`Updating flags:`,e),Y.updateModeOptions(`select`,{flags:e})});let i=document.getElementById(`delete-selected-button`);i&&(i.onclick=()=>{if(Z)Y.removeFeatures([Z]);else{let e=Y.getSnapshot();if(e.length>0){let t=e[e.length-1];t.id&&Y.removeFeatures([t.id])}}});let a=document.getElementById(`undo-button`);a&&(a.onclick=()=>{if(X.length>1){let e=X.pop();e&&an.push(e);let t=X[X.length-1];console.log(`Restoring snapshot (undo):`,t),Q=!0,Y.clear(),Y.addFeatures(t),setTimeout(()=>{Q=!1},0)}});let o=document.getElementById(`redo-button`);o&&(o.onclick=()=>{if(an.length>0){let e=an.pop();console.log(`Restoring snapshot (redo):`,e),X.push(e),Q=!0,Y.clear(),Y.addFeatures(e),setTimeout(()=>{Q=!1},0)}})});function e(e,n){let r=JSON.parse(JSON.stringify(e)),i=r.geometry.coordinates,a=t(i),o=i.map(e=>e.map(e=>{let t=e[0]-a[0],r=e[1]-a[1],i=t*Math.cos(n*Math.PI/180)-r*Math.sin(n*Math.PI/180),o=t*Math.sin(n*Math.PI/180)+r*Math.cos(n*Math.PI/180);return[i+a[0],o+a[1]]}));return r.geometry.coordinates=o,r}function t(e){let t=0,n=0,r=0;return e.forEach(e=>{e.forEach(e=>{t+=e[0],n+=e[1],r++})}),[t/r,n/r]}document.addEventListener(`keydown`,t=>{if(t.key===`r`&&Z){let t=Y.getSnapshot().find(e=>e.id===Z);if(t){let n=e(t,15);Y.addFeatures([n])}}})})}catch(e){console.error(`Error loading Google Maps API:`,e)}}sn(); \ No newline at end of file diff --git a/dist/samples/map-drawing-terradraw/dist/assets/index-DReRfkKQ.css b/dist/samples/map-drawing-terradraw/dist/assets/index-DReRfkKQ.css new file mode 100644 index 000000000..bc2340ebb --- /dev/null +++ b/dist/samples/map-drawing-terradraw/dist/assets/index-DReRfkKQ.css @@ -0,0 +1 @@ +html,body{height:100%;margin:0;padding:0;font-family:Arial,sans-serif}#map{width:100%;height:100%}#mode-ui{z-index:1000;background:#fff;border-radius:5px;flex-direction:column;padding:10px;display:flex;position:absolute;top:10px;right:10px;box-shadow:0 0 10px #0003}#mode-ui button{cursor:pointer;margin:5px 0}.mode-button{box-sizing:border-box;background-color:#fff;border:1px solid #ccc;width:30px;height:30px;padding:2px}.mode-button img{-webkit-user-select:none;user-select:none;width:100%;height:100%;display:block}.mode-button.active{background-color:#e0e0e0}#select-mode,#clear-mode,#delete-selected-button,#undo-button,#redo-button,#export-button,#upload-button,#resize-button{background-color:#000}#select-mode img,#clear-mode img,#delete-selected-button img,#undo-button img,#redo-button img,#export-button img,#upload-button img,#resize-button img{filter:brightness(0)invert()}#select-mode.active,#clear-mode:active,#delete-selected-button:active,#undo-button:active,#redo-button:active,#export-button:active,#upload-button:active,#resize-button.active{background-color:#a9a9a9} diff --git a/dist/samples/map-drawing-terradraw/dist/index.html b/dist/samples/map-drawing-terradraw/dist/index.html index 01a49541e..8ac91de9a 100644 --- a/dist/samples/map-drawing-terradraw/dist/index.html +++ b/dist/samples/map-drawing-terradraw/dist/index.html @@ -14,8 +14,8 @@ key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8" }); - - + +