UNPKG

terra-draw

Version:

Frictionless map drawing across mapping provider

1 lines 232 kB
function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function i(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(e,i){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,i){if(e){if("string"==typeof e)return t(e,i);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,i):void 0}}(e))||i&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=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<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o.apply(null,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}var d,u="draw",h="edit",l="deleteCoordinate",c="insertMidpoint";!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(d||(d={}));var p="https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png",g={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},f={MODE:"mode",CURRENTLY_DRAWING:"currentlyDrawing",EDITED:"edited",CLOSING_POINT:"closingPoint",SNAPPING_POINT:"snappingPoint",COORDINATE_POINT:"coordinatePoint",COORDINATE_POINT_FEATURE_ID:"coordinatePointFeatureId",COORDINATE_POINT_IDS:"coordinatePointIds",PROVISIONAL_COORDINATE_COUNT:"provisionalCoordinateCount",COMMITTED_COORDINATE_COUNT:"committedCoordinateCount",MARKER:"marker"},y=10;function v(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function m(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function C(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var P,I="Feature is not a Polygon",S="Feature mode property does not match the mode being added to";!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(P||(P={}));var F={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},x=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=F,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=P.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){null!=t&&t.styles&&(this.styles=o({},this._styles,t.styles)),null!=t&&t.pointerDistance&&(this.pointerDistance=t.pointerDistance),null!=t&&t.validation&&(this.validate=t&&t.validation),null!=t&&t.projection&&(this.projection=t.projection),void 0!==(null==t?void 0:t.pointerEvents)&&(this.pointerEvents=t.pointerEvents),null!=t&&t.modeName&&!0===this.isInitialUpdate&&(this.mode=t.modeName),this.isInitialUpdate=!1},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(v(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(v(t.geometry))if(v(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:S}:{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.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}}])}(),O=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=P.Select,e}return r(e,t),e}(x);function M(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,d=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371e3/1e3}var w=6371008.8;function E(t){return t%360*Math.PI/180}function D(t){return t/6371.0088}function k(t){return t%(2*Math.PI)*180/Math.PI}function b(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var _=57.29577951308232,N=.017453292519943295,T=6378137,R=function(t,e){return{x:0===t?0:t*N*T,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*N/2))*T}},W=function(t,e){return{lng:0===t?0:_*(t/T),lat:0===e?0:(2*Math.atan(Math.exp(e/T))-Math.PI/2)*_}};function U(t,e,i){var n=E(t[0]),o=E(t[1]),r=E(i),s=D(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[k(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),k(a)]}function L(t){for(var e=t.center,i=t.radiusKilometers,n=t.coordinatePrecision,o=t.steps?t.steps:64,r=[],s=0;s<o;s++){var a=U(e,i,-360*s/o);r.push([b(a[0],n),b(a[1],n)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function A(t){var e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var i=[],n=0;n<e.length;n++)for(var o=0;o<e[n].length-1;o++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)d(n,o,r,s);return i.length>0;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(B(t,i)||B(t,n)||B(e,i)||B(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 B(t,e){return t[0]===e[0]&&t[1]===e[1]}function z(t,e){return G(t[0])<=e&&G(t[1])<=e}function H(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 G(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var V="Feature has holes",j="Feature has less than 4 coordinates",K="Feature has invalid coordinates",Y="Feature coordinates are not closed";function X(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:V};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:j};for(var i=0;i<t.geometry.coordinates[0].length;i++){if(!H(t.geometry.coordinates[0][i]))return{valid:!1,reason:K};if(!z(t.geometry.coordinates[0][i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return(n=t.geometry.coordinates[0][0])[0]!==(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||n[1]!==o[1]?{valid:!1,reason:Y}:{valid:!0};var n,o}function q(t,e){var i=X(t,e);return i.valid?A(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var Z=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection,d=t.undoRedoMaxStackSize;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.undoRedoMaxStackSize=void 0,this.store=e,this.mode=i,this.project=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a,this.undoRedoMaxStackSize=d};function J(t){var e=function(t){for(var e=t.coordinates[0],i=0,n=0;n<e.length-1;n++){var o=e[n],r=e[n+1];i+=(r[0]-o[0])*(r[1]+o[1])}return i<0}(t);if(!e)return{type:"Polygon",coordinates:[t.coordinates[0].reverse()]}}var $="insert-before",Q="insert-after",tt="update",et="delete",it="replace",nt=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).options=void 0,n.options=i,n}r(e,t);var i=e.prototype;return i.createPoint=function(t){var e=t.coordinates,i=t.properties,n=t.context;if((null==n?void 0:n.updateType)!==d.Finish||this.validateGeometryWithUpdateType({geometry:{type:"Point",coordinates:e},properties:i,updateType:d.Finish}))return this.handleCreateFeature({geometry:{type:"Point",coordinates:e},properties:i})},i.createLineString=function(t){return this.handleCreateFeature({geometry:{type:"LineString",coordinates:t.coordinates},properties:t.properties})},i.createPolygon=function(t){var e=t.coordinates,i=t.properties,n=t.context,o=J({type:"Polygon",coordinates:[e]}),r={type:"Polygon",coordinates:o?o.coordinates:[e]};if((null==n?void 0:n.updateType)!==d.Finish||this.validateGeometryWithUpdateType({geometry:r,properties:i,updateType:d.Finish}))return this.handleCreateFeature({geometry:r,properties:i})},i.createGuidancePoint=function(t){return this.createGuidancePoints({coordinates:[t.coordinate],type:t.type})[0]},i.createGuidancePoints=function(t){var e=this,i=t.type,n=t.additionalProperties,r=t.coordinates.map(function(t,r){var s;return{type:"Feature",geometry:{type:"Point",coordinates:t},properties:o((s={mode:e.mode},s[i]=!0,s),n?n(r):{})}});return this.createFeatures(r)},i.updatePoint=function(t){return this.handleMutateFeature({type:"Point",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.updatePolygon=function(t){return this.handleMutateFeature({type:"Polygon",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.updateLineString=function(t){return this.handleMutateFeature({type:"LineString",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.deleteFeatureIfPresent=function(t){t&&this.store.has(t)&&this.store.delete([t])},i.deleteFeaturesIfPresent=function(t){var e=this;if(0!==t.length){var i=t.filter(function(t){return e.store.has(t)});i.length&&this.store.delete(i)}},i.setDeselected=function(t){var e=this,i=t.filter(function(t){return e.store.has(t)}).map(function(t){var e;return{featureId:t,properties:(e={},e[g.SELECTED]=!1,e)}});this.updateFeatureProperties(i)},i.setSelected=function(t){var e,i=this.store.getGeometryCopy(t).type,n={featureId:t,propertyMutations:(e={},e[g.SELECTED]=!0,e),context:{updateType:d.Commit}};"Polygon"===i?this.updatePolygon(n):"LineString"===i?this.updateLineString(n):"Point"===i&&this.updatePoint(n)},i.updateGuidancePoints=function(t){this.updateFeatureGeometries(t.map(function(t){return{id:t.featureId,geometry:{type:"Point",coordinates:t.coordinate}}}))},i.handleCreateFeature=function(t){return this.createFeatureWithGeometry({geometry:t.geometry,properties:t.properties})},i.handleMutateFeature=function(t){var e=t.featureId,i=t.coordinateMutations,n=t.context;if(!this.mutateFeature({type:t.type,featureId:e,coordinateMutations:i,propertyMutations:t.propertyMutations,context:n.updateType===d.Finish?o({},n,{correctRightHandRule:!0}):o({},n)}))return null;var r=this.buildFeatureWithGeometry(e);return n.updateType!==d.Finish||i||this.validateGeometryWithUpdateType({geometry:r.geometry,properties:r.properties,updateType:n.updateType})?r:null},i.mutateFeature=function(t){var e=t.type,i=t.featureId,n=t.coordinateMutations,o=t.propertyMutations,r=t.context;if(!i)return!1;var s=this.store.getGeometryCopy(i),a=this.store.getPropertiesCopy(i);if(s.type!==e)throw new Error(e+" geometries cannot be updated on features with "+s.type+" geometries");if(n){var d=this.applyCoordinateMutations(s,n);if(r.correctRightHandRule&&"Polygon"===d.type){var u=J(d);u&&(d=u)}if(!this.validateGeometryWithUpdateType({geometry:d,properties:a,updateType:r.updateType}))return!1;this.updateFeatureGeometries([{id:i,geometry:d}])}return o&&this.updateFeatureProperties([{featureId:i,properties:o}]),!0},i.applyCoordinateMutations=function(t,e){if(this.isReplaceMutation(e))return o({},t,{coordinates:e.coordinates});if("Point"===t.type)throw new Error("Coordinate mutations are not supported for Point geometries");for(var i,r="Polygon"===t.type,s=r?t.coordinates[0].slice():t.coordinates.slice(),a=s.length,d=function(t){var e=t<0?a+t:t;if(e<0||e>=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!==$&&g.type!==Q){var f=d(g.index);u[f]=o({},g,{index:f})}else{var y=g.index,v=y<0?a+y:y;if(v<0||v>a)throw new RangeError("Index "+g.index+" (normalized to "+v+") is out of bounds");if(g.type===$){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<a;C++){for(var P,I=n(h[C]);!(P=I()).done;)m.push(P.value.coordinate);var S=u[C];S?S.type===et||m.push(S.coordinate):m.push(s[C]);for(var F,x=n(l[C]);!(F=x()).done;)m.push(F.value.coordinate)}for(var O=0,M=c;O<M.length;O++)m.push(M[O].coordinate);return o({},t,r?{coordinates:[m].concat(t.coordinates.slice(1))}:{coordinates:m})},i.isReplaceMutation=function(t){return t.type===it},i.createFeatureWithGeometry=function(t){var e=this.createFeatures([{type:"Feature",geometry:t.geometry,properties:t.properties}])[0];return{id:e,type:"Feature",properties:this.store.getPropertiesCopy(e),geometry:this.store.getGeometryCopy(e)}},i.validateGeometryWithUpdateType=function(t){return!this.options.validate||this.options.validate({type:"Feature",geometry:t.geometry,properties:t.properties||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:t.updateType}).valid},i.buildFeatureWithGeometry=function(t){return{id:t,type:"Feature",properties:this.store.getPropertiesCopy(t),geometry:this.store.getGeometryCopy(t)}},i.createFeatures=function(t){return this.store.create(t)},i.updateFeatureGeometries=function(t){this.store.updateGeometry(t)},i.updateFeatureProperties=function(t){var e=t.map(function(t){var e=t.featureId;return Object.entries(t.properties).map(function(t){return{id:e,property:t[0],value:t[1]}})}).flat();this.store.updateProperty(e)},e}(Z),ot={cancel:"Escape",finish:"Enter"},rt={start:"crosshair"},st=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="circle",i.center=void 0,i.endPosition=void 0,i.segments=64,i.currentCircleId=void 0,i.keyEvents=ot,i.cursors=rt,i.startingRadiusKilometers=1e-5,i.cursorMovedAfterInitialCursorDown=!1,i.drawInteraction="click-move",i.drawType=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction),null!=e&&e.segments&&(this.segments=e.segments<3?3:e.segments)},i.close=function(){if(void 0!==this.currentCircleId&&void 0!==this.endPosition&&this.updateCircle(this.endPosition,d.Finish)){var t=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:u})}},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click"),this.center=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];var n=L({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.mutateFeature.createPolygon({coordinates:n.geometry.coordinates[0],properties:(i={mode:this.mode,radiusKilometers:this.startingRadiusKilometers},i[f.CURRENTLY_DRAWING]=!0,i)});o&&(this.currentCircleId=o.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=e,this.setDrawing())},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.moveDrawAllowed=function(){return"click-move"===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("unset")},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.center?this.center&&void 0!==this.currentCircleId&&(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(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.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(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.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),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,lineStringDash:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.updateCircle=function(t,e){if(void 0!==this.currentCircleId&&void 0!==this.center){var i,n,o=e===d.Finish;if(this.cursorMovedAfterInitialCursorDown)if(n=M(this.center,t),"web-mercator"===this.projection){var r=function(t,e){var i=1e3*M(t,e);if(0===i)return 1;var n=R(t[0],t[1]),o=n.x,r=n.y,s=R(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-o,2)+Math.pow(a-r,2))/i}(this.center,t);i=function(t){for(var e=t.center,i=t.coordinatePrecision,n=t.steps?t.steps:64,o=1e3*t.radiusKilometers,r=R(e[0],e[1]),s=r.x,a=r.y,d=[],u=0;u<n;u++){var h=360*u/n*Math.PI/180,l=o*Math.cos(h),c=o*Math.sin(h),p=W(s+l,a+c),g=p.lat;d.push([b(p.lng,i),b(g,i)])}return d.push(d[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[d]},properties:{}}}({center:this.center,radiusKilometers:n*r,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}else{if("globe"!==this.projection)throw new Error("Invalid projection");i=L({center:this.center,radiusKilometers:n,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}var s={};return i&&n&&(s.radiusKilometers=n),o&&(s[f.CURRENTLY_DRAWING]=void 0),this.mutateFeature.updatePolygon({featureId:this.currentCircleId,coordinateMutations:i?{type:it,coordinates:i.geometry.coordinates}:void 0,propertyMutations:s,context:o?{updateType:e,action:u}:{updateType:e}})}},i.afterFeatureUpdated=function(t){this.currentCircleId===t.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),at=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)};function dt(t,e){return t[0]===e[0]&&t[1]===e[1]}var ut=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}r(e,t);var i=e.prototype;return i.getGeometryType=function(t){return this.store.getGeometryCopy(t).type},i.coordinateAtIndexIsIdentical=function(t){var e,i=t.newCoordinate,n=t.index,o=this.store.getGeometryCopy(t.featureId);if("Polygon"===o.type)e=o.coordinates[0][n];else if("LineString"===o.type)e=o.coordinates[n];else{if(0!==n)throw new Error("Point geometries only have one coordinate at index 0");e=o.coordinates}return dt(i,e)},i.getGeometry=function(t){return this.store.getGeometryCopy(t)},i.getCoordinates=function(t){var e=this.store.getGeometryCopy(t),i=e.coordinates;return"Polygon"===e.type?i[0]:i},i.getCoordinate=function(t,e){var i=this.getCoordinates(t),n=e<0?i.length+e:e;if(n<0||n>=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}(Z),ht={cancel:"Escape",finish:"Enter"},lt={start:"crosshair",close:"pointer"},ct=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand",i.canClose=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=20,i.keyEvents=ht,i.cursors=lt,i.preventPointsNearClose=!0,i.autoClose=!1,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1,i.drawInteraction="click-move",i.drawType=void 0,i.smoothing=0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.minDistance&&(this.minDistance=e.minDistance),void 0!==(null==e?void 0:e.smoothing)&&(this.smoothing=Math.min(Math.max(e.smoothing,0),.999)),void 0!==(null==e?void 0:e.preventPointsNearClose)&&(this.preventPointsNearClose=e.preventPointsNearClose),void 0!==(null==e?void 0:e.autoClose)&&(this.autoClose=e.autoClose),null!=e&&e.autoCloseTimeout&&(this.autoCloseTimeout=e.autoCloseTimeout),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)},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.beginDrawing=function(t,e){var i;void 0===e&&(e="click");var n=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i)});this.currentId=n.id,this.drawType=e,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[t.lng,t.lat],type:f.CLOSING_POINT}),this.canClose=!0,"drawing"!==this.state&&this.setDrawing()},i.addCoordinate=function(t){var e=this;if(void 0!==this.currentId&&!1!==this.canClose){var i=this.readFeature.getCoordinate(this.currentId,-2),n=i[0],o=i[1],r=this.project(n,o),s=at({x:r.x,y:r.y},{x:t.containerX,y:t.containerY}),a=this.readFeature.getCoordinate(this.currentId,0),u=this.project(a[0],a[1]);if(at({x:u.x,y:u.y},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(function(){e.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(!(s<this.minDistance)){var h=this.getSmoothedCoordinate([n,o],[t.lng,t.lat]);this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:$,index:-1,coordinate:h}],context:{updateType:d.Provisional}})}}else this.setCursor(this.cursors.start)},i.getSmoothedCoordinate=function(t,e){return 0===this.smoothing?e:[t[0]*this.smoothing+e[0]*(1-this.smoothing),t[1]*this.smoothing+e[1]*(1-this.smoothing)]},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.moveDrawAllowed()&&"click"===this.drawType&&this.addCoordinate(t)},i.onClick=function(t){if(this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))){if(this.preventNewFeature)return;if(!1===this.canClose)return void this.beginDrawing(t);this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&(this.preventNewFeature||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.addCoordinate(t)},i.onDragEnd=function(t,e){var i=this;this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.preventNewFeature=!0,setTimeout(function(){i.preventNewFeature=!1},this.autoCloseTimeout),this.close(),e(!0))},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e)},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,lineStringDash:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.zIndex=50,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return X(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x);function pt(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 gt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.create=function(t){return pt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(Z),ft=/*#__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 at({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(Z),yt=/*#__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.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)}).coordinate},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)}).coordinate},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.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,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(n,o){var s=i.pixelDistance.measure(t,n);s<r.minDist&&s<i.pointerDistance&&(r.coordinate=n,r.minDist=s,r.featureId=e.id,r.featureCoordinateIndex=o)})}),r},e}(Z);function vt(t,e,i){var n=E(t[0]),o=E(t[1]),r=E(i),s=D(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[k(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),k(a)]}function mt(t,e,i){var n=t.x,o=t.y,r=E(i);return{x:n+e*Math.cos(r),y:o+e*Math.sin(r)}}function Ct(t,e){var i=E(t[0]),n=E(e[0]),o=E(t[1]),r=E(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return k(Math.atan2(s,a))}function Pt(t,e){var i=e.x-t.x,n=e.y-t.y;if(0===i&&0===n)return 0;var o=Math.atan2(n,i);return(o*=180/Math.PI)>180?o-=360:o<-180&&(o+=360),o}function It(t){return(t+360)%360}function St(t,e,i){for(var n,o,r,s=[],a=t.length,d=0,u=0;u<t.length&&!(e>=d&&u===t.length-1);u++){if(d>e&&0===s.length){if(!(n=e-d))return s.push(t[u]),s;o=Ct(t[u],t[u-1])-180,r=vt(t[u],n,o),s.push(r)}if(d>=i)return(n=i-d)?(o=Ct(t[u],t[u-1])-180,r=vt(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+=M(t[u],t[u+1])}if(d<e&&t.length===a)throw new Error("Start position is beyond line");var h=t[t.length-1];return[h,h]}function Ft(t){return t*(Math.PI/180)}function xt(t){return t*(180/Math.PI)}var Ot=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}r(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var n=[t,e],o=0,r=0;r<n.length-1;r++)o+=M(n[0],n[1]);if(o<=i)return n;var s=o/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],d=0;d<s;d++){var u=St(n,i*d,i*(d+1));a.push(u)}for(var h=[],l=0;l<a.length;l++)h.push(a[l][1]);return this.limitCoordinates(h)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var n=M(t,e),o=function(t,e,i){var n=[],o=Ft(t[1]),r=Ft(t[0]),s=Ft(e[1]),a=Ft(e[0]);i+=1;var d=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-o)/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===d||isNaN(d))return n;for(var u=0;u<=i;u++){var h=u/i,l=Math.sin((1-h)*d)/Math.sin(d),c=Math.sin(h*d)/Math.sin(d),p=l*Math.cos(o)*Math.cos(r)+c*Math.cos(s)*Math.cos(a),g=l*Math.cos(o)*Math.sin(r)+c*Math.cos(s)*Math.sin(a),f=l*Math.sin(o)+c*Math.sin(s);if(!(isNaN(p)||isNaN(g)||isNaN(f))){var y=Math.atan2(f,Math.sqrt(Math.pow(p,2)+Math.pow(g,2))),v=Math.atan2(g,p);isNaN(y)||isNaN(v)||n.push([xt(v),xt(y)])}}return n.slice(1,-1)}(t,e,Math.floor(n/i));return this.limitCoordinates(o)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[b(t[0],e.config.coordinatePrecision),b(t[1],e.config.coordinatePrecision)]})},e}(Z);function Mt(t,e){if("LineString"!==t.geometry.type)return{valid:!1,reason:"Feature is not a LineString"};if(t.geometry.coordinates.length<2)return{valid:!1,reason:"Feature has less than 2 coordinates"};for(var i=0;i<t.geometry.coordinates.length;i++){if(!H(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!z(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function wt(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function Et(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(wt(t)*wt(e));return Math.acos(Math.min(Math.max(i,-1),1))}function Dt(t){var e=E(t[1]),i=E(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function kt(t){var e=t[0],i=t[1],n=k(Math.asin(t[2]));return[k(Math.atan2(i,e)),n]}var bt=/*#__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.getSnappableCoordinateFirstClick=function(t){var e=o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)});return e.coordinate?[b(e.coordinate[0],o.config.coordinatePrecision),b(e.coordinate[1],o.config.coordinatePrecision)]:void 0},o.getSnappableCoordinate=function(t,e){var i=o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)});return i.coordinate?[b(i.coordinate[0],o.config.coordinatePrecision),b(i.coordinate[1],o.config.coordinatePrecision)]:void 0},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,o=this.clickBoundingBox.create(t),r=this.store.search(o,e),s={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:Infinity};return r.forEach(function(e){var o;if("Polygon"===e.geometry.type)o=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;o=e.geometry.coordinates}for(var r,a=[],d=0;d<o.length-1;d++)a.push([o[d],o[d+1]]);var u=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,o,r,s,a,d,u,h,l=[Infinity,Infinity],c=Infinity,p=0,g=n(e);!(i=g()).done;){var f=i.value,y=f[0],v=f[1],m=void 0,C=Infinity,P=R(y[0],y[1]),I=R(v[0],v[1]),S=R(t[0],t[1]);if(y[0]===t[0]&&y[1]===t[1])m=y;else if(v[0]===t[0]&&v[1]===t[1])m=v;else{var F=(u=(d={x:(s=S).x-(o=P).x,y:s.y-o.y}).x*(a={x:(r=I).x-o.x,y:r.y-o.y}).x+d.y*a.y,h=Math.max(0,Math.min(1,u/(a.x*a.x+a.y*a.y))),{x:o.x+h*a.x,y:o.y+h*a.y}),x=W(F.x,F.y);m=[x.lng,x.lat]}m&&(C=at(S,R(m[0],m[1])))<c&&(l=m,c=C,p=e.indexOf(f))}return Infinity===c?void 0:{coordinate:l,lineIndex:p,distance:c}}(u,a):"globe"===i.config.projection&&(r=function(t,e){for(var i,o=[Infinity,Infinity],r=Infinity,s=0,a=n(e);!(i=a()).done;){var d,u=i.value,h=u[0],l=u[1],c=Infinity;(d=h[0]===t[0]&&h[1]===t[1]?h:l[0]===t[0]&&l[1]===t[1]?l:(p=h,g=l,f=t,O=Dt(p),w=Dt(g),E=Dt(f),D=E[0],k=E[1],b=E[2],_=[(C=(y=O)[1])*(F=(v=w)[2])-(P=y[2])*(S=v[1]),P*(I=v[0])-(m=y[0])*F,m*S-C*I],N=_[0],T=_[1],R=_[2],W=T*b-R*k,U=R*D-N*b,L=N*k-T*D,A=L*T-U*R,B=W*R-L*N,z=U*N-W*T,H=1/Math.sqrt(Math.pow(A,2)+Math.pow(B,2)+Math.pow(z,2)),G=[A*H,B*H,z*H],V=[-1*A*H,-1*B*H,-1*z*H],j=Et(O,w),K=Et(O,G),Y=Et(w,G),X=Et(O,V),q=Et(w,V),Et(O,x=K<X&&K<q||Y<X&&Y<q?G:V)>j||Et(w,x)>j?M(kt(x),kt(O))<=M(kt(x),kt(w))?[kt(O),!0,!1]:[kt(w),!1,!0]:[kt(x),!1,!1])[0])&&(c=M(t,d))<r&&(o=d,r=c,s=e.indexOf(u))}var p,g,f,y,v,m,C,P,I,S,F,x,O,w,E,D,k,b,_,N,T,R,W,U,L,A,B,z,H,G,V,j,K,Y,X,q;return Infinity===r?void 0:{coordinate:o,distance:r,lineIndex:s}}(u,a)),r){var h=i.pixelDistance.measure(t,r.coordinate);h<s.minDistance&&h<i.pointerDistance&&(s.featureId=e.id,s.coordinate=[b(r.coordinate[0],i.config.coordinatePrecision),b(r.coordinate[1],i.config.coordinatePrecision)],s.featureCoordinateIndex=r.lineIndex,s.minDistance=h)}}),s},e}(Z);function _t(t){return Array.isArray(t)&&t.length>0&&Array.isArray(t[0])&&Array.isArray(t[0][0])}var Nt=function(t){return _t(t)?t[0].slice(0,-1):t},Tt=function(t){return _t(t)?t[0]:t},Rt=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.mutateFeatureBehavior=void 0,r.readFeatureBehavior=void 0,r._startEndPoints=[],r.config=e,r.pixelDistance=i,r.mutateFeatureBehavior=n,r.readFeatureBehavior=o,r}r(e,t);var n=e.prototype;return n.create=function(t){if(this.ids.length)throw new Error("Opening and closing points already created");var e=_t(t),i=Tt(t);if(e){if(i.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[i[0],i[i.length-2]],type:f.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:i[i.length-2],type:f.CLOSING_POINT})]},n.delete=function(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])},n.updateOne=function(t,e){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[t],coordinate:e}])},n.update=function(t){var e=Tt(t);1!==this.ids.length?2===this.ids.length&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[0]},{featureId:this.ids[1],coordinate:e[e.length-3]}]):this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[e.length-2]}])},n.isLineStringClosingPoint=function(t){if(1!==this.ids.length)return{isClosing:!1};var e=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(t,e.coordinates)<this.pointerDistance}},n.isPolygonClosingPoints=function(t){if(2!==this.ids.length)return{isClosing:!1,isPreviousClosing:!1};var e=this.readFeatureBehavior.getGeometry(this.ids[0]),i=this.readFeatureBehavior.getGeometry(this.ids[1]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},i(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(Z),Wt=/*#__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.createOrUpdate=function(t){var e=this,i=t.featureId,n=t.featureCoordinates;if(this.readFeature.hasFeature(i)){var o=Nt(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)}}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=Nt(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){return this.mutateFeature.createGuidancePoints({coordinates:t,type:f.COORDINATE_POINT,additionalProperties:function(t){var n;return(n={mode:e})[f.COORDINATE_POINT]=!0,n[f.COORDINATE_POINT_FEATURE_ID]=i,n.index=t,n}})},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[f.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[f.COORDINATE_POINT_FEATURE_ID]===t});this.mutateFeature.deleteFeaturesIfPresent(e)},e}(Z),Ut=/*#__PURE__*/function(){function t(t){var e=this;this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=function(t){return e.cloneRecursively(t)};var i=null==t?void 0:t.maxStackSize;this.maxStackSize=void 0!==i&&Number.isFinite(i)?Math.max(0,Math.floor(i)):Number.POSITIVE_INFINITY}var e=t.prototype;return e.setMaxStackSize=function(t){Number.isFinite(t)?(this.maxStackSize=Math.max(0,Math.floor(t)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=Number.POSITIVE_INFINITY},e.trimHistoryToMax=function(t){if(Number.isFinite(this.maxStackSize))for(;t.length>this.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}(),Lt={cancel:"Escape",finish:"Enter"},At={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Bt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Lt,i.snapping=void 0,i.cursors=At,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommittedCoordinates=void 0,i.snappedPointId=void 0,i.lastMouseMoveEvent=void 0,i.showCoordinatePoints=!1,i.finishOnNthCoordinate=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.coordinateSnapping=void 0,i.insertPoint=voi