1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[73887],{71593:(t,e,i)=>{function o(){return(o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)({}).hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t}).apply(null,arguments)}i.r(e),i.d(e,{TerraDraw:()=>ii,TerraDrawAngledRectangleMode:()=>eT,TerraDrawCircleMode:()=>Y,TerraDrawExtend:()=>eK,TerraDrawFreehandLineStringMode:()=>eq,TerraDrawFreehandMode:()=>Q,TerraDrawLineStringMode:()=>tE,TerraDrawMarkerMode:()=>eJ,TerraDrawModeUndoRedo:()=>e5,TerraDrawPointMode:()=>tW,TerraDrawPolyLineMode:()=>tk,TerraDrawPolygonMode:()=>tB,TerraDrawRectangleMode:()=>tG,TerraDrawRenderMode:()=>tV,TerraDrawSectorMode:()=>eW,TerraDrawSelectMode:()=>ee,TerraDrawSensorMode:()=>eB,TerraDrawSessionUndoRedo:()=>it,TerraDrawUndoRedoKeyboardShortcuts:()=>e3,ValidateMaxAreaSquareMeters:()=>eM,ValidateMinAreaSquareMeters:()=>eO,ValidateNotSelfIntersecting:()=>eD,ValidationReasons:()=>eY});let r="draw",n="edit",s="deleteCoordinate",a="insertMidpoint";(eH=eV||(eV={})).Commit="commit",eH.Provisional="provisional",eH.Finish="finish";let d="https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png",h={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},l={MODE:"mode",CURRENTLY_DRAWING:"currentlyDrawing",EDITED:"edited",CLOSING_POINT:"closingPoint",SNAPPING_POINT:"snappingPoint",COORDINATE_POINT:"coordinatePoint",COORDINATE_POINT_FEATURE_ID:"coordinatePointFeatureId",COORDINATE_POINT_IDS:"coordinatePointIds",PROVISIONAL_COORDINATE_COUNT:"provisionalCoordinateCount",COMMITTED_COORDINATE_COUNT:"committedCoordinateCount",MARKER:"marker"};function u(t){return!!(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function c(t){return!!(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function p(t){return!!("number"==typeof t&&!isNaN(new Date(t).valueOf()))}let g="Feature is not a Polygon",y="Feature mode property does not match the mode being added to";(eG=ej||(ej={})).Drawing="drawing",eG.Select="select",eG.Static="static",eG.Render="render";let m={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0};class f{get state(){return this._state}set state(t){throw Error("Please use the modes lifecycle methods")}get styles(){return this._styles}set styles(t){if("object"!=typeof t)throw Error("Styling must be an object");this.onStyleChange&&this.onStyleChange([],"styling"),this._styles=t}registerBehaviors(t){}constructor(t,e=!1){this._state="unregistered",this._styles={},this.pointerEvents=m,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=ej.Drawing,this.mode="base",e?this.isInitialUpdate=!0:this.updateOptions(o({},t))}updateOptions(t){null!=t&&t.styles&&(this.styles=o({},this._styles,t.styles)),void 0!==(null==t?void 0:t.pointerDistance)&&(this.pointerDistance=t.pointerDistance),null!=t&&t.validation&&(this.validate=t&&t.validation),null!=t&&t.projection&&(this.projection=t.projection),void 0!==(null==t?void 0:t.pointerEvents)&&(this.pointerEvents=t.pointerEvents),null!=t&&t.modeName&&!0===this.isInitialUpdate&&(this.mode=t.modeName),this.isInitialUpdate=!1}allowPointerEvent(t,e){return"boolean"==typeof t?t:"function"!=typeof t||t(e)}setDrawing(){if("started"!==this._state)throw Error("Mode must be unregistered or stopped to start");this._state="drawing"}setStarted(){if("stopped"!==this._state&&"registered"!==this._state&&"drawing"!==this._state&&"selecting"!==this._state)throw Error("Mode must be unregistered or stopped to start");this._state="started",this.setDoubleClickToZoom(!1)}setStopped(){if("started"!==this._state)throw Error("Mode must be started to be stopped");this._state="stopped",this.setDoubleClickToZoom(!0)}register(t){if("unregistered"!==this._state)throw Error("Can not register unless mode is unregistered");this._state="registered",this.store=t.store,this.store.registerOnChange(t.onChange),this.setDoubleClickToZoom=t.setDoubleClickToZoom,this.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.onFinish=t.onFinish,this.coordinatePrecision=t.coordinatePrecision,this.undoRedoMaxStackSize=t.undoRedoMaxStackSize,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:t.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:t.undoRedoMaxStackSize})}
1validateFeature(t){return this.performFeatureValidation(t)}afterFeatureAdded(t){}afterFeatureUpdated(t){}performFeatureValidation(t){if("unregistered"===this._state)throw Error("Mode must be registered");let e=function(t,e){let i;if(u(t))if(null==t.id)i="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)i="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(u(t.geometry))if(u(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)return{valid:!1,reason:"Feature does not have a valid mode property"}}else i="Feature coordinates is not an array";else i="Feature is not Point, LineString or Polygon";else i="Feature has no properties";else i="Feature has no geometry";else i="Feature must match the id strategy (default is UUID4)";else i="Feature is not object";return i?{valid:!1,reason:i}:{valid:!0}}(t,this.store.idStrategy.isValidId);if(!e.valid)return e;if(this.validate){let i=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:eV.Provisional});return{valid:e.valid&&i.valid,reason:i.reason}}return{valid:e.valid,reason:e.reason}}validateModeFeature(t,e){let i=this.performFeatureValidation(t);return i.valid?t.properties.mode!==this.mode?{valid:!1,reason:y}:e(t):{valid:!1,reason:i.reason}}onFinish(t,e){}onDeselect(t){}onSelect(t){}onKeyDown(t){}onKeyUp(t){}undo(){}clearHistory(){}undoSize(){return 0}redoSize(){return 0}redo(){}onMouseMove(t){}onClick(t){}onDragStart(t,e){}onDrag(t,e){}onDragEnd(t,e){}getHexColorStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getNumericStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getUrlStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getDashArrayStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getStylingValue(t,e,i){var o;return void 0===t?e:"function"==typeof t?null!=(o=t(i))?o:e:t}}class v extends f{constructor(...t){super(...t),this.type=ej.Select}}function C(t,e){let i=t=>t*Math.PI/180,o=i(t[1]),r=i(t[0]),n=i(e[1]),s=n-o,a=i(e[0])-r,d=Math.sin(s/2)*Math.sin(s/2)+Math.cos(o)*Math.cos(n)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371e3/1e3}function P(t){return t%360*Math.PI/180}function I(t){return t%(2*Math.PI)*180/Math.PI}function S(t,e=9){let i=Math.pow(10,e);return Math.round(t*i)/i}let F=(t,e)=>({x:0===t?0:.017453292519943295*t*6378137,y:0===e?0:6378137*Math.log(Math.tan(Math.PI/4+.017453292519943295*e/2))}),x=(t,e)=>({lng:0===t?0:t/6378137*57.29577951308232,lat:0===e?0:(2*Math.atan(Math.exp(e/6378137))-Math.PI/2)*57.29577951308232});function O(t){let{center:e,radiusKilometers:i,coordinatePrecision:o}=t,r=t.steps?t.steps:64,n=[];for(let t=0;t<r;t++){let s=function(t,e,i){let o=P(t[0]),r=P(t[1]),n=P(i),s=e/6371.0088,a=Math.asin(Math.sin(r)*Math.cos(s)+Math.cos(r)*Math.sin(s)*Math.cos(n));return[I(o+Math.atan2(Math.sin(n)*Math.sin(s)*Math.cos(r),Math.cos(s)-Math.sin(r)*Math.sin(a))),I(a)]}(e,i,-360*t/r);n.push([S(s[0],o),S(s[1],o)])}return n.push(n[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[n]},properties:{}}}function M(t){let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}let i=[];for(let t=0;t<e.length;t++)for(let o=0;o<e[t].length-1;o++)for(let r=0;r<e.length;r++)for(let n=0;n<e[r].length-1;n++)!function(t,o,r,n){let s,a,d=e[t][o],h=e[t][o+1],l=e[r][n],u=e[r][n+1],c=function(t,e,i,o){if(E(t,i)||E(t,o)||E(e,i)||E(o,i))return null;let r=t[0],n=t[1],s=e[0],a=e[1],d=i[0],h=i[1],l=o[0],u=o[1],c=(r-s)*(h-u)-(n-a)*(d-l);return 0===c?null:[((r*a-n*s)*(d-l)-(r-s)*(d*u-h*l))/c,((r*a-n*s)*(h-u)-(n-a)*(d*u-h*l))/c]}(d,h,l,u);if(null!==c){var p;s=h[0]!==d[0]?(c[0]-d[0])/(h[0]-d[0]):(c[1]-d[1])/(h[1]-d[1]),a=u[0]!==l[0]?(c[0]-l[0])/(u[0]-l[0]):(c[1]-l[1])/(u[1]-l[1]),s<0||s>1||(p=a)<0||p>1||(c.toString(),i.push(c))}}(t,o,r,n);return i.length>0}function E(t,e){return t[0]===e[0]&&t[1]===e[1]}function w(t,e){return k(t[0])<=e&&k(t[1])<=e}function D(t){var e,i;return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&1/0!==t[0]&&1/0!==t[1]&&(i=t[0])>=-180&&i<=180&&(e=t[1])>=-90&&e<=90}function k(t){let e=1,i=0;for(;Math.round(t*e)/e!==t;)e*=10,i++;return i}let _="Feature has holes",b="Feature has less than 4 coordinates",T="Feature has invali
1d coordinates",N="Feature coordinates are not closed";function R(t,e){var i,o;if("Polygon"!==t.geometry.type)return{valid:!1,reason:"Feature is not a Polygon"};if(1!==t.geometry.coordinates.length)return{valid:!1,reason:_};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:b};for(let i=0;i<t.geometry.coordinates[0].length;i++){if(!D(t.geometry.coordinates[0][i]))return{valid:!1,reason:T};if(!w(t.geometry.coordinates[0][i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return(i=t.geometry.coordinates[0][0])[0]!==(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||i[1]!==o[1]?{valid:!1,reason:N}:{valid:!0}}function L(t,e){let i=R(t,e);return i.valid?M(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}class W{constructor({store:t,mode:e,project:i,unproject:o,pointerDistance:r,coordinatePrecision:n,projection:s,undoRedoMaxStackSize:a}){this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.undoRedoMaxStackSize=void 0,this.store=t,this.mode=e,this.project=i,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=n,this.projection=s,this.undoRedoMaxStackSize=a}}function U(t){if(!function(t){let e=t.coordinates[0],i=0;for(let t=0;t<e.length-1;t++){let[o,r]=e[t],[n,s]=e[t+1];i+=(n-o)*(s+r)}return i<0}(t))return{type:"Polygon",coordinates:[t.coordinates[0].reverse()]}}let A="insert-before",B="insert-after",z="update",H="delete",G="replace";class V extends W{constructor(t,e){super(t),this.options=void 0,this.options=e}createPoint({coordinates:t,properties:e,context:i}){if((null==i?void 0:i.updateType)!==eV.Finish||this.validateGeometryWithUpdateType({geometry:{type:"Point",coordinates:t},properties:e,updateType:eV.Finish}))return this.handleCreateFeature({geometry:{type:"Point",coordinates:t},properties:e})}createLineString({coordinates:t,properties:e}){return this.handleCreateFeature({geometry:{type:"LineString",coordinates:t},properties:e})}createPolygon({coordinates:t,properties:e,context:i}){let o=U({type:"Polygon",coordinates:[t]}),r={type:"Polygon",coordinates:o?o.coordinates:[t]};if((null==i?void 0:i.updateType)!==eV.Finish||this.validateGeometryWithUpdateType({geometry:r,properties:e,updateType:eV.Finish}))return this.handleCreateFeature({geometry:r,properties:e})}createGuidancePoint({coordinate:t,type:e}){return this.createGuidancePoints({coordinates:[t],type:e})[0]}createGuidancePoints({coordinates:t,type:e,additionalProperties:i}){let r=t.map((t,r)=>({type:"Feature",geometry:{type:"Point",coordinates:t},properties:o({mode:this.mode,[e]:!0},i?i(r):{})}));return this.createFeatures(r)}updatePoint({featureId:t,coordinateMutations:e,propertyMutations:i,context:o}){return this.handleMutateFeature({type:"Point",featureId:t,coordinateMutations:e,propertyMutations:i,context:o})}updatePolygon({featureId:t,coordinateMutations:e,context:i,propertyMutations:o}){return this.handleMutateFeature({type:"Polygon",featureId:t,coordinateMutations:e,propertyMutations:o,context:i})}updateLineString({featureId:t,coordinateMutations:e,context:i,propertyMutations:o}){return this.handleMutateFeature({type:"LineString",featureId:t,coordinateMutations:e,propertyMutations:o,context:i})}deleteFeatureIfPresent(t){t&&this.store.has(t)&&this.store.delete([t])}deleteFeaturesIfPresent(t){if(0===t.length)return;let e=t.filter(t=>this.store.has(t));e.length&&this.store.delete(e)}setDeselected(t){let e=t.filter(t=>this.store.has(t)).map(t=>({featureId:t,properties:{[h.SELECTED]:!1}}));this.updateFeatureProperties(e)}setSelected(t){let{type:e}=this.store.getGeometryCopy(t),i={featureId:t,propertyMutations:{[h.SELECTED]:!0},context:{updateType:eV.Commit}};"Polygon"===e?this.updatePolygon(i):"LineString"===e?this.updateLineString(i):"Point"===e&&this.updatePoint(i)}updateGuidancePoints(t){this.updateFeatureGeometries(t.map(({featureId:t,coordinate:e})=>({id:t,geometry:{type:"Point",coordinates:e}})))}handleCreateFeature({geometry:t,properties:e}){return this.createFeatureWithGeometry({geometry:t,properties:e})}
1handleMutateFeature({type:t,featureId:e,coordinateMutations:i,propertyMutations:r,context:n}){if(!this.mutateFeature({type:t,featureId:e,coordinateMutations:i,propertyMutations:r,context:n.updateType===eV.Finish?o({},n,{correctRightHandRule:!0}):o({},n)}))return null;let s=this.buildFeatureWithGeometry(e);return n.updateType!==eV.Finish||i||this.validateGeometryWithUpdateType({geometry:s.geometry,properties:s.properties,updateType:n.updateType})?s:null}mutateFeature({type:t,featureId:e,coordinateMutations:i,propertyMutations:o,context:r}){if(!e)return!1;let n=this.store.getGeometryCopy(e),s=this.store.getPropertiesCopy(e);if(n.type!==t)throw Error(`${t} geometries cannot be updated on features with ${n.type} geometries`);if(i){let t=this.applyCoordinateMutations(n,i);if(r.correctRightHandRule&&"Polygon"===t.type){let e=U(t);e&&(t=e)}if(!this.validateGeometryWithUpdateType({geometry:t,properties:s,updateType:r.updateType}))return!1;this.updateFeatureGeometries([{id:e,geometry:t}])}return o&&this.updateFeatureProperties([{featureId:e,properties:o}]),!0}applyCoordinateMutations(t,e){if(this.isReplaceMutation(e))return o({},t,{coordinates:e.coordinates});if("Point"===t.type)throw Error("Coordinate mutations are not supported for Point geometries");let i="Polygon"===t.type,r=i?t.coordinates[0].slice():t.coordinates.slice(),n=r.length,s=t=>{let e=t<0?n+t:t;if(e<0||e>=n)throw RangeError(`Index ${t} (normalized to ${e}) is out of bounds`);return e},a=Array(n).fill(void 0),d=Array.from({length:n},()=>[]),h=Array.from({length:n},()=>[]),l=[];for(let t of e){if(t.type===A||t.type===B){let e=t.index,i=e<0?n+e:e;if(i<0||i>n)throw RangeError(`Index ${t.index} (normalized to ${i}) is out of bounds`);if(t.type===A){if(i>=n)throw RangeError(`INSERT_BEFORE index ${t.index} (normalized to ${i}) is out of bounds for length ${n}`);d[i].push(t)}else i===n?l.push(t):h[i].push(t);continue}let e=s(t.index);a[e]=o({},t,{index:e})}let u=[];for(let t=0;t<n;t++){for(let e of d[t])u.push(e.coordinate);let e=a[t];for(let i of(e?e.type===H||u.push(e.coordinate):u.push(r[t]),h[t]))u.push(i.coordinate)}for(let t of l)u.push(t.coordinate);return o({},t,i?{coordinates:[u,...t.coordinates.slice(1)]}:{coordinates:u})}isReplaceMutation(t){return t.type===G}createFeatureWithGeometry({geometry:t,properties:e}){let[i]=this.createFeatures([{type:"Feature",geometry:t,properties:e}]);return{id:i,type:"Feature",properties:this.store.getPropertiesCopy(i),geometry:this.store.getGeometryCopy(i)}}validateGeometryWithUpdateType({geometry:t,properties:e,updateType:i}){return!this.options.validate||this.options.validate({type:"Feature",geometry:t,properties:e||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid}buildFeatureWithGeometry(t){return{id:t,type:"Feature",properties:this.store.getPropertiesCopy(t),geometry:this.store.getGeometryCopy(t)}}createFeatures(t){return this.store.create(t)}updateFeatureGeometries(t){this.store.updateGeometry(t)}updateFeatureProperties(t){let e=t.map(({featureId:t,properties:e})=>Object.entries(e).map(([e,i])=>({id:t,property:e,value:i}))).flat();this.store.updateProperty(e)}}let j={cancel:"Escape",finish:"Enter"},K={start:"crosshair"};class Y extends f{constructor(t){super(t,!0),this.mode="circle",this.center=void 0,this.endPosition=void 0,this.segments=64,this.currentCircleId=void 0,this.keyEvents=j,this.cursors=K,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1,this.drawInteraction="click-move",this.drawType=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.startingRadiusKilometers&&(this.startingRadiusKilometers=t.startingRadiusKilometers),null!=t&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction),null!=t&&t.segments&&(this.segments=t.segments<3?3:t.segments)}close(){if(void 0===this.currentCircleId||void 0===this.endPosition||!this.updateCircle(this.endPosition,eV.Finish))return;let t=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}beginDrawing(t,e="click"){this.center=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];
vendor: 2,142 bytes, line 1
1let i=O({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.mutateFeature.createPolygon({coordinates:i.geometry.coordinates[0],properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers,[l.CURRENTLY_DRAWING]:!0}});o&&(this.currentCircleId=o.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=e,this.setDrawing())}dragDrawAllowed(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction}moveDrawAllowed(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.center?this.center&&void 0!==this.currentCircleId&&(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))}onMouseMove(t){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,eV.Provisional)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,eV.Provisional))}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))}cleanUp(){let t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)}
1styleFeature(t){let e=o({},{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"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e}validateFeature(t){return this.validateModeFeature(t,t=>L(t,this.coordinatePrecision))}updateCircle(t,e){let i,o;if(void 0===this.currentCircleId||void 0===this.center)return;let n=e===eV.Finish;if(this.cursorMovedAfterInitialCursorDown)if(o=C(this.center,t),"web-mercator"===this.projection){let e=function(t,e){let i=1e3*C(t,e);if(0===i)return 1;let{x:o,y:r}=F(t[0],t[1]),{x:n,y:s}=F(e[0],e[1]);return Math.sqrt(Math.pow(n-o,2)+Math.pow(s-r,2))/i}(this.center,t);i=function(t){let{center:e,radiusKilometers:i,coordinatePrecision:o}=t,r=t.steps?t.steps:64,n=1e3*i,[s,a]=e,{x:d,y:h}=F(s,a),l=[];for(let t=0;t<r;t++){let e=360*t/r*Math.PI/180,[i,s]=[d+n*Math.cos(e),h+n*Math.sin(e)],{lng:a,lat:u}=x(i,s);l.push([S(a,o),S(u,o)])}return l.push(l[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[l]},properties:{}}}({center:this.center,radiusKilometers:o*e,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}else{if("globe"!==this.projection)throw Error("Invalid projection");i=O({center:this.center,radiusKilometers:o,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}let s={};return i&&o&&(s.radiusKilometers=o),n&&(s[l.CURRENTLY_DRAWING]=void 0),this.mutateFeature.updatePolygon({featureId:this.currentCircleId,coordinateMutations:i?{type:G,coordinates:i.geometry.coordinates}:void 0,propertyMutations:s,context:n?{updateType:e,action:r}:{updateType:e}})}afterFeatureUpdated(t){this.currentCircleId===t.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())}registerBehaviors(t){this.mutateFeature=new V(t,{validate:this.validate})}}let X=(t,e)=>{let{x:i,y:o}=t,{x:r,y:n}=e,s=r-i,a=n-o;return Math.sqrt(a*a+s*s)};function $(t,e){return t[0]===e[0]&&t[1]===e[1]}class q extends W{constructor(t){super(t)}getGeometryType(t){return this.store.getGeometryCopy(t).type}coordinateAtIndexIsIdentical({featureId:t,newCoordinate:e,index:i}){let o,r=this.store.getGeometryCopy(t);if("Polygon"===r.type)o=r.coordinates[0][i];else if("LineString"===r.type)o=r.coordinates[i];else{if(0!==i)throw Error("Point geometries only have one coordinate at index 0");o=r.coordinates}return $(e,o)}getGeometry(t){return this.store.getGeometryCopy(t)}getCoordinates(t){let{type:e,coordinates:i}=this.store.getGeometryCopy(t);return"Polygon"===e?i[0]:i}getCoordinate(t,e){let i=this.getCoordinates(t),o=e<0?i.length+e:e;if(o<0||o>=i.length)throw RangeError(`Index ${e} (normalized to ${o}) is out of bounds`);return i[o]}getProperties(t){return this.store.getPropertiesCopy(t)}hasFeature(t){return this.store.has(t)}getAllFeatureIdsWhere(t){return this.store.copyAllWhere(t).map(({id:t})=>t)}}let Z={cancel:"Escape",finish:"Enter"},J={start:"crosshair",close:"pointer"};class Q extends f{constructor(t){super(t,!0),this.mode="freehand",this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=20,this.keyEvents=Z,this.cursors=J,this.preventPointsNearClose=!0,this.autoClose=!1,this.autoCloseTimeout=500,this.hasLeftStartingPoint=!1,this.preventNewFeature=!1,this.drawInteraction="click-move",this.drawType=void 0,this.smoothing=0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.minDistance&&(this.minDistance=t.minDistance),void 0!==(null==t?void 0:t.smoothing)&&(this.smoothing=Math.min(Math.max(t.smoothing,0),.999)),void 0!==(null==t?void 0:t.preventPointsNearClose)&&(this.preventPointsNearClose=t.preventPointsNearClose),void 0!==(null==t?void 0:t.autoClose)&&(this.autoClose=t.autoClose),null!=t&&t.autoCloseTimeout&&(this.autoCloseTimeout=t.autoCloseTimeout),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null!=t&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction)}moveDrawAllowed(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction}dragDrawAllowed(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction}beginDrawing(t,e="click"){let{id:i}=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});this.currentId=i,this.drawType=e,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[t.lng,t.lat],type:l.CLOSING_POINT}
1),this.canClose=!0,"drawing"!==this.state&&this.setDrawing()}addCoordinate(t){if(void 0===this.currentId||!1===this.canClose)return void this.setCursor(this.cursors.start);let[e,i]=this.readFeature.getCoordinate(this.currentId,-2),{x:o,y:r}=this.project(e,i),n=X({x:o,y:r},{x:t.containerX,y:t.containerY}),[s,a]=this.readFeature.getCoordinate(this.currentId,0),{x:d,y:h}=this.project(s,a);if(X({x:d,y:h},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(()=>{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(n<this.minDistance)return;let l=this.getSmoothedCoordinate([e,i],[t.lng,t.lat]);this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:A,index:-1,coordinate:l}],context:{updateType:eV.Provisional}})}getSmoothedCoordinate(t,e){if(0===this.smoothing)return e;let[i,o]=t,[r,n]=e;return[i*this.smoothing+r*(1-this.smoothing),o*this.smoothing+n*(1-this.smoothing)]}close(){if(void 0===this.currentId||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[l.CURRENTLY_DRAWING]:void 0},context:{updateType:eV.Finish,action:r}}))return;let t=this.currentId;this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){this.moveDrawAllowed()&&"click"===this.drawType&&this.addCoordinate(t)}onClick(t){if(this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&!this.preventNewFeature){if(!1===this.canClose)return void this.beginDrawing(t);this.close()}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()}onDragStart(t,e){"drawing"!==this.state&&(this.preventNewFeature||this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1)))}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&this.addCoordinate(t)}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.preventNewFeature=!0,setTimeout(()=>{this.preventNewFeature=!1},this.autoCloseTimeout),this.close(),e(!0))}cleanUp(){let t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e)}
1styleFeature(t){let e=o({},{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"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.zIndex=50),e}validateFeature(t){return this.validateModeFeature(t,t=>R(t,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate})}}function tt({unproject:t,point:e,pointerDistance:i}){let o=i/2,{x:r,y:n}=e;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[t(r-o,n-o),t(r+o,n-o),t(r+o,n+o),t(r-o,n+o),t(r-o,n-o)].map(t=>[t.lng,t.lat])]}}}class te extends W{constructor(t){super(t)}create(t){let{containerX:e,containerY:i}=t;return tt({unproject:this.unproject,point:{x:e,y:i},pointerDistance:this.pointerDistance})}}class ti extends W{constructor(t){super(t)}measure(t,e){let{x:i,y:o}=this.project(e[0],e[1]);return X({x:i,y:o},{x:t.containerX,y:t.containerY})}}class to extends W{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappableCoordinateFirstClick(t){return this.getSnappable(t,t=>!!(t.properties&&t.properties.mode===this.mode)).coordinate}getSnappableCoordinate(t,e){return this.getSnappable(t,t=>!!(t.properties&&t.properties.mode===this.mode&&t.id!==e)).coordinate}getSnappable(t,e){let i=this.clickBoundingBox.create(t),o=this.store.search(i,e),r={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return o.forEach(e=>{let i;if("Polygon"===e.geometry.type)i=e.geometry.coordinates[0];else if("LineString"===e.geometry.type)i=e.geometry.coordinates;else{var o,n,s,a,d,u;if("Point"!==e.geometry.type||null!=(o=e.properties)&&o[l.EDITED]||null!=(n=e.properties)&&n[l.CLOSING_POINT]||null!=(s=e.properties)&&s[l.SNAPPING_POINT]||null!=(a=e.properties)&&a[l.COORDINATE_POINT]||null!=(d=e.properties)&&d[h.SELECTION_POINT]||null!=(u=e.properties)&&u[h.MID_POINT])return;i=[e.geometry.coordinates]}i.forEach((i,o)=>{let n=this.pixelDistance.measure(t,i);n<r.minDistance&&n<this.pointerDistance&&(r.coordinate=i,r.minDistance=n,r.featureId=e.id,r.featureCoordinateIndex=o)})}),r}}function tr(t,e,i){let o=P(t[0]),r=P(t[1]),n=P(i),s=e/6371.0088,a=Math.asin(Math.sin(r)*Math.cos(s)+Math.cos(r)*Math.sin(s)*Math.cos(n));return[I(o+Math.atan2(Math.sin(n)*Math.sin(s)*Math.cos(r),Math.cos(s)-Math.sin(r)*Math.sin(a))),I(a)]}function tn({x:t,y:e},i,o){let r=P(o);return{x:t+i*Math.cos(r),y:e+i*Math.sin(r)}}function ts(t,e){let i=P(t[0]),o=P(e[0]),r=P(t[1]),n=P(e[1]);return I(Math.atan2(Math.sin(o-i)*Math.cos(n),Math.cos(r)*Math.sin(n)-Math.sin(r)*Math.cos(n)*Math.cos(o-i)))}function ta({x:t,y:e},{x:i,y:o}){let r=i-t,n=o-e;if(0===r&&0===n)return 0;let s=Math.atan2(n,r);return(s*=180/Math.PI)>180?s-=360:s<-180&&(s+=360),s}function td(t){return(t+360)%360}function th(t){return Math.PI/180*t}function tl(t){return 180/Math.PI*t}class tu extends W{constructor(t){super(t),this.config=void 0,this.config=t}generateInsertionCoordinates(t,e,i){let o=[t,e],r=0;for(let t=0;t<o.length-1;t++)r+=C(o[0],o[1]);if(r<=i)return o;let n=r/i-1;Number.isInteger(n)||(n=Math.floor(n)+1);let s=[];for(let t=0;t<n;
1t++){let e=function(t,e,i){let o=[],r=t.length,n,s,a,d=0;for(let r=0;r<t.length&&!(e>=d&&r===t.length-1);r++){if(d>e&&0===o.length){if(!(n=e-d))return o.push(t[r]),o;s=ts(t[r],t[r-1])-180,a=tr(t[r],n,s),o.push(a)}if(d>=i)return(n=i-d)?(s=ts(t[r],t[r-1])-180,a=tr(t[r],n,s),o.push(a)):o.push(t[r]),o;if(d>=e&&o.push(t[r]),r===t.length-1)return o;d+=C(t[r],t[r+1])}if(d<e&&t.length===r)throw Error("Start position is beyond line");let h=t[t.length-1];return[h,h]}(o,i*t,i*(t+1));s.push(e)}let a=[];for(let t=0;t<s.length;t++)a.push(s[t][1]);return this.limitCoordinates(a)}generateInsertionGeodesicCoordinates(t,e,i){let o=C(t,e),r=function(t,e,i){let o=[],r=th(t[1]),n=th(t[0]),s=th(e[1]),a=th(e[0]);i+=1;let d=2*Math.asin(Math.sqrt(Math.sin((s-r)/2)**2+Math.cos(r)*Math.cos(s)*Math.sin((a-n)/2)**2));if(0===d||isNaN(d))return o;for(let t=0;t<=i;t++){let e=t/i,h=Math.sin((1-e)*d)/Math.sin(d),l=Math.sin(e*d)/Math.sin(d),u=h*Math.cos(r)*Math.cos(n)+l*Math.cos(s)*Math.cos(a),c=h*Math.cos(r)*Math.sin(n)+l*Math.cos(s)*Math.sin(a),p=h*Math.sin(r)+l*Math.sin(s);if(isNaN(u)||isNaN(c)||isNaN(p))continue;let g=Math.atan2(p,Math.sqrt(u**2+c**2)),y=Math.atan2(c,u);isNaN(g)||isNaN(y)||o.push([tl(y),tl(g)])}return o.slice(1,-1)}(t,e,Math.floor(o/i));return this.limitCoordinates(r)}limitCoordinates(t){return t.map(t=>[S(t[0],this.config.coordinatePrecision),S(t[1],this.config.coordinatePrecision)])}}function tc(t,e){if("LineString"!==t.geometry.type)return{valid:!1,reason:"Feature is not a LineString"};if(t.geometry.coordinates.length<2)return{valid:!1,reason:"Feature has less than 2 coordinates"};for(let i=0;i<t.geometry.coordinates.length;i++){if(!D(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!w(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function tp(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function tg(t,e){return Math.acos(Math.min(Math.max(function(t,e){let[i,o,r]=t,[n,s,a]=e;return i*n+o*s+r*a}(t,e)/(tp(t)*tp(e)),-1),1))}function ty(t){let e=P(t[1]),i=P(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function tm(t){let[e,i,o]=t,r=I(Math.asin(o));return[I(Math.atan2(i,e)),r]}class tf extends W{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.get
1SnappableCoordinateFirstClick=t=>{let e=this.getSnappable(t,t=>!!(t.properties&&t.properties.mode===this.mode));return e.coordinate?[S(e.coordinate[0],this.config.coordinatePrecision),S(e.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappableCoordinate=(t,e)=>{let i=this.getSnappable(t,t=>!!(t.properties&&t.properties.mode===this.mode&&t.id!==e));return i.coordinate?[S(i.coordinate[0],this.config.coordinatePrecision),S(i.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappable=(t,e)=>{let i=this.clickBoundingBox.create(t),o=this.store.search(i,e),r={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return o.forEach(e=>{let i,o;if("Polygon"===e.geometry.type)i=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;i=e.geometry.coordinates}let n=[];for(let t=0;t<i.length-1;t++)n.push([i[t],i[t+1]]);let s=[t.lng,t.lat];if("web-mercator"===this.config.projection?o=function(t,e){let i=[1/0,1/0],o=1/0,r=0;for(let n of e){let s=n[0],a=n[1],d,h=1/0,l=F(s[0],s[1]),u=F(a[0],a[1]),c=F(t[0],t[1]);if(s[0]===t[0]&&s[1]===t[1])d=s;else if(a[0]===t[0]&&a[1]===t[1])d=a;else{let{x:t,y:e}=function(t,e,i){let o=e.x-t.x,r=e.y-t.y,n=Math.max(0,Math.min(1,((i.x-t.x)*o+(i.y-t.y)*r)/(o*o+r*r)));return{x:t.x+n*o,y:t.y+n*r}}(l,u,c),{lng:i,lat:o}=x(t,e);d=[i,o]}d&&(h=X(c,F(d[0],d[1])))<o&&(i=d,o=h,r=e.indexOf(n))}return 1/0===o?void 0:{coordinate:i,lineIndex:r,distance:o}}(s,n):"globe"===this.config.projection&&(o=function(t,e){let i=[1/0,1/0],o=1/0,r=0;for(let n of e){let s=n[0],a=n[1],d,h=1/0;s[0]===t[0]&&s[1]===t[1]?d=s:a[0]===t[0]&&a[1]===t[1]?d=a:[d]=function(t,e,i){let o,r=ty(t),n=ty(e),[s,a,d]=ty(i),[h,l,u]=function(t,e){let[i,o,r]=t,[n,s,a]=e;return[o*a-r*s,r*n-i*a,i*s-o*n]}
1(r,n),c=l*d-u*a,p=u*s-h*d,g=h*a-l*s,y=g*l-p*u,m=c*u-g*h,f=p*h-c*l,v=1/Math.sqrt(Math.pow(y,2)+Math.pow(m,2)+Math.pow(f,2)),P=[y*v,m*v,f*v],I=[-1*y*v,-1*m*v,-1*f*v],S=tg(r,n),F=tg(r,P),x=tg(n,P),O=tg(r,I),M=tg(n,I);return tg(r,o=F<O&&F<M||x<O&&x<M?P:I)>S||tg(n,o)>S?C(tm(o),tm(r))<=C(tm(o),tm(n))?[tm(r),!0,!1]:[tm(n),!1,!0]:[tm(o),!1,!1]}(s,a,t),d&&(h=C(t,d))<o&&(i=d,o=h,r=e.indexOf(n))}return 1/0===o?void 0:{coordinate:i,distance:o,lineIndex:r}}(s,n)),!o)return;let a=this.pixelDistance.measure(t,o.coordinate);a<r.minDistance&&a<this.pointerDistance&&(r.featureId=e.id,r.coordinate=[S(o.coordinate[0],this.config.coordinatePrecision),S(o.coordinate[1],this.config.coordinatePrecision)],r.featureCoordinateIndex=o.lineIndex,r.minDistance=a)}),r},this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}}class tv{constructor(t,e){this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.coordinateSnapping=t,this.lineSnapping=e}getSnappable(t,e,i,o){let r=!1!==(null==o?void 0:o.toLine),n=t=>(void 0===e||t.id!==e)&&(!i||i(t)),s={coordinate:void 0,featureId:void 0,featureCoordinateIndex:void 0,minDistance:1/0};if(!1!==(null==o?void 0:o.toCoordinate)){let e=this.coordinateSnapping.getSnappable(t,n);e.coordinate&&e.minDistance<s.minDistance&&(s=e)}if(r){let e=this.lineSnapping.getSnappable(t,n);e.coordinate&&e.minDistance<s.minDistance&&(s=e)}return s}}function tC(t){return Array.isArray(t)&&t.length>0&&Array.isArray(t[0])&&Array.isArray(t[0][0])}let tP=t=>tC(t)?t[0].slice(0,-1):t,tI=t=>tC(t)?t[0]:t;class tS extends W{constructor(t,e,i,o){super(t),this.config=void 0,this.pixelDistance=void 0,this.mutateFeatureBehavior=void 0,this.readFeatureBehavior=void 0,this._startEndPoints=[],this.config=t,this.pixelDistance=e,this.mutateFeatureBehavior=i,this.readFeatureBehavior=o}get ids(){return this._startEndPoints.concat()}set ids(t){}create(t){if(this.ids.length)throw Error("Opening and closing points already created");let e=tC(t),i=tI(t);if(e){if(i.length<=3)throw Error("Requires at least 4 coordinates");this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[i[0],i[i.length-2]],type:l.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:i[i.length-2],type:l.CLOSING_POINT})]}delete(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])}updateOne(t,e){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[t],coordinate:e}])}update(t){let e=tI(t);1!==this.ids.length?2===this.ids.length&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[0]},{featureId:this.ids[1],coordinate:e[e.length-3]}]):this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[e.length-2]}])}isLineStringClosingPoint(t){if(1!==this.ids.length)return{isClosing:!1};let e=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(t,e.coordinates)<this.pointerDistance}}isPolygonClosingPoints(t){if(2!==this.ids.length)return{isClosing:!1,isPreviousClosing:!1};let e=this.readFeatureBehavior.getGeometry(this.ids[0]),i=this.readFeatureBehavior.getGeometry(this.ids[1]),o=this.pixelDistance.measure(t,e.coordinates),r=this.pixelDistance.measure(t,i.coordinates);return{isClosing:o<this.pointerDistance,isPreviousClosing:r<this.pointerDistance}}}class tF extends W{constructor(t,e,i){super(t),this.readFeature=void 0,this.mutateFeature=void 0,this.readFeature=e,this.mutateFeature=i}createOrUpdate({featureId:t,featureCoordinates:e}){if(!this.readFeature.hasFeature(t))return void this.deleteOrphanedPoints(t);let i=tP(e),o=this.readFeature.getProperties(t),r=o.coordinatePointIds;if(r)if(r&&r.every(t=>this.readFeature.hasFeature(t))){let e=o.coordinatePointIds,r=e.map(t=>this.readFeature.getGeometry(t).coordinates);if(e.length!==i.length){this.deleteCoordinatePoints(e);let r=this.createPoints(i,o.mode,t);this.setFeatureCoordinatePoints(t,r)}else{let t=[];i.forEach((i,o)=>{i[0]===r[o][0]&&i[1]===r[o][1]||t.push({featureId:e[o],coordinate:i})}),this.mutateFeature.updateGuidancePoints(t)}}else{let e=r.filter(t=>this.readFeature.hasFeature(t));e.length&&this.deleteCoordinatePoints(e);let n=this.createPoints(i,o.mode,t);this.setFeatureCoordinatePoints(t,n)}else{let e=this.createPoints(i,o.mode,t);this.setFeatureCoordinatePoints(t,e)}}deletePointsByFeatureIds(t){for(let e of t)this.deleteIfPresent(e)}updateOneAtIndex(t,e,i){let o=this.readFeature.getProperties(t).coordinatePointIds;o&&0!==o.length&&void 0!==o[e]&&this.mutateFeature.updateGuidancePoints([{featureId:o[e],coordinate:i}])}updateAllInPlace({featureId:t,featureCoordinates:e}){let i=this.readFeature.getProperties(t);if(!i.coordinatePointIds)return;let o=tP(e);o.length===i.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(i.coordinatePointIds.map((t,e)=>({featureId:t,coordinate:o[e]})))}createPoints(t,e,i){return this.mutateFeature.createGuidancePoints({coordinates:t,type:l.COORDINATE_POINT,additionalProperties:t=>({mode:e,[l.COORDINATE_POINT]:!0,[l.COORDINATE_POINT_FEATURE_ID]:i,index:t})})}setFeatureCoordinatePoints(t,e,i=eV.Commit){let o=this.readFeature.getGeometryType(t),r={featureId:t,propertyMutations:{[l.COORDINATE_POINT_IDS]:e},context:{updateType:i}};if("Polygon"===o)this.mutateFeature.updatePolygon(r);else{if("LineString"!==o)throw Error("Unsupported geometry type for coordinate points");this.mutateFeature.updateLineString(r)}}deleteCoordinatePoints(t){this.mutateFeature.deleteFeaturesIfPresent(t)}deleteIfPresent(t){if(!this.readFeature.hasFeature(t))return;let e=this.readFeature.getProperties(t).coordinatePointIds;e&&(this.deleteCoordinatePoints(e),this.setFeatureCoordinatePoints(t,null))}deleteOrphanedPoints(t){let e=this.readFeature.getAllFeatureIdsWhere(e=>e[l.COORDINATE_POINT_FEATURE_ID]===t);this.mutateFeature.deleteFeaturesIfPresent(e)}}class tx{constructor(t){this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=t=>this.cloneRecursively(t);const e=null==t?void 0:t.maxStackSize;this.maxStackSize=void 0!==e&&Number.isFinite(e)?Math.max(0,Math.floor(e)):1/0}setMaxStackSize(t){Number.isFinite(t)?(this.maxStackSize=Math.max(0,Math.floor(t)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)
1):this.maxStackSize=1/0}trimHistoryToMax(t){if(Number.isFinite(this.maxStackSize))for(;t.length>this.maxStackSize;)t.shift()}pushUndoEntry(t){0!==this.maxStackSize&&(this.undoHistory.push(t),this.trimHistoryToMax(this.undoHistory))}pushRedoEntry(t){0!==this.maxStackSize&&(this.redoHistory.push(t),this.trimHistoryToMax(this.redoHistory))}cloneRecursively(t){return Array.isArray(t)?t.map(t=>this.cloneRecursively(t)):null!==t&&"object"==typeof t?o({},t):t}cloneCoordinates(t){return this.cloneCoordinatesFunction(t)}cloneEntry(t){return{featureCoordinates:this.cloneCoordinates(t.featureCoordinates),currentCoordinate:t.currentCoordinate}}clear(){this.undoHistory=[],this.redoHistory=[]}undoSize(){return this.undoHistory.length}redoSize(){return this.redoHistory.length}recordSnapshot(t){this.pushUndoEntry(this.cloneEntry(t)),this.redoHistory=[]}beginUndo(){let t=this.undoHistory.pop();if(!t)return;let e=this.cloneEntry(t);this.pushRedoEntry(e);let i=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:e,previousEntry:i?this.cloneEntry(i):void 0}}takeRedo(){let t=this.redoHistory.pop();if(t)return this.cloneEntry(t)}commitRedo(t){this.pushUndoEntry(this.cloneEntry(t))}}let tO={cancel:"Escape",finish:"Enter"},tM={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"};class tE extends f{constructor(t){super(t,!0),this.mode="linestring",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=tO,this.snapping=void 0,this.cursors=tM,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommittedCoordinates=void 0,this.snappedPointId=void 0,this.lastMouseMoveEvent=void 0,this.showCoordinatePoints=!1,this.finishOnNthCoordinate=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0,this.lineSnapping=void 0,this.featureSnapping=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.closingPoints=void 0,this.coordinatePoints=void 0,this.undoRedo=void 0,this.updateOptions(t)}updateOptions(t){if(super.updateOptions(t),void 0!==(null==t?void 0:t.finishOnNthCoordinate)&&Number.isInteger(t.finishOnNthCoordinate)&&t.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(t.finishOnNthCoordinate)),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null!=t&&t.snapping&&(this.snapping=t.snapping),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.insertCoordinates&&(this.insertCoordinates=t.insertCoordinates),t&&t.editable&&(this.editable=t.editable),void 0!==(null==t?void 0:t.showCoordinatePoints)){if(this.showCoordinatePoints=t.showCoordinatePoints,this.coordinatePoints&&!0===t.showCoordinatePoints)this.store.copyAllWhere(t=>t.mode===this.mode).forEach(t=>{this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let t=this.store.copyAllWhere(t=>{var e;return t.mode===this.mode&&!!(null==(e=t[l.COORDINATE_POINT_IDS])?void 0:e.length)});this.coordinatePoints.deletePointsByFeatureIds(t.map(t=>t.id))}}}shouldFinishOnCommit(t){return!!this.finishOnNthCoordinate&&Math.max(0,t.coordinates.length-1)>=this.finishOnNthCoordinate}updateSnappedCoordinate(t){let e=this.snapCoordinate(t);return e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:l.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),e}close(){if(void 0===this.currentId)return;let t=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:eV.Finish,action:r},coordinateMutations:[{type:H,index:-1}],propertyMutations:{[l.CURRENTLY_DRAWING]:void 0}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates});let e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(e,{mode:this.mode,action:r})}generateInsertCoordinates(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw Error("Strategy does not exist");let i=C(t,e)/(this.insertCoordinates.value+1),o=[];return"globe"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o}createLine(t){let e=this.mutateFeature.createLineString({coordinates:[t,t],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});this.lastCommittedCoordinates=e.geometry.coordinates,this.currentId=e.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates})}firstUpdateToLine(t){if(!this.currentId)return;this.setCursor(this.cursors.close);let e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:eV.Commit}
1,coordinateMutations:[{type:B,index:-1,coordinate:t}]});e&&(this.closingPoints.create(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.lastCommittedCoordinates=e.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(e.geometry)&&this.close())}updateToLine(t,e){if(!this.currentId)return;let{isClosing:i}=this.closingPoints.isLineStringClosingPoint(t);if(i)return void this.close();this.setCursor(this.cursors.close);let o=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:eV.Commit},coordinateMutations:[{type:B,index:-1,coordinate:e}]});o&&(this.closingPoints.update(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.lastCommittedCoordinates=o.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(o.geometry)&&this.close())}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(t,e){let i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}syncClosingPoints(t){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()}undo(){if("drawing"!==this.state||!this.currentId)return;let t=this.undoRedo.beginUndo();if(!t)return;let{previousEntry:e}=t;if(!e){let t=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),void this.updateSnappedGuidancePointFromLastMouseMove()}let i=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:G,coordinates:e.featureCoordinates},propertyMutations:{[l.CURRENTLY_DRAWING]:!0},context:{updateType:eV.Commit}});i&&(this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=i.geometry.coordinates,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let t=this.undoRedo.takeRedo();if(t){if(this.currentId){let e=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:G,coordinates:t.featureCoordinates},propertyMutations:{[l.CURRENTLY_DRAWING]:!0},context:{updateType:eV.Commit}});if(!e)return;this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=e.geometry.coordinates,this.syncClosingPoints(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates})}else{let{id:e,geometry:i}=this.mutateFeature.createLineString({coordinates:t.featureCoordinates,properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});this.currentId=e,this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=i.coordinates,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(i.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:i.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}}registerBehaviors(t){this.insertPoint=new tu(t),this.clickBoundingBox=new te(t),this.pixelDistance=new ti(t),this.lineSnapping=new tf(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new to(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new tv
1(this.coordinateSnapping,this.lineSnapping),this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate}),this.closingPoints=new tS(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new tF(t,this.readFeature,this.mutateFeature),this.undoRedo=new tx({maxStackSize:t.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t;let e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(void 0===this.currentId||0===this.currentCoordinate)return;let{isClosing:i}=this.closingPoints.isLineStringClosingPoint(t);i&&this.setCursor(this.cursors.close);let o=[{type:z,index:-1,coordinate:e}];if(this.insertCoordinates){let t=this.getInsertCoordinates(e);t&&(o={type:G,coordinates:t})}let r=this.mutateFeature.updateLineString({coordinateMutations:o,featureId:this.currentId,context:{updateType:eV.Provisional}});r&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates})}getInsertCoordinates(t){if(!this.lastCommittedCoordinates)return;let e=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if($(e,t))return;let i=this.generateInsertCoordinates(e,t);return[...this.lastCommittedCoordinates.slice(0,-1),...i,t]}onRightClick(t){if(!this.editable||"started"!==this.state)return;let{featureId:e,featureCoordinateIndex:i}=this.coordinateSnapping.getSnappable(t,t=>this.lineStringFilter(t));if(!e||void 0===i)return;let o=this.readFeature.getGeometry(e);if("LineString"!==o.type||o.coordinates.length<=2)return;let r=this.mutateFeature.updateLineString({featureId:e,coordinateMutations:[{type:H,index:i}],context:{updateType:eV.Finish,action:n}});r&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:r.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(e,{mode:this.mode,action:s})}onLeftClick(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);let e=this.snapCoordinate(t)||[t.lng,t.lat];0===this.currentCoordinate?this.createLine(e):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(t,e)}onClick(t){void 0===this.currentId||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button?this.onRightClick(t):"left"===t.button&&this.onLeftClick(t))}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(t,e){let i;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){if("started"===this.state){let e=this.lineSnapping.getSnappable(t,t=>this.lineStringFilter(t));e.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=e.featureCoordinateIndex,this.editedFeatureId=e.featureId,i=e.coordinate);let o=this.coordinateSnapping.getSnappable(t,t=>this.lineStringFilter(t));o.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,i=o.coordinate)}this.editedFeatureId&&i&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:l.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}}onDrag(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){if("coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex){let e=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:eV.Provisional},coordinateMutations:[{type:z,index:this.editedFeatureCoordinateIndex,coordinate:[t.lng,t.lat]}]});if(!e)return;this.showCoordinatePoints&&(void 0!==this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:e.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[t.lng,t.lat]))}else if("line"===this.editedSnapType&&void 0===this.editedInsertIndex){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;let t=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:eV.Provisional}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:t.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[t.lng,t.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:eV.Provisional},propertyMutations:{[l.EDITED]:!0}})}}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||void 0===this.editedFeatureId||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:{[l.EDITED]:!1},context:{updateType:eV.Finish,action:n}})))return;let i=this.editedFeatureId;e(!0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(i,{mode:this.mode,action:n})}cleanUp(){let t=this.currentId,e=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.delete()}
1styleFeature(t){let e=o({},{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("Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode)return e.lineStringDash=this.getDashArrayStylingValue(this.styles.lineStringDash,void 0,t),e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,void 0===e.lineStringOpacity?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=10,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){let i=t.properties[l.COORDINATE_POINT],o=t.properties[l.CLOSING_POINT]?"closingPoint":t.properties[l.SNAPPING_POINT]?"snappingPoint":i?"coordinatePoint":void 0;if(!o)return e;let r={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(r[o].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(r[o].opacity,1,t),e.pointColor=this.getHexColorStylingValue(r[o].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(r[o].outlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(r[o].outlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(r[o].outlineOpacity,1,t),e.zIndex=i?20:50,e}return e}validateFeature(t){return this.validateModeFeature(t,t=>tc(t,this.coordinatePrecision))}lineStringFilter(t){return!!("LineString"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)}snapCoordinate(t){var e,i,o,r;let n;if(null!=(e=this.snapping)&&e.toLine){let e;(e=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(n=e)}if(null!=(i=this.snapping)&&i.toCoordinate){let e;(e=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(n=e)}if(null!=(o=this.snapping)&&o.toCustom){let e=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});e&&(n=e)}if(null!=(r=this.snapping)&&r.toFeature){let e=this.featureSnapping.getSnappable(t,this.currentId,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});e.coordinate&&(n=e.coordinate)}return n}afterFeatureUpdated(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted())}afterFeatureAdded(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})}}let tw={cancel:"Escape",finish:"Enter"},tD={start:"crosshair",close:"pointer"};class tk extends f{constructor(t){super(t,!0),this.mode="polyline",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=tw,this.cursors=tD,this.mouseMove=!1,this.snapping=void 0,this.snappedPointId=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.clickBoundingBox=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.featureSnapping=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null!=t&&t.snapping&&(this.snapping=t.snapping),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents))}registerBehaviors(t){this.clickBoundingBox=new te(t),this.pixelDistance=new ti(t),this.lineSnapping=new tf(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new to(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new tv
1(this.coordinateSnapping,this.lineSnapping),this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate}),this.closingPoints=new tS(t,this.pixelDistance,this.mutateFeature,this.readFeature)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}finishLine(){if(!this.currentId||!this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:eV.Finish,action:r},coordinateMutations:[{type:H,index:-1}],propertyMutations:{[l.CURRENTLY_DRAWING]:void 0}}))return;let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}toPolygonLikeCoordinates(t){return 0===t.length?[t]:[[...t,t[0]]]}closeAsPolygon(){if(!this.currentId)return;let t=this.readFeature.getGeometry(this.currentId).coordinates.slice(0,-1);if(t.length<3)return;let e=this.currentId,i=[...t,t[0]],o=this.mutateFeature.createPolygon({coordinates:i,properties:{mode:this.mode},context:{updateType:eV.Finish,action:r}});o&&(this.mutateFeature.deleteFeatureIfPresent(e),this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(o.id,{mode:this.mode,action:r}))}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.updateSnappedCoordinate(t),!this.currentId||0===this.currentCoordinate||!this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:z,index:-1,coordinate:[t.lng,t.lat]}],context:{updateType:eV.Provisional}}))return;let{isClosing:e,isPreviousClosing:i}=this.closingPoints.isPolygonClosingPoints(t);(e&&this.currentCoordinate>=3||i&&this.currentCoordinate>=2)&&this.setCursor(this.cursors.close)}onLeftClick(t){this.updateSnappedCoordinate(t);let e=[t.lng,t.lat];if(0===this.currentCoordinate){let t=this.mutateFeature.createLineString({coordinates:[e,e],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});return this.currentId=t.id,this.currentCoordinate=1,void this.setDrawing()}if(!this.currentId)return;let{isClosing:i,isPreviousClosing:o}=this.closingPoints.isPolygonClosingPoints(t);if(i&&this.currentCoordinate>=3)return void this.closeAsPolygon();if(o&&this.currentCoordinate>=2)return void this.finishLine();let r=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:eV.Commit},coordinateMutations:[{type:B,index:-1,coordinate:e}]});if(r&&(this.currentCoordinate++,this.currentCoordinate>=2)){let t=this.toPolygonLikeCoordinates(r.geometry.coordinates);0===this.closingPoints.ids.length?this.closingPoints.create(t):this.closingPoints.update(t)}}onClick(t){"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,this.onLeftClick(t))}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.finishLine()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.closingPoints.delete()}updateSnappedCoordinate(t){let e=this.snapCoordinate(t);e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:l.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}snapCoordinate(t){var e,i,o,r;let n;if(null!=(e=this.snapping)&&e.toLine){let e;(e=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(n=e)}if(null!=(i=this.snapping)&&i.toCoordinate){let e;(e=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(n=e)}if(null!=(o=this.snapping)&&o.toFeature){let e=this.featureSnapping.getSnappable(t,this.currentId,this.snapping.toFeature.filter,{toLine
1:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});e.coordinate&&(n=e.coordinate)}if(null!=(r=this.snapping)&&r.toCustom){let e=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});e&&(n=e)}return n}styleFeature(t){let e=o({},{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)return e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,1,t),e.lineStringDash=this.getDashArrayStylingValue(this.styles.lineStringDash,void 0,t),e.zIndex=10,e;if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.polygonFillColor,e.polygonFillColor,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.polygonFillOpacity,e.polygonFillOpacity,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.polygonOutlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.polygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.polygonOutlineOpacity,1,t),e.zIndex=10,e;if("Point"===t.geometry.type){let i=!0===t.properties[l.CLOSING_POINT];if(!i&&!0!==t.properties[l.SNAPPING_POINT])return e;e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:this.styles.snappingPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:this.styles.snappingPointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(i?this.styles.closingPointOpacity:this.styles.snappingPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:this.styles.snappingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:this.styles.snappingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(i?this.styles.closingPointOutlineOpacity:this.styles.snappingPointOutlineOpacity,1,t),e.zIndex=30}return e}afterFeatureAdded(t){}afterFeatureUpdated(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted())}validateFeature(t){return this.validateModeFeature(t,t=>"LineString"===t.geometry.type?tc(t,this.coordinatePrecision):"Polygon"===t.geometry.type?R(t,this.coordinatePrecision):{valid:!1,reason:"Only LineString or Polygon features are valid"})}}let t_="Feature is not a Point",tb="Feature has invalid coordinates",tT="Feature has coordinates with excessive precision";function tN(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:t_}:D(t.geometry.coordinates)?w(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:tT}:{valid:!1,reason:tb}}class tR extends W{constructor(t,e,i){super(t),this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pixelDistance=e,this.clickBoundingBox=i}getNearestPointFeature(t){let e=this.clickBoundingBox.create(t),i=this.store.search(e),o,r=1/0;for(let e=0;e<i.length;e++){let n=i[e];if("Point"!==n.geometry.type||n.properties.mode!==this.mode)continue;let s=this.pixelDistance.measure(t,n.geometry.coordinates);s>r||s>this.pointerDistance||(r=s,o=n)}return o}}let tL={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"};class tW extends f{constructor(t){super(t,!0),this.mode="point",this.cursors=tL,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null!=t&&t.editable&&(this.editable=t.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){let e=this.pointSearch.getNearestPointFeature
1(t);this.editedFeatureId=null==e?void 0:e.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:G,coordinates:[t.lng,t.lat]},propertyMutations:{[l.EDITED]:!0},context:{updateType:eV.Provisional}})}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||void 0===this.editedFeatureId||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[l.EDITED]:!1},context:{updateType:eV.Finish,action:"edit"}}))return;let i=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(i,{mode:this.mode,action:r})}registerBehaviors(t){this.pixelDistance=new ti(t),this.clickBoundingBox=new te(t),this.pointSearch=new tR(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new V(t,{validate:this.validate})}styleFeature(t){let e=o({},{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("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){let i=!!(t.id&&this.editedFeatureId===t.id);e.pointWidth=this.getNumericStylingValue(i?this.styles.editedPointWidth:this.styles.pointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.editedPointColor:this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),e.zIndex=30}return e}validateFeature(t){return this.validateModeFeature(t,t=>tN(t,this.coordinatePrecision))}onLeftClick(t){let e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode},context:{updateType:eV.Finish,action:r}});e&&this.onFinish(e.id,{mode:this.mode,action:r})}onRightClick(t){if(!this.editable)return;let e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}afterFeatureUpdated(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}}let tU={cancel:"Escape",finish:"Enter"},tA={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"};class tB extends f{constructor(t){super(t,!0),this.mode="polygon",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=tU,this.cursors=tA,this.mouseMove=!1,this.showCoordinatePoints=!1,this.lastMouseMoveEvent=void 0,this.snapping=void 0,this.snappedPointId=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinatePoints=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.featureSnapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.undoRedo=void 0,this.updateOptions(t)}updateOptions(t){if(super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.snapping&&(this.snapping=t.snapping),void 0!==(null==t?void 0:t.editable)&&(this.editable=t.editable),void 0!==(null==t?void 0:t.pointerEvents)&&(this.pointerEvents=t.pointerEvents),void 0!==(null==t?void 0:t.showCoordinatePoints)){if(this.showCoordinatePoints=t.showCoordinatePoints,this.coordinatePoints&&!0===t.showCoordinatePoints)this.store.copyAllWhere(t=>t.mode===this.mode).filter(t=>"Polygon"===t.geometry.type).forEach(t=>{this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let t=this.store.copyAllWhere(t=>t.mode===this.mode&&!!t[l.COORDINATE_POINT_IDS]).filter(t=>"Polygon"===t.geometry.type);this.coordinatePoints.deletePointsByFeatureIds(t.map(t=>
1t.id))}}}close(){if(void 0===this.currentId||this.readFeature.getCoordinates(this.currentId).length<5)return;let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:-2}],propertyMutations:{[l.CURRENTLY_DRAWING]:void 0,[l.COMMITTED_COORDINATE_COUNT]:void 0,[l.PROVISIONAL_COORDINATE_COUNT]:void 0},context:{updateType:eV.Finish,action:r}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),"drawing"===this.state&&this.setStarted(),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.closingPoints.delete();let e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(e,{mode:this.mode,action:r})}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate}),this.clickBoundingBox=new te(t),this.pixelDistance=new ti(t),this.lineSnapping=new tf(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new to(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new tv(this.coordinateSnapping,this.lineSnapping),this.closingPoints=new tS(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new tF(t,this.readFeature,this.mutateFeature),this.undoRedo=new tx({maxStackSize:t.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}updateSnappedCoordinate(t){let e=this.snapCoordinate(t);e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:l.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(t,e){let i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)}syncClosingPoints(t){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()}undo(){if("drawing"!==this.state||!this.currentId)return;let t=this.undoRedo.beginUndo();if(!t)return;let{previousEntry:e}=t;if(!e){let t=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),void this.updateSnappedGuidancePointFromLastMouseMove()}let i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:G,coordinates:e.featureCoordinates},propertyMutations:{[l.CURRENTLY_DRAWING]:!0,[l.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[l.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate},context:{updateType:eV.Commit}});i&&(this.currentCoordinate=e.currentCoordinate,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let t=this.undoRedo.takeRedo();if(t){if(this.currentId){let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:G,coordinates:t.featureCoordinates},propertyMutations:{[l.CURRENTLY_DRAWING]:!0,[l.COMMITTED_COORDINATE_COUNT]:t.currentCoordinate,[l.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate},context:{updateType:eV.Commit}});if(!e)return;this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates})}else{let e=this.undoRedo.cloneCoordinates(t.featureCoordinates)[0],{id:i,geometry:o}=this.mutateFeature.createPolygon({coordinates:e,properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0,[l.COMM
1ITTED_COORDINATE_COUNT]:t.currentCoordinate,[l.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate}});this.currentId=i,this.currentCoordinate=t.currentCoordinate,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(o.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:i,featureCoordinates:o.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}}onMouseMove(t){let e;if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),void 0===this.currentId||0===this.currentCoordinate)return;let i=this.readFeature.getCoordinate(this.currentId,0),o=[t.lng,t.lat];if(1===this.currentCoordinate)e=[{type:z,index:1,coordinate:o},{type:z,index:2,coordinate:[t.lng,t.lat]}];else if(2===this.currentCoordinate)e=[{type:z,index:2,coordinate:o}];else{let{isClosing:r,isPreviousClosing:n}=this.closingPoints.isPolygonClosingPoints(t);n||r?(this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.setCursor(this.cursors.close),e=[{type:z,index:-1,coordinate:i},{type:z,index:-2,coordinate:i}]):e=[{type:z,index:-2,coordinate:o},{type:z,index:-1,coordinate:i}]}let r=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,propertyMutations:{[l.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:eV.Provisional}});r&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates})}snapCoordinate(t){var e,i,o,r,n;let s;if(null!=(e=this.snapping)&&e.toLine){let e;(e=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(s=e)}if(null!=(i=this.snapping)&&i.toCoordinate){let e;(e=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(s=e)}if(null!=(o=this.snapping)&&o.toFeature){let e=this.featureSnapping.getSnappable(t,this.currentId,null==(n=this.snapping)?void 0:n.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});e.coordinate&&(s=e.coordinate)}if(null!=(r=this.snapping)&&r.toCustom){let e=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});e&&(s=e)}return s}polygonFilter(t){return!!("Polygon"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)}onRightClick(t){let e;if(!this.editable||"started"!==this.state)return;let{featureId:i,featureCoordinateIndex:o}=this.coordinateSnapping.getSnappable(t,t=>this.polygonFilter(t));if(!i||void 0===o)return;let r=this.readFeature.getGeometry(i);if("Polygon"!==r.type)return;let s=r.coordinates[0];if(s.length<=4)return;e=0===o||o===s.length-1?[{type:H,index:0},{type:H,index:-1},{type:B,index:-1,coordinate:s[1]}]:[{type:H,index:o}];let a=this.mutateFeature.updatePolygon({featureId:i,coordinateMutations:e,context:{updateType:eV.Finish,action:n}});if(a){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:i,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){let e=this.snapCoordinate(t);if(e){let[t]=this.mutateFeature.createGuidancePoints({type:l.SNAPPING_POINT,coordinates:[e]});this.snappedPointId=t}}this.onFinish(i,{mode:this.mode,action:n})}}onLeftClick(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);let e=this.snapCoordinate(t)||[t.lng,t.lat];if(0===this.currentCoordinate){let{id:t,geometry:i}=this.mutateFeature.createPolygon({coordinates:[e,e,e,e],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0,[l.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1,[l.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1}});this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:i.coordinates}),this.currentId=t,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}
1else if(1===this.currentCoordinate&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:0}))return;let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:z,index:1,coordinate:e},{type:z,index:2,coordinate:e}],propertyMutations:{[l.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:eV.Commit}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(2===this.currentCoordinate&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:1}))return;let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:z,index:2,coordinate:e},{type:B,index:2,coordinate:e}],propertyMutations:{[l.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:eV.Commit}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),2===this.currentCoordinate&&this.closingPoints.create(t.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){let{isClosing:i,isPreviousClosing:o}=this.closingPoints.isPolygonClosingPoints(t);if(o||i)this.close();else{if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:this.currentCoordinate-1}))return;let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:A,index:-1,coordinate:e}],propertyMutations:{[l.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:eV.Commit}});if(!t)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(t.geometry.coordinates)}}}onClick(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(t,e){let i;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){if("started"===this.state){let e=this.lineSnapping.getSnappable(t,t=>this.polygonFilter(t));e.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=e.featureCoordinateIndex,this.editedFeatureId=e.featureId,i=e.coordinate);let o=this.coordinateSnapping.getSnappable(t,t=>this.polygonFilter(t));o.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,i=o.coordinate)}this.editedFeatureId&&i&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:l.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}}onDrag(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDrag,t)||void 0===this.editedFeatureId||void 0===this.editedFeatureCoordinateIndex)return;let i=this.readFeature.getGeometry(this.editedFeatureId),o=[t.lng,t.lat],r=[];if("coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex?r=0===this.editedFeatureCoordinateIndex||this.editedFeatureCoordinateIndex===i.coordinates[0].length-1?[{type:z,index:0,coordinate:o},{type:z,index:-1,coordinate:o}]:[{type:z,index:this.editedFeatureCoordinateIndex,coordinate:o}]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,r=[{type:A,index:this.editedInsertIndex,coordinate:o}],this.editedFeatureCoordinateIndex++),0===r.length)return;let n=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:r,propertyMutations:{[l.EDITED]:!0},context:{updateType:eV.Provisional}});n&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:n.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,n.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:o}]))}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||void 0===this.editedFeatureId||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:{[l.EDITED]:!1},context:{updateType:eV.Finish,action:n}})))return;let i=this.editedFeatureId;this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,e(!0),this.onFinish(i,{mode:this.mode,action:n})}cleanUp(){let t=this.currentId,e=this.snappedPointId,i=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),t&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(i),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.ids.length&&this.closingPoints.delete()}
1styleFeature(t){let e=o({},{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("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.zIndex=10,e;if("Point"===t.geometry.type){let i=t.properties[l.EDITED],o=t.properties[l.COORDINATE_POINT],r=i?"editedPoint":t.properties[l.CLOSING_POINT]?"closingPoint":t.properties[l.SNAPPING_POINT]?"snappingPoint":o?"coordinatePoint":void 0;if(!r)return e;let n={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(n[r].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(n[r].opacity,1,t),e.pointColor=this.getHexColorStylingValue(n[r].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(n[r].outlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(n[r].outlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(n[r].outlineWidth,2,t),e.zIndex=i?40:o?20:30,e}}return e}afterFeatureAdded(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})}afterFeatureUpdated(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),"drawing"===this.state&&this.setStarted())}validateFeature(t){return this.validateModeFeature(t,t=>R(t,this.coordinatePrecision))}}let tz={cancel:"Escape",finish:"Enter"},tH={start:"crosshair"};class tG extends f{constructor(t){super(t,!0),this.mode="rectangle",this.startPosition=void 0,this.endPosition=void 0,this.currentRectangleId=void 0,this.keyEvents=tz,this.cursors=tH,this.drawInteraction="click-move",this.drawType=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.drawInteraction&&(this.drawInteraction=t.drawInteraction)}updateRectangle(t,e){if(!this.startPosition||!this.currentRectangleId)return;let i=e===eV.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:z,index:1,coordinate:[t[0],this.startPosition[1]]},{type:z,index:2,coordinate:t},{type:z,index:3,coordinate:[this.startPosition[0],t[1]]}],propertyMutations:i?{[l.CURRENTLY_DRAWING]:void 0}:{},context:i?{updateType:e,action:r}:{updateType:e}})}close(){if(!this.currentRectangleId||!this.endPosition||!this.updateRectangle(this.endPosition,eV.Finish))return;let t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}beginDrawing(t,e="click"){this.startPosition=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];let i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});this.currentRectangleId=i.id,this.drawType=e,this.setDrawing()}moveDrawAllowed(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction}dragDrawAllowed(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.startPosition?(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))}onMouseMove(t){this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,eV.Provisional)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,eV.Provisional))}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))}cleanUp(){let t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)}
1styleFeature(t){let e=o({},{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"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e}validateFeature(t){return this.validateModeFeature(t,t=>L(t,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentRectangleId===t.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate})}}class tV extends f{constructor(t){if(!t.modeName)throw Error("Mode name is required for TerraDrawRenderMode");super(t,!0),this.type=ej.Render,this.mode="render",this.updateOptions(t)}updateOptions(t){super.updateOptions(t)}registerBehaviors(t){this.mode=t.mode}start(){this.setStarted()}stop(){this.setStopped()}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}
1styleFeature(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOpacity:this.getNumericStylingValue(this.styles.pointOpacity,1,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),pointOutlineOpacity:this.getNumericStylingValue(this.styles.pointOutlineOpacity,1,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),lineStringOpacity:this.getNumericStylingValue(this.styles.lineStringOpacity,1,t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t),lineStringDash:void 0}}validateFeature(t){let e=super.validateFeature(t);if(e.valid){let e=tN(t,this.coordinatePrecision).valid||R(t,this.coordinatePrecision).valid||tc(t,this.coordinatePrecision).valid;return e?{valid:!0}:{valid:e,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return e}}function tj(t,e){let i=P(t[1]),o=P(e[1]),r=P(e[0]-t[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);let n=(I(Math.atan2(r,Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(i/2+Math.PI/4))))+360)%360;return n>180?-(360-n):n}function tK(t,e,i){let o=e;e<0&&(o=-Math.abs(o));let r=o/6371008.8,n=t[0]*Math.PI/180,s=P(t[1]),a=P(i),d=r*Math.cos(a),h=s+d;Math.abs(h)>Math.PI/2&&(h=h>0?Math.PI-h:-Math.PI-h);let l=Math.log(Math.tan(h/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),u=[(180*(n+r*Math.sin(a)/(Math.abs(l)>
11e-11?d/l:Math.cos(s)))/Math.PI+540)%360-180,180*h/Math.PI];return u[0]+=u[0]-t[0]>180?-360:360*(t[0]-u[0]>180),u}function tY(t,e,i,o,r){let n=o(t[0],t[1]),s=o(e[0],e[1]),{lng:a,lat:d}=r((n.x+s.x)/2,(n.y+s.y)/2);return[S(a,i),S(d,i)]}function tX({featureCoords:t,precision:e,unproject:i,project:o,projection:r}){let n=[];for(let s=0;s<t.length-1;s++){let a;if("web-mercator"===r)a=tY(t[s],t[s+1],e,o,i);else{if("globe"!==r)throw Error("Invalid projection");a=function(t,e,i){let o=tK(t,1e3*C(t,e)/2,tj(t,e));return[S(o[0],i),S(o[1],i)]}(t[s],t[s+1],e)}n.push(a)}return n}class t$ extends W{constructor(t,e,i,o,r,n){super(t),this.config=void 0,this.selectionPointBehavior=void 0,this.coordinatePointBehavior=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this._midPoints=[],this.config=t,this.selectionPointBehavior=e,this.coordinatePointBehavior=i,this.mutateFeature=o,this.readFeature=r,this.pixelDistance=n}getMidpointConfig(t){return{featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}}get ids(){return this._midPoints.concat()}set ids(t){}getNearestMidPoint(t){let e,i=1/0;return this.ids.forEach(o=>{let r=this.readFeature.getGeometry(o),n=this.pixelDistance.measure(t,r.coordinates);n<this.pointerDistance&&n<i&&(i=n,e=o)}),e}insert({featureId:t,midPointId:e}){let i=this.readFeature.getGeometry(e),{midPointFeatureId:o,midPointSegment:r}=this.readFeature.getProperties(e),n=this.readFeature.getGeometry(o),s={featureId:o,coordinateMutations:[{type:B,index:r,coordinate:i.coordinates}],context:{updateType:eV.Commit}},a=null;if("Polygon"===n.type)a=this.mutateFeature.updatePolygon(s);else{if("LineString"!==n.type)throw Error("Midpoints can only be added to polygons or linestrings");a=this.mutateFeature.updateLineString(s)}if(!a)throw Error("Failed to insert midpoint coordinate");let d=a.geometry.coordinates;this.readFeature.getProperties(t)[l.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate({featureId:t,featureCoordinates:d}),this.mutateFeature.deleteFeaturesIfPresent([...this.selectionPointBehavior.ids,...this._midPoints]),this.create({featureCoordinates:d,featureId:o}),this.selectionPointBehavior.create({featureCoordinates:d,featureId:t})}create({featureCoordinates:t,featureId:e}){if(!this.readFeature.hasFeature(e))throw Error("Store does not have feature with this id");let i=tI(t),o=tX(this.getMidpointConfig(i));this._midPoints=this.mutateFeature.createGuidancePoints({additionalProperties:t=>({mode:this.mode,midPointSegment:t,midPointFeatureId:e,[h.MID_POINT]:!0}),coordinates:o,type:h.MID_POINT})}delete(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])}updateAllInPlace({featureCoordinates:t}){if(0===this._midPoints.length)return;let e=tI(t),i=tX(this.getMidpointConfig(e));this.mutateFeature.updateGuidancePoints(this._midPoints.map((t,e)=>({featureId:t,coordinate:i[e]})))}updateOneAtIndex(t,e){if(t<0&&(t=this._midPoints.length+t),void 0===this._midPoints[t])return;let i=tI(e),o=tX(this.getMidpointConfig(i));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[t],coordinate:o[t]}])}}class tq extends W{constructor(t,e){super(t),this.mutateFeature=void 0,this._selectionPoints=[],this.mutateFeature=e}get ids(){return this._selectionPoints.concat()}set ids(t){}create({featureId:t,featureCoordinates:e}){let i=tP(e);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:i,type:h.SELECTION_POINT,additionalProperties:e=>({[h.SELECTION_POINT_FEATURE_ID]:t,index:e})})}delete(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])}updateAllInPlace({featureCoordinates:t}){if(0===this._selectionPoints.length)return;let e=tP(t);e.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map((t,i)=>({featureId:t,coordinate:e[i]})))}updateOneAtIndex(t,e){void 0!==this._selectionPoints[t]&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[t],coordinate:e}])}}function tZ(t,e){var i,o;let r=!1;for(let n=0,s=e.length;n<s;n++){let s=e[n];for(let e=0,n=s.length,a=n-1;e<n;a=e++)(i=s[e])[1]>t[1]!=(o=s[a])[1]>t[1]&&t[0]<(o[0]-i[0])*(t[1]-i[1])/(o[1]-i[1])+i[0]&&(r=!r)}return r}let tJ=(t,e,i)=>{let o=(t,e)=>{let i,o;return(i=t.x-e.x)*i+(o=t.y-e.y)*o};return Math.sqrt(((t,e,i)=>{let r=o(e,i);if(0===r)return o(t,e);let n=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/r;return n=Math.max(0,Math.min(1,n)),o(t,{x:e.x+n*(i.x-e.x),y:e.y+n*(i.y-e.y)})})(t,e,i))};class tQ extends W{constructor(t,e,i){super(t),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=t,this.createClickBoundingBox=e,this.pixelDistance=i}find(t,e){let i,o,r,n=1/0,s=1/0,a=this.createClickBoundingBox.create(t),d=this.store.search(a);for(let a=0;a<d.length;a++){let l=d[a],u=l.geometry;if("Point"===u.type){if(l.properties.selectionPoint||l.properties.coordinatePoint||!e&&l.properties[h.MID_POINT])continue;let o=this.pixelDistance.measure(t,u.coordinates);!l.properties[h.MID_POINT]&&o<this.pointerDistance&&o<n&&(n=o,i=l)}else if("LineString"===u.type){if(i)continue;for(let e=0;e<u.coordinates.length-1;e++){let i=u.coordinates[e],r=u.coordinates[e+1],n=tJ({x:t.containerX,y:t.containerY},this.project(i[0],i[1]),this.project(r[0],r[1]));n<this.pointerDistance&&n<s&&(s=n,o=l)}}else if("Polygon"===u.type){if(i||o)continue;tZ([t.lng,t.lat],u.coordinates)&&(r=l)}}return{clickedFeature:i||o||r}}}class t0 extends W{constructor(t,e,i,o,r,n,s){super(t),this.config=void 0,this.featuresAtCursorEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=t,this.featuresAtCursorEvent=e,this.selectionPoints=i,this.midPoints=o,this.coordinatePoints=r,this.readFeature=n,this.mutateFeature=s}startDragging(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return null!==this.draggedFeatureId}canDrag(t,e){let{clickedFeature:i}=this.featuresAtCursorEvent.find(t,!0);return!(!i||i.id!==e)}drag(t){if(!this.draggedFeatureId)return;if(!1===this.readFeature.hasFeature(this.draggedFeatureId))return this.stopDragging(),!1;let e=this.readFeature.getGeometry(this.draggedFeatureId),i=[t.lng,t.lat];if("Polygon"===e.type||"LineString"===e.type){let o,r;if(r="Polygon"===e.type?(o=e.coordinates[0]).length-1:(o=e.coordinates).length,!this.dragPosition)return!1;for(let t=0;t<r;t++){let e,r,n=o[t];if("web-mercator"===this.config.projection){let t=F(this.dragPosition[0],this.dragPosition[1]),o=F(i[0],i[1]),s=F(n[0],n[1]),a={x:t.x-o.x,y:t.y-o.y},{lng:d,lat:h}=x(s.x-a.x,s.y-a.y);e=d,r=h}else{let t=[this.dragPosition[0]-i[0],this.dragPosition[1]-i[1]];e=n[0]-t[0],r=n[1]-t[1]}if(e=S(e,this.config.coordinatePrecision),r=S(r,this.config.coordinatePrecision),e>180||e<-180||r>90||r<-90)return!1;o[t]=[e,r]}"Polygon"===e.type&&(o[o.length-1]=[o[0][0],o[0][1]]);let n=this.draggedFeatureId,s=null;if("Polygon"===e.type)s=this.mutateFeature.updatePolygon({featureId:n,coordinateMutations:{type:G,coordinates:[o]},context:{updateType:eV.Provisional}});else{if("LineString"!==e.type)return;s=this.mutateFeature.updateLineString({featureId:n,coordinateMutations:{type:G,coordinates:o},context:{updateType:eV.Provisional}})}if(!s)return!1;let a=s.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:a}),this.selectionPoints.updateAllInPlace({featureCoordinates:a}),this.coordinatePoints.updateAllInPlace({featureId:n,featureCoordinates:a}),this.dragPosition=[t.lng,t.lat]}else"Point"===e.type&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:G,coordinates:i},context:{updateType:eV.Provisional}}),this.dragPosition=[t.lng,t.lat])}}class t1 extends W{constructor(t,e,i,o,r,n,s,a,d){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.featureSnapping=void 0,this.draggedCoordinate={id:null,index:-1},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=o,this.coordinatePoints=r,this.coordinateSnapping=n,this.lineSnapping=s,this.readFeature=a,this.mutateFeature=d,this.featureSnapping=new tv
1(this.coordinateSnapping,this.lineSnapping)}getClosestCoordinate(t,e){let i,o={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(let r=0;r<i.length;r++){let n=this.pixelDistance.measure(t,i[r]);if(n<this.pointerDistance&&n<o.dist){let t="Polygon"===e.type&&(r===i.length-1||0===r);o.dist=n,o.index=t?0:r,o.isFirstOrLastPolygonCoord=t}}return o}getDraggable(t,e){let i=this.readFeature.getGeometry(e);return this.getClosestCoordinate(t,i)}getDraggableIndex(t,e){let i=this.readFeature.getGeometry(e),o=this.getClosestCoordinate(t,i);return -1===o.index?-1:o.index}snapCoordinate(t,e,i){let o=[t.lng,t.lat],r=t=>!!(t.properties&&t.properties.mode===i.properties.mode&&t.id!==this.draggedCoordinate.id);if(null!=e&&e.toLine){let e;(e=this.lineSnapping.getSnappable(t,r).coordinate)&&(o=e)}if(e.toCoordinate){let e;(e=this.coordinateSnapping.getSnappable(t,r).coordinate)&&(o=e)}if(null!=e&&e.toFeature){let r=this.featureSnapping.getSnappable(t,i.id,e.toFeature.filter,{toLine:e.toFeature.toLine,toCoordinate:e.toFeature.toCoordinate});r.coordinate&&(o=r.coordinate)}if(null!=e&&e.toCustom){let r;(r=e.toCustom(t,{currentCoordinate:this.draggedCoordinate.index,currentId:i.id,getCurrentGeometrySnapshot:i.id?()=>this.readFeature.getGeometry(i.id):()=>null,project:this.project,unproject:this.unproject}))&&(o=r)}return o}drag(t,e,i){let o=this.draggedCoordinate.id;if(null===o)return!1;if(!1===this.readFeature.hasFeature(o))return this.stopDragging(),!1;let r=this.draggedCoordinate.index,n=this.readFeature.getGeometry(o),s=this.readFeature.getProperties(o),a="LineString"===n.type?n.coordinates:n.coordinates[0],d="Polygon"===n.type&&(r===a.length-1||0===r),h=this.snapCoordinate(t,i,{type:"Feature",id:o,geometry:n,properties:s});if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(d){let t=a.length-1;a[0]=h,a[t]=h}else a[r]=h;if("Point"!==n.type&&!e&&M({type:"Feature",geometry:n,properties:{}}))return!1;let l=null;return"Polygon"===n.type?l=this.mutateFeature.updatePolygon({featureId:o,coordinateMutations:{type:G,coordinates:[a]},context:{updateType:eV.Provisional}}):"LineString"===n.type&&(l=this.mutateFeature.updateLineString({featureId:o,coordinateMutations:{type:G,coordinates:a},context:{updateType:eV.Provisional}})),!!l&&(this.midPoints.updateOneAtIndex(r>0?r-1:-1,a),this.midPoints.updateOneAtIndex(r,a),this.selectionPoints.updateOneAtIndex(r,h),this.coordinatePoints.updateOneAtIndex(o,r,h),!0)}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}}function t3(t){let e=0,i=0,o=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(t=>{e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}let t2=(t,e)=>{if(0===e||360===e||-360===e)return t;let i=.017453292519943295*e,o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(([t,e])=>F(t,e)),r=o.reduce((t,e)=>({x:t.x+e.x,y:t.y+e.y}),{x:0,y:0});r.x/=o.length,r.y/=o.length;let n=o.map(t=>({x:r.x+(t.x-r.x)*Math.cos(i)-(t.y-r.y)*Math.sin(i),y:r.y+(t.x-r.x)*Math.sin(i)+(t.y-r.y)*Math.cos(i)})).map(({x:t,y:e})=>[x(t,e).lng,x(t,e).lat]);return"Polygon"===t.geometry.type?t.geometry.coordinates[0]=n:t.geometry.coordinates=n,t};function t9(t){let e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(t=>{let{x:e,y:i}=F(t[0],t[1]);return[e,i]});return"Polygon"===t.geometry.type?function(t){let e=0,i=0,o=0,r=t.length;for(let n=0;n<r-1;n++){let[r,s]=t[n],[a,d]=t[n+1],h=r*d-a*s;e+=h,i+=(r+a)*h,o+=(s+d)*h}return e/=2,{x:i/=6*e,y:o/=6*e}}(e):function(t){let e=t.length,i=0,o=0;for(let r=0;r<e;r++){let[e,n]=t[r];
1i+=e,o+=n}return{x:i/e,y:o/e}}(e)}class t7 extends W{constructor(t,e,i,o,r,n){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryCentroid=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i,this.coordinatePoints=o,this.readFeature=r,this.mutateFeature=n}reset(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0}rotate(t,e){let i;this.selectedGeometry||(this.selectedGeometry=this.readFeature.getGeometry(e));let o=this.selectedGeometry;if("Polygon"!==o.type&&"LineString"!==o.type)return;let r=[t.lng,t.lat],n={type:"Feature",geometry:o,properties:{}};if("web-mercator"===this.config.projection){this.selectedGeometryWebMercatorCentroid||(this.selectedGeometryWebMercatorCentroid=t9(n));let e=F(t.lng,t.lat);if(0===(i=ta(this.selectedGeometryWebMercatorCentroid,e)))return;if(!this.lastBearing)return void(this.lastBearing=i);t2(n,-(this.lastBearing-i))}else{if("globe"!==this.config.projection)throw Error("Unsupported projection");if(this.selectedGeometryCentroid||(this.selectedGeometryCentroid=t3({type:"Feature",geometry:o,properties:{}})),i=tj(this.selectedGeometryCentroid,r),!this.lastBearing)return void(this.lastBearing=i+180);!function(t,e){if(0===e||360===e||-360===e)return;let i=t3(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{let o,r,n,s,a,d,h=tj(i,t)+e,l=(i[0]+=i[0]-t[0]>180?-360:360*(t[0]-i[0]>180),o=t[1]*Math.PI/180,n=(r=i[1]*Math.PI/180)-o,(s=Math.abs(i[0]-t[0])*Math.PI/180)>Math.PI&&(s-=2*Math.PI),d=Math.abs(a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)))>1e-11?n/a:Math.cos(o),6371008.8*Math.sqrt(n*n+d*d*s*s)),u=tK(i,l,h);t[0]=u[0],t[1]=u[1]})}(n,-(this.lastBearing-(i+180)))}let s="Polygon"===o.type?o.coordinates[0]:o.coordinates;s.forEach(t=>{t[0]=S(t[0],this.coordinatePrecision),t[1]=S(t[1],this.coordinatePrecision)});let a={featureId:e,coordinateMutations:{type:G,coordinates:"Polygon"===o.type?[s]:s},context:{updateType:eV.Provisional}},d=null;if("Polygon"===n.geometry.type)d=this.mutateFeature.updatePolygon(a);else{if("LineString"!==n.geometry.type)return;d=this.mutateFeature.updateLineString(a)}if(!d)return!1;let h=d.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:h}),this.selectionPoints.updateAllInPlace({featureCoordinates:h}),this.coordinatePoints.updateAllInPlace({featureId:e,featureCoordinates:h}),"web-mercator"===this.projection?this.lastBearing=i:"globe"===this.projection&&(this.lastBearing=i+180)}}class t4 extends W{constructor(t,e){super(t),this.config=void 0,this.dragCoordinateResizeBehavior=void 0,this.config=t,this.dragCoordinateResizeBehavior=e}scale(t,e){if(!this.dragCoordinateResizeBehavior.isDragging()){let i=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,i)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed")}reset(){this.dragCoordinateResizeBehavior.stopDragging()}}function t6({coordinates:t,originX:e,originY:i,xScale:o,yScale:r}){1===o&&1===r||t.forEach(t=>{let{x:n,y:s}=F(t[0],t[1]),{lng:a,lat:d}=x(e+(n-e)*o,i+(s-i)*r);t[0]=a,t[1]=d})}class t8 extends W{constructor(t,e,i,o,r,n,s){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=o,this.coordinatePoints=r,this.readFeature=n,this.mutateFeature=s}getClosestCoordinate(t,e){let i,o={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(let r=0;r<i.length;r++){let n=this.pixelDistance.measure(t,i[r]);if(n<this.pointerDistance&&n<o.dist){let t="Polygon"===e.type&&(r===i.length-1||0===r);o.dist=n,o.index=t?0:r,o.isFirstOrLastPolygonCoord=t}}return o}isValidDragWebMercator(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;let t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;let e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}}centerWebMercatorDrag(t){let e=this.getSelectedFeatureDataWebMercator();if(!e)return null;let{feature:i,boundingBox:o,updatedCoords:r,selectedCoordinate:n}=e,s=t9(i);if(!s)return null;
1let a=F(n[0],n[1]),{closestBBoxIndex:d}=this.getIndexesWebMercator(o,a),h=F(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:r,webMercatorCursor:h,webMercatorSelected:a,webMercatorOrigin:s}),r}centerFixedWebMercatorDrag(t){let e=this.getSelectedFeatureDataWebMercator();if(!e)return null;let{feature:i,boundingBox:o,updatedCoords:r,selectedCoordinate:n}=e,s=t9(i);if(!s)return null;let a=F(n[0],n[1]),{closestBBoxIndex:d}=this.getIndexesWebMercator(o,a),h=F(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:r,webMercatorCursor:h,webMercatorSelected:a,webMercatorOrigin:s}),r}scaleFixedWebMercator({closestBBoxIndex:t,webMercatorOrigin:e,webMercatorSelected:i,webMercatorCursor:o,updatedCoords:r}){if(!this.isValidDragWebMercator(t,e.x-o.x,e.y-o.y))return null;let n=X(e,o)/X(e,i);return n<0&&(n=this.minimumScale),t6({coordinates:r,originX:e.x,originY:e.y,xScale:n,yScale:n}),r}oppositeFixedWebMercatorDrag(t){let e=this.getSelectedFeatureDataWebMercator();if(!e)return null;let{boundingBox:i,updatedCoords:o,selectedCoordinate:r}=e,n=F(r[0],r[1]),{oppositeBboxIndex:s,closestBBoxIndex:a}=this.getIndexesWebMercator(i,n),d={x:i[s][0],y:i[s][1]},h=F(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:h,webMercatorSelected:n,webMercatorOrigin:d}),o}oppositeWebMercatorDrag(t){let e=this.getSelectedFeatureDataWebMercator();if(!e)return null;let{boundingBox:i,updatedCoords:o,selectedCoordinate:r}=e,n=F(r[0],r[1]),{oppositeBboxIndex:s,closestBBoxIndex:a}=this.getIndexesWebMercator(i,n),d={x:i[s][0],y:i[s][1]},h=F(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:h,webMercatorSelected:n,webMercatorOrigin:d}),o}scaleWebMercator({closestBBoxIndex:t,webMercatorOrigin:e,webMercatorSelected:i,webMercatorCursor:o,updatedCoords:r}){let n=e.x-o.x,s=e.y-o.y;if(!this.isValidDragWebMercator(t,n,s))return null;let a=1;0!==n&&1!==t&&5!==t&&(a=1-(e.x-i.x-n)/n);let d=1;return 0!==s&&3!==t&&7!==t&&(d=1-(e.y-i.y-s)/s),this.validateScale(a,d)?(a<0&&(a=this.minimumScale),d<0&&(d=this.minimumScale),this.performWebMercatorScale(r,e.x,e.y,a,d),r):null}getFeature(t){if(null===this.draggedCoordinate.id)return null;let e=this.readFeature.getGeometry(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{id:t,type:"Feature",geometry:e,properties:{}}}getNormalisedCoordinates(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates}validateScale(t,e){let i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,o=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&o}performWebMercatorScale(t,e,i,o,r){t.forEach(t=>{let{x:n,y:s}=F(t[0],t[1]),{lng:a,lat:d}=x(e+(n-e)*o,i+(s-i)*r);t[0]=a,t[1]=d})}getBBoxWebMercator(t){let e=[1/0,1/0,-1/0,-1/0];(t=t.map(t=>{let{x:e,y:i}=F(t[0],t[1]);return[e,i]})).forEach(([t,i])=>{t<e[0]&&(e[0]=t),i<e[1]&&(e[1]=i),t>e[2]&&(e[2]=t),i>e[3]&&(e[3]=i)});let[i,o,r,n]=e;return[[i,n],[(i+r)/2,n],[r,n],[r,n+(o-n)/2],[r,o],[(i+r)/2,o],[i,o],[i,n+(o-n)/2]]}getIndexesWebMercator(t,e){let i,o=1/0;for(let r=0;r<t.length;r++){let n=X({x:e.x,y:e.y},{x:t[r][0],y:t[r][1]});n<o&&(i=r,o=n)}if(void 0===i)throw Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}getDraggableIndex(t,e){let i=this.readFeature.getGeometry(e),o=this.getClosestCoordinate(t,i);return -1===o.index?-1:o.index}drag(t,e){if(!this.draggedCoordinate.id)return!1;let i=this.getFeature(this.draggedCoordinate.id);if(!i)return!1;let o=null;if("center"===e?o=this.centerWebMercatorDrag(t):"opposite"===e?o=this.oppositeWebMercatorDrag(t):"center-fixed"===e?o=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(o=this.oppositeFixedWebMercatorDrag(t)),!o)return!1;for(let t=0;t<o.length;t++){let e=o[t];if(e[0]=S(e[0],this.coordinatePrecision),e[1]=S(e[1],this.coordinatePrecision),!w(e,this.coordinatePrecision))return!1}let r=i.id,n=null;if("Polygon"===i.geometry.type?n=this.mutateFeature.updatePolygon({featureId:r,coordinateMutations:{type:G,coordinates:[o]},context:{updateType:eV.Provisional}}):"LineString"===i.geometry.type&&(n=this.mutateFeature.updateLineString({featureId:r,coordinateMutations:{type:G,coordinates:o},context:{updateType:eV.Provisional}})),!n)return!1;let s=n.geometry.coordinates;return this.midPoints.updateAllInPlace({featureCoordinates:s}),this.selectionPoints.updateAllInPlace({featureCoordinates:s}),this.coordinatePoints.updateAllInPlace({featureId:r,featureCoordinates:s}),!0}}let t5={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]},et={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"};
1class ee extends v{getPointerOverFeatureCursor(){var t;return null!=(t=this.cursors.pointerOverFeature)?t:this.cursors.pointerOver}getPointerOverCoordinateCursor(){var t;return null!=(t=this.cursors.pointerOverCoordinate)?t:this.cursors.pointerOver}getPointerOverResizeHandleCursor(){var t;return null!=(t=this.cursors.pointerOverResizeHandle)?t:this.cursors.pointerOver}constructor(t){super(t,!0),this.mode="select",this.allowManualDeselection=!0,this.allowManualSelection=!0,this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags={},this.keyEvents=t5,this.cursors=et,this.validations={},this.dragTarget={type:"none"},this.selectionPoints=void 0,this.midPoints=void 0,this.coordinateSnap=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.dragCoordinateResizeFeature=void 0,this.coordinatePoints=void 0,this.lineSnap=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(t)}updateOptions(t){if(super.updateOptions(t),this.cursors=t&&t.cursors?o({},this.cursors,t.cursors):et,null===(null==t?void 0:t.keyEvents)?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),void 0!==(null==t?void 0:t.dragEventThrottle)&&(this.dragEventThrottle=t.dragEventThrottle),void 0!==(null==t?void 0:t.allowManualDeselection)&&(this.allowManualDeselection=t.allowManualDeselection),void 0!==(null==t?void 0:t.allowManualSelection)&&(this.allowManualSelection=t.allowManualSelection),null!=t&&t.flags)for(let e in this.flags=o({},this.flags,t.flags),this.validations={},this.flags){let t=this.flags[e].feature;t&&t.validation&&(this.validations[e]=t.validation)}}selectFeature(t){this.select(t,!1)}setSelecting(){if("started"!==this._state)throw Error("Mode must be started to move to selecting state");this._state="selecting"}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:(t,e)=>{let i=t.properties.mode;return this.validations&&this.validations[i]?this.validations[i](t,e):{valid:!0}}}),this.pixelDistance=new ti(t),this.clickBoundingBox=new te(t),this.featuresAtMouseEvent=new tQ(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new tq(t,this.mutateFeature),this.coordinatePoints=new tF(t,this.readFeature,this.mutateFeature),this.midPoints=new t$(t,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new to(t,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new tf(t,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new t7(t,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new t0(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new t1(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new t8(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new t4(t,this.dragCoordinateResizeFeature)}deselectFeature(t){this.deselect(t)}deselect(t){this.selected.includes(t)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:"none"})}deleteSelected(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:"none"}}clearDragTargetAndCursor(){this.dragTarget={type:"none"},this.setCursor("unset")}getSelectedFlags(t){let e=this.readFeature.getProperties(t),i=this.flags[e.mode],o=null==i?void 0:i.feature,r=null==o?void 0:o.coordinates;return{featureFlags:o,coordinatesFlags:r,hasDraggableFlags:o&&(o.draggable||(null==r?void 0:r.draggable)||(null==r?void 0:r.resizable)||"object"==typeof(null==r?void 0:r.midpoints)&&r.midpoints.draggable)}}onRightClick(t){let e;if(!this.selectionPoints.ids.length)return;let i,o=1/0;
1if(this.selectionPoints.ids.forEach(e=>{let r=this.readFeature.getGeometry(e),n=this.pixelDistance.measure(t,r.coordinates);n<this.pointerDistance&&n<o&&(o=n,i=this.readFeature.getProperties(e))}),!i)return;let r=i.selectionPointFeatureId,n=i.index,a=this.readFeature.getProperties(r),d=this.flags[a.mode];if(!(d&&d.feature&&d.feature.coordinates&&d.feature.coordinates.deletable))return;let h=this.readFeature.getGeometry(r);if("Polygon"===h.type){if((e=h.coordinates[0]).length<=4)return}else if("LineString"!==h.type||(e=h.coordinates).length<=2)return;"Polygon"!==h.type||0!==n&&n!==e.length-1?e.splice(n,1):(e.shift(),e.pop(),e.push([e[0][0],e[0][1]]));let l=null;if("Polygon"===h.type?l=this.mutateFeature.updatePolygon({featureId:r,coordinateMutations:{type:G,coordinates:[e]},context:{updateType:eV.Commit}}):"LineString"===h.type&&(l=this.mutateFeature.updateLineString({featureId:r,coordinateMutations:{type:G,coordinates:e},context:{updateType:eV.Commit}})),!l)return;let u=l.geometry.coordinates;this.mutateFeature.deleteFeaturesIfPresent([...this.midPoints.ids,...this.selectionPoints.ids]),a.coordinatePointIds&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:u}),this.selectionPoints.create({featureCoordinates:u,featureId:r}),d&&d.feature&&d.feature.coordinates&&d.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:u,featureId:r}),this.onFinish(r,{action:s,mode:this.mode})}select(t,e=!0){if(this.selected[0]===t)return;let{mode:i}=this.readFeature.getProperties(t),o=this.flags[i];if(!o||!o.feature)return;let r=this.selected[0];if(r){if(r===t)return;this.deselect(r)}e&&this.setCursor(this.getPointerOverFeatureCursor()),this.selected=[t],this.mutateFeature.setSelected(t),this.onSelect(t);let{type:n,coordinates:s}=this.readFeature.getGeometry(t);"LineString"!==n&&"Polygon"!==n||s&&o&&o.feature.coordinates&&(this.selectionPoints.create({featureCoordinates:s,featureId:t}),o.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:s,featureId:t}))}onLeftClick(t){let{clickedFeature:e}=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=this.midPoints.getNearestMidPoint(t),o=this.selected[0];if(o){var r;let{featureFlags:e}=this.getSelectedFlags(o);
1if(null!=e&&null!=(r=e.coordinates)&&r.midpoints&&i){if(e.coordinates.draggable){let e=this.pixelDistance.measure(t,this.readFeature.getGeometry(i).coordinates),{dist:r}=this.dragCoordinate.getDraggable(t,o);if(void 0!==r&&e>r)return}return this.midPoints.insert({featureId:o,midPointId:i}),void this.onFinish(this.selected[0],{action:a,mode:this.mode})}}if(null!=e&&e.id)this.allowManualSelection&&this.select(e.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)}canScale(t){return this.keyEvents.scale&&this.keyEvents.scale.every(e=>t.heldKeys.includes(e))}canRotate(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(e=>t.heldKeys.includes(e))}preventDefaultKeyEvent(t){let e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()}onKeyDown(t){this.preventDefaultKeyEvent(t)}onKeyUp(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;let t=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([t]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect(this.selected[0])}onDragStart(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,t))return;let i=this.selected[0];if(!i)return;let{featureFlags:o,coordinatesFlags:r,hasDraggableFlags:n}=this.getSelectedFlags(i);if(!n)return;this.dragEventCount=0;let s="none"!==this.dragTarget.type&&this.dragTarget.featureId===i?this.dragTarget:{type:"none"},d="coordinate"===s.type?s.coordinateIndex:this.dragCoordinate.getDraggableIndex(t,i),h="resize"===s.type?s.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(t,i),l=(null==r?void 0:r.resizable)&&-1!==h,u=(null==r?void 0:r.draggable)&&-1!==d,c=r&&"object"==typeof r.midpoints&&r.midpoints.draggable,p=(null==o?void 0:o.draggable)&&("feature"===s.type||this.dragFeature.canDrag(t,i));if(l)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(i,h),void e(!1);if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(i,d),void e(!1);if(c){let o="midpoint"===s.type?s.midPointId:this.midPoints.getNearestMidPoint(t);if(this.selected.length&&o){this.midPoints.insert({featureId:i,midPointId:o}),this.onFinish(this.selected[0],{action:a,mode:this.mode});let r=this.dragCoordinate.getDraggableIndex(t,i);return this.dragCoordinate.startDragging(i,r),void e(!1)}}p?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,i),e(!1)):this.setCursor("unset")}onDrag(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDrag,t))return;let i=this.selected[0];if(!i)return;let o=this.readFeature.getProperties(i),r=this.flags[o.mode],n=!0===(r&&r.feature&&r.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(r&&r.feature&&r.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i);if(r&&r.feature&&r.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i);if(this.dragCoordinateResizeFeature.isDragging()&&r.feature&&r.feature.coordinates&&r.feature.coordinates.resizable){if("globe"===this.projection)throw Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,r.feature.coordinates.resizable)}if(this.dragCoordinate.isDragging()){var s;let e=null==(s=r.feature)||null==(s=s.coordinates)?void 0:s.snappable,i={toCoordinate:!1};return!0===e?i={toCoordinate:!0}:"object"==typeof e&&(i=e),void this.dragCoordinate.drag(t,n,i)}this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)}}onDragEnd(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0))}onMouseMove(t){let e,i=this.selected[0];if(!i)return void this.clearDragTargetAndCursor();if(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())return;let{featureFlags:o}=this.getSelectedFlags(i);if(!o)return void this.clearDragTargetAndCursor();let r=o.coordinates;if(null!=r&&r.midpoints&&(e=this.midPoints.getNearestMidPoint(t))&&(this.dragTarget={type:"midpoint",featureId:i,midPointId:e},this.setCursor(this.cursors.insertMidpoint)),r&&r.draggable){let{index:o,dist:r}=this.dragCoordinate.getDraggable(t,i);if(o>-1){if(e&&this.pixelDistance.measure(t,this.readFeature.getGeometry(e).coordinates)<r)return;return this.dragTarget={type:"coordinate",featureId:i,coordinateIndex:o}
1,void this.setCursor(this.getPointerOverCoordinateCursor())}}if(r&&r.resizable){let e=this.dragCoordinateResizeFeature.getDraggableIndex(t,i);if(e>-1)return this.dragTarget={type:"resize",featureId:i,coordinateIndex:e},void this.setCursor(this.getPointerOverResizeHandleCursor())}if(o.draggable&&this.dragFeature.canDrag(t,i)){if(e)return;return this.dragTarget={type:"feature",featureId:i},void this.setCursor(this.getPointerOverFeatureCursor())}e||this.clearDragTargetAndCursor()}styleFeature(t){let e=o({},{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&&"Point"===t.geometry.type){if(t.properties[h.SELECTION_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties[h.MID_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=50,e}else if(t.properties[h.SELECTED]){if("Point"===t.geometry.type&&t.properties[l.MARKER])return e.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,d,t),e.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),e.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),e;if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.selectedLineStringOpacity,1,t),e.lineStringDash=this.getDashArrayStylingValue(this.styles.selectedLineStringDash,void 0,t),e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=10,e}return e}afterFeatureUpdated(t){if(this.selected.length&&t.id===this.selected[0]){var e,i;let o=this.flags[t.properties.mode];if(null==o||null==(e=o.feature)||!e.coordinates)return;let r=t.geometry.type,n=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),"LineString"!==r&&"Polygon"!==r)return;let s=t.geometry.coordinates;this.selectionPoints.create({featureCoordinates:s,featureId:n}),null!=o&&null!=(i=o.feature)&&null!=(i=i.coordinates)&&i.midpoints&&this.midPoints.create({featureCoordinates:s,featureId:n})}}}class ei extends f{constructor(...t){super(...t),this.type=ej.Static,this.mode="static"}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}
1styleFeature(){return o({},{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 eo(t,e,i){let o=t[e];t[e]=t[i],t[i]=o}function er(t,e){en(t,0,t.children.length,e,t)}function en(t,e,i,o,r){r||(r=ep([])),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let n=e;n<i;n++){let e=t.children[n];es(r,t.leaf?o(e):e)}return r}function es(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function ea(t,e){return t.minX-e.minX}function ed(t,e){return t.minY-e.minY}function eh(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function el(t){return t.maxX-t.minX+(t.maxY-t.minY)}function eu(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function ec(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ep(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function eg(t,e,i,o,r){let n=[e,i];for(;n.length;){if((i=n.pop())-(e=n.pop())<=o)continue;let s=e+Math.ceil((i-e)/o/2)*o;(function t(e,i,o,r,n){for(;r>o;){if(r-o>600){let s=r-o+1,a=i-o+1,d=Math.log(s),h=.5*Math.exp(2*d/3),l=.5*Math.sqrt(d*h*(s-h)/s)*(a-s/2<0?-1:1);t(e,i,Math.max(o,Math.floor(i-a*h/s+l)),Math.min(r,Math.floor(i+(s-a)*h/s+l)),n)}let s=e[i],a=o,d=r;for(eo(e,o,i),n(e[r],s)>0&&eo(e,o,r);a<d;){for(eo(e,a,d),a++,d--;0>n(e[a],s);)a++;for(;n(e[d],s)>0;)d--}0===n(e[o],s)?eo(e,o,d):eo(e,++d,r),d<=i&&(o=d+1),i<=d&&(r=d-1)}})(t,s,e,i,r),n.push(e,s,s,i)}}class ey{constructor(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(t){let e=this.data,i=[];if(!ec(t,e))return i;let o=this.toBBox,r=[];for(;e;){for(let n=0;n<e.children.length;n++){let s=e.children[n],a=e.leaf?o(s):s;ec(t,a)&&(e.leaf?i.push(s):eu(t,a)?this._all(s,i):r.push(s))}e=r.pop()}return i}collides(t){let e=this.data;if(ec(t,e)){let i=[];for(;e;){for(let o=0;o<e.children.length;o++){let r=e.children[o],n=e.leaf?this.toBBox(r):r;if(ec(t,n)){if(e.leaf||eu(t,n))return!0;i.push(r)}}e=i.pop()}}return!1}load(t){if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){let t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e}insert(t){this._insert(t,this.data.height-1)}clear(){this.data=ep([])}remove(t){let e=this.data,i=this.toBBox(t),o=[],r=[],n,s,a=!1;for(;e||o.length;){if(e||(e=o.pop(),s=o[o.length-1],n=r.pop(),a=!0),e.leaf){let i=e.children.indexOf(t);-1!==i&&(e.children.splice(i,1),o.push(e),this._condense(o))}a||e.leaf||!eu(e,i)?s?(n++,e=s.children[n],a=!1):e=null:(o.push(e),r.push(n),n=0,s=e,e=e.children[0])}}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}_all(t,e){let i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,o){let r=i-e+1,n,s=this._maxEntries;if(r<=s)return er(n=ep(t.slice(e,i+1)),this.toBBox),n;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),(n=ep([])).leaf=!1,n.height=o;let a=Math.ceil(r/s),d=a*Math.ceil(Math.sqrt(s));eg(t,e,i,d,this.compareMinX);for(let r=e;r<=i;r+=d){let e=Math.min(r+d-1,i);eg(t,r,e,a,this.compareMinY);for(let i=r;i<=e;i+=a){let r=Math.min(i+a-1,e);n.children.push(this._build(t,i,r,o-1))}}return er(n,this.toBBox),n}_chooseSubtree(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){let i,o=1/0,r=1/0;for(let n=0;n<e.children.length;n++){let s=e.children[n],a=eh(s),d=(Math.max(s.maxX,t.maxX)-Math.min(s.minX,t.minX))*(Math.max(s.maxY,t.maxY)-Math.min(s.minY,t.minY))-a;d<r?(r=d,o=a<o?a:o,i=s):d===r&&a<o&&(o=a,i=s)}e=i||e.children[0]}return e}_insert(t,e,i){let o=i?t:this.toBBox(t),r=[],n=this._chooseSubtree(o,this.data,e,r);for(n.children.push(t),es(n,o);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(o,r,e)}_split(t,e){let i=t[e],o=i.children.length,r=this._minEntries;this._chooseSplitAxis(i,r,o);let n=this._chooseSplitIndex(i,r,o),s=ep(i.children.splice(n,i.children.length-n));s.height=i.height,s.leaf=i.leaf,er(i,this.toBBox),er(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)}_splitRoot(t,e){this.data=ep([t,e]),this.data.height=t.height+1,this.data.leaf=!1,er(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let o,r=1/0,n=1/0;for(let s=e;s<=i-e;s++){let e=en(t,0,s,this.toBBox),a=en(t,s,i,this.toBBox),d=function(t,e){let i=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY);return Math.max(0,Math.min(t.maxX,e.maxX)-i)*Math.max(0,Math.min(t.maxY,e.maxY)-o)}(e,a),h=eh(e)+eh(a);d<r?(r=d,o=s,n=h<n?h:n):d===r&&h<n&&(n=h,o=s)}return o||i-e}_chooseSplitAxis(t,e,i){let o=t.leaf?this.compareMinX:ea,r=t.leaf?this.compareMinY:ed;
1this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,r)&&t.children.sort(o)}_allDistMargin(t,e,i,o){t.children.sort(o);let r=this.toBBox,n=en(t,0,e,r),s=en(t,i-e,i,r),a=el(n)+el(s);for(let o=e;o<i-e;o++){let e=t.children[o];es(n,t.leaf?r(e):e),a+=el(n)}for(let o=i-e-1;o>=e;o--){let e=t.children[o];es(s,t.leaf?r(e):e),a+=el(s)}return a}_adjustParentBBoxes(t,e,i){for(let o=i;o>=0;o--)es(e[o],t)}_condense(t){for(let e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():er(t[i],this.toBBox)}}class em{constructor(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new ey(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)}toBBox(t){let e,i=[],o=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(let t=0;t<e.length;t++)o.push(e[t][1]),i.push(e[t][0]);return{minX:Math.min(...i),minY:Math.min(...o),maxX:Math.max(...i),maxY:Math.max(...o)}}insert(t){if(this.idToNode.get(String(t.id)))throw Error("Feature already exists");let e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}load(t){let e=[],i=new Set;t.forEach(t=>{let o=this.toBBox(t);if(this.setMaps(t,o),i.has(String(t.id)))throw Error(`Duplicate feature ID found ${t.id}`);i.add(String(t.id)),e.push(o)}),this.tree.load(e)}update(t){this.remove(t.id);let e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}remove(t){let e=this.idToNode.get(t);if(!e)throw Error(`${t} not inserted into the spatial index`);this.tree.remove(e)}clear(){this.tree.clear()}search(t){return this.tree.search(this.toBBox(t)).map(t=>this.nodeToId.get(t))}collides(t){return this.tree.collides(this.toBBox(t))}}let ef={getId:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}),isValidId:t=>"string"==typeof t&&36===t.length},ev={target:"geometry"},eC={target:"properties"};class eP{constructor(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new em,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:ef}clone(t){return JSON.parse(JSON.stringify(t))}getId(){return this.idStrategy.getId()}has(t){return!!this.store[t]}load(t,e,i,o){if(0===t.length)return[];let r=this.clone(t),n=[],s=[];r=r.filter(t=>{null==t.id&&(t.id=this.idStrategy.getId());let i=t.id;if(e){let o=e(t);if(!o.valid)return n.push({id:i,valid:!1,reason:o.reason}),!1}if(this.tracked){if(t.properties.createdAt){if(!p(t.properties.createdAt))return n.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!p(t.properties.updatedAt))return n.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return this.has(i)?(n.push({id:i,valid:!1,reason:`Feature already exists with this id: ${i}`}),!1):(this.store[i]=t,s.push(t),n.push({id:i,valid:!0}),!0)}),this.spatialIndex.load(r);let a=s.map(({id:t})=>t);return a.length>0&&(this._onChange(a,"create",o),i&&s.forEach(t=>{i(t)})),n}search(t,e){let i=this.spatialIndex.search(t).map(t=>this.store[t]);return this.clone(e?i.filter(e):i)}registerOnChange(t){this._onChange=(e,i,o)=>{t(e,i,o)}}getGeometryCopy(t){let e=this.store[t];if(!e)throw Error(`No feature with this id (${t}), can not get geometry copy`);return this.clone(e.geometry)}getPropertiesCopy(t){let e=this.store[t];if(!e)throw Error(`No feature with this id (${t}), can not get properties copy`);return this.clone(e.properties)}updateProperty(t,e){let i=new Set;t.forEach(({id:t,property:e,value:o})=>{let r=this.store[t];if(!r)throw Error(`No feature with this (${t}), can not update geometry`);r.properties[e]!==o&&(i.add(t),void 0===o?delete r.properties[e]:r.properties[e]=o,this.tracked&&(r.properties.updatedAt=+new Date))}),this._onChange&&i.size>0&&this._onChange(Array.from(i),"update",e?o({},e,eC):eC)}updateGeometry(t,e){let i=new Set;t.forEach(({id:t,geometry:e})=>{i.add(t);let o=this.store[t];if(!o)throw Error(`No feature with this (${t}), can not update geometry`);o.geometry=this.clone(e),this.spatialIndex.update(o),this.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&i.size>0&&this._onChange(Array.from(i),"update",e?o({},e,ev):ev)}create(t,e){let i=[];return t.forEach(({geometry:t,properties:e})=>{let r,n=o({},e);this.tracked&&(r=+new Date,e?(n.createdAt="number"==typeof e.createdAt?e.createdAt:r,n.updatedAt="number"==typeof e.updatedAt?e.updatedAt:r):n={createdAt:r,updatedAt:r});let s=this.getId(),a={id:s,type:"Feature",geometry:t,properties:n};this.store[s]=a,this.spatialIndex.insert(a),i.push(s)}),this._onChange&&this._onChange([...i],"create",e),i}delete(t,e){t.forEach(t=>{if(!this.store[t])throw Error(`No feature with id ${t}, can not delete`);delete this.store[t],this.spatialIndex.remove(t)}),this._onChange&&this._onChange([...t],"delete",e)}
1copy(t){return this.clone(this.store[t])}copyAll(){return this.clone(Object.keys(this.store).map(t=>this.store[t]))}copyAllWhere(t){return this.clone(Object.keys(this.store).map(t=>this.store[t]).filter(e=>e.properties&&t(e.properties)))}clear(t){let e=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(e,"delete",t)}size(){return Object.keys(this.store).length}}function eI(t){let e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(eF(e[0]));for(let t=1;t<e.length;t++)i-=Math.abs(eF(e[t]))}return i}let eS=Math.PI/180;function eF(t){let e=t.length;if(e<=2)return 0;let i=0,o=0;for(;o<e;)i+=(t[o+2>=e?(o+2)%e:o+2][0]*eS-t[o][0]*eS)*Math.sin(t[o+1===e?0:o+1][1]*eS),o++;return 20294876564838.72*i}let ex="Feature is smaller than the minimum area",eO=(t,e)=>"Polygon"!==t.geometry.type?{valid:!1,reason:g}:eI(t.geometry)<e?{valid:!1,reason:ex}:{valid:!0},eM=(t,e)=>"Polygon"!==t.geometry.type?{valid:!1,reason:g}:eI(t.geometry)>e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0},eE="Feature is not a Polygon or LineString",ew="Feature intersects itself",eD=t=>"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:eE}:M(t)?{valid:!1,reason:ew}:{valid:!0};function ek(t,e,i){let o=ta(t,e),r=ta(e,i)-o;return r<0&&(r+=360),180-Math.abs(r-90-90)}let e_={cancel:"Escape",finish:"Enter"},eb={start:"crosshair",close:"pointer"};class eT extends f{constructor(t){super(t,!0),this.mode="angled-rectangle",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=e_,this.cursors=eb,this.mouseMove=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents))}close(){if(void 0===this.currentId||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[l.CURRENTLY_DRAWING]:void 0},context:{updateType:eV.Finish,action:r}}))return;let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;let e=[];
1if(1===this.currentCoordinate)e=this.getUpdateForSecondCoordinate(t);else{if(2!==this.currentCoordinate)return;e=this.getNewSecondAndThirdCoordinates(t)}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:eV.Provisional}})}getUpdateForSecondCoordinate(t){return[{type:z,index:1,coordinate:[t.lng,t.lat]},{type:z,index:2,coordinate:[t.lng,t.lat]}]}getNewSecondAndThirdCoordinates(t){let e;if(!this.currentId)throw Error("No current feature being drawn");let i=this.readFeature.getCoordinate(this.currentId,0),o=this.readFeature.getCoordinate(this.currentId,1),r=tY(i,o,this.coordinatePrecision,this.project,this.unproject),n=F(i[0],i[1]),s=F(r[0],r[1]),a=F(o[0],o[1]),d=F(t.lng,t.lat),h=X(d,n)<X(d,a),l=ek(n,s,d),u=h?90-l:ek(n,s,d)-90,c=X(s,d),p=Math.cos(P(u))*c,g=ta(n,a)+("right"==((e=(d.x-a.x)*(n.y-a.y)-(d.y-a.y)*(n.x-a.x))>1e-10?"left":e<-1e-10?"right":"left")?-90:90),y=tn(n,p,g),m=tn(a,p,g),f=x(y.x,y.y),v=x(m.x,m.y);return[{type:z,index:2,coordinate:[S(v.lng,this.coordinatePrecision),S(v.lat,this.coordinatePrecision)]},{type:z,index:3,coordinate:[S(f.lng,this.coordinatePrecision),S(f.lat,this.coordinatePrecision)]}]}onClick(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){let{id:e}=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});this.currentId=e,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){let e=this.readFeature.getCoordinate(this.currentId,0);if($([t.lng,t.lat],e)||!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:z,index:1,coordinate:[t.lng,t.lat]},{type:B,index:1,coordinate:[t.lng,t.lat]}],context:{updateType:eV.Commit}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()}onKeyUp(t){if(t.key===this.keyEvents.cancel)this.cleanUp();else if(t.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)}
1styleFeature(t){let e=o({},{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.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e}validateFeature(t){return this.validateModeFeature(t,t=>L(t,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentId===t.id&&(this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate})}}function eN(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}let eR={cancel:"Escape",finish:"Enter"},eL={start:"crosshair",close:"pointer"};class eW extends f{constructor(t){super(t,!0),this.mode="sector",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=eR,this.direction=void 0,this.arcPoints=64,this.cursors=eL,this.mouseMove=!1,this.readFeature=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.arcPoints&&(this.arcPoints=t.arcPoints)}close(){if(void 0===this.currentId||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[l.CURRENTLY_DRAWING]:void 0},coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:G},context:{updateType:eV.Finish,action:r}}))return;let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}getSectorCoordinates(t){let e,i=this.readFeature.getCoordinates(this.currentId),o=i[0],r=i[1],n=[t.lng,t.lat],s=F(o[0],o[1]),a=F(r[0],r[1]),d=F(n[0],n[1]);if(void 0===this.direction){let t=eN(s,a,d);this.direction=t?"clockwise":"anticlockwise"}let h=X(s,a),l=ta(s,a),u=ta(s,d),c=this.arcPoints,p=[o],g=td(l),y=td(u);"anticlockwise"===this.direction?(e=y-g)<0&&(e+=360):(e=g-y)<0&&(e+=360);let m=("anticlockwise"===this.direction?1:-1)*e/c;p.push(r);for(let t=0;t<=c;t++){let e=tn(s,h,g+t*m),{lng:i,lat:o}=x(e.x,e.y),r=[S(i,this.coordinatePrecision),S(o,this.coordinatePrecision)];r[0]!==p[p.length-1][0]&&r[1]!==p[p.length-1][1]&&p.push(r)}return p.push(o),p}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){let e;if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){if(1===this.currentCoordinate)e=[{type:z,index:1,coordinate:[t.lng,t.lat]},{type:z,index:2,coordinate:[t.lng,t.lat]}];else{if(2!==this.currentCoordinate)return;{let i=this.getSectorCoordinates(t);if(!i)return;e={type:G,coordinates:[i]}}}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:eV.Provisional}})}}onClick(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){let e=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});this.currentId=null==e?void 0:e.id,this.currentCoordinate++,this.setDrawing()}
1else if(1===this.currentCoordinate&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,index:0,newCoordinate:[t.lng,t.lat]})||!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:z,index:1,coordinate:[t.lng,t.lat]},{type:z,index:2,coordinate:[t.lng,t.lat]}],context:{updateType:eV.Provisional}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let t=this.currentId;this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)}styleFeature(t){let e=o({},{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.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e}validateFeature(t){return this.validateModeFeature(t,t=>L(t,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentId===t.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate})}}let eU={cancel:"Escape",finish:"Enter"},eA={start:"crosshair",close:"pointer"};class eB extends f{constructor(t){super(t,!0),this.mode="sensor",this.currentCoordinate=0,this.currentId=void 0,this.currentInitialArcId=void 0,this.currentStartingPointId=void 0,this.keyEvents=eU,this.direction=void 0,this.arcPoints=64,this.cursors=eA,this.mouseMove=!1,this.readFeature=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.arcPoints&&(this.arcPoints=t.arcPoints)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentInitialArcId&&void 0!==this.currentStartingPointId&&0!==this.currentCoordinate){if(2===this.currentCoordinate){let e=this.getUpdatedLineStringCoordinates(t);if(!e)return;this.mutateFeature.updateLineString({featureId:this.currentInitialArcId,coordinateMutations:{type:G,coordinates:e},context:{updateType:eV.Provisional}})}else if(3===this.currentCoordinate){let e=this.getUpdatedPolygonCoordinates(t);if(!e)return;if(this.currentId)this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:G,coordinates:[e]},context:{updateType:eV.Provisional}});else{let t=this.mutateFeature.createPolygon({coordinates:e,properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});if(!t)return;this.currentId=t.id}}}}onClick(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){let e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode}});if(!e)return;this.currentStartingPointId=e.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){let e=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode}});if(!e)return;this.currentInitialArcId=e.id,this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.mutateFeature.deleteFeatureIfPresent(this.currentId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()}
1styleFeature(t){let e=o({},{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.properties.mode===this.mode&&("Polygon"===t.geometry.type?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=10):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.centerPointOpacity,1,t),e.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.centerPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=20)),e}validateFeature(t){return this.validateModeFeature(t,t=>L(t,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate})}close(){if(void 0===this.currentStartingPointId)return;let t=this.currentStartingPointId,e=this.currentInitialArcId;if(this.currentId&&!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[l.CURRENTLY_DRAWING]:void 0},coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:G},context:{updateType:eV.Finish,action:r}}))return;let i=this.currentId;this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),i&&this.onFinish(i,{mode:this.mode,action:r})}getUpdatedPolygonCoordinates(t){if(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<3)return;let e=this.readFeature.getCoordinates(this.currentInitialArcId);if(e.length<2||!this.direction)return;let i=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,o=e[0],r=e[e.length-1],n=F(t.lng,t.lat),s=F(o[0],o[1]),a=F(r[0],r[1]),d=F(i[0],i[1]),h=X(d,s),l=X(d,n)<h?s:n,u=ta(d,n),c=ta(d,s),p=ta(d,a),g=td(c),y=td(p),m=td(u);if(this.notInSector({normalizedCursor:m,normalizedStart:g,normalizedEnd:y,direction:this.direction}))return;let f=this.getDeltaBearing(this.direction,g,y),v=this.arcPoints,C=("anticlockwise"===this.direction?1:-1)*f/v,P=X(d,l),I=[];for(let t=0;t<=v;t++){let i=tn(d,P,g+t*C),{lng:o,lat:r}=x(i.x,i.y),n=[S(o,this.coordinatePrecision),S(r,this.coordinatePrecision)];n[0]!==e[e.length-1][0]&&n[1]!==e[e.length-1][1]&&I.unshift(n)}return e.push(...I),e.push(e[0]),e}getUpdatedLineStringCoordinates(t){let e;if(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<2)return;let i=this.readFeature.getGeometry(this.currentInitialArcId).coordinates,o=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,r=i[0],n=[t.lng,t.lat],s=F(r[0],r[1]),a=F(n[0],n[1]),d=F(o[0],o[1]),h=X(d,s);if(void 0===this.direction){let t=eN(d,s,a);this.direction=t?"clockwise":"anticlockwise"}let l=ta(d,s),u=ta(d,a),c=this.arcPoints,p=[r],g=td(l),y=td(u);
1"anticlockwise"===this.direction?(e=y-g)<0&&(e+=360):(e=g-y)<0&&(e+=360);let m=("anticlockwise"===this.direction?1:-1)*e/c;for(let t=0;t<=c;t++){let e=tn(d,h,g+t*m),{lng:i,lat:o}=x(e.x,e.y),r=[S(i,this.coordinatePrecision),S(o,this.coordinatePrecision)];r[0]!==p[p.length-1][0]&&r[1]!==p[p.length-1][1]&&p.push(r)}return p}getDeltaBearing(t,e,i){let o;return"anticlockwise"===t?(o=i-e)<0&&(o+=360):(o=e-i)<0&&(o+=360),o}notInSector({normalizedCursor:t,normalizedStart:e,normalizedEnd:i,direction:o}){return"clockwise"===o?e<=i?t>=e&&t<=i:t>=e||t<=i:e>=i?t<=e&&t>=i:t<=e||t>=i}}class ez{constructor({name:t,callback:e,unregister:i,register:o}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=t,this.register=()=>{this.registered||(this.registered=!0,o(e))},this.unregister=()=>{this.register&&(this.registered=!1,i(e))},this.callback=e}}var eH,eG,eV,ej,eK={__proto__:null,GeoJSONStore:eP,TerraDrawBaseDrawMode:f,TerraDrawBaseSelectMode:v,TerraDrawBaseAdapter:class{constructor(t){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="boolean"==typeof t.ignoreMismatchedPointerEvents&&t.ignoreMismatchedPointerEvents,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}getButton(t){return -1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"}getMapElementXYPosition(t){let{left:e,top:i}=this.getMapEventElement(t.type).getBoundingClientRect();return{containerX:t.clientX-e,containerY:t.clientY-i}}getDrawEventFromEvent(t,e=!1){let i=this.getLngLatFromEvent(t);if(!i)return null;let{lng:o,lat:r}=i,{containerX:n,containerY:s}=this.getMapElementXYPosition(t),a=this.getButton(t),d=Array.from(this._heldKeys);return{lng:S(o,this._coordinatePrecision),lat:S(r,this._coordinatePrecision),containerX:n,containerY:s,button:a,heldKeys:d,isContextMenu:e}}register(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(t=>{t.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new ez({name:"pointerdown",callback:t=>{if(!this._currentModeCallbacks||!t.isPrimary)return;let e=this.getDrawEventFromEvent(t);e&&(this._dragState="pre-dragging",this._lastDrawEvent=e,this._lastPointerDownEventTarget=t.target?t.target:void 0)},register:t=>{this.getMapEventElement("pointerdown").addEventListener("pointerdown",t)},unregister:t=>{this.getMapEventElement("pointerdown").removeEventListener("pointerdown",t)}}),new ez({name:"pointermove",callback:t=>{if(!this._currentModeCallbacks||!t.isPrimary)return;t.preventDefault();let e=this.getDrawEventFromEvent(t);if(e)if("not-dragging"===this._dragState)this._currentModeCallbacks.onMouseMove(e),this._lastDrawEvent=e;else if("pre-dragging"===this._dragState){if(!this._lastDrawEvent)return;let t={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},i={x:e.containerX,y:e.containerY},o=this._currentModeCallbacks.getState(),r=X(t,i);if("drawing"===o?r<this._minPixelDragDistanceDrawing:"selecting"===o?r<this._minPixelDragDistanceSelecting:r<this._minPixelDragDistance)return;this._nextKeyUpIsContextMenu=!1,this._dragState="dragging",this._currentModeCallbacks.onDragStart(e,t=>{this.setDraggability.bind(this)(t)})}else"dragging"===this._dragState&&this._currentModeCallbacks.onDrag(e,t=>{this.setDraggability.bind(this)(t)})},register:t=>{this.getMapEventElement("pointermove").addEventListener("pointermove",t)},unregister:t=>{this.getMapEventElement("pointermove").removeEventListener("pointermove",t)}}),new ez({name:"contextmenu",callback:t=>{this._currentModeCallbacks&&(t.preventDefault(),this._nextKeyUpIsContextMenu=!0)},register:t=>{this.getMapEventElement("contextmenu").addEventListener("contextmenu",t)},unregister:t=>{this.getMapEventElement("contextmenu").removeEventListener("contextmenu",t)}}),new ez({name:"pointerup",callback:t=>{if(!this._currentModeCallbacks||t.target!==this.getMapEventElement("pointerup")||this._ignoreMismatchedPointerEvents&&this._lastPointerDownEventTarget!==t.target||(this._lastPointerDownEventTarget=void 0,!t.isPrimary))return;let e=this.getDrawEventFromEvent(t);e&&("dragging"===this._dragState?this._currentModeCallbacks.onDragEnd(e,t=>{this.setDraggability.bind(this)(t)}):"not-dragging"!==this._dragState&&"pre-dragging"!==this._dragState||(this._nextKeyUpIsContextMenu&&(e.isContextMenu=!0,this._nextKeyUpIsContextMenu=!1),this._currentModeCallbacks.onClick(e)),this._dragState="not-dragging",this.setDraggability(!0))},register:t=>{this.getMapEventElement("pointerup").addEventListener("pointerup",t)},unregister:t=>{this.getMapEventElement("pointerup").removeEventListener("pointerup",t)}}),new ez({name:"keyup",callback:t=>{this._currentModeCallbacks&&(this._heldKeys.delete(t.key),this._currentModeCallbacks.onKeyUp({key:t.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>t.preventDefault()}))},register:t=>{this.getMapEventElement("keyup").addEventListener("keyup",t)},unregister:t=>{this.getMapEventElement("keyup").removeEventListener("keyup",t)}}),new ez({name:"keydown",callback:t=>{this._currentModeCallbacks&&(this._heldKeys.add(t.key),this._currentModeCallbacks.onKeyDown({key:t.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>t.preventDefault()}))},register:t=>{this.getMapEventElement("keydown").addEventListener("keydown",t)},unregister:t=>{this.getMapEventElement("keydown").removeEventListener("keydown",t)}})]}
1unregister(){this._listeners.forEach(t=>{t.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:h};let eY={ValidationReasonFeatureNotPoint:t_,ValidationReasonFeatureInvalidCoordinates:tb,ValidationReasonFeatureInvalidCoordinatePrecision:tT,ValidationReasonFeatureNotPolygon:g,ValidationReasonFeatureHasHoles:_,ValidationReasonFeatureLessThanFourCoordinates:b,ValidationReasonFeatureHasInvalidCoordinates:T,ValidationReasonFeatureCoordinatesNotClosed:N,ValidationReasonFeatureNotPolygonOrLineString:eE,ValidationReasonFeatureSelfIntersects:ew,ValidationReasonFeatureLessThanMinSize:ex,ValidationReasonModeMismatch:y},eX={cancel:"Escape",finish:"Enter"},e$={start:"crosshair",close:"pointer"};class eq extends f{constructor(t){super(t,!0),this.mode="freehand-linestring",this.canClose=!1,this.currentId=void 0,this.minDistance=20,this.keyEvents=eX,this.cursors=e$,this.preventNewFeature=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.minDistance&&(this.minDistance=t.minDistance),null===(null==t?void 0:t.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=t&&t.keyEvents&&(this.keyEvents=o({},this.keyEvents,t.keyEvents)),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors))}close(){if(void 0===this.currentId||!this.mutateFeature.updateLineString({featureId:this.currentId,propertyMutations:{[l.CURRENTLY_DRAWING]:void 0},context:{updateType:eV.Finish,action:r}}))return;let t=this.currentId;this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:r})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onMouseMove(t){if(void 0===this.currentId||!1===this.canClose)return void this.setCursor(this.cursors.start);let[e,i]=this.readFeature.getCoordinate(this.currentId,-2),{x:o,y:r}=this.project(e,i),n=X({x:o,y:r},{x:t.containerX,y:t.containerY}),[s,a]=this.readFeature.getCoordinate(this.currentId,-1),{x:d,y:h}=this.project(s,a),l=X({x:d,y:h},{x:t.containerX,y:t.containerY});if(this.setCursor(l<this.pointerDistance?this.cursors.close:this.cursors.start),n<this.minDistance)return;let u=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:B,index:-1,coordinate:[t.lng,t.lat]}],context:{updateType:eV.Provisional}});u&&this.closingPoints.update(u.geometry.coordinates)}onClick(t){if(("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&!this.preventNewFeature){if(!1===this.canClose){let{id:e,geometry:i}=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode,[l.CURRENTLY_DRAWING]:!0}});return this.closingPoints.create(i.coordinates),this.currentId=e,this.canClose=!0,void("drawing"!==this.state&&this.setDrawing())}this.close()}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let t=this.currentId;this.currentId=void 0,this.canClose=!1,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()}
1styleFeature(t){let e=o({},{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"Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode?(e.lineStringDash=this.getDashArrayStylingValue(this.styles.lineStringDash,void 0,t),e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,void 0===e.lineStringOpacity?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=10):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,1,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=50),e}validateFeature(t){return this.validateModeFeature(t,t=>tc(t,this.coordinatePrecision))}afterFeatureUpdated(t){this.currentId===t.id&&(this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0)}registerBehaviors(t){this.readFeature=new q(t),this.mutateFeature=new V(t,{validate:this.validate}),this.pixelDistance=new ti(t),this.closingPoints=new tS(t,this.pixelDistance,this.mutateFeature,this.readFeature)}}let eZ={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"};class eJ extends f{constructor(t){super(t,!0),this.mode="marker",this.cursors=eZ,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(t)}updateOptions(t){super.updateOptions(t),null!=t&&t.cursors&&(this.cursors=o({},this.cursors,t.cursors)),null!=t&&t.editable&&(this.editable=t.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor("unset")}onClick(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){let e=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=null==e?void 0:e.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}}onDrag(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:G,coordinates:[t.lng,t.lat]},propertyMutations:{[l.EDITED]:!0},context:{updateType:eV.Provisional}})}onDragEnd(t,e){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,t)||void 0===this.editedFeatureId||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[l.EDITED]:!1},context:{updateType:eV.Finish,action:"edit"}}))return;let i=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(i,{mode:this.mode,action:r})}registerBehaviors(t){this.pixelDistance=new ti(t),this.clickBoundingBox=new te(t),this.pointSearch=new tR(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new V(t,{validate:this.validate})}
1styleFeature(t){var e,i,r;let n=o({},{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"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(n.zIndex=30,n.markerHeight=this.getNumericStylingValue(null==(e=this.styles)?void 0:e.markerHeight,40,t),n.markerWidth=this.getNumericStylingValue(null==(i=this.styles)?void 0:i.markerWidth,32,t),n.markerUrl=this.getUrlStylingValue(null==(r=this.styles)?void 0:r.markerUrl,d,t)),n}validateFeature(t){return this.validateModeFeature(t,t=>tN(t,this.coordinatePrecision))}onLeftClick(t){let e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode,[l.MARKER]:!0},context:{updateType:eV.Finish,action:r}});e&&this.onFinish(e.id,{mode:this.mode,action:r})}onRightClick(t){if(!this.editable)return;let e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}afterFeatureUpdated(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}}let eQ=[{key:"z",heldKeys:["meta"]},{key:"z",heldKeys:["control"]}],e0=[{key:"z",heldKeys:["meta","shift"]},{key:"z",heldKeys:["control","shift"]},{key:"y",heldKeys:["control"]}],e1=(t,e)=>{let i=t.key.toLowerCase(),o=new Set(t.heldKeys.map(t=>t.toLowerCase()).filter(t=>t!==i));if(e.key.toLowerCase()!==i)return!1;let r=new Set(e.heldKeys.map(t=>t.toLowerCase()));if(o.size!==r.size)return!1;for(let t of r)if(!o.has(t))return!1;return!0};class e3{constructor(t){var e,i;this.undoKeyboardShortcuts=void 0,this.redoKeyboardShortcuts=void 0,this.undoKeyboardShortcuts=null!=(e=null==t?void 0:t.undo)?e:eQ,this.redoKeyboardShortcuts=null!=(i=null==t?void 0:t.redo)?i:e0}isUndoKeyboardShortcut(t){return this.undoKeyboardShortcuts.some(e=>e1(t,e))}isRedoKeyboardShortcut(t){return this.redoKeyboardShortcuts.some(e=>e1(t,e))}}function e2(t){return void 0!==t&&Number.isFinite(t)?Math.max(0,Math.floor(t)):1/0}let e9="undo",e7="redo",e4="push",e6="mode",e8="session";class e5{constructor(t){this.getModeState=void 0,this.getModeHistorySizes=void 0,this.undoMode=void 0,this.redoMode=void 0,this.clearModeHistory=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.lastHistorySizes={undoSize:0,redoSize:0},this.maxStackSize=e2(null==t?void 0:t.maxStackSize)}getMaxStackSize(){return this.maxStackSize}register(t){this.getModeState=t.getModeState,this.getModeHistorySizes=t.getModeHistorySizes,this.undoMode=t.undoMode,this.redoMode=t.redoMode,this.clearModeHistory=t.clearModeHistory,this.onHistoryChange=t.onHistoryChange}inDrawingState(){return!!this.getModeState&&"drawing"===this.getModeState()}canUndo(){if(!this.inDrawingState())return!1;let{undoSize:t}=this.getHistorySizes();return t>0}canRedo(){if(!this.inDrawingState())return!1;let{redoSize:t}=this.getHistorySizes();return t>0}undo(){return!(!this.canUndo()||!this.undoMode||(this.undoMode(),this.emitHistoryChange(e9),0))}redo(){return!(!this.canRedo()||!this.redoMode||(this.redoMode(),this.emitHistoryChange(e7),0))}clearHistory(){this.clearModeHistory&&this.clearModeHistory(),this.lastHistorySizes={undoSize:0,redoSize:0}}getHistorySizes(){return this.getModeHistorySizes?this.getModeHistorySizes():{undoSize:0,redoSize:0}}undoSize(){return this.getHistorySizes().undoSize}redoSize(){return this.getHistorySizes().redoSize}emitPushIfHistoryChangedFromLastSnapshot(){if(!this.inDrawingState())return;let t=this.getHistorySizes();t.undoSize===this.lastHistorySizes.undoSize&&t.redoSize===this.lastHistorySizes.redoSize||this.emitHistoryChange(e4)}emitPushIfHistoryChanged(t){if(!this.inDrawingState())return;let e=this.getHistorySizes();e.undoSize===t.undoSize&&e.redoSize===t.redoSize||this.emitHistoryChange(e4)}emitHistoryChange(t){if(!this.onHistoryChange)return;let{undoSize:e,redoSize:i}=this.getHistorySizes();this.lastHistorySizes={undoSize:e,redoSize:i},this.onHistoryChange({cause:t,stack:e6,undoStackSize:e,redoStackSize:i})}}class it{constructor(t){this.draw=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.historyById={},this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[],this.isReplayingHistory=!1,this.emitStackChange=t=>{this.onHistoryChange&&this.onHistoryChange({cause:t,stack:e8,undoStackSize:this.undoStack.length,redoStackSize:this.redoStack.length})},this.handleChange=(t,e,i)=>{if(!this.draw||this.isDrawing()||0===this.maxStackSize)return;if("update"===e){if(void 0===i||!("origin"in i)||"api"!==i.origin||this.isReplayingHistory)return;let e=Array.isArray(t)?t:[t],o=!1;for(let t of e){if(null==t)continue;
1let e=String(t),i=this.draw.getSnapshotFeature(t);i&&(this.historyById[e]||(this.historyById[e]=[]),this.historyById[e].push(i),this.pushUndoStackEntry({id:t,toIndex:this.historyById[e].length-1,action:"single"}),o=!0)}return void(o&&(this.redoStack.length=0,this.emitStackChange(e4)))}if("delete"!==e&&"create"!==e)return;if("create"===e){if(void 0===i||!("origin"in i)||"api"!==i.origin)return;let e=!1,o=Array.isArray(t)?t:[t],r=[];for(let t of o){if(this.ignoreProgrammaticCreate[t]){delete this.ignoreProgrammaticCreate[t],delete this.deletedFeatureIds[t];continue}let i=String(t),o=this.draw.getSnapshotFeature(t);o&&(this.deletedFeatureIds[t]&&(this.historyById[i]=[],delete this.deletedFeatureIds[t]),this.historyById[i]||(this.historyById[i]=[]),this.historyById[i].push(o),r.push({id:t,toIndex:this.historyById[i].length-1,snapshot:o}),e=!0)}if(r.length>1)this.pushUndoStackEntry({id:r[0].id,toIndex:r[0].toIndex,action:"batch-create",metadata:{entries:r}});else if(1===r.length){let t=r[0];this.pushUndoStackEntry({id:t.id,toIndex:t.toIndex,action:"single"})}return void(e&&(this.redoStack.length=0,this.emitStackChange(e4)))}let o=!1,r=Array.isArray(t)?t:[t],n=[];for(let t of r){let e=String(t);if(this.ignoreProgrammaticDelete[t]){delete this.ignoreProgrammaticDelete[t];continue}if(!this.historyById[e])continue;let i=this.historyById[e].length-1;if(i>=0){let r=this.historyById[e][i];if(!r)continue;n.push({id:t,toIndex:i,snapshot:r}),this.deletedFeatureIds[t]=!0,o=!0}}if(n.length>1)this.pushUndoStackEntry({id:n[0].id,toIndex:n[0].toIndex,action:"batch-delete",metadata:{entries:n}});else if(1===n.length){let t=n[0];this.pushUndoStackEntry({id:t.id,toIndex:t.toIndex,action:"single"})}o&&(this.redoStack.length=0,this.emitStackChange(e4))},this.handleFinish=t=>{if(!this.draw||0===this.maxStackSize||this.isReplayingHistory)return;let e=Array.isArray(t)?t:[t],i=!1;for(let t of e){if(null==t)continue;let e=String(t),o=this.draw.getSnapshotFeature(t);o&&(this.historyById[e]||(this.historyById[e]=[]),this.historyById[e].push(o),i||(this.redoStack.length=0,i=!0),this.pushUndoStackEntry({id:t,toIndex:this.historyById[e].length-1,action:"single"}),this.emitStackChange(e4))}},this.maxStackSize=e2(null==t?void 0:t.maxStackSize)}register(t){this.draw!==t.draw&&(this.draw&&(this.draw.off("change",this.handleChange),this.draw.off("finish",this.handleFinish)),this.draw=t.draw,this.draw.on("change",this.handleChange),this.draw.on("finish",this.handleFinish)),this.onHistoryChange=t.onHistoryChange}pushUndoStackEntry(t){0!==this.maxStackSize&&(this.undoStack.push(t),this.undoStack.length>this.maxStackSize&&this.undoStack.shift())}pushRedoStackEntry(t){0!==this.maxStackSize&&(this.redoStack.push(t),this.redoStack.length>this.maxStackSize&&this.redoStack.shift())}isDrawing(){return!!this.draw&&"drawing"===this.draw.getModeState()}
1applySnapshotDuringReplay(t,e){if(this.draw){this.isReplayingHistory=!0;try{this.draw.hasFeature(t)&&(this.ignoreProgrammaticDelete[t]=!0,this.draw.removeFeatures([t])),this.ignoreProgrammaticCreate[t]=!0,delete this.deletedFeatureIds[t],this.draw.addFeatures([e])}finally{this.isReplayingHistory=!1}}}canUndo(){return!(!this.draw||this.isDrawing())&&this.undoStack.length>0}canRedo(){return!(!this.draw||this.isDrawing())&&this.redoStack.length>0}undo(){var t,e;if(!this.canUndo()||!this.draw)return!1;let i=this.undoStack.pop();if(!i)return this.emitStackChange(e9),!1;if("batch-create"===i.action){let e=(null==(t=i.metadata)?void 0:t.entries)||[];if(0===e.length)return this.emitStackChange(e9),!1;let o=e.map(t=>t.id);return o.forEach(t=>{this.ignoreProgrammaticDelete[t]=!0,this.deletedFeatureIds[t]=!0}),this.draw.removeFeatures(o),this.pushRedoStackEntry({id:e[0].id,toIndex:e[0].toIndex,action:"batch-create",metadata:{entries:e}}),this.emitStackChange(e9),!0}if("batch-delete"===i.action){let t=(null==(e=i.metadata)?void 0:e.entries)||[];if(0===t.length)return this.emitStackChange(e9),!1;let o=t.map(t=>t.snapshot).filter(t=>void 0!==t);return o.length>0&&(t.forEach(t=>{this.ignoreProgrammaticCreate[t.id]=!0,delete this.deletedFeatureIds[t.id]}),this.draw.addFeatures(o)),this.pushRedoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:"batch-delete",metadata:{entries:t}}),this.emitStackChange(e9),!0}let o=i.id,r=i.toIndex,n=String(o),s=this.historyById[n];if(!s||0===s.length)return this.emitStackChange(e9),!1;let a=Math.min(r,s.length-1);if(!this.draw.hasFeature(o)){let t=s[a];return t?(this.ignoreProgrammaticCreate[o]=!0,delete this.deletedFeatureIds[o],this.draw.addFeatures([t]),this.pushRedoStackEntry({id:o,toIndex:a,action:"delete",snapshot:t}),this.emitStackChange(e9),!0):(this.emitStackChange(e9),!1)}if(a<=0)return this.pushRedoStackEntry({id:o,toIndex:0,action:"create"}),this.ignoreProgrammaticDelete[o]=!0,this.deletedFeatureIds[o]=!0,this.draw.removeFeatures([o]),this.undoStack=this.undoStack.filter(t=>t.id!==o),this.emitStackChange(e9),!0;let d=s[a],h=s[a-1];return d&&this.pushRedoStackEntry({id:o,toIndex:a,snapshot:d,action:"update"}),this.applySnapshotDuringReplay(o,h),s.length=a,this.emitStackChange(e9),!0}redo(){if(!this.canRedo()||!this.draw)return!1;let{id:t,toIndex:e,snapshot:i,action:o,metadata:r}=this.redoStack.pop();if("batch-create"===o){let t=(null==r?void 0:r.entries)||[];if(0===t.length)return this.emitStackChange(e7),!1;let e=t.map(t=>t.snapshot).filter(t=>void 0!==t);return e.length>0&&(t.forEach(t=>{this.ignoreProgrammaticCreate[t.id]=!0}),this.draw.addFeatures(e)),this.pushUndoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:"batch-create",metadata:{entries:t}}),this.emitStackChange(e7),!0}if("batch-delete"===o){let t=(null==r?void 0:r.entries)||[];if(0===t.length)return this.emitStackChange(e7),!1;let e=t.map(t=>t.id);return e.forEach(t=>{this.ignoreProgrammaticDelete[t]=!0,this.deletedFeatureIds[t]=!0}),this.draw.removeFeatures(e),this.pushUndoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:"batch-delete",metadata:{entries:t}}),this.emitStackChange(e7),!0}let n=String(t),s=this.historyById[n]||(this.historyById[n]=[]);if("delete"===o)return this.ignoreProgrammaticDelete[t]=!0,this.deletedFeatureIds[t]=!0,this.draw.removeFeatures([t]),this.pushUndoStackEntry({id:t,toIndex:e,action:"single"}),this.emitStackChange(e7),!0;if(e<=0){let e=s[0];return!!e&&(this.ignoreProgrammaticCreate[t]=!0,this.draw.addFeatures([e]),this.pushUndoStackEntry({id:t,toIndex:0,action:"single"}),this.emitStackChange(e7),!0)}let a=i||s[e];return!!a&&(s.length===e?s.push(a):(s[e]=a,s.length=e+1),this.applySnapshotDuringReplay(t,a),this.pushUndoStackEntry({id:t,toIndex:e,action:"single"}),this.emitStackChange(e7),!0)}clearHistory(){let t={};if(this.draw&&!this.isDrawing())for(let e of this.draw.getSnapshot())t[String(e.id)]=[e];this.historyById=t,this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[]}undoSize(){return this.undoStack.length}redoSize(){return this.redoStack.length}}class ie{constructor(t){var e;this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=t.modeLevel,this.sessionLevel=t.sessionLevel,this.shouldPreferMode=t.shouldPreferMode,this.onHistoryChange=t.onHistoryChange,this.shouldEmitHistoryChange=null!=(e=t.shouldEmitHistoryChange)?e:()=>!0}emitStackHistoryChange(t){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:t.cause,stack:t.stack,undoSize:t.undoStackSize,redoSize:t.redoStackSize})}hasSessionUndo(){return!!(this.sessionLevel&&this.sessionLevel.canUndo())}hasSessionRedo(){return!!(this.sessionLevel&&this.sessionLevel.canRedo())}activeStackForUndo(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canUndo()?e6:this.hasSessionUndo()?e8:null!=(e=this.modeLevel)&&e.canUndo()?e6:void 0}activeStackForRedo(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canRedo()?e6:this.hasSessionRedo()?e8:null!=(e=this.modeLevel)&&e.canRedo()?e6:void 0}canUndo(){return void 0!==this.activeStackForUndo()}canRedo(){return void 0!==this.activeStackForRedo()}undo(){let t=this.activeStackForUndo();return!!t&&(t===e6?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){let t=this.activeStackForRedo();return!!t&&(t===e6?!!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:e4,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:e8}):this.modeLevel&&this.emitStackHistoryChange({cause:e4,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:e6})}}class ii{constructor(t){var e,i,r,n;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsM
1atcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=t.adapter,this._instanceSelectModes=[];const s=null==t||null==(e=t.undoRedo)?void 0:e.modeLevel;s&&(this.drawingUndoRedo=s);const a=null==t||null==(i=t.undoRedo)?void 0:i.keyboardShortcuts;a&&(this.keyboardShortcutsMatcher=a),this.sessionUndoRedoEnabled=!!(null==t||null==(r=t.undoRedo)?void 0:r.sessionLevel);const d=null==t||null==(n=t.undoRedo)?void 0:n.sessionLevel;this._mode=new ei;const h=new Set,l=t.modes.reduce((t,e)=>{if(h.has(e.mode))throw Error(`There is already a ${e.mode} mode provided`);return h.add(e.mode),t[e.mode]=e,t},{}),u=Object.keys(l);if(0===u.length)throw Error("No modes provided");u.forEach(t=>{l[t].type===ej.Select&&this._instanceSelectModes.push(t)}),this._modes=o({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new eP({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});const c=t=>{let e=[],i=this._store.copyAll().filter(i=>!t.includes(i.id)||(e.push(i),!1));return{changed:e,unchanged:i}},p=(t,e)=>{var i;this._enabled&&(this._eventListeners.finish.forEach(i=>{i(t,e)}),null==(i=this.undoRedoCoordinator)||i.emitHistoryPushForCompletedAction())},g=(t,e,i)=>{if(!this._enabled)return;this._eventListeners.change.forEach(o=>{o(t,e,i)}),this.emitDrawingPushIfHistoryChangedFromLastSnapshot();let{changed:o,unchanged:r}=c(t);"create"===e?this._adapter.render({created:o,deletedIds:[],unchanged:r,updated:[]},this.getModeStyles()):"update"===e?this._adapter.render({created:[],deletedIds:[],unchanged:r,updated:o},this.getModeStyles()):"delete"===e?this._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},this.getModeStyles()):"styling"===e&&this._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},this.getModeStyles())},y=t=>{if(!this._enabled)return;this._eventListeners.select.forEach(e=>{e(t)});let{changed:e,unchanged:i}=c([t]);this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())},m=t=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(e=>{e(t)});let{changed:e,unchanged:i}=c([t]);e&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())};Object.keys(this._modes).forEach(t=>{var e;this._modes[t].register({mode:t,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:g,onSelect:y,onDeselect:m,onFinish:p,coordinatePrecision:this._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:null==(e=this.drawingUndoRedo)||null==e.getMaxStackSize?void 0:e.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&d&&(this.sessionUndoRedo=d,d.register({draw:this,onHistoryChange:t=>{var e;null==(e=this.undoRedoCoordinator)||e.emitStackHistoryChange(t)}})),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 t=this._mode;t.clearHistory&&t.clearHistory()},onHistoryChange:t=>{var e;null==(e=this.undoRedoCoordinator)||e.emitStackHistoryChange(t)}}),this.undoRedoCoordinator=new ie({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:()=>"drawing"===this.getModeState(),onHistoryChange:t=>
1{this._eventListeners.history.forEach(e=>{e(t)})},shouldEmitHistoryChange:()=>this._enabled})}checkEnabled(){if(!this._enabled)throw Error("Terra Draw is not enabled")}handleUndoRedoKeyboardShortcut(t){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled||!this.keyboardShortcutsMatcher)return!1;let e=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(t),i=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(t);if(e){if(!this.canUndo())return!1;let e=this.undo();return e&&t.preventDefault(),e}if(i){if(!this.canRedo())return!1;let e=this.redo();return e&&t.preventDefault(),e}return!1}getDrawingHistorySizes(){return{undoSize:this._mode.undoSize&&"function"==typeof this._mode.undoSize?this._mode.undoSize():0,redoSize:this._mode.redoSize&&"function"==typeof this._mode.redoSize?this._mode.redoSize():0}}emitDrawingPushIfHistoryChangedFromLastSnapshot(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()}emitDrawingPushIfHistoryChanged(t){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(t)}getModeStyles(){let t={},e=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(i=>{t[i]=t=>e&&t.properties[h.SELECTED]?this._modes[e].styleFeature.bind(this._modes[e])(t):this._modes[i].styleFeature.bind(this._modes[i])(t)}),t}featuresAtLocation({lng:t,lat:e},i){let o=i&&void 0!==i.pointerDistance?i.pointerDistance:30,r=!i||void 0===i.ignoreSelectFeatures||i.ignoreSelectFeatures,n=!(!i||void 0===i.ignoreCoordinatePoints)&&i.ignoreCoordinatePoints,s=!(!i||void 0===i.ignoreCurrentlyDrawing)&&i.ignoreCurrentlyDrawing,a=!(!i||void 0===i.ignoreClosingPoints)&&i.ignoreClosingPoints,d=!(!i||void 0===i.ignoreSnappingPoints)&&i.ignoreSnappingPoints,u=this._adapter.unproject.bind(this._adapter),c=this._adapter.project.bind(this._adapter),p=c(t,e),g=tt({unproject:u,point:p,pointerDistance:o});return this._store.search(g).filter(u=>{if(r&&(u.properties[h.MID_POINT]||u.properties[h.SELECTION_POINT])||n&&u.properties[l.COORDINATE_POINT]||a&&u.properties[l.CLOSING_POINT]||s&&u.properties[l.CURRENTLY_DRAWING]||d&&u.properties[l.SNAPPING_POINT])return!1;if("Point"===u.geometry.type){let t=u.geometry.coordinates;return X(p,c(t[0],t[1]))<o}if("LineString"===u.geometry.type){let t=u.geometry.coordinates;for(let e=0;e<t.length-1;e++){let i=t[e],r=t[e+1];if(tJ(p,c(i[0],i[1]),c(r[0],r[1]))<o)return!0}return!1}if(tZ([t,e],u.geometry.coordinates))return!0;if(null!=i&&i.includePolygonsWithinPointerDistance)for(let t of u.geometry.coordinates)for(let e=0;e<t.length-1;e++){let i=t[e],r=t[e+1];if(tJ(p,c(i[0],i[1]),c(r[0],r[1]))<o)return!0}return!1}).map(o=>{let r;if(null==i||!i.addClosestCoordinateInfoToProperties)return o;if("Polygon"===o.geometry.type)r=o.geometry.coordinates[0].slice(0,-1);else{if("LineString"!==o.geometry.type)return o;r=o.geometry.coordinates}let n,s=-1,a=1/0;for(let t=0;t<r.length;t++){let e=r[t],i=X(c(e[0],e[1]),p);i<a&&(s=t,a=i,n=e)}return o.properties.closestCoordinateIndexToEvent=s,o.properties.closestCoordinatePixelDistanceToEvent=a,o.properties.closestCoordinateDistanceKmToEvent=C(n,[t,e]),o})}getSelectModeOrThrow(t){let e=this.getSelectMode({switchToSelectMode:!0,selectMode:t});if(!e)throw Error("No select mode defined in instance");return e}getSelectMode({switchToSelectMode:t,selectMode:e}){let i;this.checkEnabled();let o=this.getMode();if(0===this._instanceSelectModes.length)return null;if(void 0!==e&&!this._instanceSelectModes.includes(e))throw Error(`No select mode with this name present: ${e}`);return i=void 0!==e?e:this._instanceSelectModes.includes(o)?o:this._instanceSelectModes[0],t&&o!==i&&this.setMode(i),this._modes[i]}isGuidanceFeature(t){return!!(t.properties[h.MID_POINT]||t.properties[h.SELECTION_POINT]||t.properties[l.COORDINATE_POINT]||t.properties[l.SNAPPING_POINT])}setModeStyles(t,e){if(this.checkEnabled(),!this._modes[t])throw Error("No mode with this name present");this._modes[t].styles=e}updateModeOptions(t,e){if(this.checkEnabled(),!this._modes[t])throw Error("No mode with this name present");this._modes[t].updateOptions(e)}getSnapshot(){return this._store.copyAll()}
1getSnapshotFeature(t){if(this._store.has(t))return this._store.copy(t)}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(t){throw Error("Enabled is read only")}getMode(){return this._mode.mode}getModeState(){return this._mode.state}setMode(t){if(this.checkEnabled(),!this._modes[t])throw Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()}removeFeatures(t){let e;this.checkEnabled();let i=[],o=[];t.forEach(t=>{if(!this._store.has(t))throw Error(`No feature with id ${t}, can not delete`);let r=this._store.getPropertiesCopy(t);r[h.SELECTED]&&this.deselectFeature(t),r[l.CURRENTLY_DRAWING]&&this._modes[r.mode]?e=r.mode:(r[l.COORDINATE_POINT_IDS]&&i.push(...r[l.COORDINATE_POINT_IDS]),o.push(t))}),this._store.delete([...o,...i],{origin:"api"}),e&&this._modes[e]&&this._modes[e].cleanUp()&&this._modes[e].cleanUp()}selectFeature(t,e){this.getSelectModeOrThrow(e).selectFeature(t)}deselectFeature(t){this.getSelectModeOrThrow().deselectFeature(t)}getFeatureId(){return this._store.getId()}hasFeature(t){return this._store.has(t)}checkIsReservedProperty(t){return![...Object.values(h),...Object.values(l)].includes(t)}updateFeatureProperties(t,e){var i;if(!this._store.has(t))throw Error(`No feature with id ${t} present in store`);let o=this._store.copy(t);if(this.isGuidanceFeature(o))throw Error("Guidance features are not allowed to be updated directly.");let r=o.properties.mode;if(!this._modes[r])throw Error(`No mode with name ${r} present in instance`);let n=Object.entries(e);n.forEach(([t,e])=>{if(!this.checkIsReservedProperty(t))throw Error(`You are trying to update a reserved property name: ${t}. Please choose another name.`);if(void 0!==e&&!function t(e){if(null===e||"boolean"==typeof e||"string"==typeof e)return!0;if(void 0===e)return!1;if("number"==typeof e)return Number.isFinite(e);if("bigint"==typeof e||"symbol"==typeof e||"function"==typeof e||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Date)return!1;if("object"==typeof e&&null!==e&&!Array.isArray(e)){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&null!==t)return!1}if(ArrayBuffer.isView(e)&&!(e instanceof DataView))return!1;if(Array.isArray(e)){for(let i of e)if(!t(i))return!1}return"object"==typeof e&&Object.keys(e).every(i=>"string"==typeof i&&t(e[i]))}(e))throw Error(`Invalid JSON value provided for property ${t}`)}),this._store.updateProperty(n.map(([t,e])=>({id:o.id,property:t,value:e})),{origin:"api"}),null==(i=this.undoRedoCoordinator)||i.emitHistoryPushForCompletedAction()}updateFeatureGeometry(t,e){var i;if(!this._store.has(t))throw Error(`No feature with id ${t} present in store`);let r=this._store.copy(t);if(this.isGuidanceFeature(r))throw Error("Guidance features are not allowed to be updated directly.");if(!(r&&e&&e.type&&e.coordinates))throw Error("Invalid geometry provided");if(e.type!==r.geometry.type)throw Error(`Geometry type mismatch: expected ${r.geometry.type}, got ${e.type}`);let n=r.properties.mode,s=this._modes[n];if(!s)throw Error(`No mode with name ${n} present in instance`);let a=o({},r,{geometry:e}),d=s.validateFeature(a);if(!d.valid)throw Error(`Feature validation failed: ${d.reason||"Unknown reason"}`);if(this._store.updateGeometry([{id:r.id,geometry:e}],{origin:"api"}),s.afterFeatureUpdated){s.afterFeatureUpdated(a);let t=a.properties[h.SELECTED],e=this.getSelectMode({switchToSelectMode:!1});e&&t&&e.afterFeatureUpdated(a)}null==(i=this.undoRedoCoordinator)||i.emitHistoryPushForCompletedAction()}transformFeatureGeometry(t,e){var i;let o;if(!this._store.has(t))throw Error(`No feature with id ${t} present in store`);let r=this._store.copy(t);if(this.isGuidanceFeature(r))throw Error("Guidance features are not allowed to be updated directly.");let n=r.properties.mode,s=this._modes[n];if(!s)throw Error(`No mode with name ${n} present in instance`);if("Polygon"===r.geometry.type)o=r.geometry.coordinates[0];else{if("LineString"!==r.geometry.type)throw Error(`Feature geometry type ${r.geometry.type} is not supported for transformation`);o=r.geometry.coordinates}if("web-mercator"!=e.projection)throw Error(`Projection ${e.projection} is not currently supported for transformation`);if("scale"===e.type){let{x:t,y:i}=F(e.origin[0],e.origin[1]);t6({coordinates:o,originX:t,originY:i,xScale:e.options.xScale||1,yScale:e.options.yScale||1})}else"rotate"===e.type&&(o="Polygon"===(r=t2(r,e.options.angle||0)).geometry.type?r.geometry.coordinates[0]:r.geometry.coordinates);if(o=o.map(t=>[S(t[0],this._adapter.getCoordinatePrecision()),S(t[1],this._adapter.getCoordinatePrecision())]),r.geometry.coordinates="Polygon"===r.geometry.type?[o]:o,this._store.updateGeometry([{id:r.id,geometry:r.geometry}],{origin:"api"}),s.afterFeatureUpdated){s.afterFeatureUpdated(r);let t=r.properties[h.SELECTED],e=this.getSelectMode({switchToSelectMode:!1});e&&t&&e.afterFeatureUpdated(r)}null==(i=this.undoRedoCoordinator)||i.emitHistoryPushForCompletedAction()}undo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()}canUndo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()}canRedo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()}redo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()}clearUndoRedoHistory(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()}addFeatures(t){return this.checkEnabled(),0===t.length?[]:this._store.load(t,t=>{if(c(t)){let e=t.properties.mode,i=this._modes[e];
vendor: 1,656 bytes, line 1
1if(!i)return{id:t.id,valid:!1,reason:`${e} mode is not in the list of instantiated modes`};let o=i.validateFeature.bind(i)(t);return{id:t.id,valid:o.valid,reason:o.reason?o.reason:o.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}},t=>{if(c(t)){let e=this._modes[t.properties.mode];e&&e.afterFeatureAdded&&e.afterFeatureAdded(t)}},{origin:"api"})}start(){this._enabled||(this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(t=>{t()})},getState:()=>this._mode.state,onClick:t=>{let e=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onClick(t),this.emitDrawingPushIfHistoryChanged(e)},onMouseMove:t=>{this._mode.onMouseMove(t)},onKeyDown:t=>{this.handleUndoRedoKeyboardShortcut(t)||this._mode.onKeyDown(t)},onKeyUp:t=>{let e=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onKeyUp(t),this.emitDrawingPushIfHistoryChanged(e)},onDragStart:(t,e)=>{this._mode.onDragStart(t,e)},onDrag:(t,e)=>{this._mode.onDrag(t,e)},onDragEnd:(t,e)=>{this._mode.onDragEnd(t,e)},onClear:()=>{this._mode.cleanUp(),this._store.clear({origin:"api"})}}))}getFeaturesAtLngLat(t,e){let{lng:i,lat:o}=t;return this.featuresAtLocation({lng:i,lat:o},e)}getFeaturesAtPointerEvent(t,e){let i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)}stop(){this._enabled&&(this._enabled=!1,this._adapter.unregister())}on(t,e){let i=this._eventListeners[t];i.includes(e)||i.push(e)}off(t,e){let i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.