function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e=0&&Number.isFinite(t)},x=function(t){return"boolean"==typeof t},M=function(t){return null===t},E=function(t){return"object"==typeof t&&null!==t},D=function(t){return"string"==typeof t&&t.length>0},k=function(t){return"click-move"===t||"click-drag"===t||"click-move-or-drag"===t};!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(S||(S={}));var b={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},N=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=b,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=S.Drawing,this.mode="base",e?this.isInitialUpdate=!0:this.updateOptions(o({},t))}var e=t.prototype;return e.registerBehaviors=function(t){},e.updateOptions=function(t){E(null==t?void 0:t.styles)&&(this.styles=o({},this._styles,t.styles)),w(null==t?void 0:t.pointerDistance)&&(this.pointerDistance=t.pointerDistance),"function"==typeof(null==t?void 0:t.validation)&&(this.validate=t.validation),D(null==t?void 0:t.projection)&&(this.projection=t.projection),E(null==t?void 0:t.pointerEvents)&&(this.pointerEvents=t.pointerEvents),D(null==t?void 0:t.modeName)&&!0===this.isInitialUpdate&&(this.mode=t.modeName),this.isInitialUpdate=!1},e.allowPointerEvent=function(t,e){return"boolean"==typeof t?t:"function"!=typeof t||t(e)},e.setDrawing=function(){if("started"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="drawing"},e.setStarted=function(){if("stopped"!==this._state&&"registered"!==this._state&&"drawing"!==this._state&&"selecting"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started",this.setDoubleClickToZoom(!1)},e.setStopped=function(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped",this.setDoubleClickToZoom(!0)},e.register=function(t){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=t.store,this.store.registerOnChange(t.onChange),this.setDoubleClickToZoom=t.setDoubleClickToZoom,this.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.onFinish=t.onFinish,this.coordinatePrecision=t.coordinatePrecision,this.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})},e.validateFeature=function(t){return this.performFeatureValidation(t)},e.afterFeatureAdded=function(t){},e.afterFeatureUpdated=function(t){},e.performFeatureValidation=function(t){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var i;if(C(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(C(t.geometry))if(C(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){var i=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Provisional});return{valid:e.valid&&i.valid,reason:i.reason}}return{valid:e.valid,reason:e.reason}},e.validateModeFeature=function(t,e){var i=this.performFeatureValidation(t);return i.valid?t.properties.mode===this.mode?e(t):{valid:!1,reason:O}:{valid:!1,reason:i.reason}},e.onFinish=function(t,e){},e.onDeselect=function(t){},e.onSelect=function(t){},e.onKeyDown=function(t){},e.onKeyUp=function(t){},e.undo=function(){},e.clearHistory=function(){},e.undoSize=function(){return 0},e.redoSize=function(){return 0},e.redo=function(){},e.onMouseMove=function(t){},e.onClick=function(t){},e.onDragStart=function(t,e){},e.onDrag=function(t,e){},e.onDragEnd=function(t,e){},e.getHexColorStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getNumericStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getUrlStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getMarkerAnchorStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getDashArrayStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?null!=(n=t(i))?n:e:t;var n},i(t,[{key:"state",get:function(){return this._state},set:function(t){throw new Error("Please use the modes lifecycle methods")}},{key:"styles",get:function(){return this._styles},set:function(t){if("object"!=typeof t)throw new Error("Styling must be an object");this.onStyleChange&&this.onStyleChange([],"styling"),this._styles=t}}])}(),_=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o0;function a(t){return t<0||t>1}function d(t,n,o,r){var s,d=e[t][n],u=e[t][n+1],h=e[o][r],l=e[o][r+1],c=function(t,e,i,n){if(et(t,i)||et(t,n)||et(e,i)||et(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],d=i[0],u=i[1],h=n[0],l=n[1],c=(o-s)*(u-l)-(r-a)*(d-h);return 0===c?null:[((o*a-r*s)*(d-h)-(o-s)*(d*l-u*h))/c,((o*a-r*s)*(u-l)-(r-a)*(d*l-u*h))/c]}(d,u,h,l);null!==c&&(s=l[0]!==h[0]?(c[0]-h[0])/(l[0]-h[0]):(c[1]-h[1])/(l[1]-h[1]),a(u[0]!==d[0]?(c[0]-d[0])/(u[0]-d[0]):(c[1]-d[1])/(u[1]-d[1]))||a(s)||(c.toString(),i.push(c)))}}function et(t,e){return t[0]===e[0]&&t[1]===e[1]}function it(t,e){return ot(t[0])<=e&&ot(t[1])<=e}function nt(t){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(i=t[0])>=-180&&i<=180&&(e=t[1])>=-90&&e<=90;var e,i}function ot(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var rt="Feature has holes",st="Feature has less than 4 coordinates",at="Feature has invalid coordinates",dt="Feature coordinates are not closed";function ut(t,e){if("Polygon"!==t.geometry.type)return{valid:!1,reason:"Feature is not a Polygon"};if(1!==t.geometry.coordinates.length)return{valid:!1,reason:rt};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:st};for(var i=0;i=a)throw new RangeError("Index "+t+" (normalized to "+e+") is out of bounds");return e},u=new Array(a).fill(void 0),h=Array.from({length:a},function(){return[]}),l=Array.from({length:a},function(){return[]}),c=[],p=n(e);!(i=p()).done;){var g=i.value;if(g.type!==pt&&g.type!==gt){var y=d(g.index);u[y]=o({},g,{index:y})}else{var f=g.index,v=f<0?a+f:f;if(v<0||v>a)throw new RangeError("Index "+g.index+" (normalized to "+v+") is out of bounds");if(g.type===pt){if(v>=a)throw new RangeError("INSERT_BEFORE index "+g.index+" (normalized to "+v+") is out of bounds for length "+a);h[v].push(g)}else v===a?c.push(g):l[v].push(g)}}for(var m=[],C=0;C=i.length)throw new RangeError("Index "+e+" (normalized to "+n+") is out of bounds");return i[n]},i.getProperties=function(t){return this.store.getPropertiesCopy(t)},i.hasFeature=function(t){return this.store.has(t)},i.getAllFeatureIdsWhere=function(t){return this.store.copyAllWhere(t).map(function(t){return t.id})},e}(lt);function It(t){return Array.isArray(t)&&t.length>0&&Array.isArray(t[0])&&Array.isArray(t[0][0])}var St=function(t){return It(t)?t[0].slice(0,-1):t},Ft=function(t){return It(t)?t[0]:t},Ot=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).readFeature=void 0,o.mutateFeature=void 0,o.readFeature=i,o.mutateFeature=n,o}r(e,t);var i=e.prototype;return i.setEnabled=function(t){var e=this,i=this.store.copyAllWhere(function(t){return t.mode===e.mode}).filter(function(t){return"LineString"===t.geometry.type||"Polygon"===t.geometry.type});t?i.forEach(function(t){e.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})}):this.deletePointsByFeatureIds(i.filter(function(t){return Boolean(t.properties[y.COORDINATE_POINT_IDS])}).map(function(t){return t.id}))},i.createOrUpdate=function(t){var e=this,i=t.featureId,n=t.featureCoordinates;if(this.readFeature.hasFeature(i)){var o=St(n),r=this.readFeature.getProperties(i),s=r.coordinatePointIds;if(s)if(s&&s.every(function(t){return e.readFeature.hasFeature(t)})){var a=r.coordinatePointIds,d=a.map(function(t){return e.readFeature.getGeometry(t).coordinates});if(a.length!==o.length){this.deleteCoordinatePoints(a);var u=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,u)}else{var h=[];o.forEach(function(t,e){t[0]===d[e][0]&&t[1]===d[e][1]||h.push({featureId:a[e],coordinate:t})}),this.mutateFeature.updateGuidancePoints(h),this.syncCurrentlyDrawing(s,r)}}else{var l=s.filter(function(t){return e.readFeature.hasFeature(t)});l.length&&this.deleteCoordinatePoints(l);var c=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,c)}else{var p=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,p)}}else this.deleteOrphanedPoints(i)},i.deletePointsByFeatureIds=function(t){for(var e,i=n(t);!(e=i()).done;)this.deleteIfPresent(e.value)},i.updateOneAtIndex=function(t,e,i){var n=this.readFeature.getProperties(t).coordinatePointIds;n&&0!==n.length&&void 0!==n[e]&&this.mutateFeature.updateGuidancePoints([{featureId:n[e],coordinate:i}])},i.updateAllInPlace=function(t){var e=t.featureCoordinates,i=this.readFeature.getProperties(t.featureId);if(i.coordinatePointIds){var n=St(e);n.length===i.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(i.coordinatePointIds.map(function(t,e){return{featureId:t,coordinate:n[e]}}))}},i.createPoints=function(t,e,i){var n=!0===this.readFeature.getProperties(i)[y.CURRENTLY_DRAWING];return this.mutateFeature.createGuidancePoints({coordinates:t,type:y.COORDINATE_POINT,additionalProperties:function(t){var r,s;return o(((r={mode:e})[y.COORDINATE_POINT]=!0,r[y.COORDINATE_POINT_FEATURE_ID]=i,r),n?((s={})[y.CURRENTLY_DRAWING]=!0,s):{},{index:t})}})},i.syncCurrentlyDrawing=function(t,e){var i=this,n=!0===e[y.CURRENTLY_DRAWING];t.forEach(function(t){var e;i.readFeature.hasFeature(t)&&i.mutateFeature.updatePoint({featureId:t,propertyMutations:(e={},e[y.CURRENTLY_DRAWING]=!!n||void 0,e),context:{updateType:d.Commit}})})},i.setFeatureCoordinatePoints=function(t,e,i){var n;void 0===i&&(i=d.Commit);var o=this.readFeature.getGeometryType(t),r={featureId:t,propertyMutations:(n={},n[y.COORDINATE_POINT_IDS]=e,n),context:{updateType:i}};if("Polygon"===o)this.mutateFeature.updatePolygon(r);else{if("LineString"!==o)throw new Error("Unsupported geometry type for coordinate points");this.mutateFeature.updateLineString(r)}},i.deleteCoordinatePoints=function(t){this.mutateFeature.deleteFeaturesIfPresent(t)},i.deleteIfPresent=function(t){if(this.readFeature.hasFeature(t)){var e=this.readFeature.getProperties(t).coordinatePointIds;e&&(this.deleteCoordinatePoints(e),this.setFeatureCoordinatePoints(t,null))}},i.deleteOrphanedPoints=function(t){var e=this.readFeature.getAllFeatureIdsWhere(function(e){return e[y.COORDINATE_POINT_FEATURE_ID]===t});this.mutateFeature.deleteFeaturesIfPresent(e)},e}(lt),wt=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)},xt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return wt({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(lt);function Mt(t){var e=t.unproject,i=t.point,n=t.pointerDistance/2,o=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(o-n,r-n),e(o+n,r-n),e(o+n,r+n),e(o-n,r+n),e(o-n,r-n)].map(function(t){return[t.lng,t.lat]})]}}}var Et=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.create=function(t){return Mt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(lt),Dt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}r(e,t);var i=e.prototype;return i.getSnappableCoordinateFirstClick=function(t){var e=this;return this.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===e.mode)}).coordinate},i.getSnappableCoordinate=function(t,e){var i=this;return this.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===i.mode&&t.id!==e)}).coordinate},i.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else if("LineString"===e.geometry.type)n=e.geometry.coordinates;else{if("Point"!==e.geometry.type)return;var o,s,a,d,u,h;if(null!=(o=e.properties)&&o[y.EDITED]||null!=(s=e.properties)&&s[y.CLOSING_POINT]||null!=(a=e.properties)&&a[y.SNAPPING_POINT]||null!=(d=e.properties)&&d[y.COORDINATE_POINT]||null!=(u=e.properties)&&u[g.SELECTION_POINT]||null!=(h=e.properties)&&h[g.MID_POINT])return;n=[e.geometry.coordinates]}n.forEach(function(n,o){var s=i.pixelDistance.measure(t,n);sj||bt(x,O)>j?V(_t(O),_t(w))<=V(_t(O),_t(x))?[_t(w),!0,!1]:[_t(x),!1,!0]:[_t(O),!1,!1])[0])&&(c=V(t,d))180?o-=360:o<-180&&(o+=360),o}function $t(t){return(t+360)%360}function Qt(t,e,i){for(var n,o,r,s=[],a=t.length,d=0,u=0;u=d&&u===t.length-1);u++){if(d>e&&0===s.length){if(!(n=e-d))return s.push(t[u]),s;o=Zt(t[u],t[u-1])-180,r=Lt(t[u],n,o),s.push(r)}if(d>=i)return(n=i-d)?(o=Zt(t[u],t[u-1])-180,r=Lt(t[u],n,o),s.push(r),s):(s.push(t[u]),s);if(d>=e&&s.push(t[u]),u===t.length-1)return s;d+=V(t[u],t[u+1])}if(dthis.maxStackSize;)t.shift()},e.pushUndoEntry=function(t){0!==this.maxStackSize&&(this.undoHistory.push(t),this.trimHistoryToMax(this.undoHistory))},e.pushRedoEntry=function(t){0!==this.maxStackSize&&(this.redoHistory.push(t),this.trimHistoryToMax(this.redoHistory))},e.cloneRecursively=function(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.cloneRecursively(t)}):null!==t&&"object"==typeof t?o({},t):t},e.cloneCoordinates=function(t){return this.cloneCoordinatesFunction(t)},e.cloneEntry=function(t){return{featureCoordinates:this.cloneCoordinates(t.featureCoordinates),currentCoordinate:t.currentCoordinate}},e.clear=function(){this.undoHistory=[],this.redoHistory=[]},e.undoSize=function(){return this.undoHistory.length},e.redoSize=function(){return this.redoHistory.length},e.recordSnapshot=function(t){this.pushUndoEntry(this.cloneEntry(t)),this.redoHistory=[]},e.beginUndo=function(){var t=this.undoHistory.pop();if(t){var e=this.cloneEntry(t);this.pushRedoEntry(e);var i=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:e,previousEntry:i?this.cloneEntry(i):void 0}}},e.takeRedo=function(){var t=this.redoHistory.pop();if(t)return this.cloneEntry(t)},e.commitRedo=function(t){this.pushUndoEntry(this.cloneEntry(t))},t}(),se=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.EPSILON=1e-9,i.DEFAULT_DEGREE=90,i.config=e,i}r(e,t);var i=e.prototype;return i.getSnappableCoordinate=function(t,e,i,n){if(void 0===n&&(n={}),!(i<2)){var o="Polygon"===e.type?e.coordinates[0]:e.coordinates,r=o[i-2],s=o[i-1];if(r&&s){var a=this.getDegree(n.degree),d=[t.lng,t.lat],u=!0===n.backTracking,h="globe"===this.projection?this.snapOnGlobe(r,s,d,a,u):this.snapOnWebMercator(r,s,d,a,u);if("Polygon"===e.type&&i>=3){var l=this.getClosingCandidate(r,s,o[0],d,a,u);l&&this.pixelDistance(d,l)0&&t<=180&&360/t<=1e4?t:this.DEFAULT_DEGREE},i.offsets=function(t,e){for(var i=[],n=0;n<360-this.EPSILON;n+=t){var o=(n%360+360)%360;!e&&Math.abs(o-180)1&&(this.finishOnNthCoordinate=Math.floor(e.finishOnNthCoordinate)),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),E(null==e?void 0:e.snapping)&&(this.snapping=e.snapping),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),E(null==e?void 0:e.insertCoordinates)&&(this.insertCoordinates=e.insertCoordinates),x(null==e?void 0:e.editable)&&(this.editable=e.editable),void 0!==(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints))},i.shouldFinishOnCommit=function(t){return!!this.finishOnNthCoordinate&&Math.max(0,t.coordinates.length-1)>=this.finishOnNthCoordinate},i.updateSnappedCoordinate=function(t){var e,i=this.snapCoordinate(t);return i&&!1!==(null==(e=this.snapping)?void 0:e.showSnappingPoint)?this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:i}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:y.SNAPPING_POINT}):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),i&&(t.lng=i[0],t.lat=i[1]),i},i.close=function(){var t;if(void 0!==this.currentId){var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Finish,action:u},coordinateMutations:[{type:ft,index:-1}],propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=void 0,t)});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});var i=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(i,{mode:this.mode,action:u})}}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=V(t,e)/(this.insertCoordinates.value+1),n=[];return"globe"===this.projection?n=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(n=this.insertPoint.generateInsertionCoordinates(t,e,i)),n},i.createLine=function(t){var e,i=this.mutateFeature.createLineString({coordinates:[t,t],properties:(e={mode:this.mode},e[y.CURRENTLY_DRAWING]=!0,e)});this.lastCommittedCoordinates=i.geometry.coordinates,this.currentId=i.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})},i.firstUpdateToLine=function(t){if(this.currentId){this.setCursor(this.cursors.close);var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:gt,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())}},i.updateToLine=function(t,e){if(this.currentId)if(this.closingPoints.isLineStringClosingPoint(t).isClosing)this.close();else{this.setCursor(this.cursors.close);var i=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:gt,index:-1,coordinate:e}]});i&&(this.closingPoints.update(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.lastCommittedCoordinates=i.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(i.geometry)&&this.close())}},i.undoSize=function(){return this.undoRedo.undoSize()},i.clearHistory=function(){this.undoRedo.clear()},i.pushHistorySnapshot=function(t,e){var i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})},i.updateSnappedGuidancePointFromLastMouseMove=function(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.syncClosingPoints=function(t){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()},i.undo=function(){var t;if("drawing"===this.state&&this.currentId){var e=this.undoRedo.beginUndo();if(e){var i=e.previousEntry;if(!i){var n=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([n]),this.mutateFeature.deleteFeatureIfPresent(n),void this.updateSnappedGuidancePointFromLastMouseMove()}var o=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:vt,coordinates:i.featureCoordinates},propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=!0,t),context:{updateType:d.Commit}});o&&(this.currentCoordinate=i.currentCoordinate,this.lastCommittedCoordinates=o.geometry.coordinates,this.syncClosingPoints(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}}},i.redoSize=function(){return this.undoRedo.redoSize()},i.redo=function(){var t=this.undoRedo.takeRedo();if(t){if(this.currentId){var e,i=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:vt,coordinates:t.featureCoordinates},propertyMutations:(e={},e[y.CURRENTLY_DRAWING]=!0,e),context:{updateType:d.Commit}});if(!i)return;this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=i.geometry.coordinates,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}else{var n,o=this.mutateFeature.createLineString({coordinates:t.featureCoordinates,properties:(n={mode:this.mode},n[y.CURRENTLY_DRAWING]=!0,n)}),r=o.id,s=o.geometry;this.currentId=r,this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=s.coordinates,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(s.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:s.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}},i.registerBehaviors=function(t){this.insertPoint=new ie(t),this.clickBoundingBox=new Et(t),this.pixelDistance=new xt(t),this.lineSnapping=new Tt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Dt(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Rt(this.coordinateSnapping,this.lineSnapping),this.degreeSnapping=new se(t),this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.closingPoints=new oe(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature),this.undoRedo=new re({maxStackSize:t.undoRedoMaxStackSize})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t;var e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){this.closingPoints.isLineStringClosingPoint(t).isClosing&&this.setCursor(this.cursors.close);var i=[{type:yt,index:-1,coordinate:e}];if(this.insertCoordinates){var n=this.getInsertCoordinates(e);n&&(i={type:vt,coordinates:n})}var o=this.mutateFeature.updateLineString({coordinateMutations:i,featureId:this.currentId,context:{updateType:d.Provisional}});o&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates})}},i.getInsertCoordinates=function(t){if(this.lastCommittedCoordinates){var e=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(!Ct(e,t)){var i=this.generateInsertCoordinates(e,t),n=this.lastCommittedCoordinates.slice(0,-1);return[].concat(n,i,[t])}}},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.lineStringFilter(t)}),n=i.featureId,o=i.featureCoordinateIndex;if(n&&void 0!==o){var r=this.readFeature.getGeometry(n);if("LineString"===r.type&&!(r.coordinates.length<=2)){var s=this.mutateFeature.updateLineString({featureId:n,coordinateMutations:[{type:ft,index:o}],context:{updateType:d.Finish,action:h}});s&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:s.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(n,{mode:this.mode,action:l})}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);var 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)},i.onClick=function(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))},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var n=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,n=o.coordinate);var r=this.coordinateSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});r.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:n,type:y.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;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){var n=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional},coordinateMutations:[{type:yt,index:this.editedFeatureCoordinateIndex,coordinate:[t.lng,t.lat]}]});if(!n)return;this.showCoordinatePoints&&(void 0!==this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:n.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;var o=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional}});if(!o)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:o.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:d.Provisional},propertyMutations:(i={},i[y.EDITED]=!0,i)})}},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:(i={},i[y.EDITED]=!1,i),context:{updateType:d.Finish,action:h}}))){var n=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(n,{mode:this.mode,action:h})}},i.cleanUp=function(){var 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()},i.styleFeature=function(t){var 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,markerAnchor:"bottom",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=f,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[y.COORDINATE_POINT],n=t.properties[y.CLOSING_POINT]?"closingPoint":t.properties[y.SNAPPING_POINT]?"snappingPoint":i?"coordinatePoint":void 0;if(!n)return e;var 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[n].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(r[n].opacity,1,t),e.pointColor=this.getHexColorStylingValue(r[n].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(r[n].outlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(r[n].outlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(r[n].outlineOpacity,1,t),e.zIndex=i?v:50,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ne(t,e.coordinatePrecision)})},i.lineStringFilter=function(t){return Boolean("LineString"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.snapCoordinate=function(t){var e,i,n,o,r,s,a,d,u=this;if(null!=(e=this.snapping)&&e.toDegree&&this.currentId&&(s=this.degreeSnapping.getSnappableCoordinate(t,this.readFeature.getGeometry(this.currentId),this.currentCoordinate,this.snapping.toDegree)),null!=(i=this.snapping)&&i.toLine&&(a=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(s=a),null!=(n=this.snapping)&&n.toCoordinate&&(d=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(s=d),null!=(o=this.snapping)&&o.toCustom){var h=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return u.readFeature.getGeometry(u.currentId)}:function(){return null},project:this.project,unproject:this.unproject});h&&(s=h)}if(null!=(r=this.snapping)&&r.toFeature){var l=this.featureSnapping.getSnappable(t,this.currentId,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});l.coordinate&&(s=l.coordinate)}return s},i.afterFeatureUpdated=function(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())},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},e}(N),he={cancel:R,finish:T},le={start:W,close:A},ce=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="polyline",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=he,i.cursors=le,i.mouseMove=!1,i.snapping=void 0,i.snappedPointId=void 0,i.showCoordinatePoints=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.clickBoundingBox=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.featureSnapping=void 0,i.degreeSnapping=void 0,i.coordinatePoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i;t.prototype.updateOptions.call(this,e),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),E(null==e?void 0:e.snapping)&&(this.snapping=e.snapping),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),x(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints))},i.registerBehaviors=function(t){this.clickBoundingBox=new Et(t),this.pixelDistance=new xt(t),this.lineSnapping=new Tt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Dt(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Rt(this.coordinateSnapping,this.lineSnapping),this.degreeSnapping=new se(t),this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.closingPoints=new oe(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.finishLine=function(){var t;if(this.currentId){var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Finish,action:u},coordinateMutations:[{type:ft,index:-1}],propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=void 0,t)});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});var i=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(i,{mode:this.mode,action:u})}}},i.toPolygonLikeCoordinates=function(t){return 0===t.length?[t]:[[].concat(t,[t[0]])]},i.closeAsPolygon=function(){if(this.currentId){var t=this.readFeature.getGeometry(this.currentId).coordinates.slice(0,-1);if(!(t.length<3)){var e=this.currentId,i=[].concat(t,[t[0]]),n=this.mutateFeature.createPolygon({coordinates:i,properties:{mode:this.mode},context:{updateType:d.Finish,action:u}});n&&(this.showCoordinatePoints&&(this.coordinatePoints.deletePointsByFeatureIds([e]),this.coordinatePoints.createOrUpdate({featureId:n.id,featureCoordinates:n.geometry.coordinates})),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(n.id,{mode:this.mode,action:u}))}}},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.updateSnappedCoordinate(t),this.currentId&&0!==this.currentCoordinate){var e=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:yt,index:-1,coordinate:[t.lng,t.lat]}],context:{updateType:d.Provisional}});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});var i=this.closingPoints.isPolygonClosingPoints(t);(i.isClosing&&this.currentCoordinate>=3||i.isPreviousClosing&&this.currentCoordinate>=2)&&this.setCursor(this.cursors.close)}}},i.onLeftClick=function(t){this.updateSnappedCoordinate(t);var e=[t.lng,t.lat];if(0===this.currentCoordinate){var i,n=this.mutateFeature.createLineString({coordinates:[e,e],properties:(i={mode:this.mode},i[y.CURRENTLY_DRAWING]=!0,i)});return this.currentId=n.id,this.currentCoordinate=1,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n.id,featureCoordinates:n.geometry.coordinates}),void this.setDrawing()}if(this.currentId){var o=this.closingPoints.isPolygonClosingPoints(t),r=o.isPreviousClosing;if(o.isClosing&&this.currentCoordinate>=3)this.closeAsPolygon();else if(r&&this.currentCoordinate>=2)this.finishLine();else{var s=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:gt,index:-1,coordinate:e}]});if(s&&(this.currentCoordinate++,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates}),this.currentCoordinate>=2)){var a=this.toPolygonLikeCoordinates(s.geometry.coordinates);0===this.closingPoints.ids.length?this.closingPoints.create(a):this.closingPoints.update(a)}}}},i.onClick=function(t){"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,this.onLeftClick(t))},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.finishLine()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.closingPoints.delete()},i.updateSnappedCoordinate=function(t){var e,i=this.snapCoordinate(t);i&&!1!==(null==(e=this.snapping)?void 0:e.showSnappingPoint)?this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:i}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:y.SNAPPING_POINT}):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),i&&(t.lng=i[0],t.lat=i[1])},i.snapCoordinate=function(t){var e,i,n,o,r,s,a,d,u=this;if(null!=(e=this.snapping)&&e.toDegree&&this.currentId&&(s=this.degreeSnapping.getSnappableCoordinate(t,this.readFeature.getGeometry(this.currentId),this.currentCoordinate,this.snapping.toDegree)),null!=(i=this.snapping)&&i.toLine&&(a=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(s=a),null!=(n=this.snapping)&&n.toCoordinate&&(d=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(s=d),null!=(o=this.snapping)&&o.toFeature){var h=this.featureSnapping.getSnappable(t,this.currentId,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});h.coordinate&&(s=h.coordinate)}if(null!=(r=this.snapping)&&r.toCustom){var l=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return u.readFeature.getGeometry(u.currentId)}:function(){return null},project:this.project,unproject:this.unproject});l&&(s=l)}return s},i.styleFeature=function(t){var 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,markerAnchor:"bottom",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=f,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=f,e;if("Point"===t.geometry.type){var i=!0===t.properties[y.CLOSING_POINT],n=!0===t.properties[y.SNAPPING_POINT],r=!0===t.properties[y.COORDINATE_POINT];if(!i&&!n&&!r)return e;e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:n?this.styles.snappingPointColor:this.styles.coordinatePointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:n?this.styles.snappingPointWidth:this.styles.coordinatePointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(i?this.styles.closingPointOpacity:n?this.styles.snappingPointOpacity:this.styles.coordinatePointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:n?this.styles.snappingPointOutlineColor:this.styles.coordinatePointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:n?this.styles.snappingPointOutlineWidth:this.styles.coordinatePointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(i?this.styles.closingPointOutlineOpacity:n?this.styles.snappingPointOutlineOpacity:this.styles.coordinatePointOutlineOpacity,1,t),e.zIndex=r?v:m}return e},i.afterFeatureAdded=function(t){!this.showCoordinatePoints||"LineString"!==t.geometry.type&&"Polygon"!==t.geometry.type||this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.afterFeatureUpdated=function(t){!this.showCoordinatePoints||"LineString"!==t.geometry.type&&"Polygon"!==t.geometry.type||this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),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())},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return"LineString"===t.geometry.type?ne(t,e.coordinatePrecision):"Polygon"===t.geometry.type?ut(t,e.coordinatePrecision):{valid:!1,reason:"Only LineString or Polygon features are valid"}})},e}(N),pe="Feature is not a Point",ge="Feature has invalid coordinates",ye="Feature has coordinates with excessive precision";function fe(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:pe}:nt(t.geometry.coordinates)?it(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:ye}:{valid:!1,reason:ge}}var ve=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).pixelDistance=void 0,o.clickBoundingBox=void 0,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getNearestPointFeature=function(t){for(var e=this.clickBoundingBox.create(t),i=this.store.search(e),n=Infinity,o=void 0,r=0;rn||a>this.pointerDistance||(n=a,o=s)}}return o},e}(lt),me={create:W,dragStart:U,dragEnd:W},Ce=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="point",i.cursors=me,i.editable=!1,i.snapping=void 0,i.editedFeatureId=void 0,i.snappedPointId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.pointSearch=void 0,i.mutateFeature=void 0,i.coordinateSnapping=void 0,i.lineSnapping=void 0,i.featureSnapping=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),E(null==e?void 0:e.snapping)&&(this.snapping=e.snapping),x(null==e?void 0:e.editable)&&(this.editable=e.editable)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.onClick=function(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)},i.onMouseMove=function(t){t&&this.updateSnappedCoordinate(t)},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){this.editedFeatureId=void 0,this.deleteSnappedPoint()},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){var i=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=null==i?void 0:i.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:vt,coordinates:this.snapCoordinate(t,this.editedFeatureId)},propertyMutations:(i={},i[y.EDITED]=!0,i),context:{updateType:d.Provisional}})},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:(i={mode:this.mode},i[y.EDITED]=!1,i),context:{updateType:d.Finish,action:"edit"}})){var n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,this.deleteSnappedPoint(),e(!0),this.onFinish(n,{mode:this.mode,action:u})}},i.registerBehaviors=function(t){this.pixelDistance=new xt(t),this.clickBoundingBox=new Et(t),this.pointSearch=new ve(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Dt(t,this.pixelDistance,this.clickBoundingBox),this.lineSnapping=new Tt(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Rt(this.coordinateSnapping,this.lineSnapping),this.mutateFeature=new mt(t,{validate:this.validate})},i.styleFeature=function(t){var 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,markerAnchor:"bottom",lineStringDash:void 0});if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[y.SNAPPING_POINT],n=Boolean(t.id&&this.editedFeatureId===t.id);e.pointWidth=this.getNumericStylingValue(i?this.styles.snappingPointWidth:n?this.styles.editedPointWidth:this.styles.pointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(i?this.styles.snappingPointOpacity:this.styles.pointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.snappingPointColor:n?this.styles.editedPointColor:this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.snappingPointOutlineColor:n?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(i?this.styles.snappingPointOutlineOpacity:this.styles.pointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.snappingPointOutlineWidth:n?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),e.zIndex=i?40:m}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return fe(t,e.coordinatePrecision)})},i.onLeftClick=function(t){this.deleteSnappedPoint();var e=this.mutateFeature.createPoint({coordinates:this.snapCoordinate(t),properties:{mode:this.mode},context:{updateType:d.Finish,action:u}});e&&this.onFinish(e.id,{mode:this.mode,action:u})},i.snapCoordinate=function(t,e){var i;return null!=(i=this.getSnappedCoordinate(t,e))?i:[t.lng,t.lat]},i.updateSnappedCoordinate=function(t){var e,i=this.getSnappedCoordinate(t);i&&!0===(null==(e=this.snapping)?void 0:e.showSnappingPoint)?this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:i}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:y.SNAPPING_POINT}):this.deleteSnappedPoint()},i.deleteSnappedPoint=function(){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.getSnappedCoordinate=function(t,e){var i,n,o,r;if(null!=(i=this.snapping)&&i.toCoordinate){var s=e?this.coordinateSnapping.getSnappableCoordinate(t,e):this.coordinateSnapping.getSnappableCoordinateFirstClick(t);s&&(r=s)}if(null!=(n=this.snapping)&&n.toFeature){var a=this.featureSnapping.getSnappable(t,e,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});a.coordinate&&(r=a.coordinate)}if(null!=(o=this.snapping)&&o.toCustom){var d=this.snapping.toCustom(t,{currentCoordinate:0,currentId:e,getCurrentGeometrySnapshot:function(){return null},project:this.project,unproject:this.unproject});d&&(r=d)}return r},i.onRightClick=function(t){if(this.editable){var e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(N),Pe={cancel:R,finish:T},Ie={start:W,close:A,dragStart:U,dragEnd:W},Se=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Pe,i.cursors=Ie,i.mouseMove=!1,i.showCoordinatePoints=!1,i.lastMouseMoveEvent=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinatePoints=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.featureSnapping=void 0,i.degreeSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.clickBoundingBox=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.undoRedo=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i;t.prototype.updateOptions.call(this,e),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),E(null==e?void 0:e.snapping)&&(this.snapping=e.snapping),x(null==e?void 0:e.editable)&&(this.editable=e.editable),E(null==e?void 0:e.pointerEvents)&&(this.pointerEvents=e.pointerEvents),x(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints))},i.close=function(){var t;if(void 0!==this.currentId&&!(this.readFeature.getCoordinates(this.currentId).length<5)){var e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:ft,index:-2}],propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=void 0,t[y.COMMITTED_COORDINATE_COUNT]=void 0,t[y.PROVISIONAL_COORDINATE_COUNT]=void 0,t),context:{updateType:d.Finish,action:u}});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.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();var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(i,{mode:this.mode,action:u})}}},i.registerBehaviors=function(t){this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.clickBoundingBox=new Et(t),this.pixelDistance=new xt(t),this.lineSnapping=new Tt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Dt(t,this.pixelDistance,this.clickBoundingBox),this.featureSnapping=new Rt(this.coordinateSnapping,this.lineSnapping),this.degreeSnapping=new se(t),this.closingPoints=new oe(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature),this.undoRedo=new re({maxStackSize:t.undoRedoMaxStackSize})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.updateSnappedCoordinate=function(t){var e,i=this.snapCoordinate(t);i&&!1!==(null==(e=this.snapping)?void 0:e.showSnappingPoint)?this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:i}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:i,type:y.SNAPPING_POINT}):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),i&&(t.lng=i[0],t.lat=i[1])},i.undoSize=function(){return this.undoRedo.undoSize()},i.clearHistory=function(){this.undoRedo.clear()},i.pushHistorySnapshot=function(t,e){var i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})},i.updateSnappedGuidancePointFromLastMouseMove=function(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.syncClosingPoints=function(t){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()},i.undo=function(){var t;if("drawing"===this.state&&this.currentId){var e=this.undoRedo.beginUndo();if(e){var i=e.previousEntry;if(!i){var n=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([n]),this.mutateFeature.deleteFeatureIfPresent(n),void this.updateSnappedGuidancePointFromLastMouseMove()}var o=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:vt,coordinates:i.featureCoordinates},propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=!0,t[y.COMMITTED_COORDINATE_COUNT]=i.currentCoordinate,t[y.PROVISIONAL_COORDINATE_COUNT]=i.currentCoordinate,t),context:{updateType:d.Commit}});o&&(this.currentCoordinate=i.currentCoordinate,this.syncClosingPoints(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}}},i.redoSize=function(){return this.undoRedo.redoSize()},i.redo=function(){var t=this.undoRedo.takeRedo();if(t){if(this.currentId){var e,i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:vt,coordinates:t.featureCoordinates},propertyMutations:(e={},e[y.CURRENTLY_DRAWING]=!0,e[y.COMMITTED_COORDINATE_COUNT]=t.currentCoordinate,e[y.PROVISIONAL_COORDINATE_COUNT]=t.currentCoordinate,e),context:{updateType:d.Commit}});if(!i)return;this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}else{var n,o=this.undoRedo.cloneCoordinates(t.featureCoordinates)[0],r=this.mutateFeature.createPolygon({coordinates:o,properties:(n={mode:this.mode},n[y.CURRENTLY_DRAWING]=!0,n[y.COMMITTED_COORDINATE_COUNT]=t.currentCoordinate,n[y.PROVISIONAL_COORDINATE_COUNT]=t.currentCoordinate,n)}),s=r.id,a=r.geometry;this.currentId=s,this.currentCoordinate=t.currentCoordinate,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(a.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:s,featureCoordinates:a.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}},i.onMouseMove=function(t){var e;if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),void 0!==this.currentId&&0!==this.currentCoordinate){var i,n=this.readFeature.getCoordinate(this.currentId,0),o=[t.lng,t.lat];if(1===this.currentCoordinate)i=[{type:yt,index:1,coordinate:o},{type:yt,index:2,coordinate:[t.lng,t.lat]}];else if(2===this.currentCoordinate)i=[{type:yt,index:2,coordinate:o}];else{var r=this.closingPoints.isPolygonClosingPoints(t);r.isPreviousClosing||r.isClosing?(this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.setCursor(this.cursors.close),i=[{type:yt,index:-1,coordinate:n},{type:yt,index:-2,coordinate:n}]):i=[{type:yt,index:-2,coordinate:o},{type:yt,index:-1,coordinate:n}]}var s=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:i,propertyMutations:(e={},e[y.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,e),context:{updateType:d.Provisional}});s&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates})}},i.snapCoordinate=function(t){var e,i,n,o,r,s,a,d=this,u=void 0;if(null!=(e=this.snapping)&&e.toDegree&&this.currentId&&(u=this.degreeSnapping.getSnappableCoordinate(t,this.readFeature.getGeometry(this.currentId),this.currentCoordinate,this.snapping.toDegree)),null!=(i=this.snapping)&&i.toLine&&(s=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(u=s),null!=(n=this.snapping)&&n.toCoordinate&&(a=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(u=a),null!=(o=this.snapping)&&o.toFeature){var h,l=this.featureSnapping.getSnappable(t,this.currentId,null==(h=this.snapping)?void 0:h.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});l.coordinate&&(u=l.coordinate)}if(null!=(r=this.snapping)&&r.toCustom){var c=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return d.readFeature.getGeometry(d.currentId)}:function(){return null},project:this.project,unproject:this.unproject});c&&(u=c)}return u},i.polygonFilter=function(t){return Boolean("Polygon"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.polygonFilter(t)}),n=i.featureId,o=i.featureCoordinateIndex;if(n&&void 0!==o){var r=this.readFeature.getGeometry(n);if("Polygon"===r.type){var s=r.coordinates[0];if(!(s.length<=4)){var a=this.mutateFeature.updatePolygon({featureId:n,coordinateMutations:0===o||o===s.length-1?[{type:ft,index:0},{type:ft,index:-1},{type:gt,index:-1,coordinate:s[1]}]:[{type:ft,index:o}],context:{updateType:d.Finish,action:h}});if(a){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){var u=this.snapCoordinate(t);if(u){var l=this.mutateFeature.createGuidancePoints({type:y.SNAPPING_POINT,coordinates:[u]});this.snappedPointId=l[0]}}this.onFinish(n,{mode:this.mode,action:h})}}}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);var e=this.snapCoordinate(t)||[t.lng,t.lat];if(0===this.currentCoordinate){var i,n=this.mutateFeature.createPolygon({coordinates:[e,e,e,e],properties:(i={mode:this.mode},i[y.CURRENTLY_DRAWING]=!0,i[y.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,i[y.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,i)}),o=n.id;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:o,featureCoordinates:n.geometry.coordinates}),this.currentId=o,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var r;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:0}))return;var s=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:yt,index:1,coordinate:e},{type:yt,index:2,coordinate:e}],propertyMutations:(r={},r[y.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,r),context:{updateType:d.Commit}});if(!s)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(2===this.currentCoordinate&&this.currentId){var a;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:1}))return;var u=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:yt,index:2,coordinate:e},{type:gt,index:2,coordinate:e}],propertyMutations:(a={},a[y.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,a),context:{updateType:d.Commit}});if(!u)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:u.geometry.coordinates}),2===this.currentCoordinate&&this.closingPoints.create(u.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){var h=this.closingPoints.isPolygonClosingPoints(t);if(h.isPreviousClosing||h.isClosing)this.close();else{var l;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:this.currentCoordinate-1}))return;var c=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:pt,index:-1,coordinate:e}],propertyMutations:(l={},l[y.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,l),context:{updateType:d.Commit}});if(!c)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:c.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(c.geometry.coordinates)}}},i.onClick=function(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)},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var n=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t,function(t){return i.polygonFilter(t)});o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,n=o.coordinate);var r=this.coordinateSnapping.getSnappable(t,function(t){return i.polygonFilter(t)});r.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:n,type:y.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){var n=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===n.coordinates[0].length-1?[{type:yt,index:0,coordinate:o},{type:yt,index:-1,coordinate:o}]:[{type:yt,index:this.editedFeatureCoordinateIndex,coordinate:o}]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,r=[{type:pt,index:this.editedInsertIndex,coordinate:o}],this.editedFeatureCoordinateIndex++),0!==r.length){var s=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:r,propertyMutations:(i={},i[y.EDITED]=!0,i),context:{updateType:d.Provisional}});s&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:s.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,s.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}]))}}},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:(i={},i[y.EDITED]=!1,i),context:{updateType:d.Finish,action:h}}))){var n=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(n,{mode:this.mode,action:h})}},i.cleanUp=function(){var 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()},i.styleFeature=function(t){var 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,markerAnchor:"bottom",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=f,e;if("Point"===t.geometry.type){var i=t.properties[y.EDITED],n=t.properties[y.COORDINATE_POINT],r=i?"editedPoint":t.properties[y.CLOSING_POINT]?"closingPoint":t.properties[y.SNAPPING_POINT]?"snappingPoint":n?"coordinatePoint":void 0;if(!r)return e;var s={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(s[r].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(s[r].opacity,1,t),e.pointColor=this.getHexColorStylingValue(s[r].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(s[r].outlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(s[r].outlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(s[r].outlineWidth,2,t),e.zIndex=i?40:n?v:m,e}}return e},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.afterFeatureUpdated=function(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())},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ut(t,e.coordinatePrecision)})},e}(N),Fe={cancel:R,finish:T},Oe={start:W},we=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="rectangle",i.startPosition=void 0,i.endPosition=void 0,i.currentRectangleId=void 0,i.keyEvents=Fe,i.cursors=Oe,i.drawInteraction="click-move",i.drawType=void 0,i.showCoordinatePoints=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.coordinatePoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i;t.prototype.updateOptions.call(this,e),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),k(null==e?void 0:e.drawInteraction)&&(this.drawInteraction=e.drawInteraction),x(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints))},i.updateRectangle=function(t,e){var i;if(this.startPosition&&this.currentRectangleId){var n=e===d.Finish,o=this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:yt,index:1,coordinate:[t[0],this.startPosition[1]]},{type:yt,index:2,coordinate:t},{type:yt,index:3,coordinate:[this.startPosition[0],t[1]]}],propertyMutations:n?(i={},i[y.CURRENTLY_DRAWING]=void 0,i):{},context:n?{updateType:e,action:u}:{updateType:e}});return o&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentRectangleId,featureCoordinates:o.geometry.coordinates}),o}},i.close=function(){if(this.currentRectangleId&&this.endPosition&&this.updateRectangle(this.endPosition,d.Finish)){var 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:u})}},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click"),this.startPosition=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];var n=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:(i={mode:this.mode},i[y.CURRENTLY_DRAWING]=!0,i)});this.currentRectangleId=n.id,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n.id,featureCoordinates:n.geometry.coordinates}),this.drawType=e,this.setDrawing()},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.onClick=function(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))},i.onMouseMove=function(t){this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,d.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,d.Provisional))},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))},i.cleanUp=function(){var t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var 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,markerAnchor:"bottom",lineStringDash:void 0});return"Feature"===t.type&&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.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=f,e):"Feature"===t.type&&t.properties.mode===this.mode&&"Point"===t.geometry.type&&t.properties[y.COORDINATE_POINT]?(e.pointWidth=this.getNumericStylingValue(this.styles.coordinatePointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.coordinatePointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.coordinatePointOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.coordinatePointOutlineWidth,2,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.coordinatePointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.coordinatePointOutlineOpacity,1,t),e.zIndex=v,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ht(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&"Polygon"===t.geometry.type&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.currentRectangleId===t.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&"Polygon"===t.geometry.type&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.registerBehaviors=function(t){this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature)},e}(N),xe=/*#__PURE__*/function(t){function e(e){var i;if(!e.modeName)throw new Error("Mode name is required for TerraDrawRenderMode");return(i=t.call(this,e,!0)||this).type=S.Render,i.mode="render",i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e)},i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(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}},i.validateFeature=function(e){var i=t.prototype.validateFeature.call(this,e);if(i.valid){var n=e,o=fe(n,this.coordinatePrecision).valid||ut(n,this.coordinatePrecision).valid||ne(n,this.coordinatePrecision).valid;return o?{valid:!0}:{valid:o,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(N);function Me(t,e){var i=t,n=e,o=H(i[1]),r=H(n[1]),s=H(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=(j(Math.atan2(s,a))+360)%360;return d>180?-(360-d):d}function Ee(t,e,i){var n=e;e<0&&(n=-Math.abs(n));var o=n/z,r=t[0]*Math.PI/180,s=H(t[1]),a=H(i),d=o*Math.cos(a),u=s+d;Math.abs(u)>Math.PI/2&&(u=u>0?Math.PI-u:-Math.PI-u);var h=Math.log(Math.tan(u/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),l=Math.abs(h)>1e-11?d/h:Math.cos(s),c=[(180*(r+o*Math.sin(a)/l)/Math.PI+540)%360-180,180*u/Math.PI];return c[0]+=c[0]-t[0]>180?-360:t[0]-c[0]>180?360:0,c}function De(t,e,i,n,o){var r=n(t[0],t[1]),s=n(e[0],e[1]),a=o((r.x+s.x)/2,(r.y+s.y)/2),d=a.lat;return[K(a.lng,i),K(d,i)]}function ke(t,e,i){var n=Ee(t,1e3*V(t,e)/2,Me(t,e));return[K(n[0],i),K(n[1],i)]}function be(t){for(var e=t.featureCoords,i=t.precision,n=t.unproject,o=t.project,r=t.projection,s=[],a=0;a(i=t)[1]!=(o=d[l])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var Re=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},We=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return r(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=void 0,a=this.createClickBoundingBox.create(t),d=this.store.search(a),u=0;u180||a<-180||u>90||u<-90)return!1;n[r]=[a,u]}"Polygon"===e.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var f=this.draggedFeatureId,v=null;if("Polygon"===e.type)v=this.mutateFeature.updatePolygon({featureId:f,coordinateMutations:{type:vt,coordinates:[n]},context:{updateType:d.Provisional}});else{if("LineString"!==e.type)return;v=this.mutateFeature.updateLineString({featureId:f,coordinateMutations:{type:vt,coordinates:n},context:{updateType:d.Provisional}})}if(!v)return!1;var m=v.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:m}),this.selectionPoints.updateAllInPlace({featureCoordinates:m}),this.coordinatePoints.updateAllInPlace({featureId:f,featureCoordinates:m}),this.dragPosition=[t.lng,t.lat]}else"Point"===e.type&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:vt,coordinates:i},context:{updateType:d.Provisional}}),this.dragPosition=[t.lng,t.lat])}},e}(lt),Ue=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a,d,u){var h;return(h=t.call(this,e)||this).config=void 0,h.pixelDistance=void 0,h.selectionPoints=void 0,h.midPoints=void 0,h.coordinatePoints=void 0,h.coordinateSnapping=void 0,h.lineSnapping=void 0,h.readFeature=void 0,h.mutateFeature=void 0,h.featureSnapping=void 0,h.draggedCoordinate={id:null,index:-1},h.config=e,h.pixelDistance=i,h.selectionPoints=n,h.midPoints=o,h.coordinatePoints=r,h.coordinateSnapping=s,h.lineSnapping=a,h.readFeature=d,h.mutateFeature=u,h.featureSnapping=new Rt(h.coordinateSnapping,h.lineSnapping),h}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(u){var l=a.length-1;a[0]=h,a[l]=h}else a[o]=h;if("Point"!==r.type&&!e&&tt({type:"Feature",geometry:r,properties:{}}))return!1;var c=n,p=null;return"Polygon"===r.type?p=this.mutateFeature.updatePolygon({featureId:c,coordinateMutations:{type:vt,coordinates:[a]},context:{updateType:d.Provisional}}):"LineString"===r.type&&(p=this.mutateFeature.updateLineString({featureId:c,coordinateMutations:{type:vt,coordinates:a},context:{updateType:d.Provisional}})),!!p&&(this.midPoints.updateOneAtIndex(o>0?o-1:-1,a),this.midPoints.updateOneAtIndex(o,a),this.selectionPoints.updateOneAtIndex(o,h),this.coordinatePoints.updateOneAtIndex(c,o,h),!0)},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(lt);function Le(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}var Be=function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return Z(t[0],t[1])}),o=n.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});o.x/=n.length,o.y/=n.length;var r=n.map(function(t){return{x:o.x+(t.x-o.x)*Math.cos(i)-(t.y-o.y)*Math.sin(i),y:o.y+(t.x-o.x)*Math.sin(i)+(t.y-o.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[J(e,i).lng,J(e,i).lat]});return"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r,t};function Ve(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=Z(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,n=0,o=t.length,r=0;r180?-360:e[0]-t[0]>180?360:0;var i=z,n=e[1]*Math.PI/180,o=t[1]*Math.PI/180,r=o-n,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=Math.abs(a)>1e-11?r/a:Math.cos(n);return Math.sqrt(r*r+d*d*s*s)*i}(i,t),r=Ee(i,o,n);t[0]=r[0],t[1]=r[1]})}(s,-(this.lastBearing-(o+180)))}var u="Polygon"===n.type?n.coordinates[0]:n.coordinates;u.forEach(function(t){t[0]=K(t[0],i.coordinatePrecision),t[1]=K(t[1],i.coordinatePrecision)});var h={featureId:e,coordinateMutations:{type:vt,coordinates:"Polygon"===n.type?[u]:u},context:{updateType:d.Provisional}},l=null;if("Polygon"===s.geometry.type)l=this.mutateFeature.updatePolygon(h);else{if("LineString"!==s.geometry.type)return;l=this.mutateFeature.updateLineString(h)}if(!l)return!1;var c=l.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:c}),this.selectionPoints.updateAllInPlace({featureCoordinates:c}),this.coordinatePoints.updateAllInPlace({featureId:e,featureCoordinates:c}),"web-mercator"===this.projection?this.lastBearing=o:"globe"===this.projection&&(this.lastBearing=o+180)}},e}(lt),He=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.dragCoordinateResizeBehavior=void 0,n.config=e,n.dragCoordinateResizeBehavior=i,n}r(e,t);var i=e.prototype;return i.scale=function(t,e){if(!this.dragCoordinateResizeBehavior.isDragging()){var i=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,i)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed")},i.reset=function(){this.dragCoordinateResizeBehavior.stopDragging()},e}(lt);function Ge(t){var e=t.originX,i=t.originY,n=t.xScale,o=t.yScale;1===n&&1===o||t.coordinates.forEach(function(t){var r=Z(t[0],t[1]),s=J(e+(r.x-e)*n,i+(r.y-i)*o),a=s.lat;t[0]=s.lng,t[1]=a})}var je=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.pixelDistance=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.readFeature=void 0,d.mutateFeature=void 0,d.minimumScale=1e-4,d.draggedCoordinate={id:null,index:-1},d.centerOrigin=null,d.oppositeOrigin=null,d.oppositeClosestBBoxIndex=null,d.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},d.config=e,d.pixelDistance=i,d.selectionPoints=n,d.midPoints=o,d.coordinatePoints=r,d.readFeature=s,d.mutateFeature=a,d}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o=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},i.getSelectedFeatureDataWebMercator=function(){if(null===this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e,i=this.getSelectedFeatureDataWebMercator();if(!i)return null;var n=i.boundingBox,o=i.updatedCoords,r=i.selectedCoordinate,s=null!=(e=this.centerOrigin)?e:Ve(i.feature);if(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y))return null;this.centerOrigin=s;var a=Z(r[0],r[1]),d=this.getIndexesWebMercator(n,a).closestBBoxIndex,u=Z(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:u,webMercatorSelected:a,webMercatorOrigin:s})},i.centerFixedWebMercatorDrag=function(t){var e,i=this.getSelectedFeatureDataWebMercator();if(!i)return null;var n=i.boundingBox,o=i.updatedCoords,r=i.selectedCoordinate,s=null!=(e=this.centerOrigin)?e:Ve(i.feature);if(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y))return null;this.centerOrigin=s;var a=Z(r[0],r[1]),d=this.getIndexesWebMercator(n,a).closestBBoxIndex,u=Z(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:u,webMercatorSelected:a,webMercatorOrigin:s})},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,n=t.webMercatorCursor,o=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-n.x,e.y-n.y))return null;var r=wt(e,n)/wt(e,i);return Number.isFinite(r)?(re[2]&&(e[2]=i),n>e[3]&&(e[3]=n)});var i=e[0],n=e[1],o=e[2],r=e[3];return[[i,r],[(i+o)/2,r],[o,r],[o,r+(n-r)/2],[o,n],[(i+o)/2,n],[i,n],[i,r+(n-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,n=Infinity,o=0;o0).clickedFeature,i=this.midPoints.getNearestMidPoint(t),n=this.selected[0];if(n){var o,r=this.getSelectedFlags(n).featureFlags;if(null!=r&&null!=(o=r.coordinates)&&o.midpoints&&i){if(r.coordinates.draggable){var s=this.pixelDistance.measure(t,this.readFeature.getGeometry(i).coordinates),a=this.dragCoordinate.getDraggable(t,n).dist;if(void 0!==a&&s>a)return}return this.midPoints.insert({featureId:n,midPointId:i}),void this.onFinish(this.selected[0],{action:c,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])},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(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)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;var e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect(this.selected[0])},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){var i=this.selected[0];if(i){var n=this.getSelectedFlags(i),o=n.featureFlags,r=n.coordinatesFlags;if(n.hasDraggableFlags){this.dragEventCount=0;var s="none"!==this.dragTarget.type&&this.dragTarget.featureId===i?this.dragTarget:{type:"none"},a="coordinate"===s.type?s.coordinateIndex:this.dragCoordinate.getDraggableIndex(t,i),d="resize"===s.type?s.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(t,i),u=(null==r?void 0:r.resizable)&&-1!==d,h=(null==r?void 0:r.draggable)&&-1!==a,l=r&&"object"==typeof r.midpoints&&r.midpoints.draggable,p=(null==o?void 0:o.draggable)&&("feature"===s.type||this.dragFeature.canDrag(t,i));if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(i,d),void e(!1);if(h)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(i,a),void e(!1);if(l){var g="midpoint"===s.type?s.midPointId:this.midPoints.getNearestMidPoint(t);if(this.selected.length&&g){this.midPoints.insert({featureId:i,midPointId:g}),this.onFinish(this.selected[0],{action:c,mode:this.mode});var y=this.dragCoordinate.getDraggableIndex(t,i);return this.dragCoordinate.startDragging(i,y),void e(!1)}}if(p)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,i),void e(!1);this.setCursor(B)}}}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)){var i=this.selected[0];if(i){var n=this.readFeature.getProperties(i),o=this.flags[n.mode],r=!0===(o&&o.feature&&o.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(o&&o.feature&&o.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i);if(o&&o.feature&&o.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i);if(this.dragCoordinateResizeFeature.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,o.feature.coordinates.resizable)}if(this.dragCoordinate.isDragging()){var s,a=null==(s=o.feature)||null==(s=s.coordinates)?void 0:s.snappable,d={toCoordinate:!1};return!0===a?d={toCoordinate:!0}:"object"==typeof a&&(d=a),void this.dragCoordinate.drag(t,r,d)}this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)}}}},i.onDragEnd=function(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))},i.onMouseMove=function(t){var e=this.selected[0];if(e){if(!(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())){var i=this.getSelectedFlags(e).featureFlags;if(i){var n=void 0,o=i.coordinates;if(null!=o&&o.midpoints&&(n=this.midPoints.getNearestMidPoint(t))&&(this.dragTarget={type:"midpoint",featureId:e,midPointId:n},this.setCursor(this.cursors.insertMidpoint)),o&&o.draggable){var r=this.dragCoordinate.getDraggable(t,e),s=r.index,a=r.dist;if(s>-1){if(n&&this.pixelDistance.measure(t,this.readFeature.getGeometry(n).coordinates)-1)return this.dragTarget={type:"resize",featureId:e,coordinateIndex:d},void this.setCursor(this.getPointerOverResizeHandleCursor())}if(i.draggable&&this.dragFeature.canDrag(t,e)){if(n)return;return this.dragTarget={type:"feature",featureId:e},void this.setCursor(this.getPointerOverFeatureCursor())}n||this.clearDragTargetAndCursor()}else this.clearDragTargetAndCursor()}}else this.clearDragTargetAndCursor()},i.styleFeature=function(t){var 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,markerAnchor:"bottom",lineStringDash:void 0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties[g.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=m,e;if(t.properties[g.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[g.SELECTED]){if("Point"===t.geometry.type&&t.properties[y.MARKER])return e.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,p,t),e.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),e.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),e.markerAnchor=this.getMarkerAnchorStylingValue(this.styles.selectedMarkerAnchor,"bottom",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=f,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=f,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=f,e}return e},i.afterFeatureUpdated=function(t){if(this.selected.length&&t.id===this.selected[0]){var e,i,n=this.flags[t.properties.mode];if(null==n||null==(e=n.feature)||!e.coordinates)return;var o=t.geometry.type,r=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),"LineString"!==o&&"Polygon"!==o)return;var s=t.geometry.coordinates;this.selectionPoints.create({featureCoordinates:s,featureId:r}),null!=n&&null!=(i=n.feature)&&null!=(i=i.coordinates)&&i.midpoints&&this.midPoints.create({featureCoordinates:s,featureId:r})}},e}(_),qe=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;oi;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),d=.5*Math.exp(2*a/3),u=.5*Math.sqrt(a*d*(r-d)/r)*(s-r/2<0?-1:1);Ze(t,e,Math.max(i,Math.floor(e-s*d/r+u)),Math.min(n,Math.floor(e+(r-s)*d/r+u)),o)}var h=t[e],l=i,c=n;for(Je(t,i,e),o(t[n],h)>0&&Je(t,i,n);l0;)c--}0===o(t[i],h)?Je(t,i,c):Je(t,++c,n),c<=e&&(i=c+1),e<=c&&(n=c-1)}}function Je(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function $e(t,e){Qe(t,0,t.children.length,e,t)}function Qe(t,e,i,n,o){o||(o=ai([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r=t.minX&&e.maxY>=t.minY}function ai(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function di(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;Ze(t,s,e,i,o),r.push(e,s,s,i)}}var ui=/*#__PURE__*/function(){function t(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()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!si(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=ai(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,$e(i,this.toBBox),$e(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=ai([t,e]),this.data.height=t.height+1,this.data.leaf=!1,$e(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,d,u,h=Infinity,l=Infinity,c=e;c<=i-e;c++){var p=Qe(t,0,c,this.toBBox),g=Qe(t,c,i,this.toBBox),y=(o=p,r=g,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),d=Math.min(o.maxX,r.maxX),u=Math.min(o.maxY,r.maxY),Math.max(0,d-s)*Math.max(0,u-a)),f=ni(p)+ni(g);y=e;h--){var l=t.children[h];ti(s,t.leaf?o(l):l),a+=oi(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)ti(e[n],t)},e._condense=function(t){for(var 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():$e(t[i],this.toBBox)},t}(),hi=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new ui(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],n=[];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 new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o0&&(this._onChange(d,"create",n),i&&a.forEach(function(t){i(t)})),s},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i,n){t(e,i,n)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t,e){var i=this,n=new Set;t.forEach(function(t){var e=t.id,o=t.property,r=t.value,s=i.store[e];if(!s)throw new Error("No feature with this ("+e+"), can not update geometry");s.properties[o]!==r&&(n.add(e),void 0===r?delete s.properties[o]:s.properties[o]=r,i.tracked&&(s.properties.updatedAt=+new Date))}),this._onChange&&n.size>0&&this._onChange(Array.from(n),"update",e?o({},e,pi):pi)},e.updateGeometry=function(t,e){var i=this,n=new Set;t.forEach(function(t){var e=t.id,o=t.geometry;n.add(e);var r=i.store[e];if(!r)throw new Error("No feature with this ("+e+"), can not update geometry");r.geometry=i.clone(o),i.spatialIndex.update(r),i.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&n.size>0&&this._onChange(Array.from(n),"update",e?o({},e,ci):ci)},e.create=function(t,e){var i=this,n=[];return t.forEach(function(t){var e,r=t.geometry,s=t.properties,a=o({},s);i.tracked&&(e=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:e,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:e):a={createdAt:e,updatedAt:e});var d=i.getId(),u={id:d,type:"Feature",geometry:r,properties:a};i.store[d]=u,i.spatialIndex.insert(u),n.push(d)}),this._onChange&&this._onChange([].concat(n),"create",e),n},e.delete=function(t,e){var i=this;t.forEach(function(t){if(!i.store[t])throw new Error("No feature with id "+t+", can not delete");delete i.store[t],i.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete",e)},e.copy=function(t){return this.clone(this.store[t])},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.copyAllWhere=function(t){var e=this;return this.clone(Object.keys(this.store).map(function(t){return e.store[t]}).filter(function(e){return e.properties&&t(e.properties)}))},e.clear=function(t){var e=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(e,"delete",t)},e.size=function(){return Object.keys(this.store).length},t}();function yi(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(mi(e[0]));for(var n=1;n=e?(n+2)%e:n+2][0]*vi-t[n][0]*vi)*Math.sin(t[n+1===e?0:n+1][1]*vi),n++;return i*fi}var Ci="Feature is smaller than the minimum area",Pi=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:F}:yi(t.geometry)e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0}},Si="Feature is not a Polygon or LineString",Fi="Feature intersects itself",Oi=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:Si}:tt(t)?{valid:!1,reason:Fi}:{valid:!0}};function wi(t,e,i){var n=Jt(t,e),o=Jt(e,i)-n;return o<0&&(o+=360),180-Math.abs(o-90-90)}var xi={cancel:R,finish:T},Mi={start:W,close:A},Ei=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=xi,i.cursors=Mi,i.mouseMove=!1,i.showCoordinatePoints=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.coordinatePoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i;t.prototype.updateOptions.call(this,e),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),x(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints))},i.close=function(){var t;if(void 0!==this.currentId){var e=this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(i,{mode:this.mode,action:u})}}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e=[];if(1===this.currentCoordinate)e=this.getUpdateForSecondCoordinate(t);else{if(2!==this.currentCoordinate)return;e=this.getNewSecondAndThirdCoordinates(t)}var i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:d.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}},i.getUpdateForSecondCoordinate=function(t){return[{type:yt,index:1,coordinate:[t.lng,t.lat]},{type:yt,index:2,coordinate:[t.lng,t.lat]}]},i.getNewSecondAndThirdCoordinates=function(t){if(!this.currentId)throw new Error("No current feature being drawn");var e,i,n,o,r=this.readFeature.getCoordinate(this.currentId,0),s=this.readFeature.getCoordinate(this.currentId,1),a=De(r,s,this.coordinatePrecision,this.project,this.unproject),d=Z(r[0],r[1]),u=Z(a[0],a[1]),h=Z(s[0],s[1]),l=Z(t.lng,t.lat),c=wt(l,d)1e-10?"left":o<-1e-10?"right":"left")?-90:90),m=Bt(d,f,v),C=Bt(h,f,v),P=J(m.x,m.y),I=J(C.x,C.y);return[{type:yt,index:2,coordinate:[K(I.lng,this.coordinatePrecision),K(I.lat,this.coordinatePrecision)]},{type:yt,index:3,coordinate:[K(P.lng,this.coordinatePrecision),K(P.lat,this.coordinatePrecision)]}]},i.onClick=function(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){var e,i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[y.CURRENTLY_DRAWING]=!0,e)});this.currentId=i.id,this.currentCoordinate++,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:i.id,featureCoordinates:i.geometry.coordinates}),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.readFeature.getCoordinate(this.currentId,0);if(Ct([t.lng,t.lat],n))return;var o=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:yt,index:1,coordinate:[t.lng,t.lat]},{type:gt,index:1,coordinate:[t.lng,t.lat]}],context:{updateType:d.Commit}});if(!o)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(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()}},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var 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,markerAnchor:"bottom",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=f):"Point"===t.geometry.type&&t.properties[y.COORDINATE_POINT]&&(e.pointWidth=this.getNumericStylingValue(this.styles.coordinatePointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.coordinatePointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.coordinatePointOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.coordinatePointOutlineWidth,2,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.coordinatePointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.coordinatePointOutlineOpacity,1,t),e.zIndex=v)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ht(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&"Polygon"===t.geometry.type&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.currentId===t.id&&(this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&"Polygon"===t.geometry.type&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.registerBehaviors=function(t){this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature)},e}(N);function Di(t,e,i,n){var o=("anticlockwise"===t?$t(i-e):-$t(e-i))+($t(n-i+180)-180);return"anticlockwise"===t&&o<0?"clockwise":"clockwise"===t&&o>0?"anticlockwise":t}function ki(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var bi={cancel:R,finish:T},Ni={start:W,close:A},_i=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sector",i.snapping=void 0,i.snappedPointId=void 0,i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=bi,i.direction=void 0,i.arcPoints=64,i.cursors=Ni,i.mouseMove=!1,i.showCoordinatePoints=!1,i.allowDirectionChange=!1,i.previousEndBearing=void 0,i.coordinateSnapping=void 0,i.featureSnapping=void 0,i.readFeature=void 0,i.mutateFeature=void 0,i.coordinatePoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i;t.prototype.updateOptions.call(this,e),E(null==e?void 0:e.snapping)&&(this.snapping=e.snapping),x(null==e?void 0:e.allowDirectionChange)&&(this.allowDirectionChange=e.allowDirectionChange),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),w(null==e?void 0:e.arcPoints)&&e.arcPoints>0&&(this.arcPoints=e.arcPoints),x(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints))},i.updateSnappedCoordinate=function(t){var e;t&&!1!==(null==(e=this.snapping)?void 0:e.showSnappingPoint)?this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:y.SNAPPING_POINT}):this.deleteSnappedPoint()},i.deleteSnappedPoint=function(){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.getSnappedCoordinate=function(t){var e,i,n,o=this;if(!(this.currentCoordinate>=2)){var r,s=this.currentId;if(null!=(e=this.snapping)&&e.toCoordinate){var a=void 0!==s?this.coordinateSnapping.getSnappableCoordinate(t,s):this.coordinateSnapping.getSnappableCoordinateFirstClick(t);a&&(r=a)}if(null!=(i=this.snapping)&&i.toFeature){var d=this.featureSnapping.getSnappable(t,s,this.snapping.toFeature.filter,{toLine:this.snapping.toFeature.toLine,toCoordinate:this.snapping.toFeature.toCoordinate});d.coordinate&&(r=d.coordinate)}if(null!=(n=this.snapping)&&n.toCustom){var u=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:s,getCurrentGeometrySnapshot:void 0!==s?function(){return o.readFeature.getGeometry(s)}:function(){return null},project:this.project,unproject:this.unproject});u&&(r=u)}return r}},i.close=function(){var t;if(void 0!==this.currentId){var e=this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=void 0,t),coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:vt},context:{updateType:d.Finish,action:u}});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.deleteSnappedPoint();var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,this.previousEndBearing=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(i,{mode:this.mode,action:u})}}},i.getSectorCoordinates=function(t){var e=this.readFeature.getCoordinates(this.currentId),i=e[0],n=e[1],o=[t.lng,t.lat],r=Z(i[0],i[1]),s=Z(n[0],n[1]),a=Z(o[0],o[1]);if(void 0===this.direction){var d=ki(r,s,a);this.direction=d?"clockwise":"anticlockwise"}var u=wt(r,s),h=Jt(r,s),l=Jt(r,a);this.allowDirectionChange&&void 0!==this.previousEndBearing&&(this.direction=Di(this.direction,h,this.previousEndBearing,l)),this.previousEndBearing=l;var c,p=this.arcPoints,g=[i],y=$t(h),f=$t(l);"anticlockwise"===this.direction?(c=f-y)<0&&(c+=360):(c=y-f)<0&&(c+=360);var v=("anticlockwise"===this.direction?1:-1)*c/p;g.push(n);for(var m=0;m<=p;m++){var C=Bt(r,u,y+m*v),P=J(C.x,C.y),I=P.lat,S=[K(P.lng,this.coordinatePrecision),K(I,this.coordinatePrecision)];S[0]!==g[g.length-1][0]&&S[1]!==g[g.length-1][1]&&g.push(S)}return g.push(i),g},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.getSnappedCoordinate(t);this.updateSnappedCoordinate(e);var i=null!=e?e:[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var n;if(1===this.currentCoordinate)n=[{type:yt,index:1,coordinate:i},{type:yt,index:2,coordinate:i}];else{if(2!==this.currentCoordinate)return;var o=this.getSectorCoordinates(t);if(!o)return;n={type:vt,coordinates:[o]}}var r=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:n,context:{updateType:d.Provisional}});r&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates})}},i.onClick=function(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)){var e;this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1;var i=null!=(e=this.getSnappedCoordinate(t))?e:[t.lng,t.lat];if(this.deleteSnappedPoint(),0===this.currentCoordinate){var n,o=this.mutateFeature.createPolygon({coordinates:[i,i,i,i],properties:(n={mode:this.mode},n[y.CURRENTLY_DRAWING]=!0,n)});this.currentId=null==o?void 0:o.id,this.currentCoordinate++,o&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:o.id,featureCoordinates:o.geometry.coordinates}),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,index:0,newCoordinate:i}))return;if(!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:yt,index:1,coordinate:i},{type:yt,index:2,coordinate:i}],context:{updateType:d.Provisional}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()}},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){this.deleteSnappedPoint();var t=this.currentId;this.currentId=void 0,this.direction=void 0,this.previousEndBearing=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t])},i.styleFeature=function(t){var 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,markerAnchor:"bottom",lineStringDash:void 0});if(t.properties.mode===this.mode)if("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=f;else if("Point"===t.geometry.type&&t.properties[y.SNAPPING_POINT]){var i,n;e.zIndex=40,e.pointColor=this.getHexColorStylingValue(this.styles.snappingPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.snappingPointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.snappingPointOpacity,null!=(i=e.pointOpacity)?i:1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.snappingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.snappingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.snappingPointOutlineOpacity,null!=(n=e.pointOutlineOpacity)?n:1,t),e.zIndex=40}else"Point"===t.geometry.type&&t.properties[y.COORDINATE_POINT]&&(e.pointWidth=this.getNumericStylingValue(this.styles.coordinatePointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.coordinatePointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.coordinatePointOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.coordinatePointOutlineWidth,2,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.coordinatePointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.coordinatePointOutlineOpacity,1,t),e.zIndex=v);return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ht(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.deleteSnappedPoint(),this.currentId=void 0,this.direction=void 0,this.previousEndBearing=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()),this.showCoordinatePoints&&"Polygon"===t.geometry.type&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.registerBehaviors=function(t){var e=new xt(t),i=new Et(t);this.coordinateSnapping=new Dt(t,e,i);var n=new Tt(t,e,i);this.featureSnapping=new Rt(this.coordinateSnapping,n),this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature)},e}(N),Ti={cancel:R,finish:T},Ri={start:W,close:A},Wi=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=Ti,i.direction=void 0,i.arcPoints=64,i.cursors=Ri,i.mouseMove=!1,i.showCoordinatePoints=!1,i.allowDirectionChange=!1,i.previousEndBearing=void 0,i.readFeature=void 0,i.mutateFeature=void 0,i.coordinatePoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i;t.prototype.updateOptions.call(this,e),x(null==e?void 0:e.allowDirectionChange)&&(this.allowDirectionChange=e.allowDirectionChange),E(null==e?void 0:e.cursors)&&(this.cursors=o({},this.cursors,e.cursors)),M(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:E(null==e?void 0:e.keyEvents)&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),w(null==e?void 0:e.arcPoints)&&e.arcPoints>0&&(this.arcPoints=e.arcPoints),x(null==e?void 0:e.showCoordinatePoints)&&(this.showCoordinatePoints=e.showCoordinatePoints,null==(i=this.coordinatePoints)||i.setEnabled(this.showCoordinatePoints),this.updateInitialArcCoordinatePoints())},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor(B)},i.onMouseMove=function(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){var e=this.getUpdatedLineStringCoordinates(t);if(!e)return;this.mutateFeature.updateLineString({featureId:this.currentInitialArcId,coordinateMutations:{type:vt,coordinates:e},context:{updateType:d.Provisional}})&&this.updateInitialArcCoordinatePoints()}else if(3===this.currentCoordinate){var i=this.getUpdatedPolygonCoordinates(t);if(!i)return;var n=i.map(function(t){return[].concat(t)});if(this.currentId)this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:vt,coordinates:[i]},context:{updateType:d.Provisional}})&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:[n]});else{var o,r=this.mutateFeature.createPolygon({coordinates:i,properties:(o={mode:this.mode},o[y.CURRENTLY_DRAWING]=!0,o)});if(!r)return;this.currentId=r.id,this.coordinatePoints.deletePointsByFeatureIds([this.currentInitialArcId]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:r.id,featureCoordinates:[n]})}}},i.onClick=function(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){var 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){var i=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode}});if(!i)return;this.currentInitialArcId=i.id,this.updateInitialArcCoordinatePoints(),this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.deleteInitialArc(),this.currentId&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([this.currentId]),this.mutateFeature.deleteFeatureIfPresent(this.currentId),this.currentStartingPointId=void 0,this.direction=void 0,this.previousEndBearing=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var 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,markerAnchor:"bottom",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=f):"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=f):"Point"===t.geometry.type&&t.properties[y.COORDINATE_POINT]?(e.pointColor=this.getHexColorStylingValue(this.styles.coordinatePointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.coordinatePointOpacity,1,t),e.pointWidth=this.getNumericStylingValue(this.styles.coordinatePointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.coordinatePointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.coordinatePointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.coordinatePointOutlineWidth,2,t),e.zIndex=v):"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=v)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ht(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.showCoordinatePoints&&"Polygon"===t.geometry.type&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.deleteInitialArc(),this.currentStartingPointId=void 0,this.direction=void 0,this.previousEndBearing=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new Pt(t),this.mutateFeature=new mt(t,{validate:this.validate}),this.coordinatePoints=new Ot(t,this.readFeature,this.mutateFeature)},i.updateInitialArcCoordinatePoints=function(){if(this.showCoordinatePoints&&void 0!==this.currentInitialArcId)if(void 0===this.currentId){var t=this.readFeature.getCoordinates(this.currentInitialArcId);this.coordinatePoints.createOrUpdate({featureId:this.currentInitialArcId,featureCoordinates:t})}else this.coordinatePoints.deletePointsByFeatureIds([this.currentInitialArcId])},i.deleteInitialArc=function(t){void 0===t&&(t=this.currentInitialArcId),void 0!==t&&(this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t)),this.currentInitialArcId=void 0},i.close=function(){if(void 0!==this.currentStartingPointId){var t,e=this.currentStartingPointId,i=this.currentInitialArcId;if(this.currentId&&!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[y.CURRENTLY_DRAWING]=void 0,t),coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:vt},context:{updateType:d.Finish,action:u}}))return;var n=this.currentId;this.mutateFeature.deleteFeatureIfPresent(e),this.deleteInitialArc(i),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,this.previousEndBearing=void 0,"drawing"===this.state&&this.setStarted(),n&&this.onFinish(n,{mode:this.mode,action:u})}},i.getUpdatedPolygonCoordinates=function(t){if(!(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<3)){var e=this.readFeature.getCoordinates(this.currentInitialArcId);if(!(e.length<2)&&this.direction){var i=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,n=e[0],o=e[e.length-1],r=Z(t.lng,t.lat),s=Z(n[0],n[1]),a=Z(o[0],o[1]),d=Z(i[0],i[1]),u=wt(d,s),h=wt(d,r)=i&&e<=n:e>=i||e<=n:i>=n?e<=i&&e>=n:e<=i||e>=n},e}(N),Ai=function(t){var e=this,i=t.name,n=t.callback,o=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(n))},this.unregister=function(){e.register&&(e.registered=!1,o(n))},this.callback=n},Ui={__proto__:null,GeoJSONStore:gi,TerraDrawBaseDrawMode:N,TerraDrawBaseSelectMode:_,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(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}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement(t.type).getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t,e){void 0===e&&(e=!1);var i=this.getLngLatFromEvent(t);if(!i)return null;var n=i.lng,o=i.lat,r=this.getMapElementXYPosition(t),s=r.containerX,a=r.containerY,d=this.getButton(t),u=Array.from(this._heldKeys);return{lng:K(n,this._coordinatePrecision),lat:K(o,this._coordinatePrecision),containerX:s,containerY:a,button:d,heldKeys:u,isContextMenu:e}},e.register=function(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(function(t){t.register()})},e.getCoordinatePrecision=function(){return this._coordinatePrecision},e.getAdapterListeners=function(){var t=this;return[new Ai({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i,t._lastPointerDownEventTarget=e.target?e.target:void 0)}},register:function(e){t.getMapEventElement("pointerdown").addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement("pointerdown").removeEventListener("pointerdown",e)}}),new Ai({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var n={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},o={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=wt(n,o);if("drawing"===r?s0},e.canRedo=function(){return!!this.inDrawingState()&&this.getHistorySizes().redoSize>0},e.undo=function(){return!(!this.canUndo()||!this.undoMode||(this.undoMode(),this.emitHistoryChange(Ji),0))},e.redo=function(){return!(!this.canRedo()||!this.redoMode||(this.redoMode(),this.emitHistoryChange($i),0))},e.clearHistory=function(){this.clearModeHistory&&this.clearModeHistory(),this.lastHistorySizes={undoSize:0,redoSize:0}},e.getHistorySizes=function(){return this.getModeHistorySizes?this.getModeHistorySizes():{undoSize:0,redoSize:0}},e.undoSize=function(){return this.getHistorySizes().undoSize},e.redoSize=function(){return this.getHistorySizes().redoSize},e.emitPushIfHistoryChangedFromLastSnapshot=function(){if(this.inDrawingState()){var t=this.getHistorySizes();t.undoSize===this.lastHistorySizes.undoSize&&t.redoSize===this.lastHistorySizes.redoSize||this.emitHistoryChange(Qi)}},e.emitPushIfHistoryChanged=function(t){if(this.inDrawingState()){var e=this.getHistorySizes();e.undoSize===t.undoSize&&e.redoSize===t.redoSize||this.emitHistoryChange(Qi)}},e.emitHistoryChange=function(t){if(this.onHistoryChange){var e=this.getHistorySizes(),i=e.undoSize,n=e.redoSize;this.lastHistorySizes={undoSize:i,redoSize:n},this.onHistoryChange({cause:t,stack:tn,undoStackSize:i,redoStackSize:n})}},t}(),on=/*#__PURE__*/function(){function t(t){var e=this;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=function(t){e.onHistoryChange&&e.onHistoryChange({cause:t,stack:en,undoStackSize:e.undoStack.length,redoStackSize:e.redoStack.length})},this.handleChange=function(t,i,o){if(e.draw&&!e.isDrawing()&&0!==e.maxStackSize)if("update"!==i){if("delete"===i||"create"===i)if("create"!==i){for(var r,s=!1,a=[],d=n(Array.isArray(t)?t:[t]);!(r=d()).done;){var u=r.value,h=String(u);if(e.ignoreProgrammaticDelete[u])delete e.ignoreProgrammaticDelete[u];else if(e.historyById[h]){var l=e.historyById[h].length-1;if(l>=0){var c=e.historyById[h][l];if(!c)continue;a.push({id:u,toIndex:l,snapshot:c}),e.deletedFeatureIds[u]=!0,s=!0}}}if(a.length>1)e.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:"batch-delete",metadata:{entries:a}});else if(1===a.length){var p=a[0];e.pushUndoStackEntry({id:p.id,toIndex:p.toIndex,action:"single"})}s&&(e.redoStack.length=0,e.emitStackChange(Qi))}else{if(void 0===o||!("origin"in o)||"api"!==o.origin)return;for(var g,y=!1,f=[],v=n(Array.isArray(t)?t:[t]);!(g=v()).done;){var m=g.value;if(e.ignoreProgrammaticCreate[m])delete e.ignoreProgrammaticCreate[m],delete e.deletedFeatureIds[m];else{var C=String(m),P=e.draw.getSnapshotFeature(m);P&&(e.deletedFeatureIds[m]&&(e.historyById[C]=[],delete e.deletedFeatureIds[m]),e.historyById[C]||(e.historyById[C]=[]),e.historyById[C].push(P),f.push({id:m,toIndex:e.historyById[C].length-1,snapshot:P}),y=!0)}}if(f.length>1)e.pushUndoStackEntry({id:f[0].id,toIndex:f[0].toIndex,action:"batch-create",metadata:{entries:f}});else if(1===f.length){var I=f[0];e.pushUndoStackEntry({id:I.id,toIndex:I.toIndex,action:"single"})}y&&(e.redoStack.length=0,e.emitStackChange(Qi))}}else{if(void 0===o||!("origin"in o)||"api"!==o.origin||e.isReplayingHistory)return;for(var S,F=!1,O=n(Array.isArray(t)?t:[t]);!(S=O()).done;){var w=S.value;if(null!=w){var x=String(w),M=e.draw.getSnapshotFeature(w);M&&(e.historyById[x]||(e.historyById[x]=[]),e.historyById[x].push(M),e.pushUndoStackEntry({id:w,toIndex:e.historyById[x].length-1,action:"single"}),F=!0)}}F&&(e.redoStack.length=0,e.emitStackChange(Qi))}},this.handleFinish=function(t){if(e.draw&&0!==e.maxStackSize&&!e.isReplayingHistory)for(var i,o=!1,r=n(Array.isArray(t)?t:[t]);!(i=r()).done;){var s=i.value;if(null!=s){var a=String(s),d=e.draw.getSnapshotFeature(s);d&&(e.historyById[a]||(e.historyById[a]=[]),e.historyById[a].push(d),o||(e.redoStack.length=0,o=!0),e.pushUndoStackEntry({id:s,toIndex:e.historyById[a].length-1,action:"single"}),e.emitStackChange(Qi))}}},this.maxStackSize=Zi(null==t?void 0:t.maxStackSize)}var e=t.prototype;return e.register=function(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):this.onHistoryChange=t.onHistoryChange},e.pushUndoStackEntry=function(t){0!==this.maxStackSize&&(this.undoStack.push(t),this.undoStack.length>this.maxStackSize&&this.undoStack.shift())},e.pushRedoStackEntry=function(t){0!==this.maxStackSize&&(this.redoStack.push(t),this.redoStack.length>this.maxStackSize&&this.redoStack.shift())},e.isDrawing=function(){return!!this.draw&&"drawing"===this.draw.getModeState()},e.applySnapshotDuringReplay=function(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}}},e.canUndo=function(){return!(!this.draw||this.isDrawing())&&this.undoStack.length>0},e.canRedo=function(){return!(!this.draw||this.isDrawing())&&this.redoStack.length>0},e.undo=function(){var t=this;if(!this.canUndo())return!1;if(!this.draw)return!1;var e=this.undoStack.pop();if(!e)return this.emitStackChange(Ji),!1;if("batch-create"===e.action){var i,n=(null==(i=e.metadata)?void 0:i.entries)||[];if(0===n.length)return this.emitStackChange(Ji),!1;var o=n.map(function(t){return t.id});return o.forEach(function(e){t.ignoreProgrammaticDelete[e]=!0,t.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(o),this.pushRedoStackEntry({id:n[0].id,toIndex:n[0].toIndex,action:"batch-create",metadata:{entries:n}}),this.emitStackChange(Ji),!0}if("batch-delete"===e.action){var r,s=(null==(r=e.metadata)?void 0:r.entries)||[];if(0===s.length)return this.emitStackChange(Ji),!1;var a=s.map(function(t){return t.snapshot}).filter(function(t){return void 0!==t});return a.length>0&&(s.forEach(function(e){t.ignoreProgrammaticCreate[e.id]=!0,delete t.deletedFeatureIds[e.id]}),this.draw.addFeatures(a)),this.pushRedoStackEntry({id:s[0].id,toIndex:s[0].toIndex,action:"batch-delete",metadata:{entries:s}}),this.emitStackChange(Ji),!0}var d=e.id,u=e.toIndex,h=String(d),l=this.historyById[h];if(!l||0===l.length)return this.emitStackChange(Ji),!1;var c=Math.min(u,l.length-1);if(!this.draw.hasFeature(d)){var p=l[c];return p?(this.ignoreProgrammaticCreate[d]=!0,delete this.deletedFeatureIds[d],this.draw.addFeatures([p]),this.pushRedoStackEntry({id:d,toIndex:c,action:"delete",snapshot:p}),this.emitStackChange(Ji),!0):(this.emitStackChange(Ji),!1)}if(c<=0)return this.pushRedoStackEntry({id:d,toIndex:0,action:"create"}),this.ignoreProgrammaticDelete[d]=!0,this.deletedFeatureIds[d]=!0,this.draw.removeFeatures([d]),this.undoStack=this.undoStack.filter(function(t){return t.id!==d}),this.emitStackChange(Ji),!0;var g=l[c],y=l[c-1];return g&&this.pushRedoStackEntry({id:d,toIndex:c,snapshot:g,action:"update"}),this.applySnapshotDuringReplay(d,y),l.length=c,this.emitStackChange(Ji),!0},e.redo=function(){var t=this;if(!this.canRedo())return!1;if(!this.draw)return!1;var e=this.redoStack.pop(),i=e.id,n=e.toIndex,o=e.snapshot,r=e.action,s=e.metadata;if("batch-create"===r){var a=(null==s?void 0:s.entries)||[];if(0===a.length)return this.emitStackChange($i),!1;var d=a.map(function(t){return t.snapshot}).filter(function(t){return void 0!==t});return d.length>0&&(a.forEach(function(e){t.ignoreProgrammaticCreate[e.id]=!0}),this.draw.addFeatures(d)),this.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:"batch-create",metadata:{entries:a}}),this.emitStackChange($i),!0}if("batch-delete"===r){var u=(null==s?void 0:s.entries)||[];if(0===u.length)return this.emitStackChange($i),!1;var h=u.map(function(t){return t.id});return h.forEach(function(e){t.ignoreProgrammaticDelete[e]=!0,t.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(h),this.pushUndoStackEntry({id:u[0].id,toIndex:u[0].toIndex,action:"batch-delete",metadata:{entries:u}}),this.emitStackChange($i),!0}var l=String(i),c=this.historyById[l]||(this.historyById[l]=[]);if("delete"===r)return this.ignoreProgrammaticDelete[i]=!0,this.deletedFeatureIds[i]=!0,this.draw.removeFeatures([i]),this.pushUndoStackEntry({id:i,toIndex:n,action:"single"}),this.emitStackChange($i),!0;if(n<=0){var p=c[0];return!!p&&(this.ignoreProgrammaticCreate[i]=!0,this.draw.addFeatures([p]),this.pushUndoStackEntry({id:i,toIndex:0,action:"single"}),this.emitStackChange($i),!0)}var g=o||c[n];return!!g&&(c.length===n?c.push(g):(c[n]=g,c.length=n+1),this.applySnapshotDuringReplay(i,g),this.pushUndoStackEntry({id:i,toIndex:n,action:"single"}),this.emitStackChange($i),!0)},e.clearHistory=function(){var t={};if(this.draw&&!this.isDrawing())for(var e,i=n(this.draw.getSnapshot());!(e=i()).done;){var o=e.value;t[String(o.id)]=[o]}this.historyById=t,this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[]},e.undoSize=function(){return this.undoStack.length},e.redoSize=function(){return this.redoStack.length},t}(),rn=/*#__PURE__*/function(){function t(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:function(){return!0}}var e=t.prototype;return e.emitStackHistoryChange=function(t){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:t.cause,stack:t.stack,undoSize:t.undoStackSize,redoSize:t.redoStackSize})},e.hasSessionUndo=function(){return Boolean(this.sessionLevel&&this.sessionLevel.canUndo())},e.hasSessionRedo=function(){return Boolean(this.sessionLevel&&this.sessionLevel.canRedo())},e.activeStackForUndo=function(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canUndo()?tn:this.hasSessionUndo()?en:null!=(e=this.modeLevel)&&e.canUndo()?tn:void 0},e.activeStackForRedo=function(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canRedo()?tn:this.hasSessionRedo()?en:null!=(e=this.modeLevel)&&e.canRedo()?tn:void 0},e.canUndo=function(){return void 0!==this.activeStackForUndo()},e.canRedo=function(){return void 0!==this.activeStackForRedo()},e.undo=function(){var t=this.activeStackForUndo();return!!t&&(t===tn?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())},e.redo=function(){var t=this.activeStackForRedo();return!!t&&(t===tn?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())},e.clearHistory=function(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()},e.emitHistoryPushForCompletedAction=function(){this.sessionLevel?this.emitStackHistoryChange({cause:Qi,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:en}):this.modeLevel&&this.emitStackHistoryChange({cause:Qi,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:tn})},t}(),sn=/*#__PURE__*/function(){function t(t){var e,i,n,r,s=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=t.adapter,this._instanceSelectModes=[];var a=null==t||null==(e=t.undoRedo)?void 0:e.modeLevel;a&&(this.drawingUndoRedo=a);var d=null==t||null==(i=t.undoRedo)?void 0:i.keyboardShortcuts;d&&(this.keyboardShortcutsMatcher=d),this.sessionUndoRedoEnabled=Boolean(null==t||null==(n=t.undoRedo)?void 0:n.sessionLevel);var u=null==t||null==(r=t.undoRedo)?void 0:r.sessionLevel;this._mode=new qe;var h=new Set,l=t.modes.reduce(function(t,e){if(h.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return h.add(e.mode),t[e.mode]=e,t},{}),c=Object.keys(l);if(0===c.length)throw new Error("No modes provided");c.forEach(function(t){l[t].type===S.Select&&s._instanceSelectModes.push(t)}),this._modes=o({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new gi({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var p=function(t){var e=[],i=s._store.copyAll().filter(function(i){return!t.includes(i.id)||(e.push(i),!1)});return{changed:e,unchanged:i}},g=function(t,e){var i;s._enabled&&(s._eventListeners.finish.forEach(function(i){i(t,e)}),null==(i=s.undoRedoCoordinator)||i.emitHistoryPushForCompletedAction())},y=function(t,e,i){if(s._enabled){s._eventListeners.change.forEach(function(n){n(t,e,i)}),s.emitDrawingPushIfHistoryChangedFromLastSnapshot();var n=p(t),o=n.changed,r=n.unchanged;"create"===e?s._adapter.render({created:o,deletedIds:[],unchanged:r,updated:[]},s.getModeStyles()):"update"===e?s._adapter.render({created:[],deletedIds:[],unchanged:r,updated:o},s.getModeStyles()):"delete"===e?s._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},s.getModeStyles()):"styling"===e&&s._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},s.getModeStyles())}},f=function(t){if(s._enabled){s._eventListeners.select.forEach(function(e){e(t)});var e=p([t]);s._adapter.render({created:[],deletedIds:[],unchanged:e.unchanged,updated:e.changed},s.getModeStyles())}},v=function(t){if(s._enabled){s._eventListeners.deselect.forEach(function(e){e(t)});var e=p([t]),i=e.changed;i&&s._adapter.render({created:[],deletedIds:[],unchanged:e.unchanged,updated:i},s.getModeStyles())}};Object.keys(this._modes).forEach(function(t){var e;s._modes[t].register({mode:t,store:s._store,setCursor:s._adapter.setCursor.bind(s._adapter),project:s._adapter.project.bind(s._adapter),unproject:s._adapter.unproject.bind(s._adapter),setDoubleClickToZoom:s._adapter.setDoubleClickToZoom.bind(s._adapter),onChange:y,onSelect:f,onDeselect:v,onFinish:g,coordinatePrecision:s._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:null==(e=s.drawingUndoRedo)||null==e.getMaxStackSize?void 0:e.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&u&&(this.sessionUndoRedo=u,u.register({draw:this,onHistoryChange:function(t){var e;null==(e=s.undoRedoCoordinator)||e.emitStackHistoryChange(t)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:function(){return s.getModeState()},getModeHistorySizes:function(){return s.getDrawingHistorySizes()},undoMode:function(){s._mode.undo&&s._mode.undo()},redoMode:function(){s._mode.redo&&s._mode.redo()},clearModeHistory:function(){var t=s._mode;t.clearHistory&&t.clearHistory()},onHistoryChange:function(t){var e;null==(e=s.undoRedoCoordinator)||e.emitStackHistoryChange(t)}}),this.undoRedoCoordinator=new rn({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:function(){return"drawing"===s.getModeState()},onHistoryChange:function(t){s._eventListeners.history.forEach(function(e){e(t)})},shouldEmitHistoryChange:function(){return s._enabled}})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.handleUndoRedoKeyboardShortcut=function(t){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled)return!1;if(!this.keyboardShortcutsMatcher)return!1;var e=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(t),i=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(t);if(e){if(!this.canUndo())return!1;var n=this.undo();return n&&t.preventDefault(),n}if(i){if(!this.canRedo())return!1;var o=this.redo();return o&&t.preventDefault(),o}return!1},e.getDrawingHistorySizes=function(){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}},e.emitDrawingPushIfHistoryChangedFromLastSnapshot=function(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()},e.emitDrawingPushIfHistoryChanged=function(t){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(t)},e.getModeStyles=function(){var t=this,e={},i=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(function(n){e[n]=function(e){return i&&e.properties[g.SELECTED]?t._modes[i].styleFeature.bind(t._modes[i])(e):t._modes[n].styleFeature.bind(t._modes[n])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,r=e&&void 0!==e.pointerDistance?e.pointerDistance:30,s=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,a=!(!e||void 0===e.ignoreCoordinatePoints)&&e.ignoreCoordinatePoints,d=!(!e||void 0===e.ignoreCurrentlyDrawing)&&e.ignoreCurrentlyDrawing,u=!(!e||void 0===e.ignoreClosingPoints)&&e.ignoreClosingPoints,h=!(!e||void 0===e.ignoreSnappingPoints)&&e.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),c=this._adapter.project.bind(this._adapter),p=c(i,o),f=Mt({unproject:l,point:p,pointerDistance:r});return this._store.search(f).filter(function(t){if(s&&(t.properties[g.MID_POINT]||t.properties[g.SELECTION_POINT]))return!1;if(a&&t.properties[y.COORDINATE_POINT])return!1;if(u&&t.properties[y.CLOSING_POINT])return!1;if(d&&t.properties[y.CURRENTLY_DRAWING])return!1;if(h&&t.properties[y.SNAPPING_POINT])return!1;if("Point"===t.geometry.type){var l=t.geometry.coordinates,f=c(l[0],l[1]);return wt(p,f)