From 8c3716c637814116d7dfb6f5b57f09f0828b6feb Mon Sep 17 00:00:00 2001 From: googlemaps-bot Date: Wed, 7 Oct 2026 16:35:35 +0000 Subject: [PATCH] Update dist folder [skip ci] --- dist/samples/map-drawing-terradraw/app/package.json | 2 +- .../samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js | 1 - .../samples/map-drawing-terradraw/dist/assets/index-rPLOhjGd.js | 1 + dist/samples/map-drawing-terradraw/dist/index.html | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js create mode 100644 dist/samples/map-drawing-terradraw/dist/assets/index-rPLOhjGd.js diff --git a/dist/samples/map-drawing-terradraw/app/package.json b/dist/samples/map-drawing-terradraw/app/package.json index af8c6e1ad..9ce3ad567 100644 --- a/dist/samples/map-drawing-terradraw/app/package.json +++ b/dist/samples/map-drawing-terradraw/app/package.json @@ -10,7 +10,7 @@ "preview": "vite preview --config ../../vite.config.js" }, "dependencies": { - "terra-draw": "^1.32.3", + "terra-draw": "^1.36.0", "terra-draw-google-maps-adapter": "^1.6.2" }, "author": "Google LLC" diff --git a/dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js b/dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js deleted file mode 100644 index 0cb338f14..000000000 --- a/dist/samples/map-drawing-terradraw/dist/assets/index-DJSfg9xg.js +++ /dev/null @@ -1 +0,0 @@ -(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-rPLOhjGd.js b/dist/samples/map-drawing-terradraw/dist/assets/index-rPLOhjGd.js new file mode 100644 index 000000000..de4678989 --- /dev/null +++ b/dist/samples/map-drawing-terradraw/dist/assets/index-rPLOhjGd.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;ttypeof e==`number`&&e>=0&&Number.isFinite(e),g=e=>typeof e==`boolean`,_=e=>e===null,v=e=>typeof e==`object`&&!!e,ee=e=>typeof e==`string`&&e.length>0,te=e=>e===`click-move`||e===`click-drag`||e===`click-move-or-drag`,y;(function(e){e.Drawing=`drawing`,e.Select=`select`,e.Static=`static`,e.Render=`render`})(y||={});var ne={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},b=class{get state(){return this._state}set state(e){throw Error(`Please use the modes lifecycle methods`)}get styles(){return this._styles}set styles(e){if(typeof e!=`object`)throw Error(`Styling must be an object`);this.onStyleChange&&this.onStyleChange([],`styling`),this._styles=e}registerBehaviors(e){}constructor(t,n=!1){this._state=`unregistered`,this._styles={},this.pointerEvents=ne,this.behaviors=[],this.validate=void 0,this.pointerDistance=40,this.coordinatePrecision=void 0,this.undoRedoMaxStackSize=void 0,this.onStyleChange=void 0,this.store=void 0,this.projection=`web-mercator`,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.isInitialUpdate=!1,this.type=y.Drawing,this.mode=`base`,n?this.isInitialUpdate=!0:this.updateOptions(e({},t))}updateOptions(t){v(t?.styles)&&(this.styles=e({},this._styles,t.styles)),h(t?.pointerDistance)&&(this.pointerDistance=t.pointerDistance),typeof t?.validation==`function`&&(this.validate=t.validation),ee(t?.projection)&&(this.projection=t.projection),v(t?.pointerEvents)&&(this.pointerEvents=t.pointerEvents),ee(t?.modeName)&&!0===this.isInitialUpdate&&(this.mode=t.modeName),this.isInitialUpdate=!1}allowPointerEvent(e,t){return typeof e==`boolean`?e:typeof e!=`function`||e(t)}setDrawing(){if(this._state!==`started`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`drawing`}setStarted(){if(this._state!==`stopped`&&this._state!==`registered`&&this._state!==`drawing`&&this._state!==`selecting`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`started`,this.setDoubleClickToZoom(!1)}setStopped(){if(this._state!==`started`)throw Error(`Mode must be started to be stopped`);this._state=`stopped`,this.setDoubleClickToZoom(!0)}register(e){if(this._state!==`unregistered`)throw Error(`Can not register unless mode is unregistered`);this._state=`registered`,this.store=e.store,this.store.registerOnChange(e.onChange),this.setDoubleClickToZoom=e.setDoubleClickToZoom,this.project=e.project,this.unproject=e.unproject,this.onSelect=e.onSelect,this.onDeselect=e.onDeselect,this.setCursor=e.setCursor,this.onStyleChange=e.onChange,this.onFinish=e.onFinish,this.coordinatePrecision=e.coordinatePrecision,this.undoRedoMaxStackSize=e.undoRedoMaxStackSize,this.registerBehaviors({mode:e.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:e.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:e.undoRedoMaxStackSize})}validateFeature(e){return this.performFeatureValidation(e)}afterFeatureAdded(e){}afterFeatureUpdated(e){}performFeatureValidation(e){if(this._state===`unregistered`)throw Error(`Mode must be registered`);let t=function(e,t){let n;if(d(e)){if(e.id==null)n=`Feature has no id`;else if(typeof e.id!=`string`&&typeof e.id!=`number`)n=`Feature must be string or number as per GeoJSON spec`;else if(t(e.id)){if(d(e.geometry)){if(d(e.properties)){if(typeof e.geometry.type==`string`&&[`Polygon`,`LineString`,`Point`].includes(e.geometry.type)){if(Array.isArray(e.geometry.coordinates)){if(!e.properties.mode||typeof e.properties.mode!=`string`)return{valid:!1,reason:`Feature does not have a valid mode property`}}else n=`Feature coordinates is not an array`}else n=`Feature is not Point, LineString or Polygon`}else n=`Feature has no properties`}else n=`Feature has no geometry`}else n=`Feature must match the id strategy (default is UUID4)`}else n=`Feature is not object`;return n?{valid:!1,reason:n}:{valid:!0}}(e,this.store.idStrategy.isValidId);if(!t.valid)return t;if(this.validate){let n=this.validate(e,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:a.Provisional});return{valid:t.valid&&n.valid,reason:n.reason}}return{valid:t.valid,reason:t.reason}}validateModeFeature(e,t){let n=this.performFeatureValidation(e);return n.valid?e.properties.mode===this.mode?t(e):{valid:!1,reason:m}:{valid:!1,reason:n.reason}}onFinish(e,t){}onDeselect(e){}onSelect(e){}onKeyDown(e){}onKeyUp(e){}undo(){}clearHistory(){}undoSize(){return 0}redoSize(){return 0}redo(){}onMouseMove(e){}onClick(e){}onDragStart(e,t){}onDrag(e,t){}onDragEnd(e,t){}getHexColorStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getNumericStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getUrlStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getDashArrayStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getStylingValue(e,t,n){return e===void 0?t:typeof e==`function`?(r=e(n))??t:e;var r}},re=class extends b{constructor(...e){super(...e),this.type=y.Select}},x=`Enter`,S=`Escape`,C=`crosshair`,ie=`pointer`,ae=`grabbing`,oe=`move`,w=`unset`;function T(e,t){let n=e=>e*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 se=6371008.8;function E(e){return e%360*Math.PI/180}function ce(e){return e/6371.0088}function D(e){return e%(2*Math.PI)*180/Math.PI}function O(e,t=9){let n=10**t;return Math.round(e*n)/n}var le=57.29577951308232,ue=.017453292519943295,de=6378137,k=(e,t)=>({x:e===0?0:e*ue*de,y:t===0?0:Math.log(Math.tan(Math.PI/4+t*ue/2))*de}),A=(e,t)=>({lng:e===0?0:e/de*le,lat:t===0?0:(2*Math.atan(Math.exp(t/de))-Math.PI/2)*le});function fe(e,t,n){let r=E(e[0]),i=E(e[1]),a=E(n),o=ce(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[D(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),D(s)]}function pe(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(he(e,n)||he(e,r)||he(t,n)||he(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 he(e,t){return e[0]===t[0]&&e[1]===t[1]}function ge(e,t){return ve(e[0])<=t&&ve(e[1])<=t}function _e(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 ve(e){let t=1,n=0;for(;Math.round(e*t)/t!==e;)t*=10,n++;return n}var ye=`Feature has holes`,be=`Feature has less than 4 coordinates`,xe=`Feature has invalid coordinates`,Se=`Feature coordinates are not closed`;function Ce(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:ye};if(e.geometry.coordinates[0].length<4)return{valid:!1,reason:be};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==null)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=Te(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===M||t.type===N){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===M){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)}};function Ee(e,t){return e[0]===t[0]&&e[1]===t[1]}var R=class extends j{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 Ee(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)}};function De(e){return Array.isArray(e)&&e.length>0&&Array.isArray(e[0])&&Array.isArray(e[0][0])}var Oe=e=>De(e)?e[0].slice(0,-1):e,z=e=>De(e)?e[0]:e,B=class extends j{constructor(e,t,n){super(e),this.readFeature=void 0,this.mutateFeature=void 0,this.readFeature=t,this.mutateFeature=n}setEnabled(e){let t=this.store.copyAllWhere(e=>e.mode===this.mode).filter(e=>e.geometry.type===`LineString`||e.geometry.type===`Polygon`);e?t.forEach(e=>{this.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}):this.deletePointsByFeatureIds(t.filter(e=>!!e.properties[c.COORDINATE_POINT_IDS]).map(e=>e.id))}createOrUpdate({featureId:e,featureCoordinates:t}){if(!this.readFeature.hasFeature(e))return void this.deleteOrphanedPoints(e);let n=Oe(t),r=this.readFeature.getProperties(e),i=r.coordinatePointIds;if(i){if(i&&i.every(e=>this.readFeature.hasFeature(e))){let t=r.coordinatePointIds,a=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]===a[r][0]&&n[1]===a[r][1]||e.push({featureId:t[r],coordinate:n})}),this.mutateFeature.updateGuidancePoints(e),this.syncCurrentlyDrawing(i,r)}}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=Oe(t);r.length===n.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(n.coordinatePointIds.map((e,t)=>({featureId:e,coordinate:r[t]})))}createPoints(t,n,r){let i=!0===this.readFeature.getProperties(r)[c.CURRENTLY_DRAWING];return this.mutateFeature.createGuidancePoints({coordinates:t,type:c.COORDINATE_POINT,additionalProperties:t=>e({mode:n,[c.COORDINATE_POINT]:!0,[c.COORDINATE_POINT_FEATURE_ID]:r},i?{[c.CURRENTLY_DRAWING]:!0}:{},{index:t})})}syncCurrentlyDrawing(e,t){let n=!0===t[c.CURRENTLY_DRAWING];e.forEach(e=>{this.readFeature.hasFeature(e)&&this.mutateFeature.updatePoint({featureId:e,propertyMutations:{[c.CURRENTLY_DRAWING]:!!n||void 0},context:{updateType:a.Commit}})})}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)}},ke={cancel:S,finish:x},Ae={start:C},je=class extends b{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=ke,this.cursors=Ae,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.cancelled=!1,this.minimumSegments=3,this.showCoordinatePoints=!1,this.readFeature=void 0,this.coordinatePoints=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(t){var n;if(super.updateOptions(t),g(t?.showCoordinatePoints)&&(this.showCoordinatePoints=t.showCoordinatePoints,(n=this.coordinatePoints)==null||n.setEnabled(this.showCoordinatePoints)),v(t?.cursors)&&(this.cursors=e({},this.cursors,t.cursors)),_(t?.keyEvents)?this.keyEvents={cancel:null,finish:null}:v(t?.keyEvents)&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),h(t?.startingRadiusKilometers)&&(this.startingRadiusKilometers=t.startingRadiusKilometers),te(t?.drawInteraction)&&(this.drawInteraction=t.drawInteraction),h(t?.segments)){let e=Math.trunc(t.segments);this.segments=ewe(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=T(this.center,e),this.projection===`web-mercator`){let t=function(e,t){let n=1e3*T(e,t);if(n===0)return 1;let{x:r,y:i}=k(e[0],e[1]),{x:a,y:o}=k(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}=k(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)},Ne={cancel:S,finish:x},Pe={start:C,close:ie},Fe=class extends b{constructor(e){super(e,!0),this.mode=`freehand`,this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=20,this.keyEvents=Ne,this.cursors=Pe,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.showCoordinatePoints=!1,this.coordinatePoints=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(t){var n;super.updateOptions(t),g(t?.showCoordinatePoints)&&(this.showCoordinatePoints=t.showCoordinatePoints,(n=this.coordinatePoints)==null||n.setEnabled(this.showCoordinatePoints)),h(t?.minDistance)&&(this.minDistance=t.minDistance),h(t?.smoothing)&&(this.smoothing=Math.min(Math.max(t.smoothing,0),.999)),g(t?.preventPointsNearClose)&&(this.preventPointsNearClose=t.preventPointsNearClose),g(t?.autoClose)&&(this.autoClose=t.autoClose),h(t?.autoCloseTimeout)&&(this.autoCloseTimeout=t.autoCloseTimeout),_(t?.keyEvents)?this.keyEvents={cancel:null,finish:null}:v(t?.keyEvents)&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),v(t?.cursors)&&(this.cursors=e({},this.cursors,t.cursors)),te(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 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.id,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n.id,featureCoordinates:n.geometry.coordinates}),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=V({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(V({x:l,y:u},{x:e.containerX,y:e.containerY}){this.preventNewFeature=!1},this.autoCloseTimeout),void this.close();if(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(),e!==void 0&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),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.properties.mode===this.mode&&t.geometry.type===`Point`&&t.properties[c.COORDINATE_POINT]?(n.pointWidth=this.getNumericStylingValue(this.styles.coordinatePointWidth,n.pointWidth,t),n.pointColor=this.getHexColorStylingValue(this.styles.coordinatePointColor,n.pointColor,t),n.pointOpacity=this.getNumericStylingValue(this.styles.coordinatePointOpacity,1,t),n.pointOutlineWidth=this.getNumericStylingValue(this.styles.coordinatePointOutlineWidth,2,t),n.pointOutlineColor=this.getHexColorStylingValue(this.styles.coordinatePointOutlineColor,n.pointOutlineColor,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.coordinatePointOutlineOpacity,1,t),n.zIndex=u,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=>Ce(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.showCoordinatePoints&&e.geometry.type===`Polygon`&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.currentId===e.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)}afterFeatureAdded(e){this.showCoordinatePoints&&e.geometry.type===`Polygon`&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}registerBehaviors(e){this.readFeature=new R(e),this.mutateFeature=new L(e,{validate:this.validate}),this.coordinatePoints=new B(e,this.readFeature,this.mutateFeature)}};function Ie({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 Le=class extends j{constructor(e){super(e)}create(e){let{containerX:t,containerY:n}=e;return Ie({unproject:this.unproject,point:{x:t,y:n},pointerDistance:this.pointerDistance})}},Re=class extends j{constructor(e){super(e)}measure(e,t){let{x:n,y:r}=this.project(t[0],t[1]);return V({x:n,y:r},{x:e.containerX,y:e.containerY})}},ze=class extends j{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 Ve(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=H(e[i],e[i-1])-180,s=Me(e[i],a,o),r.push(s)}if(c>=n)return a=n-c,a?(o=H(e[i],e[i-1])-180,s=Me(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+=T(e[i],e[i+1])}if(c[O(e[0],this.config.coordinatePrecision),O(e[1],this.config.coordinatePrecision)])}};function Ge(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;nte||U(i,x)>te?T(W(x),W(r))<=T(W(x),W(i))?[W(r),!0,!1]:[W(i),!1,!0]:[W(x),!1,!1]}function Ye(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 Xe=class extends j{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?[O(t.coordinate[0],this.config.coordinatePrecision),O(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?[O(n.coordinate[0],this.config.coordinatePrecision),O(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.minDistancethis.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))}},et=class extends j{constructor(e){super(e),this.config=void 0,this.EPSILON=1e-9,this.DEFAULT_DEGREE=90,this.config=e}getSnappableCoordinate(e,t,n,r={}){if(n<2)return;let i=t.type===`Polygon`?t.coordinates[0]:t.coordinates,a=i[n-2],o=i[n-1];if(!a||!o)return;let s=this.getDegree(r.degree),c=[e.lng,e.lat],l=!0===r.backTracking,u=this.projection===`globe`?this.snapOnGlobe(a,o,c,s,l):this.snapOnWebMercator(a,o,c,s,l);if(t.type===`Polygon`&&n>=3){let e=this.getClosingCandidate(a,o,i[0],c,s,l);e&&this.pixelDistance(c,e)0&&e<=180&&360/e<=1e4?e:this.DEFAULT_DEGREE}offsets(e,t){let n=[];for(let r=0;r<360-this.EPSILON;r+=e){let e=(r%360+360)%360;!t&&Math.abs(e-180)t?this.distance(e,n)1&&(this.finishOnNthCoordinate=Math.floor(t.finishOnNthCoordinate)),v(t?.cursors)&&(this.cursors=e({},this.cursors,t.cursors)),v(t?.snapping)&&(this.snapping=t.snapping),_(t?.keyEvents)?this.keyEvents={cancel:null,finish:null}:v(t?.keyEvents)&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),v(t?.insertCoordinates)&&(this.insertCoordinates=t.insertCoordinates),g(t?.editable)&&(this.editable=t.editable),t?.showCoordinatePoints!==void 0&&(this.showCoordinatePoints=t.showCoordinatePoints,(n=this.coordinatePoints)==null||n.setEnabled(this.showCoordinatePoints))}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:F,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=T(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:N,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:N,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:I,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:I,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 We(e),this.clickBoundingBox=new Le(e),this.pixelDistance=new Re(e),this.lineSnapping=new Xe(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new ze(e,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Ze(this.coordinateSnapping,this.lineSnapping),this.degreeSnapping=new et(e),this.readFeature=new R(e),this.mutateFeature=new L(e,{validate:this.validate}),this.closingPoints=new Qe(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new B(e,this.readFeature,this.mutateFeature),this.undoRedo=new $e({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(w)}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:P,index:-1,coordinate:t}];if(this.insertCoordinates){let e=this.getInsertCoordinates(t);e&&(r={type:I,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(Ee(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:F,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:P,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?u:50,n}return n}validateFeature(e){return this.validateModeFeature(e,e=>Ge(e,this.coordinatePrecision))}lineStringFilter(e){return!!(e.geometry.type===`LineString`&&e.properties&&e.properties.mode===this.mode)}snapCoordinate(e){var t,n,r,i,a;let o;if((t=this.snapping)!=null&&t.toDegree&&this.currentId&&(o=this.degreeSnapping.getSnappableCoordinate(e,this.readFeature.getGeometry(this.currentId),this.currentCoordinate,this.snapping.toDegree)),(n=this.snapping)!=null&&n.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(o=t)}if((r=this.snapping)!=null&&r.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(o=t)}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&&(o=t)}if((a=this.snapping)!=null&&a.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&&(o=t.coordinate)}return o}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})}},it=`Feature is not a Point`,at=`Feature has invalid coordinates`,ot=`Feature has coordinates with excessive precision`;function st(e,t){return e.geometry.type===`Point`?_e(e.geometry.coordinates)?ge(e.geometry.coordinates,t)?{valid:!0}:{valid:!1,reason:ot}:{valid:!1,reason:at}:{valid:!1,reason:it}}var ct=class extends j{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}},lt={create:C,dragStart:ae,dragEnd:C},ut=class extends b{constructor(e){super(e,!0),this.mode=`point`,this.cursors=lt,this.editable=!1,this.snapping=void 0,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.featureSnapping=void 0,this.updateOptions(e)}updateOptions(t){super.updateOptions(t),v(t?.cursors)&&(this.cursors=e({},this.cursors,t.cursors)),v(t?.snapping)&&(this.snapping=t.snapping),g(t?.editable)&&(this.editable=t.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(w)}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:I,coordinates:this.snapCoordinate(e,this.editedFeatureId)},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 Re(e),this.clickBoundingBox=new Le(e),this.pointSearch=new ct(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new ze(e,this.pixelDistance,this.clickBoundingBox),this.lineSnapping=new Xe(e,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Ze(this.coordinateSnapping,this.lineSnapping),this.mutateFeature=new L(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=>st(e,this.coordinatePrecision))}onLeftClick(e){let n=this.mutateFeature.createPoint({coordinates:this.snapCoordinate(e),properties:{mode:this.mode},context:{updateType:a.Finish,action:t}});n&&this.onFinish(n.id,{mode:this.mode,action:t})}snapCoordinate(e,t){var n,r,i;let a=[e.lng,e.lat];if((n=this.snapping)!=null&&n.toCoordinate){let n=t?this.coordinateSnapping.getSnappableCoordinate(e,t):this.coordinateSnapping.getSnappableCoordinateFirstClick(e);n&&(a=n)}if((r=this.snapping)!=null&&r.toFeature){let n=this.featureSnapping.getSnappable(e,t,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});n.coordinate&&(a=n.coordinate)}if((i=this.snapping)!=null&&i.toCustom){let n=this.snapping.toCustom(e,{currentCoordinate:0,currentId:t,getCurrentGeometrySnapshot:()=>null,project:this.project,unproject:this.unproject});n&&(a=n)}return a}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))}},dt={cancel:S,finish:x},ft={start:C,close:ie,dragStart:ae,dragEnd:C},pt=class extends b{constructor(e){super(e,!0),this.mode=`polygon`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=dt,this.cursors=ft,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.degreeSnapping=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){var n;super.updateOptions(t),v(t?.cursors)&&(this.cursors=e({},this.cursors,t.cursors)),_(t?.keyEvents)?this.keyEvents={cancel:null,finish:null}:v(t?.keyEvents)&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),v(t?.snapping)&&(this.snapping=t.snapping),g(t?.editable)&&(this.editable=t.editable),v(t?.pointerEvents)&&(this.pointerEvents=t.pointerEvents),g(t?.showCoordinatePoints)&&(this.showCoordinatePoints=t.showCoordinatePoints,(n=this.coordinatePoints)==null||n.setEnabled(this.showCoordinatePoints))}close(){if(this.currentId===void 0||this.readFeature.getCoordinates(this.currentId).length<5)return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:F,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 R(e),this.mutateFeature=new L(e,{validate:this.validate}),this.clickBoundingBox=new Le(e),this.pixelDistance=new Re(e),this.lineSnapping=new Xe(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new ze(e,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Ze(this.coordinateSnapping,this.lineSnapping),this.degreeSnapping=new et(e),this.closingPoints=new Qe(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new B(e,this.readFeature,this.mutateFeature),this.undoRedo=new $e({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(w)}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:I,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:I,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:P,index:1,coordinate:n},{type:P,index:2,coordinate:[e.lng,e.lat]}];else if(this.currentCoordinate===2)r=[{type:P,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:P,index:-1,coordinate:t},{type:P,index:-2,coordinate:t}]):r=[{type:P,index:-2,coordinate:n},{type:P,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,a;let o;if((t=this.snapping)!=null&&t.toDegree&&this.currentId&&(o=this.degreeSnapping.getSnappableCoordinate(e,this.readFeature.getGeometry(this.currentId),this.currentCoordinate,this.snapping.toDegree)),(n=this.snapping)!=null&&n.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(o=t)}if((r=this.snapping)!=null&&r.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(o=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&&(o=t.coordinate)}if((a=this.snapping)!=null&&a.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&&(o=t)}return o}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:F,index:0},{type:F,index:-1},{type:N,index:-1,coordinate:o[1]}]:[{type:F,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:P,index:1,coordinate:t},{type:P,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:P,index:2,coordinate:t},{type:N,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:M,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:P,index:0,coordinate:r},{type:P,index:-1,coordinate:r}]:[{type:P,index:this.editedFeatureCoordinateIndex,coordinate:r}]:this.editedSnapType===`line`&&this.editedInsertIndex===void 0&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i=[{type:M,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?u: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=>Ce(e,this.coordinatePrecision))}},mt={cancel:S,finish:x},ht={start:C},gt=class extends b{constructor(e){super(e,!0),this.mode=`rectangle`,this.startPosition=void 0,this.endPosition=void 0,this.currentRectangleId=void 0,this.keyEvents=mt,this.cursors=ht,this.drawInteraction=`click-move`,this.drawType=void 0,this.showCoordinatePoints=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.coordinatePoints=void 0,this.updateOptions(e)}updateOptions(t){var n;super.updateOptions(t),v(t?.cursors)&&(this.cursors=e({},this.cursors,t.cursors)),_(t?.keyEvents)?this.keyEvents={cancel:null,finish:null}:v(t?.keyEvents)&&(this.keyEvents=e({},this.keyEvents,t.keyEvents)),te(t?.drawInteraction)&&(this.drawInteraction=t.drawInteraction),g(t?.showCoordinatePoints)&&(this.showCoordinatePoints=t.showCoordinatePoints,(n=this.coordinatePoints)==null||n.setEnabled(this.showCoordinatePoints))}updateRectangle(e,n){if(!this.startPosition||!this.currentRectangleId)return;let r=n===a.Finish,i=this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:P,index:1,coordinate:[e[0],this.startPosition[1]]},{type:P,index:2,coordinate:e},{type:P,index:3,coordinate:[this.startPosition[0],e[1]]}],propertyMutations:r?{[c.CURRENTLY_DRAWING]:void 0}:{},context:r?{updateType:n,action:t}:{updateType:n}});return i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentRectangleId,featureCoordinates:i.geometry.coordinates}),i}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.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n.id,featureCoordinates:n.geometry.coordinates}),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(w)}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(),e&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),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.properties.mode===this.mode&&t.geometry.type===`Polygon`?(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.properties.mode===this.mode&&t.geometry.type===`Point`&&t.properties[c.COORDINATE_POINT]?(n.pointWidth=this.getNumericStylingValue(this.styles.coordinatePointWidth,n.pointWidth,t),n.pointColor=this.getHexColorStylingValue(this.styles.coordinatePointColor,n.pointColor,t),n.pointOpacity=this.getNumericStylingValue(this.styles.coordinatePointOpacity,1,t),n.pointOutlineWidth=this.getNumericStylingValue(this.styles.coordinatePointOutlineWidth,2,t),n.pointOutlineColor=this.getHexColorStylingValue(this.styles.coordinatePointOutlineColor,n.pointOutlineColor,t),n.pointOutlineOpacity=this.getNumericStylingValue(this.styles.coordinatePointOutlineOpacity,1,t),n.zIndex=u,n):n}validateFeature(e){return this.validateModeFeature(e,e=>we(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.showCoordinatePoints&&e.geometry.type===`Polygon`&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.currentRectangleId===e.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted())}afterFeatureAdded(e){this.showCoordinatePoints&&e.geometry.type===`Polygon`&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}registerBehaviors(e){this.readFeature=new R(e),this.mutateFeature=new L(e,{validate:this.validate}),this.coordinatePoints=new B(e,this.readFeature,this.mutateFeature)}};function _t(e,t){let n=e,r=t,i=E(n[1]),a=E(r[1]),o=E(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=(D(Math.atan2(o,s))+360)%360;return c>180?-(360-c):c}function vt(e,t,n){let r=t;t<0&&(r=-Math.abs(r));let i=r/se,a=e[0]*Math.PI/180,o=E(e[1]),s=E(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 yt(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[O(s,n),O(c,n)]}function bt(e,t,n){let r=vt(e,1e3*T(e,t)/2,_t(e,t));return[O(r[0],n),O(r[1],n)]}function xt({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=z(e),n=xt(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=z(t),r=xt(this.getMidpointConfig(n));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[e],coordinate:r[e]}])}},Ct=class extends j{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=Oe(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=Oe(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 wt(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 Tt=(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))},Et=class extends j{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:I,coordinates:[r]},context:{updateType:a.Provisional}});else{if(t.type!==`LineString`)return;s=this.mutateFeature.updateLineString({featureId:o,coordinateMutations:{type:I,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:I,coordinates:n},context:{updateType:a.Provisional}}),this.dragPosition=[e.lng,e.lat])}},Ot=class extends j{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 Ze(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&&me({type:`Feature`,geometry:o,properties:{}}))return!1;let d=r,f=null;return o.type===`Polygon`?f=this.mutateFeature.updatePolygon({featureId:d,coordinateMutations:{type:I,coordinates:[c]},context:{updateType:a.Provisional}}):o.type===`LineString`&&(f=this.mutateFeature.updateLineString({featureId:d,coordinateMutations:{type:I,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 kt(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 At=(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])=>k(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})=>[A(e,t).lng,A(e,t).lat]);return e.geometry.type===`Polygon`?e.geometry.coordinates[0]=a:e.geometry.coordinates=a,e};function jt(e){let t=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(e=>{let{x:t,y:n}=k(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=_t(n,e)+t,i=function(e,t){e[0]+=e[0]-t[0]>180?-360:t[0]-e[0]>180?360:0;let n=se,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=vt(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]=O(e[0],this.coordinatePrecision),e[1]=O(e[1],this.coordinatePrecision)});let c={featureId:t,coordinateMutations:{type:I,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)}},Nt=class extends j{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 Pt({coordinates:e,originX:t,originY:n,xScale:r,yScale:i}){r===1&&i===1||e.forEach(e=>{let{x:a,y:o}=k(e[0],e[1]),{lng:s,lat:c}=A(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}var Ft=class extends j{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.centerOrigin=null,this.oppositeOrigin=null,this.oppositeClosestBBoxIndex=null,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===null||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=this.centerOrigin??jt(n);if(!o||!Number.isFinite(o.x)||!Number.isFinite(o.y))return null;this.centerOrigin=o;let s=k(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=k(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o})}centerFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=this.centerOrigin??jt(n);if(!o||!Number.isFinite(o.x)||!Number.isFinite(o.y))return null;this.centerOrigin=o;let s=k(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=k(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o})}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=V(t,r)/V(t,n);return Number.isFinite(a)?(a{let{x:a,y:o}=k(e[0],e[1]),{lng:s,lat:c}=A(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}=k(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 Re(e),this.clickBoundingBox=new Le(e),this.featuresAtMouseEvent=new Et(e,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Ct(e,this.mutateFeature),this.coordinatePoints=new B(e,this.readFeature,this.mutateFeature),this.midPoints=new St(e,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new ze(e,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new Xe(e,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new Mt(e,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new Dt(e,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new Ot(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new Ft(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new Nt(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(w)}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(w)}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})}}},zt=class extends b{constructor(...e){super(...e),this.type=y.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 Bt(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);Bt(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(Vt(e,n,t),i(e[r],a)>0&&Vt(e,n,r);o0;)s--}i(e[n],a)===0?Vt(e,n,s):(s++,Vt(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}}function Vt(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function G(e,t){Ht(e,0,e.children.length,t,e)}function Ht(e,t,n,r,i){i||=K([]),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 K(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Zt(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;Bt(e,o,t,n,i),a.push(t,o,o,n)}}var Qt=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(!Xt(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=K(n.children.splice(a,n.children.length-a));o.height=n.height,o.leaf=n.leaf,G(n,this.toBBox),G(o,this.toBBox),t?e[t-1].children.push(o):this._splitRoot(n,o)}_splitRoot(e,t){this.data=K([e,t]),this.data.height=e.height+1,this.data.leaf=!1,G(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=Ht(e,0,o,this.toBBox),s=Ht(e,o,n,this.toBBox),c=Jt(t,s),l=Kt(t)+Kt(s);c=t;r--){let t=e.children[r];Ut(o,e.leaf?i(t):t),s+=qt(o)}return s}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)Ut(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():G(e[n],this.toBBox)}},$t=class{constructor(e){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Qt(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))}},en={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},tn={target:`geometry`},nn={target:`properties`},rn=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 $t,this.tracked=!e||!1!==e.tracked,this.idStrategy=e&&e.idStrategy?e.idStrategy:en}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(!p(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(!p(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,nn):nn)}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,tn):tn)}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}},q=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}},an={__proto__:null,GeoJSONStore:rn,TerraDrawBaseDrawMode:b,TerraDrawBaseSelectMode:re,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:O(r,this._coordinatePrecision),lat:O(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 q({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 q({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=V(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 q({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 q({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 q({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 q({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 on(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(!on(t))return!1}return typeof e==`object`&&Object.keys(e).every(t=>typeof t==`string`&&on(e[t]))}var sn=`push`,J=`mode`,cn=`session`,ln=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()?J:this.hasSessionUndo()?cn:(t=this.modeLevel)!=null&&t.canUndo()?J:void 0}activeStackForRedo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canRedo()?J:this.hasSessionRedo()?cn:(t=this.modeLevel)!=null&&t.canRedo()?J:void 0}canUndo(){return this.activeStackForUndo()!==void 0}canRedo(){return this.activeStackForRedo()!==void 0}undo(){let e=this.activeStackForUndo();return!!e&&(e===J?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){let e=this.activeStackForRedo();return!!e&&(e===J?!!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:sn,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:cn}):this.modeLevel&&this.emitStackHistoryChange({cause:sn,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:J})}},un=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 zt;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===y.Select&&this._instanceSelectModes.push(e)}),this._modes=e({},u,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new rn({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())},m=(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())},h=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())},g=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:m,onSelect:h,onDeselect:g,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 ln({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=Ie({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 V(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&&!on(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}=k(t.origin[0],t.origin[1]);Pt({coordinates:o,originX:e,originY:n,xScale:t.options.xScale||1,yScale:t.options.yScale||1})}else t.type===`rotate`&&(r=At(r,t.options.angle||0),o=r.geometry.type===`Polygon`?r.geometry.coordinates[0]:r.geometry.coordinates);if(o=o.map(e=>[O(e[0],this._adapter.getCoordinatePrecision()),O(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(f(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(f(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 dn(){return dn=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 dn({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()}},pn=[`#E74C3C`,`#FF0066`,`#9B59B6`,`#673AB7`,`#3F51B5`,`#3498DB`,`#03A9F4`,`#00BCD4`,`#009688`,`#27AE60`,`#8BC34A`,`#CDDC39`,`#F1C40F`,`#FFC107`,`#F39C12`,`#FF5722`,`#795548`],Y=()=>pn[Math.floor(Math.random()*pn.length)];function mn(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 hn(){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=()=>{gn(t);let n=e[t];X&&(n===`static`?(X.clear(),X.setMode(`static`)):n&&X.setMode(n))})}}function gn(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 _n(){gn(`point-mode`)}var vn,X,Z=[],yn=[],Q=null,bn=!1,$=!1,xn;async function Sn(){try{let{Map:e}=await google.maps.importLibrary(`maps`);vn=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}),vn.addListener(`click`,()=>{X&&console.log(`Current draw mode on map click:`,X.getMode())}),vn.addListener(`projection_changed`,()=>{X=new un({adapter:new fn({map:vn,lib:google.maps,coordinatePrecision:9}),modes:[new Rt({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 ut({editable:!0,styles:{pointColor:Y()}}),new rt({editable:!0,styles:{lineStringColor:Y()}}),new pt({editable:!0,styles:(()=>{let e=Y();return{fillColor:e,outlineColor:e}})()}),new gt({styles:(()=>{let e=Y();return{fillColor:e,outlineColor:e}})()}),new je({styles:(()=>{let e=Y();return{fillColor:e,outlineColor:e}})()}),new Fe({styles:(()=>{let e=Y();return{fillColor:e,outlineColor:e}})()})]}),X.start(),X.on(`ready`,()=>{console.log(`TerraDraw is ready!`),_n(),hn(),X.setMode(`point`),gn(`point-mode`),X.on(`select`,e=>{Q&&Q!==e&&X.deselectFeature(Q),Q=e}),X.on(`deselect`,()=>{Q=null}),Z.push(mn(X.getSnapshot())),X.on(`change`,()=>{bn||(xn&&clearTimeout(xn),xn=window.setTimeout(()=>{let e=mn(X.getSnapshot()).filter(e=>!e.properties.midPoint&&!e.properties.selectionPoint);Z.push(e),yn=[]},200))});let e=document.getElementById(`export-button`);e&&(e.onclick=()=>{let e={type:`FeatureCollection`,features:X.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`?X.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),X.updateModeOptions(`select`,{flags:e})});let i=document.getElementById(`delete-selected-button`);i&&(i.onclick=()=>{if(Q)X.removeFeatures([Q]);else{let e=X.getSnapshot();if(e.length>0){let t=e[e.length-1];t.id&&X.removeFeatures([t.id])}}});let a=document.getElementById(`undo-button`);a&&(a.onclick=()=>{if(Z.length>1){let e=Z.pop();e&&yn.push(e);let t=Z[Z.length-1];console.log(`Restoring snapshot (undo):`,t),bn=!0,X.clear(),X.addFeatures(t),setTimeout(()=>{bn=!1},0)}});let o=document.getElementById(`redo-button`);o&&(o.onclick=()=>{if(yn.length>0){let e=yn.pop();console.log(`Restoring snapshot (redo):`,e),Z.push(e),bn=!0,X.clear(),X.addFeatures(e),setTimeout(()=>{bn=!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`&&Q){let t=X.getSnapshot().find(e=>e.id===Q);if(t){let n=e(t,15);X.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/index.html b/dist/samples/map-drawing-terradraw/dist/index.html index 8ac91de9a..88af26fdc 100644 --- a/dist/samples/map-drawing-terradraw/dist/index.html +++ b/dist/samples/map-drawing-terradraw/dist/index.html @@ -14,7 +14,7 @@ key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8" }); - +