UNPKG

terra-draw

Version:

Frictionless map drawing across mapping provider

1 lines 147 kB
function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,o=Array(e);i<e;i++)o[i]=t[i];return o}function e(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function i(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(e,i){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return(o=o.call(e)).next.bind(o);if(Array.isArray(e)||(o=function(e,i){if(e){if("string"==typeof e)return t(e,i);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?t(e,i):void 0}}(e))||i&&e&&"number"==typeof e.length){o&&(e=o);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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 n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)({}).hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},n.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;!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(d||(d={}));var l={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},c="edited",h="closingPoint",u="snappingPoint",p="coordinatePoint",g="coordinatePointIds",f=10;function y(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function v(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function m(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var C,P="Feature is not a Polygon",I="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"}(C||(C={}));var x={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},M=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=x,this.behaviors=[],this.validate=void 0,this.pointerDistance=40,this.coordinatePrecision=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.type=C.Drawing,this.mode="base",e||this.updateOptions(t)}var e=t.prototype;return e.registerBehaviors=function(t){},e.updateOptions=function(t){null!=t&&t.styles&&(this.styles=n({},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)},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.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:t.coordinatePrecision,projection:this.projection})},e.validateFeature=function(t){return this.performFeatureValidation(t)},e.afterFeatureAdded=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(y(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(y(t.geometry))if(y(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(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:I}:{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.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.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?t(i):t},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}}])}(),S=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,o=new Array(i),n=0;n<i;n++)o[n]=arguments[n];return(e=t.call.apply(t,[this].concat(o))||this).type=C.Select,e}return r(e,t),e}(M);function E(t,e){var i=function(t){return t*Math.PI/180},o=i(t[1]),n=i(t[0]),r=i(e[1]),s=r-o,a=i(e[0])-n,d=Math.sin(s/2)*Math.sin(s/2)+Math.cos(o)*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 F=6371008.8;function w(t){return t%360*Math.PI/180}function b(t){return t/6371.0088}function D(t){return t%(2*Math.PI)*180/Math.PI}function k(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var O=57.29577951308232,_=.017453292519943295,j=6378137,B=function(t,e){return{x:0===t?0:t*_*j,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*_/2))*j}},W=function(t,e){return{lng:0===t?0:O*(t/j),lat:0===e?0:(2*Math.atan(Math.exp(e/j))-Math.PI/2)*O}};function G(t,e,i){var o=w(t[0]),n=w(t[1]),r=w(i),s=b(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[D(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),D(a)]}function N(t){for(var e=t.center,i=t.radiusKilometers,o=t.coordinatePrecision,n=t.steps?t.steps:64,r=[],s=0;s<n;s++){var a=G(e,i,-360*s/n);r.push([k(a[0],o),k(a[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function L(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=[],o=0;o<e.length;o++)for(var n=0;n<e[o].length-1;n++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)d(o,n,r,s);return i.length>0;function a(t){return t<0||t>1}function d(t,o,n,r){var s,d=e[t][o],l=e[t][o+1],c=e[n][r],h=e[n][r+1],u=function(t,e,i,o){if(T(t,i)||T(t,o)||T(e,i)||T(o,i))return null;var n=t[0],r=t[1],s=e[0],a=e[1],d=i[0],l=i[1],c=o[0],h=o[1],u=(n-s)*(l-h)-(r-a)*(d-c);return 0===u?null:[((n*a-r*s)*(d-c)-(n-s)*(d*h-l*c))/u,((n*a-r*s)*(l-h)-(r-a)*(d*h-l*c))/u]}(d,l,c,h);null!==u&&(s=h[0]!==c[0]?(u[0]-c[0])/(h[0]-c[0]):(u[1]-c[1])/(h[1]-c[1]),a(l[0]!==d[0]?(u[0]-d[0])/(l[0]-d[0]):(u[1]-d[1])/(l[1]-d[1]))||a(s)||(u.toString(),i.push(u)))}}function T(t,e){return t[0]===e[0]&&t[1]===e[1]}function V(t,e){return A(t[0])<=e&&A(t[1])<=e}function U(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 A(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var R="Feature has holes",K="Feature has less than 4 coordinates",z="Feature has invalid coordinates",X="Feature coordinates are not closed";function Y(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:R};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:K};for(var i=0;i<t.geometry.coordinates[0].length;i++){if(!U(t.geometry.coordinates[0][i]))return{valid:!1,reason:z};if(!V(t.geometry.coordinates[0][i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return(o=t.geometry.coordinates[0][0])[0]!==(n=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||o[1]!==n[1]?{valid:!1,reason:X}:{valid:!0};var o,n}function H(t,e){var i=Y(t,e);return i.valid?L(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var q={cancel:"Escape",finish:"Enter"},Z={start:"crosshair"},J=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="circle",i.center=void 0,i.clickCount=0,i.currentCircleId=void 0,i.keyEvents=q,i.cursors=Z,i.startingRadiusKilometers=1e-5,i.cursorMovedAfterInitialCursorDown=!1,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=n({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=n({},this.keyEvents,e.keyEvents)),null!=e&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers)},i.close=function(){if(void 0!==this.currentCircleId){var t=this.currentCircleId;if(this.validate&&t){var e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Finish}).valid)return}this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},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(0===this.clickCount){this.center=[t.lng,t.lat];var e=N({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=i[0],this.clickCount++,this.cursorMovedAfterInitialCursorDown=!1,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.cursorMovedAfterInitialCursorDown&&this.updateCircle(t),this.close()},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.updateCircle(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(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t])}catch(t){}},i.styleFeature=function(t){var e=n({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=f,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return H(t,e.coordinatePrecision)})},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=E(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var o=function(t,e){var i=1e3*E(t,e);if(0===i)return 1;var o=B(t[0],t[1]),n=o.x,r=o.y,s=B(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-n,2)+Math.pow(a-r,2))/i}(this.center,[t.lng,t.lat]);e=function(t){for(var e=t.center,i=t.coordinatePrecision,o=t.steps?t.steps:64,n=1e3*t.radiusKilometers,r=B(e[0],e[1]),s=r.x,a=r.y,d=[],l=0;l<o;l++){var c=360*l/o*Math.PI/180,h=n*Math.cos(c),u=n*Math.sin(c),p=W(s+h,a+u),g=p.lat;d.push([k(p.lng,i),k(g,i)])}return d.push(d[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[d]},properties:{}}}({center:this.center,radiusKilometers:i*o,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");e=N({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision})}if(this.validate&&!this.validate({type:"Feature",id:this.currentCircleId,geometry:e.geometry,properties:{radiusKilometers:i}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},e}(M),$=function(t,e){var i=e.x-t.x,o=e.y-t.y;return Math.sqrt(o*o+i*i)};function Q(t){var e=function(t){for(var e=t.coordinates[0],i=0,o=0;o<e.length-1;o++){var n=e[o],r=e[o+1];i+=(r[0]-n[0])*(r[1]+n[1])}return i<0}(t);if(!e)return{type:"Polygon",coordinates:[t.coordinates[0].reverse()]}}var tt={cancel:"Escape",finish:"Enter"},et={start:"crosshair",close:"pointer"},it=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand",i.startingClick=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=20,i.keyEvents=tt,i.cursors=et,i.preventPointsNearClose=!0,i.autoClose=!1,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1,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.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=n({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=n({},this.cursors,e.cursors))},i.close=function(){if(void 0!==this.currentId){if(this.currentId){var t=Q(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}])}var e=this.currentId;if(this.validate&&e){var i=this.store.getGeometryCopy(e);if(!this.validate({type:"Feature",id:e,geometry:i,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Finish}).valid)return}this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){var e=this;if(void 0!==this.currentId&&!1!==this.startingClick){var i=this.store.getGeometryCopy(this.currentId),o=i.coordinates[0][i.coordinates[0].length-2],n=this.project(o[0],o[1]),r=$({x:n.x,y:n.y},{x:t.containerX,y:t.containerY}),s=i.coordinates[0][0],a=this.project(s[0],s[1]);if($({x:a.x,y:a.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(!(r<this.minDistance)){i.coordinates[0].pop();var l={type:"Polygon",coordinates:[[].concat(i.coordinates[0],[[t.lng,t.lat],i.coordinates[0][0]])]};if(this.validate&&!this.validate({type:"Feature",id:this.currentId,geometry:l,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:l}])}}},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.preventNewFeature)return;if(!1===this.startingClick){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(e={mode:this.mode},e[h]=!0,e)}]),o=i[1];return this.currentId=i[0],this.closingPointId=o,this.startingClick=!0,void this.setDrawing()}this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.startingClick&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==e&&this.store.delete([e])}catch(t){}},i.styleFeature=function(t){var e=n({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=f,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.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=50,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Y(t,e.coordinatePrecision)})},e}(M),ot=function(t){var e=t.store,i=t.mode,o=t.project,n=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection;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.store=e,this.mode=i,this.project=o,this.unproject=n,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a};function nt(t){var e=t.unproject,i=t.point,o=t.pointerDistance/2,n=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(n-o,r-o),e(n+o,r-o),e(n+o,r+o),e(n-o,r+o),e(n-o,r-o)].map(function(t){return[t.lng,t.lat]})]}}}var rt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.create=function(t){return nt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(ot),st=/*#__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 $({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(ot),at=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.getSnappableCoordinateFirstClick=function(t){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)}).coordinate},n.getSnappableCoordinate=function(t,e){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)}).coordinate},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,o=this.clickBoundingBox.create(t),n=this.store.search(o,e),r={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDist:Infinity};return n.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}o.forEach(function(o,n){var s=i.pixelDistance.measure(t,o);s<r.minDist&&s<i.pointerDistance&&(r.coordinate=o,r.minDist=s,r.featureId=e.id,r.featureCoordinateIndex=n)})}),r},e}(ot);function dt(t,e,i){var o=w(t[0]),n=w(t[1]),r=w(i),s=b(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[D(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),D(a)]}function lt(t,e,i){var o=t.x,n=t.y,r=w(i);return{x:o+e*Math.cos(r),y:n+e*Math.sin(r)}}function ct(t,e){var i=w(t[0]),o=w(e[0]),n=w(t[1]),r=w(e[1]),s=Math.sin(o-i)*Math.cos(r),a=Math.cos(n)*Math.sin(r)-Math.sin(n)*Math.cos(r)*Math.cos(o-i);return D(Math.atan2(s,a))}function ht(t,e){var i=e.x-t.x,o=e.y-t.y;if(0===i&&0===o)return 0;var n=Math.atan2(o,i);return(n*=180/Math.PI)>180?n-=360:n<-180&&(n+=360),n}function ut(t){return(t+360)%360}function pt(t,e,i){for(var o,n,r,s=[],a=t.length,d=0,l=0;l<t.length&&!(e>=d&&l===t.length-1);l++){if(d>e&&0===s.length){if(!(o=e-d))return s.push(t[l]),s;n=ct(t[l],t[l-1])-180,r=dt(t[l],o,n),s.push(r)}if(d>=i)return(o=i-d)?(n=ct(t[l],t[l-1])-180,r=dt(t[l],o,n),s.push(r),s):(s.push(t[l]),s);if(d>=e&&s.push(t[l]),l===t.length-1)return s;d+=E(t[l],t[l+1])}if(d<e&&t.length===a)throw new Error("Start position is beyond line");var c=t[t.length-1];return[c,c]}function gt(t){return t*(Math.PI/180)}function ft(t){return t*(180/Math.PI)}var yt=/*#__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 o=[t,e],n=0,r=0;r<o.length-1;r++)n+=E(o[0],o[1]);if(n<=i)return o;var s=n/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],d=0;d<s;d++){var l=pt(o,i*d,i*(d+1));a.push(l)}for(var c=[],h=0;h<a.length;h++)c.push(a[h][1]);return this.limitCoordinates(c)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var o=E(t,e),n=function(t,e,i){var o=[],n=gt(t[1]),r=gt(t[0]),s=gt(e[1]),a=gt(e[0]);i+=1;var d=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-n)/2),2)+Math.cos(n)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===d||isNaN(d))return o;for(var l=0;l<=i;l++){var c=l/i,h=Math.sin((1-c)*d)/Math.sin(d),u=Math.sin(c*d)/Math.sin(d),p=h*Math.cos(n)*Math.cos(r)+u*Math.cos(s)*Math.cos(a),g=h*Math.cos(n)*Math.sin(r)+u*Math.cos(s)*Math.sin(a),f=h*Math.sin(n)+u*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)||o.push([ft(v),ft(y)])}}return o.slice(1,-1)}(t,e,Math.floor(o/i));return this.limitCoordinates(n)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[k(t[0],e.config.coordinatePrecision),k(t[1],e.config.coordinatePrecision)]})},e}(ot);function vt(t,e){return t[0]===e[0]&&t[1]===e[1]}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(!U(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!V(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function Ct(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function Pt(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(Ct(t)*Ct(e));return Math.acos(Math.min(Math.max(i,-1),1))}function It(t){var e=w(t[1]),i=w(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function xt(t){var e=t[0],i=t[1],o=D(Math.asin(t[2]));return[D(Math.atan2(i,e)),o]}var Mt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.getSnappableCoordinateFirstClick=function(t){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)}).coordinate},n.getSnappableCoordinate=function(t,e){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)}).coordinate},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),r=this.store.search(n,e),s={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:Infinity};return r.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}for(var r,a=[],d=0;d<n.length-1;d++)a.push([n[d],n[d+1]]);var l=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,n,r,s,a,d,l,c,h=[Infinity,Infinity],u=Infinity,p=0,g=o(e);!(i=g()).done;){var f=i.value,y=f[0],v=f[1],m=void 0,C=Infinity,P=B(y[0],y[1]),I=B(v[0],v[1]),x=B(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 M=(l=(d={x:(s=x).x-(n=P).x,y:s.y-n.y}).x*(a={x:(r=I).x-n.x,y:r.y-n.y}).x+d.y*a.y,c=Math.max(0,Math.min(1,l/(a.x*a.x+a.y*a.y))),{x:n.x+c*a.x,y:n.y+c*a.y}),S=W(M.x,M.y);m=[S.lng,S.lat]}m&&(C=$(x,B(m[0],m[1])))<u&&(h=m,u=C,p=e.indexOf(f))}return Infinity===u?void 0:{coordinate:h,lineIndex:p,distance:u}}(l,a):"globe"===i.config.projection&&(r=function(t,e){for(var i,n=[Infinity,Infinity],r=Infinity,s=0,a=o(e);!(i=a()).done;){var d,l=i.value,c=l[0],h=l[1],u=Infinity;(d=c[0]===t[0]&&c[1]===t[1]?c:h[0]===t[0]&&h[1]===t[1]?h:(p=c,g=h,f=t,F=It(p),w=It(g),b=It(f),D=b[0],k=b[1],O=b[2],_=[(C=(y=F)[1])*(M=(v=w)[2])-(P=y[2])*(x=v[1]),P*(I=v[0])-(m=y[0])*M,m*x-C*I],j=_[0],B=_[1],W=_[2],G=B*O-W*k,N=W*D-j*O,L=j*k-B*D,T=L*B-N*W,V=G*W-L*j,U=N*j-G*B,A=1/Math.sqrt(Math.pow(T,2)+Math.pow(V,2)+Math.pow(U,2)),R=[T*A,V*A,U*A],K=[-1*T*A,-1*V*A,-1*U*A],z=Pt(F,w),X=Pt(F,R),Y=Pt(w,R),H=Pt(F,K),q=Pt(w,K),Pt(F,S=X<H&&X<q||Y<H&&Y<q?R:K)>z||Pt(w,S)>z?E(xt(S),xt(F))<=E(xt(S),xt(w))?[xt(F),!0,!1]:[xt(w),!1,!0]:[xt(S),!1,!1])[0])&&(u=E(t,d))<r&&(n=d,r=u,s=e.indexOf(l))}var p,g,f,y,v,m,C,P,I,x,M,S,F,w,b,D,k,O,_,j,B,W,G,N,L,T,V,U,A,R,K,z,X,Y,H,q;return Infinity===r?void 0:{coordinate:n,distance:r,lineIndex:s}}(l,a)),r){var c=i.pixelDistance.measure(t,r.coordinate);c<s.minDistance&&c<i.pointerDistance&&(s.featureId=e.id,s.coordinate=r.coordinate,s.featureCoordinateIndex=r.lineIndex,s.minDistance=c)}}),s},e}(ot),St={cancel:"Escape",finish:"Enter"},Et={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Ft=/*#__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.closingPointId=void 0,i.keyEvents=St,i.snapping=void 0,i.cursors=Et,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommitedCoordinates=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.coordinateSnapping=void 0,i.insertPoint=void 0,i.lineSnapping=void 0,i.pixelDistance=void 0,i.clickBoundingBox=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=n({},this.cursors,e.cursors)),null!=e&&e.snapping&&(this.snapping=e.snapping),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=n({},this.keyEvents,e.keyEvents)),null!=e&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable)},i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.updateGeometries([].concat(t.coordinates),void 0,d.Commit);var e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.snappedPointId=void 0,this.lastCommitedCoordinates=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}},i.updateGeometries=function(t,e,i){if(this.currentId){var o={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid)return;var n=[{id:this.currentId,geometry:o}];this.closingPointId&&e&&n.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=o.coordinates),this.store.updateGeometry(n)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=E(t,e)/(this.insertCoordinates.value+1),o=[];return"globe"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var o=[].concat(e,[t]);this.updateGeometries(o,void 0,d.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],n=this.project(o[0],o[1]);if($({x:n.x,y:n.y},{x:e.x,y:e.y})<this.pointerDistance)this.close();else{this.setCursor(this.cursors.close);var r=[].concat(i,[t]);this.updateGeometries(r,i[i.length-1],d.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.coordinateSnapping=new at(t,new st(t),new rt(t)),this.insertPoint=new yt(t),this.clickBoundingBox=new rt(t),this.pixelDistance=new st(t),this.lineSnapping=new Mt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new at(t,this.pixelDistance,this.clickBoundingBox)},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.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,o=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[u]=!0,i)}]);this.snappedPointId=o[0]}t.lng=e[0],t.lat=e[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);var n=e||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var r=this.store.getGeometryCopy(this.currentId).coordinates;if(r.pop(),this.closingPointId){var s=r[r.length-1],a=this.project(s[0],s[1]);$({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var l=[].concat(r,[n]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var c=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],h=n;if(!vt(c,h)){var p=this.generateInsertCoordinates(c,h);l=[].concat(this.lastCommitedCoordinates.slice(0,-1),p,[n])}}this.updateGeometries(l,void 0,d.Provisional)}},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)}),o=i.featureId,n=i.featureCoordinateIndex;if(o&&void 0!==n){var r,s=this.store.getGeometryCopy(o);if("LineString"===s.type&&!((r=s.coordinates).length<=2)){if(r.splice(n,1),this.validate&&!this.validate({id:o,type:"Feature",geometry:s,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Commit}).valid)return;this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.store.updateGeometry([{id:o,geometry:s}]),this.onFinish(o,{mode:this.mode,action:"edit"})}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.store.delete([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(e,{x:t.containerX,y:t.containerY})},i.onClick=function(t){("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 o=void 0;if("started"===this.state){var n=this.lineSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});n.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=n.featureCoordinateIndex,this.editedFeatureId=n.featureId,o=n.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,o=r.coordinate)}if(this.editedFeatureId&&o){if(!this.editedPointId){var s,a=this.store.create([{geometry:{type:"Point",coordinates:o},properties:(s={mode:this.mode},s[c]=!0,s)}]);this.editedPointId=a[0]}this.setCursor(this.cursors.dragStart),e(!1)}}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){var i=this.store.getGeometryCopy(this.editedFeatureId);"coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex?i.coordinates[this.editedFeatureCoordinateIndex]=[t.lng,t.lat]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i.coordinates.splice(this.editedInsertIndex,0,[t.lng,t.lat]),this.editedFeatureCoordinateIndex++);var o={type:"LineString",coordinates:i.coordinates};if(this.validate&&!this.validate({type:"Feature",geometry:o,properties:this.store.getPropertiesCopy(this.editedFeatureId)},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Provisional}).valid)return;this.snapping&&this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.store.updateGeometry([{id:this.editedFeatureId,geometry:o}]),this.editedPointId&&this.store.updateGeometry([{id:this.editedPointId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:c,value:!0}])}},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.editedPointId&&(this.store.delete([this.editedPointId]),this.editedPointId=void 0),this.store.updateProperty([{id:this.editedFeatureId,property:c,value:!1}]),this.onFinish(this.editedFeatureId,{mode:this.mode,action:"edit"}),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,e(!0))},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId,i=this.snappedPointId;this.closingPointId=void 0,this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==i&&this.store.delete([i]),void 0!==e&&this.store.delete([e])}catch(t){}},i.styleFeature=function(t){var e=n({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if("Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode)return e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,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[h];return e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:this.styles.snappingPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:this.styles.snappingPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:this.styles.snappingPointOutlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:this.styles.snappingPointOutlineWidth,2,t),e.zIndex=50,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return mt(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,o,n,r,s=this;return null!=(e=this.snapping)&&e.toLine&&(r=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(n=r),null!=(i=this.snapping)&&i.toCoordinate&&(n=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t)),null!=(o=this.snapping)&&o.toCustom&&(n=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return s.store.getGeometryCopy(s.currentId)}:function(){return null},project:this.project,unproject:this.unproject})),n},e}(M),wt="Feature is not a Point",bt="Feature has invalid coordinates",Dt="Feature has coordinates with excessive precision";function kt(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:wt}:U(t.geometry.coordinates)?V(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:Dt}:{valid:!1,reason:bt}}var Ot={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},_t=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="point",i.cursors=Ot,i.editable=!1,i.editedFeatureId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=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=n({},this.cursors,e.cursors)),null!=e&&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("unset")},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(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){this.editedFeatureId=void 0},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){var i=this.getNearestPointFeature(t);this.editedFeatureId=null==i?void 0:i.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId){if(this.validate&&!this.validate({type:"Feature",geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:this.store.getPropertiesCopy(this.editedFeatureId)},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Finish}).valid)return;this.store.updateGeometry([{id:this.editedFeatureId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:c,value:!0}])}},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.onFinish(this.editedFeatureId,{mode:this.mode,action:"edit"}),this.setCursor(this.cursors.dragEnd),this.store.updateProperty([{id:this.editedFeatureId,property:c,value:!1}]),this.editedFeatureId=void 0,e(!0))},i.registerBehaviors=function(t){this.pixelDistance=new st(t),this.clickBoundingBox=new rt(t)},i.styleFeature=function(t){var e=n({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=Boolean(t.id&&this.editedFeatureId===t.id);e.pointWidth=this.getNumericStylingValue(i?this.styles.editedPointWidth:this.styles.pointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.editedPointColor:this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),e.zIndex=30}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return kt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e={type:"Point",coordinates:[t.lng,t.lat]},i={mode:this.mode};if(!this.validate||this.validate({type:"Feature",geometry:e,properties:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Finish}).valid){var o=this.store.create([{geometry:e,properties:i}]);this.onFinish(o[0],{mode:this.mode,action:"draw"})}},i.onRightClick=function(t){if(this.editable){var e=this.getNearestPointFeature(t);e&&this.store.delete([e.id])}},i.getNearestPointFeature=function(t){for(var e=this.clickBoundingBox.create(t),i=this.store.search(e),o=Infinity,n=void 0,r=0;r<i.length;r++){var s=i[r];if("Point"===s.geometry.type&&s.properties.mode===this.mode){var a=this.pixelDistance.measure(t,s.geometry.coordinates);a>o||a>this.pointerDistance||(o=a,n=s)}}return n},e}(M),jt=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o._startEndPoints=[],o.config=e,o.pixelDistance=i,o}r(e,t);var o=e.prototype;return o.create=function(t,e){var i,o;if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i[h]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(o={mode:e},o[h]=!0,o)}])},o.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},o.update=function(t){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:t[t.length-3]}}])},o.isClosingPoint=function(t){var e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),o=this.pixelDistance.measure(t,e.coordinates),n=this.pixelDistance.measure(t,i.coordinates);return{isClosing:o<this.pointerDistance,isPreviousClosing:n<this.pointerDistance}},i(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(ot),Bt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}r(e,t);var i=e.prototype;return i.createOrUpdate=function(t){var e,i=this,o=this.store.getGeometryCopy(t),n=this.store.getPropertiesCopy(t);if("Polygon"===o.type)e=o.coordinates[0].slice(0,-1);else{if("LineString"!==o.type)return;e=o.coordinates}var r=this.store.getPropertiesCopy(t),s=r.coordinatePointIds;if(s)if(s&&s.every(function(t){return i.store.has(t)})){var a=r.coordinatePointIds,d=a.map(function(t){return i.store.getGeometryCopy(t).coordinates});if(a.length!==e.length){this.deleteCoordinatePoints(a);var l=this.createPoints(e,n.mode,t);this.setFeatureCoordinatePoints(t,l)}else e.forEach(function(t,e){t[0]===d[e][0]&&t[1]===d[e][1]||i.store.updateGeometry([{id:a[e],geometry:{type:"Point",coordinates:t}}])})}else{var c=s.filter(function(t){return i.store.has(t)});c.length&&this.deleteCoordinatePoints(c);var h=this.createPoints(e,n.mode,t);this.setFeatureCoordinatePoints(t,h)}else{var u=this.createPoints(e,n.mode,t);this.setFeatureCoordinatePoints(t,u)}},i.deletePointsByFeatureIds=function(t){for(var e,i=o(t);!(e=i()).done;)this.deleteIfPresent(e.value)},i.getUpdated=function(t,e){var i=this,o=this.store.getPropertiesCopy(t);if(o.coordinatePointIds)return o.coordinatePointIds.map(function(t,o){return{id:t,geometry:n({},i.store.getGeometryCopy(t),{coordinates:e[o]})}})},i.createPoints=function(t,e,i){return this.store.create(t.map(function(t,o){var n;return{geometry:{type:"Point",coordinates:t},properties:(n={mode:e},n[p]=!0,n.coordinatePointFeatureId=i,n.index=o,n)}}))},i.setFeatureCoordinatePoints=function(t,e){this.store.updateProperty([{id:t,property:g,value:e}])},i.deleteCoordinatePoints=function(t){var e=this,i=t.filter(function(t){return e.store.has(t)});this.store.delete(i)},i.deleteIfPresent=function(t){var e=this.store.getPropertiesCopy(t).coordinatePointIds;e&&(this.deleteCoordinatePoints(e),this.setFeatureCoordinatePoints(t,null))},e}(ot),Wt={cancel:"Escape",finish:"Enter"},Gt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Nt=/*#__PURE__*/func