terra-draw 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).terraDraw={})}(this,function(t){function e(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 i(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,d(o.key),o)}}function o(t,e,o){return e&&i(t.prototype,e),o&&i(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t,i){var o="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(o)return(o=o.call(t)).next.bind(o);if(Array.isArray(t)||(o=function(t,i){if(t){if("string"==typeof t)return e(t,i);var o={}.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(t,i):void 0}}(t))||i&&t&&"number"==typeof t.length){o&&(t=o);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[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 r(){return r=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},r.apply(null,arguments)}function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function d(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 l;!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(l||(l={}));var c={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},h={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"},u=10;function p(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function g(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function f(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var y,v="Feature is not a Polygon",m="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"}(y||(y={}));var C={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},P=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=C,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=y.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=r({},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.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(p(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(p(t.geometry))if(p(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:l.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:m}:{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.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?t(i):t},o(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}}])}(),I=/*#__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=y.Select,e}return s(e,t),e}(P);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 x=6371008.8;function S(t){return t%360*Math.PI/180}function M(t){return t/6371.0088}function F(t){return t%(2*Math.PI)*180/Math.PI}function D(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var w=57.29577951308232,O=.017453292519943295,k=6378137,_=function(t,e){return{x:0===t?0:t*O*k,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*O/2))*k}},b=function(t,e){return{lng:0===t?0:w*(t/k),lat:0===e?0:(2*Math.atan(Math.exp(e/k))-Math.PI/2)*w}};function N(t,e,i){var o=S(t[0]),n=S(t[1]),r=S(i),s=M(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[F(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),F(a)]}function T(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=N(e,i,-360*s/n);r.push([D(a[0],o),D(a[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function W(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(j(t,i)||j(t,o)||j(e,i)||j(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 j(t,e){return t[0]===e[0]&&t[1]===e[1]}function B(t,e){return R(t[0])<=e&&R(t[1])<=e}function G(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 R(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var U="Feature has holes",L="Feature has less than 4 coordinates",A="Feature has invalid coordinates",V="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:U};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:L};for(var i=0;i<t.geometry.coordinates[0].length;i++){if(!G(t.geometry.coordinates[0][i]))return{valid:!1,reason:A};if(!B(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:V}:{valid:!0};var o,n}function K(t,e){var i=Y(t,e);return i.valid?W(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var z={cancel:"Escape",finish:"Enter"},H={start:"crosshair"},X=/*#__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=z,i.cursors=H,i.startingRadiusKilometers=1e-5,i.cursorMovedAfterInitialCursorDown=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers)},i.close=function(){if(void 0!==this.currentCircleId){this.store.updateProperty([{id:this.currentCircleId,property:h.CURRENTLY_DRAWING,value:void 0}]);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:l.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){var e;this.center=[t.lng,t.lat];var i=T({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.store.create([{geometry:i.geometry,properties:(e={mode:this.mode,radiusKilometers:this.startingRadiusKilometers},e[h.CURRENTLY_DRAWING]=!0,e)}]);this.currentCircleId=o[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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return K(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=_(t[0],t[1]),n=o.x,r=o.y,s=_(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=_(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=b(s+h,a+u),g=p.lat;d.push([D(p.lng,i),D(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=T({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:l.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},i.afterFeatureUpdated=function(t){this.currentCircleId===t.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted())},e}(P),q=function(t,e){var i=e.x-t.x,o=e.y-t.y;return Math.sqrt(o*o+i*i)};function Z(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 J={cancel:"Escape",finish:"Enter"},$={start:"crosshair",close:"pointer"},Q=/*#__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=J,i.cursors=$,i.preventPointsNearClose=!0,i.autoClose=!1,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1,i.updateOptions(e),i}s(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=r({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors))},i.close=function(){if(void 0!==this.currentId){if(this.currentId){var t=Z(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}]),this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0}])}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:l.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=q({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(q({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 d={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:d,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:d}])}}else this.setCursor(this.cursors.start)},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,o=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e)},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(i={mode:this.mode},i[h.CLOSING_POINT]=!0,i)}]),n=o[1];return this.currentId=o[0],this.closingPointId=n,this.startingClick=!0,void("drawing"!==this.state&&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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u,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)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)},e}(P),tt=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 et(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 it=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return s(e,t),e.prototype.create=function(t){return et({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(tt),ot=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return s(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return q({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(tt),nt=/*#__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 s(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}(tt);function rt(t,e,i){var o=S(t[0]),n=S(t[1]),r=S(i),s=M(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[F(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),F(a)]}function st(t,e,i){var o=t.x,n=t.y,r=S(i);return{x:o+e*Math.cos(r),y:n+e*Math.sin(r)}}function at(t,e){var i=S(t[0]),o=S(e[0]),n=S(t[1]),r=S(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 F(Math.atan2(s,a))}function dt(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 lt(t){return(t+360)%360}function ct(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=at(t[l],t[l-1])-180,r=rt(t[l],o,n),s.push(r)}if(d>=i)return(o=i-d)?(n=at(t[l],t[l-1])-180,r=rt(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 ht(t){return t*(Math.PI/180)}function ut(t){return t*(180/Math.PI)}var pt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}s(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=ct(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=ht(t[1]),r=ht(t[0]),s=ht(e[1]),a=ht(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([ut(v),ut(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[D(t[0],e.config.coordinatePrecision),D(t[1],e.config.coordinatePrecision)]})},e}(tt);function gt(t,e){return t[0]===e[0]&&t[1]===e[1]}function ft(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(!G(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!B(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function yt(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function vt(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(yt(t)*yt(e));return Math.acos(Math.min(Math.max(i,-1),1))}function mt(t){var e=S(t[1]),i=S(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function Ct(t){var e=t[0],i=t[1],o=F(Math.asin(t[2]));return[F(Math.atan2(i,e)),o]}var Pt=/*#__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){var e=n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)});return e.coordinate?[D(e.coordinate[0],n.config.coordinatePrecision),D(e.coordinate[1],n.config.coordinatePrecision)]:void 0},n.getSnappableCoordinate=function(t,e){var i=n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)});return i.coordinate?[D(i.coordinate[0],n.config.coordinatePrecision),D(i.coordinate[1],n.config.coordinatePrecision)]:void 0},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return s(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 l=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,o,r,s,a,d,l,c,h=[Infinity,Infinity],u=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=_(y[0],y[1]),I=_(v[0],v[1]),E=_(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 x=(l=(d={x:(s=E).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,c=Math.max(0,Math.min(1,l/(a.x*a.x+a.y*a.y))),{x:o.x+c*a.x,y:o.y+c*a.y}),S=b(x.x,x.y);m=[S.lng,S.lat]}m&&(C=q(E,_(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,o=[Infinity,Infinity],r=Infinity,s=0,a=n(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=mt(p),D=mt(g),w=mt(f),O=w[0],k=w[1],_=w[2],b=[(C=(y=F)[1])*(S=(v=D)[2])-(P=y[2])*(x=v[1]),P*(I=v[0])-(m=y[0])*S,m*x-C*I],N=b[0],T=b[1],W=b[2],j=T*_-W*k,B=W*O-N*_,G=N*k-T*O,R=G*T-B*W,U=j*W-G*N,L=B*N-j*T,A=1/Math.sqrt(Math.pow(R,2)+Math.pow(U,2)+Math.pow(L,2)),V=[R*A,U*A,L*A],Y=[-1*R*A,-1*U*A,-1*L*A],K=vt(F,D),z=vt(F,V),H=vt(D,V),X=vt(F,Y),q=vt(D,Y),vt(F,M=z<X&&z<q||H<X&&H<q?V:Y)>K||vt(D,M)>K?E(Ct(M),Ct(F))<=E(Ct(M),Ct(D))?[Ct(F),!0,!1]:[Ct(D),!1,!0]:[Ct(M),!1,!1])[0])&&(u=E(t,d))<r&&(o=d,r=u,s=e.indexOf(l))}var p,g,f,y,v,m,C,P,I,x,S,M,F,D,w,O,k,_,b,N,T,W,j,B,G,R,U,L,A,V,Y,K,z,H,X,q;return Infinity===r?void 0:{coordinate:o,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=[D(r.coordinate[0],i.config.coordinatePrecision),D(r.coordinate[1],i.config.coordinatePrecision)],s.featureCoordinateIndex=r.lineIndex,s.minDistance=c)}}),s},e}(tt),It={cancel:"Escape",finish:"Enter"},Et={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},xt=/*#__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=It,i.snapping=void 0,i.cursors=Et,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommittedCoordinates=void 0,i.snappedPointId=void 0,i.lastMouseMoveEvent=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}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},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=r({},this.keyEvents,e.keyEvents)),null!=e&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable)},i.updateSnappedCoordinate=function(t){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[h.SNAPPING_POINT]=!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);return e},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,l.Commit),this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0}]);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.lastCommittedCoordinates=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.lastCommittedCoordinates=o.coordinates),this.store.updateGeometry(n)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=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,i=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e)}])[0];this.lastCommittedCoordinates=[t,t],this.currentId=i,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){var e;if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:(e={mode:this.mode},e[h.CLOSING_POINT]=!0,e)}]);this.closingPointId=o[0],this.setCursor(this.cursors.close);var n=[].concat(i,[t]);this.updateGeometries(n,void 0,l.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.lastCommittedCoordinates?this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1]:i[i.length-2],n=this.project(o[0],o[1]);if(q({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],l.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.coordinateSnapping=new nt(t,new ot(t),new it(t)),this.insertPoint=new pt(t),this.clickBoundingBox=new it(t),this.pixelDistance=new ot(t),this.lineSnapping=new Pt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new nt(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),this.lastMouseMoveEvent=t;var e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var i=this.store.getGeometryCopy(this.currentId).coordinates;if(i.pop(),this.closingPointId){var o=i[i.length-1],n=this.project(o[0],o[1]);q({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var r=[].concat(i,[e]);if(this.insertCoordinates&&this.currentId&&this.lastCommittedCoordinates){var s=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1],a=e;if(!gt(s,a)){var d=this.generateInsertCoordinates(s,a);r=[].concat(this.lastCommittedCoordinates.slice(0,-1),d,[e])}}this.updateGeometries(r,void 0,l.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:l.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[h.EDITED]=!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:l.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:h.EDITED,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:h.EDITED,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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 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=u,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[h.CLOSING_POINT];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 ft(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},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&this.editedPointId&&(this.store.delete([this.editedPointId]),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.closingPointId&&(this.store.delete([this.closingPointId]),this.closingPointId=void 0),this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted())},e}(P),St="Feature is not a Point",Mt="Feature has invalid coordinates",Ft="Feature has coordinates with excessive precision";function Dt(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:St}:G(t.geometry.coordinates)?B(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:Ft}:{valid:!1,reason:Mt}}var wt={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},Ot=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="point",i.cursors=wt,i.editable=!1,i.editedFeatureId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},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:l.Finish}).valid)return;this.store.updateGeometry([{id:this.editedFeatureId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:h.EDITED,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:h.EDITED,value:!1}]),this.editedFeatureId=void 0,e(!0))},i.registerBehaviors=function(t){this.pixelDistance=new ot(t),this.clickBoundingBox=new it(t)},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 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 Dt(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:l.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},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(P),kt=/*#__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}s(e,t);var i=e.prototype;return i.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.CLOSING_POINT]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(o={mode:e},o[h.CLOSING_POINT]=!0,o)}])},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},i.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]}}])},i.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}},o(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(tt),_t=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}s(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=n(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:r({},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[h.COORDINATE_POINT]=!0,n[h.COORDINATE_POINT_FEATURE_ID]=i,n.index=o,n)}}))},i.setFeatureCoordinatePoints=function(t,e){this.store.updateProperty([{id:t,property:h.COORDINATE_POINT_IDS,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}(tt),bt={cancel:"Escape",finish:"Enter"},Nt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Tt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=bt,i.cursors=Nt,i.mouseMove=!1,i.showCoordinatePoints=!1,i.lastMouseMoveEvent=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinatePoints=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.clickBoundingBox=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){var i=this;if(t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.snapping&&(this.snapping=e.snapping),void 0!==(null==e?void 0:e.editable)&&(this.editable=e.editable),void 0!==(null==e?void 0:e.pointerEvents)&&(this.pointerEvents=e.pointerEvents),void 0!==(null==e?void 0:e.showCoordinatePoints))if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(function(t){return t.mode===i.mode}).map(function(t){return t.id}).forEach(function(t){i.coordinatePoints.createOrUpdate(t)});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){var o=this.store.copyAllWhere(function(t){return t.mode===i.mode&&Boolean(t[h.COORDINATE_POINT_IDS])});this.coordinatePoints.deletePointsByFeatureIds(o.map(function(t){return t.id}))}},i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId).coordinates[0];if(!(t.length<5)&&this.updatePolygonGeometry([].concat(t.slice(0,-2),[t[0]]),l.Finish)){var e=this.currentId;if(this.currentId){var i=Z(this.store.getGeometryCopy(this.currentId));i&&(this.store.updateGeometry([{id:this.currentId,geometry:i}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(this.currentId)),this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0},{id:this.currentId,property:h.COMMITTED_COORDINATE_COUNT,value:void 0},{id:this.currentId,property:h.PROVISIONAL_COORDINATE_COUNT,value:void 0}])}this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.snappedPointId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}}},i.registerBehaviors=function(t){this.clickBoundingBox=new it(t),this.pixelDistance=new ot(t),this.lineSnapping=new Pt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new nt(t,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new kt(t,this.pixelDistance),this.coordinatePoints=new _t(t)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.updateSnappedCoordinate=function(t){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[h.SNAPPING_POINT]=!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)},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var o=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,o);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-n],i[0]]}else if(2===this.currentCoordinate)e=[i[0],i[1],[t.lng,t.lat],i[0]];else{var r=this.closingPoints.isClosingPoint(t);r.isPreviousClosing||r.isClosing?(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.setCursor(this.cursors.close),e=[].concat(i.slice(0,-2),[i[0],i[0]])):e=[].concat(i.slice(0,-2),[[t.lng,t.lat],i[0]])}this.store.updateProperty([{id:this.currentId,property:h.PROVISIONAL_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.updatePolygonGeometry(e,l.Provisional)}},i.updatePolygonGeometry=function(t,e){if(!this.currentId)return!1;var i={type:"Polygon",coordinates:[t]};return!(this.validate&&!this.validate({type:"Feature",geometry:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid||(this.store.updateGeometry([{id:this.currentId,geometry:i}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(this.currentId),0))},i.snapCoordinate=function(t){var e,i,o,n,r,s=this,a=void 0;return null!=(e=this.snapping)&&e.toLine&&(n=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(a=n),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(a=r),null!=(o=this.snapping)&&o.toCustom&&(a=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})),a},i.polygonFilter=function(t){return Boolean("Polygon"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.polygonFilter(t)}),o=i.featureId,n=i.featureCoordinateIndex;if(o&&void 0!==n){var r,s=this.store.getGeometryCopy(o);if("Polygon"===s.type&&!((r=s.coordinates[0]).length<=4)){if("Polygon"!==s.type||0!==n&&n!==r.length-1?r.splice(n,1):(r.shift(),r.pop(),r.push([r[0][0],r[0][1]])),this.validate&&!this.validate({id:o,type:"Feature",geometry:s,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Commit}).valid)return;this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.store.updateGeometry([{id:o,geometry:s}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(o),this.onFinish(o,{mode:this.mode,action:"edit"})}}}},i.onLeftClick=function(t){if(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),0===this.currentCoordinate){var e,i=this.snapCoordinate(t);i&&(t.lng=i[0],t.lat=i[1]);var o=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e[h.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,e[h.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,e)}])[0];this.currentId=o,this.currentCoordinate++,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(o),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.snapCoordinate(t);n&&(t.lng=n[0],t.lat=n[1]);var r=this.store.getGeometryCopy(this.currentId);if(gt([t.lng,t.lat],r.coordinates[0][0]))return;if(!this.updatePolygonGeometry([r.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],r.coordinates[0][0]],l.Commit))return;this.store.updateProperty([{id:this.currentId,property:h.COMMITTED_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var s=this.snapCoordinate(t);s&&(t.lng=s[0],t.lat=s[1]);var a=this.store.getGeometryCopy(this.currentId).coordinates[0];if(gt([t.lng,t.lat],a[1]))return;if(!this.updatePolygonGeometry([a[0],a[1],[t.lng,t.lat],[t.lng,t.lat],a[0]],l.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(a,"polygon"),this.store.updateProperty([{id:this.currentId,property:h.COMMITTED_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.currentCoordinate++}else if(this.currentId){var d=this.store.getGeometryCopy(this.currentId).coordinates[0],c=this.closingPoints.isClosingPoint(t);if(c.isPreviousClosing||c.isClosing)this.close();else{var u=this.snapCoordinate(t);if(u&&(t.lng=u[0],t.lat=u[1]),gt([t.lng,t.lat],d[this.currentCoordinate-1]))return;var p=(void 0===(g=[[].concat(d.slice(0,-1),[[t.lng,t.lat],d[0]])])&&(g=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:g},properties:{}});if(!this.updatePolygonGeometry(p.geometry.coordinates[0],l.Commit))return;this.store.updateProperty([{id:this.currentId,property:h.COMMITTED_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(p.geometry.coordinates[0])}}var g},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var o=void 0;if("started"===this.state){var n=this.lineSnapping.getSnappable(t,function(t){return i.polygonFilter(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.polygonFilter(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[h.EDITED]=!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),o=i.coordinates[0];"coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex?0===this.editedFeatureCoordinateIndex||this.editedFeatureCoordinateIndex===i.coordinates[0].length-1?(o[0]=[t.lng,t.lat],o[o.length-1]=[t.lng,t.lat]):o[this.editedFeatureCoordinateIndex]=[t.lng,t.lat]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i.coordinates[0].splice(this.editedInsertIndex,0,[t.lng,t.lat]),this.editedFeatureCoordinateIndex++);var n={type:"Polygon",coordinates:i.coordinates};if(this.validate&&!this.validate({type:"Feature",geometry:n,properties:this.store.getPropertiesCopy(this.editedFeatureId)},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Provisional}).valid)return;this.snapping&&this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.store.updateGeometry([{id:this.editedFeatureId,geometry:n}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(this.editedFeatureId),this.editedPointId&&this.store.updateGeometry([{id:this.editedPointId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:h.EDITED,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:h.EDITED,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.snappedPointId,i=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{t&&this.coordinatePoints.deletePointsByFeatureIds([t]),void 0!==t&&this.store.delete([t]),void 0!==i&&this.store.delete([i]),void 0!==e&&this.store.delete([e]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u,e;if("Point"===t.geometry.type){var i=t.properties[h.EDITED],o=t.properties[h.COORDINATE_POINT],n=i?"editedPoint":t.properties[h.CLOSING_POINT]?"closingPoint":t.properties[h.SNAPPING_POINT]?"snappingPoint":o?"coordinatePoint":void 0;if(!n)return e;var s={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth}};return e.pointWidth=this.getNumericStylingValue(s[n].width,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(s[n].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(s[n].outlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(s[n].outlineWidth,2,t),e.zIndex=i?40:o?20:30,e}}return e},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(t.id)},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(t.id),this.editedFeatureId===t.id&&this.editedPointId&&(this.store.delete([this.editedPointId]),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted())},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Y(t,e.coordinatePrecision)})},e}(P),Wt={cancel:"Escape",finish:"Enter"},jt={start:"crosshair"},Bt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="rectangle",i.center=void 0,i.clickCount=0,i.currentRectangleId=void 0,i.keyEvents=Wt,i.cursors=jt,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents))},i.updateRectangle=function(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){var i=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],o={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid)return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:o}])}},i.close=function(){var t=this.currentRectangleId;if(t){var e=Z(this.store.getGeometryCopy(t));e&&this.store.updateGeometry([{id:t,geometry:e}]),this.store.updateProperty([{id:t,property:h.CURRENTLY_DRAWING,value:void 0}])}this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&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){var e;this.center=[t.lng,t.lat];var 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:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e)}]);this.currentRectangleId=i[0],this.clickCount++,this.setDrawing()}else this.updateRectangle(t,l.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,l.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(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&this.store.delete([t])},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return K(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentRectangleId===t.id&&(this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted())},e}(P),Gt=/*#__PURE__*/function(t){function e(e){var i;if(!e.modeName)throw new Error("Mode name is required for TerraDrawRenderMode");return(i=t.call(this,e,!0)||this).type=y.Render,i.mode="render",i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.modeName&&(this.mode=e.modeName)},i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}},i.validateFeature=function(e){var i=t.prototype.validateFeature.call(this,e);if(i.valid){var o=e,n=Dt(o,this.coordinatePrecision).valid||Y(o,this.coordinatePrecision).valid||ft(o,this.coordinatePrecision).valid;return n?{valid:!0}:{valid:n,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(P);function Rt(t,e){var i=t,o=e,n=S(i[1]),r=S(o[1]),s=S(o[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=(F(Math.atan2(s,a))+360)%360;return d>180?-(360-d):d}function Ut(t,e,i){var o=e;e<0&&(o=-Math.abs(o));var n=o/x,r=t[0]*Math.PI/180,s=S(t[1]),a=S(i),d=n*Math.cos(a),l=s+d;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);var c=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),h=Math.abs(c)>1e-11?d/c:Math.cos(s),u=[(180*(r+n*Math.sin(a)/h)/Math.PI+540)%360-180,180*l/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function Lt(t,e,i,o,n){var r=o(t[0],t[1]),s=o(e[0],e[1]),a=n((r.x+s.x)/2,(r.y+s.y)/2),d=a.lat;return[D(a.lng,i),D(d,i)]}function At(t,e,i){var o=Ut(t,1e3*E(t,e)/2,Rt(t,e));return[D(o[0],i),D(o[1],i)]}function Vt(t){for(var e=t.featureCoords,i=t.precision,o=t.unproject,n=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var d=void 0;if("web-mercator"===r)d=Lt(e[a],e[a+1],i,n,o);else{if("globe"!==r)throw new Error("Invalid projection");d=At(e[a],e[a+1],i)}s.push(d)}return s}var Yt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n.coordinatePointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n.coordinatePointBehavior=o,n}s(e,t);var i=e.prototype;return i.insert=function(t,e,i){var o=this.store.getGeometryCopy(e),n=this.store.getPropertiesCopy(e),r=n.midPointFeatureId,s=n.midPointSegment,a=this.store.getGeometryCopy(r),d="Polygon"===a.type?a.coordinates[0]:a.coordinates;d.splice(s+1,0,o.coordinates),a.coordinates="Polygon"===a.type?[d]:d,this.store.updateGeometry([{id:r,geometry:a}]),this.store.getPropertiesCopy(t)[h.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate(t),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(d,r,i),this.selectionPointBehavior.create(d,a.type,r)},i.create=function(t,e,i){var o=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,o,n,r){return Vt({featureCoords:t,precision:i,project:o,unproject:n,projection:r}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:o.mode})[c.MID_POINT]=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i,this.config.project,this.config.unproject,this.projection))},i.delete=function(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])},i.getUpdated=function(t){var e=this;if(0!==this._midPoints.length)return Vt({featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}).map(function(t,i){return{id:e._midPoints[i],geometry:{type:"Point",coordinates:t}}})},o(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}])}(tt),Kt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}s(e,t);var i=e.prototype;return i.create=function(t,e,i){var o=this;this._selectionPoints=this.store.create(function(t,e,i){for(var o=[],n="Polygon"===e?t.length-1:t.length,r=0;r<n;r++)o.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return o}(t,e,function(t){var e;return(e={mode:o.mode,index:t})[c.SELECTION_POINT]=!0,e[c.SELECTION_POINT_FEATURE_ID]=i,e}))},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])},i.getUpdated=function(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map(function(e,i){return{id:e,geometry:{type:"Point",coordinates:t[i]}}})},i.getOneUpdated=function(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}},o(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}])}(tt);function zt(t,e){for(var i,o,n,r=!1,s=0,a=e.length;s<a;s++)for(var d=e[s],l=0,c=d.length,h=c-1;l<c;h=l++)(o=d[l])[1]>(i=t)[1]!=(n=d[h])[1]>i[1]&&i[0]<(n[0]-o[0])*(i[1]-o[1])/(n[1]-o[1])+o[0]&&(r=!r);return r}var Ht=function(t,e,i){var o=function(t){return t*t},n=function(t,e){return o(t.x-e.x)+o(t.y-e.y)};return Math.sqrt(function(t,e,i){var o=n(e,i);if(0===o)return n(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/o;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},Xt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.createClickBoundingBox=void 0,n.pixelDistance=void 0,n.config=e,n.createClickBoundingBox=i,n.pixelDistance=o,n}return s(e,t),e.prototype.find=function(t,e){for(var i=void 0,o=Infinity,n=void 0,r=Infinity,s=void 0,a=Infinity,d=void 0,l=this.createClickBoundingBox.create(t),h=this.store.search(l),u=0;u<h.length;u++){var p=h[u],g=p.geometry;if("Point"===g.type){if(p.properties.selectionPoint||p.properties.coordinatePoint||!e&&p.properties[c.MID_POINT])continue;var f=this.pixelDistance.measure(t,g.coordinates);p.properties[c.MID_POINT]&&f<this.pointerDistance&&f<a?(a=f,s=p):!p.properties[c.MID_POINT]&&f<this.pointerDistance&&f<o&&(o=f,i=p)}else if("LineString"===g.type){if(i)continue;for(var y=0;y<g.coordinates.length-1;y++){var v=g.coordinates[y],m=g.coordinates[y+1],C=Ht({x:t.containerX,y:t.containerY},this.project(v[0],v[1]),this.project(m[0],m[1]));C<this.pointerDistance&&C<r&&(r=C,n=p)}}else if("Polygon"===g.type){if(i||n)continue;zt([t.lng,t.lat],g.coordinates)&&(d=p)}}return{clickedFeature:i||n||d,clickedMidPoint:s}},e}(tt),qt=/*#__PURE__*/function(t){function e(e,i,o,n,r){var s;return(s=t.call(this,e)||this).config=void 0,s.featuresAtCursorEvent=void 0,s.selectionPoints=void 0,s.midPoints=void 0,s.coordinatePoints=void 0,s.draggedFeatureId=null,s.dragPosition=void 0,s.config=e,s.featuresAtCursorEvent=i,s.selectionPoints=o,s.midPoints=n,s.coordinatePoints=r,s}s(e,t);var i=e.prototype;return i.startDragging=function(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]},i.stopDragging=function(){this.draggedFeatureId=null,this.dragPosition=void 0},i.isDragging=function(){return null!==this.draggedFeatureId},i.canDrag=function(t,e){var i=this.featuresAtCursorEvent.find(t,!0).clickedFeature;return!(!i||i.id!==e)},i.drag=function(t,e){if(this.draggedFeatureId){var i=this.store.getGeometryCopy(this.draggedFeatureId),o=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var n,r;if(r="Polygon"===i.type?(n=i.coordinates[0]).length-1:(n=i.coordinates).length,!this.dragPosition)return!1;for(var s=0;s<r;s++){var a=n[s],d=void 0,c=void 0;if("web-mercator"===this.config.projection){var h=_(this.dragPosition[0],this.dragPosition[1]),u=_(o[0],o[1]),p=_(a[0],a[1]),g={x:h.x-u.x,y:h.y-u.y},f=b(p.x-g.x,p.y-g.y);d=f.lng,c=f.lat}else{var y=[this.dragPosition[0]-o[0],this.dragPosition[1]-o[1]];d=a[0]-y[0],c=a[1]-y[1]}if(d=D(d,this.config.coordinatePrecision),c=D(c,this.config.coordinatePrecision),d>180||d<-180||c>90||c<-90)return!1;n[s]=[d,c]}"Polygon"===i.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var v=this.selectionPoints.getUpdated(n)||[],m=this.midPoints.getUpdated(n)||[],C=this.coordinatePoints.getUpdated(this.draggedFeatureId,n)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}).valid)return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(v,m,C)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:o}}]),this.dragPosition=[t.lng,t.lat])}},e}(tt),Zt=/*#__PURE__*/function(t){function e(e,i,o,n,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.pixelDistance=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.coordinateSnapping=void 0,d.lineSnapping=void 0,d.draggedCoordinate={id:null,index:-1},d.config=e,d.pixelDistance=i,d.selectionPoints=o,d.midPoints=n,d.coordinatePoints=r,d.coordinateSnapping=s,d.lineSnapping=a,d}s(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.snapCoordinate=function(t,e,i){var o,n,r,s=this,a=[t.lng,t.lat],d=function(t){return Boolean(t.properties&&t.properties.mode===i.properties.mode&&t.id!==s.draggedCoordinate.id)};return null!=e&&e.toLine&&(o=this.lineSnapping.getSnappable(t,d).coordinate)&&(a=o),e.toCoordinate&&(n=this.coordinateSnapping.getSnappable(t,d).coordinate)&&(a=n),null!=e&&e.toCustom&&(r=e.toCustom(t,{currentCoordinate:this.draggedCoordinate.index,currentId:i.id,getCurrentGeometrySnapshot:i.id?function(){return s.store.getGeometryCopy(i.id)}:function(){return null},project:this.project,unproject:this.unproject}))&&(a=r),a},i.drag=function(t,e,i,o){var n=this.draggedCoordinate.id;if(null===n)return!1;var r=this.draggedCoordinate.index,s=this.store.getGeometryCopy(n),a=this.store.getPropertiesCopy(n),d="LineString"===s.type?s.coordinates:s.coordinates[0],c="Polygon"===s.type&&(r===d.length-1||0===r),h={type:"Feature",id:n,geometry:s,properties:a},u=this.snapCoordinate(t,o,h);if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(c){var p=d.length-1;d[0]=u,d[p]=u}else d[r]=u;var g=this.selectionPoints.getOneUpdated(r,u),f=g?[g]:[],y=this.midPoints.getUpdated(d)||[],v=this.coordinatePoints.getUpdated(n,d)||[];return!("Point"!==s.type&&!e&&W({type:"Feature",geometry:s,properties:{}})||i&&!i(h,{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}).valid||(this.store.updateGeometry([{id:n,geometry:s}].concat(f,y,v)),0))},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(tt);function Jt(t){var e=0,i=0,o=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}var $t=function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return _(t[0],t[1])}),n=o.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});n.x/=o.length,n.y/=o.length;var r=o.map(function(t){return{x:n.x+(t.x-n.x)*Math.cos(i)-(t.y-n.y)*Math.sin(i),y:n.y+(t.x-n.x)*Math.sin(i)+(t.y-n.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[b(e,i).lng,b(e,i).lat]});return"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r,t};function Qt(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=_(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,o=0,n=t.length,r=0;r<n-1;r++){var s=t[r],a=s[0],d=s[1],l=t[r+1],c=l[0],h=l[1],u=a*h-c*d;e+=u,i+=(a+c)*u,o+=(d+h)*u}return{x:i/=6*(e/=2),y:o/=6*e}}(e):function(t){for(var e=t.length,i=0,o=0,n=0;n<e;n++){var r=t[n];i+=r[0],o+=r[1]}return{x:i/e,y:o/e}}(e)}var te=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.coordinatePoints=void 0,r.lastBearing=void 0,r.selectedGeometry=void 0,r.selectedGeometryCentroid=void 0,r.selectedGeometryWebMercatorCentroid=void 0,r.config=e,r.selectionPoints=i,r.midPoints=o,r.coordinatePoints=n,r}s(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0},i.rotate=function(t,e,i){var o=this;this.selectedGeometry||(this.selectedGeometry=this.store.getGeometryCopy(e));var n=this.selectedGeometry;if("Polygon"===n.type||"LineString"===n.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:n,properties:{}};if("web-mercator"===this.config.projection){this.selectedGeometryWebMercatorCentroid||(this.selectedGeometryWebMercatorCentroid=Qt(a));var d=_(t.lng,t.lat);if(0===(r=dt(this.selectedGeometryWebMercatorCentroid,d)))return;if(!this.lastBearing)return void(this.lastBearing=r);$t(a,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(this.selectedGeometryCentroid||(this.selectedGeometryCentroid=Jt({type:"Feature",geometry:n,properties:{}})),r=Rt(this.selectedGeometryCentroid,s),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=Jt(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=Rt(i,t)+e,n=function(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=x,o=e[1]*Math.PI/180,n=t[1]*Math.PI/180,r=n-o,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(a)>1e-11?r/a:Math.cos(o);return Math.sqrt(r*r+d*d*s*s)*i}(i,t),r=Ut(i,n,o);t[0]=r[0],t[1]=r[1]})}(a,-(this.lastBearing-(r+180)))}var c="Polygon"===n.type?n.coordinates[0]:n.coordinates;c.forEach(function(t){t[0]=D(t[0],o.coordinatePrecision),t[1]=D(t[1],o.coordinatePrecision)});var h=this.midPoints.getUpdated(c)||[],u=this.selectionPoints.getUpdated(c)||[],p=this.coordinatePoints.getUpdated(e,c)||[];if(i&&!i({id:e,type:"Feature",geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:n}].concat(u,h,p)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}(tt),ee=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.dragCoordinateResizeBehavior=void 0,o.config=e,o.dragCoordinateResizeBehavior=i,o}s(e,t);var i=e.prototype;return i.scale=function(t,e,i){if(!this.dragCoordinateResizeBehavior.isDragging()){var o=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,o)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed",i)},i.reset=function(){this.dragCoordinateResizeBehavior.stopDragging()},e}(tt);function ie(t){var e=t.originX,i=t.originY,o=t.xScale,n=t.yScale;1===o&&1===n||t.coordinates.forEach(function(t){var r=_(t[0],t[1]),s=b(e+(r.x-e)*o,i+(r.y-i)*n),a=s.lat;t[0]=s.lng,t[1]=a})}var oe=/*#__PURE__*/function(t){function e(e,i,o,n,r){var s;return(s=t.call(this,e)||this).config=void 0,s.pixelDistance=void 0,s.selectionPoints=void 0,s.midPoints=void 0,s.coordinatePoints=void 0,s.minimumScale=1e-4,s.draggedCoordinate={id:null,index:-1},s.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},s.config=e,s.pixelDistance=i,s.selectionPoints=o,s.midPoints=n,s.coordinatePoints=r,s}s(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=Qt(e.feature);if(!r)return null;var s=_(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=_(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),o},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=Qt(e.feature);if(!r)return null;var s=_(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=_(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),o},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,o=t.webMercatorCursor,n=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-o.x,e.y-o.y))return null;var r=q(e,o)/q(e,i);return r<0&&(r=this.minimumScale),ie({coordinates:n,originX:e.x,originY:e.y,xScale:r,yScale:r}),n},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=_(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,l={x:i[a][0],y:i[a][1]},c=_(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:c,webMercatorSelected:r,webMercatorOrigin:l}),o},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=_(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,l={x:i[a][0],y:i[a][1]},c=_(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:c,webMercatorSelected:r,webMercatorOrigin:l}),o},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,o=t.webMercatorSelected,n=t.webMercatorCursor,r=t.updatedCoords,s=i.x-n.x,a=i.y-n.y;if(!this.isValidDragWebMercator(e,s,a))return null;var d=1;0!==s&&1!==e&&5!==e&&(d=1-(i.x-o.x-s)/s);var l=1;return 0!==a&&3!==e&&7!==e&&(l=1-(i.y-o.y-a)/a),this.validateScale(d,l)?(d<0&&(d=this.minimumScale),l<0&&(l=this.minimumScale),this.performWebMercatorScale(r,i.x,i.y,d,l),r):null},i.getFeature=function(t){if(null===this.draggedCoordinate.id)return null;var e=this.store.getGeometryCopy(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{id:t,type:"Feature",geometry:e,properties:{}}},i.getNormalisedCoordinates=function(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates},i.validateScale=function(t,e){var i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,o=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&o},i.performWebMercatorScale=function(t,e,i,o,n){t.forEach(function(t){var r=_(t[0],t[1]),s=b(e+(r.x-e)*o,i+(r.y-i)*n),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=_(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],o=t[1];i<e[0]&&(e[0]=i),o<e[1]&&(e[1]=o),i>e[2]&&(e[2]=i),o>e[3]&&(e[3]=o)});var i=e[0],o=e[1],n=e[2],r=e[3];return[[i,r],[(i+n)/2,r],[n,r],[n,r+(o-r)/2],[n,o],[(i+n)/2,o],[i,o],[i,r+(o-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,o=Infinity,n=0;n<t.length;n++){var r=q({x:e.x,y:e.y},{x:t[n][0],y:t[n][1]});r<o&&(i=n,o=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var o=this.getFeature(this.draggedCoordinate.id);if(!o)return!1;var n=null;if("center"===e?n=this.centerWebMercatorDrag(t):"opposite"===e?n=this.oppositeWebMercatorDrag(t):"center-fixed"===e?n=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(var r=0;r<n.length;r++){var s=n[r];if(s[0]=D(s[0],this.coordinatePrecision),s[1]=D(s[1],this.coordinatePrecision),!B(s,this.coordinatePrecision))return!1}var a=this.midPoints.getUpdated(n)||[],d=this.selectionPoints.getUpdated(n)||[],c=this.coordinatePoints.getUpdated(o.id,n)||[],h={type:o.geometry.type,coordinates:"Polygon"===o.geometry.type?[n]:n};return!(i&&!i({id:this.draggedCoordinate.id,type:"Feature",geometry:h,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:h}].concat(d,a,c)),0))},e}(tt),ne={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]},re={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"},se=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="select",i.allowManualDeselection=!0,i.dragEventThrottle=5,i.dragEventCount=0,i.selected=[],i.flags={},i.keyEvents=ne,i.cursors=re,i.validations={},i.selectionPoints=void 0,i.midPoints=void 0,i.coordinateSnap=void 0,i.featuresAtMouseEvent=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.dragFeature=void 0,i.dragCoordinate=void 0,i.rotateFeature=void 0,i.scaleFeature=void 0,i.dragCoordinateResizeFeature=void 0,i.coordinatePoints=void 0,i.lineSnap=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){if(t.prototype.updateOptions.call(this,e),this.cursors=e&&e.cursors?r({},this.cursors,e.cursors):re,null===(null==e?void 0:e.keyEvents)?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),void 0!==(null==e?void 0:e.dragEventThrottle)&&(this.dragEventThrottle=e.dragEventThrottle),void 0!==(null==e?void 0:e.allowManualDeselection)&&(this.allowManualDeselection=e.allowManualDeselection),null!=e&&e.flags)for(var i in this.flags=r({},this.flags,e.flags),this.validations={},this.flags){var o=this.flags[i].feature;o&&o.validation&&(this.validations[i]=o.validation)}},i.selectFeature=function(t){this.select(t,!1)},i.setSelecting=function(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"},i.registerBehaviors=function(t){this.pixelDistance=new ot(t),this.clickBoundingBox=new it(t),this.featuresAtMouseEvent=new Xt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Kt(t),this.coordinatePoints=new _t(t),this.midPoints=new Yt(t,this.selectionPoints,this.coordinatePoints),this.coordinateSnap=new nt(t,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new Pt(t,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new te(t,this.selectionPoints,this.midPoints,this.coordinatePoints),this.dragFeature=new qt(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints),this.dragCoordinate=new Zt(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap),this.dragCoordinateResizeFeature=new oe(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints),this.scaleFeature=new ee(t,this.dragCoordinateResizeFeature)},i.deselectFeature=function(){this.deselect()},i.deselect=function(){var t=this,e=this.selected.filter(function(e){return t.store.has(e)}).map(function(t){return{id:t,property:c.SELECTED,value:!1}});this.store.updateProperty(e),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},i.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,o=Infinity;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<o&&(o=s,i=e.store.getPropertiesCopy(n))}),i){var n=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(n),a=this.flags[s.mode],d=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var c,h=this.store.getGeometryCopy(n);if("Polygon"===h.type){if((c=h.coordinates[0]).length<=4)return}else if("LineString"===h.type&&(c=h.coordinates).length<=2)return;if(c){if("Polygon"!==h.type||0!==r&&r!==c.length-1?c.splice(r,1):(c.shift(),c.pop(),c.push([c[0][0],c[0][1]])),d&&!d({id:n,type:"Feature",geometry:h,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Commit}).valid)return;var u=[].concat(this.midPoints.ids,this.selectionPoints.ids);this.store.delete(u),this.store.updateGeometry([{id:n,geometry:h}]),s.coordinatePointIds&&this.coordinatePoints.createOrUpdate(n),this.selectionPoints.create(c,h.type,n),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(c,n,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),o=this.flags[i.mode];if(o&&o.feature){var n=this.selected[0];if(n){if(n===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:c.SELECTED,value:!0}]),this.onSelect(t);var r=this.store.getGeometryCopy(t),s=r.type,a=r.coordinates;if("LineString"===s||"Polygon"===s){var d="LineString"===s?a:a[0];d&&o&&o.feature.coordinates&&(this.selectionPoints.create(d,s,t),o.feature.coordinates.midpoints&&this.midPoints.create(d,t,this.coordinatePrecision))}}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,o=e.clickedMidPoint;if(this.selected.length&&o)this.midPoints.insert(this.selected[0],o.id,this.coordinatePrecision);else if(i&&i.id)this.select(i.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;var e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect()},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),o=this.flags[i.mode];if(o&&o.feature&&(o.feature.draggable||o.feature.coordinates&&o.feature.coordinates.draggable||o.feature.coordinates&&o.feature.coordinates.resizable||o.feature.coordinates&&"object"==typeof o.feature.coordinates.midpoints&&o.feature.coordinates.midpoints.draggable)){this.dragEventCount=0;var n=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,n);if(o&&o.feature&&o.feature.coordinates&&(o.feature.coordinates.draggable||o.feature.coordinates.resizable)&&-1!==r)return this.setCursor(this.cursors.dragStart),o.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(n,r):this.dragCoordinate.startDragging(n,r),void e(!1);if(o&&o.feature&&o.feature.coordinates&&"object"==typeof o.feature.coordinates.midpoints&&o.feature.coordinates.midpoints.draggable){var s=this.featuresAtMouseEvent.find(t,this.selected.length>0).clickedMidPoint;if(this.selected.length&&s){this.midPoints.insert(n,s.id,this.coordinatePrecision);var a=this.dragCoordinate.getDraggableIndex(t,n);return this.dragCoordinate.startDragging(n,a),void e(!1)}}return o&&o.feature&&o.feature.draggable&&this.dragFeature.canDrag(t,n)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,n),void e(!1)):void 0}}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)){var i=this.selected[0];if(i){var o=this.store.getPropertiesCopy(i),n=this.flags[o.mode],r=!0===(n&&n.feature&&n.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[o.mode];if(n&&n.feature&&n.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(n&&n.feature&&n.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&n.feature&&n.feature.coordinates&&n.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,n.feature.coordinates.resizable,s)}if(this.dragCoordinate.isDragging()){var a,d=null==(a=n.feature)||null==(a=a.coordinates)?void 0:a.snappable,l={toCoordinate:!1};return!0===d?l={toCoordinate:!0}:"object"==typeof d&&(l=d),void this.dragCoordinate.drag(t,r,s,l)}this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}}},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0))},i.onMouseMove=function(t){var e=this;if(this.selected.length){if(!this.dragFeature.isDragging()){var i=!1;this.midPoints.ids.forEach(function(o){if(!i){var n=e.store.getGeometryCopy(o);e.pixelDistance.measure(t,n.coordinates)<e.pointerDistance&&(i=!0)}});var o=!1;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!1,o=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var n=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(n&&n.id===this.selected[0]||o)?this.cursors.pointerOver:"unset")}}}else this.setCursor("unset")},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties.selectionPoint)return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties.midPoint)return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=50,e}else if(t.properties[c.SELECTED]){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=u,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=u,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=u,e}return e},i.afterFeatureUpdated=function(t){if(this.selected.length&&t.id===this.selected[0]){var e,i,o=this.flags[t.properties.mode];if(null==o||null==(e=o.feature)||!e.coordinates)return;var n,r=t.geometry.type,s=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),"Polygon"===r)n=t.geometry.coordinates[0];else{if("LineString"!==r)return;n=t.geometry.coordinates}this.selectionPoints.create(n,r,s),null!=o&&null!=(i=o.feature)&&null!=(i=i.coordinates)&&i.midpoints&&this.midPoints.create("Polygon"===r?t.geometry.coordinates[0]:t.geometry.coordinates,s,this.coordinatePrecision)}},e}(I),ae=/*#__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=y.Static,e.mode="static",e}s(e,t);var i=e.prototype;return i.start=function(){},i.stop=function(){},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(){return r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0})},e}(P);function de(t,e,i,o,n){for(;o>i;){if(o-i>600){var r=o-i+1,s=e-i+1,a=Math.log(r),d=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*d*(r-d)/r)*(s-r/2<0?-1:1);de(t,e,Math.max(i,Math.floor(e-s*d/r+l)),Math.min(o,Math.floor(e+(r-s)*d/r+l)),n)}var c=t[e],h=i,u=o;for(le(t,i,e),n(t[o],c)>0&&le(t,i,o);h<u;){for(le(t,h,u),h++,u--;n(t[h],c)<0;)h++;for(;n(t[u],c)>0;)u--}0===n(t[i],c)?le(t,i,u):le(t,++u,o),u<=e&&(i=u+1),e<=u&&(o=u-1)}}function le(t,e,i){var o=t[e];t[e]=t[i],t[i]=o}function ce(t,e){he(t,0,t.children.length,e,t)}function he(t,e,i,o,n){n||(n=Ce([])),n.minX=Infinity,n.minY=Infinity,n.maxX=-Infinity,n.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];ue(n,t.leaf?o(s):s)}return n}function ue(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function pe(t,e){return t.minX-e.minX}function ge(t,e){return t.minY-e.minY}function fe(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function ye(t){return t.maxX-t.minX+(t.maxY-t.minY)}function ve(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function me(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Ce(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function Pe(t,e,i,o,n){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=o)){var s=e+Math.ceil((i-e)/o/2)*o;de(t,s,e,i,n),r.push(e,s,s,i)}}var Ie=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!me(t,e))return i;for(var o=this.toBBox,n=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?o(s):s;me(t,a)&&(e.leaf?i.push(s):ve(t,a)?this._all(s,i):n.push(s))}e=n.pop()}return i},e.collides=function(t){var e=this.data;if(me(t,e))for(var i=[];e;){for(var o=0;o<e.children.length;o++){var n=e.children[o],r=e.leaf?this.toBBox(n):n;if(me(t,r)){if(e.leaf||ve(t,r))return!0;i.push(n)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var o=this.data;this.data=i,i=o}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=Ce([])},e.remove=function(t){for(var e,i,o=this.data,n=this.toBBox(t),r=[],s=[],a=!1;o||r.length;){if(o||(o=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),o.leaf){var d=o.children.indexOf(t);-1!==d&&(o.children.splice(d,1),r.push(o),this._condense(r))}a||o.leaf||!ve(o,n)?i?(e++,o=i.children[e],a=!1):o=null:(r.push(o),s.push(e),e=0,i=o,o=o.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,o){var n,r=i-e+1,s=this._maxEntries;if(r<=s)return ce(n=Ce(t.slice(e,i+1)),this.toBBox),n;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),(n=Ce([])).leaf=!1,n.height=o;var a=Math.ceil(r/s),d=a*Math.ceil(Math.sqrt(s));Pe(t,e,i,d,this.compareMinX);for(var l=e;l<=i;l+=d){var c=Math.min(l+d-1,i);Pe(t,l,c,a,this.compareMinY);for(var h=l;h<=c;h+=a){var u=Math.min(h+a-1,c);n.children.push(this._build(t,h,u,o-1))}}return ce(n,this.toBBox),n},e._chooseSubtree=function(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){for(var n=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var d=e.children[a],l=fe(d),c=(h=t,u=d,(Math.max(u.maxX,h.maxX)-Math.min(u.minX,h.minX))*(Math.max(u.maxY,h.maxY)-Math.min(u.minY,h.minY))-l);c<r?(r=c,n=l<n?l:n,s=d):c===r&&l<n&&(n=l,s=d)}e=s||e.children[0]}var h,u;return e},e._insert=function(t,e,i){var o=i?t:this.toBBox(t),n=[],r=this._chooseSubtree(o,this.data,e,n);for(r.children.push(t),ue(r,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)},e._split=function(t,e){var i=t[e],o=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,o);var r=this._chooseSplitIndex(i,n,o),s=Ce(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,ce(i,this.toBBox),ce(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=Ce([t,e]),this.data.height=t.height+1,this.data.leaf=!1,ce(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var o,n,r,s,a,d,l,c=Infinity,h=Infinity,u=e;u<=i-e;u++){var p=he(t,0,u,this.toBBox),g=he(t,u,i,this.toBBox),f=(n=p,r=g,s=Math.max(n.minX,r.minX),a=Math.max(n.minY,r.minY),d=Math.min(n.maxX,r.maxX),l=Math.min(n.maxY,r.maxY),Math.max(0,d-s)*Math.max(0,l-a)),y=fe(p)+fe(g);f<c?(c=f,o=u,h=y<h?y:h):f===c&&y<h&&(h=y,o=u)}return o||i-e},e._chooseSplitAxis=function(t,e,i){var o=t.leaf?this.compareMinX:pe,n=t.leaf?this.compareMinY:ge;this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,n)&&t.children.sort(o)},e._allDistMargin=function(t,e,i,o){t.children.sort(o);for(var n=this.toBBox,r=he(t,0,e,n),s=he(t,i-e,i,n),a=ye(r)+ye(s),d=e;d<i-e;d++){var l=t.children[d];ue(r,t.leaf?n(l):l),a+=ye(r)}for(var c=i-e-1;c>=e;c--){var h=t.children[c];ue(s,t.leaf?n(h):h),a+=ye(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var o=i;o>=0;o--)ue(e[o],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():ce(t[i],this.toBBox)},t}(),Ee=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Ie(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],o=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var n=0;n<e.length;n++)o.push(e[n][1]),i.push(e[n][0]);var r=Math.min.apply(Math,o),s=Math.max.apply(Math,o);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],o=new Set;t.forEach(function(t){var n=e.toBBox(t);if(e.setMaps(t,n),o.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);o.add(String(t.id)),i.push(n)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),xe={getId:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},isValidId:function(t){return"string"==typeof t&&36===t.length}},Se=/*#__PURE__*/function(){function t(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=function(){},this.store={},this.spatialIndex=new Ee,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:xe}var e=t.prototype;return e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.getId=function(){return this.idStrategy.getId()},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e,i,o){var n=this;if(0===t.length)return[];var r=this.clone(t),s=[],a=[];r=r.filter(function(t){null==t.id&&(t.id=n.idStrategy.getId());var i=t.id;if(e){var o=e(t);if(!o.valid)return s.push({id:i,valid:!1,reason:o.reason}),!1}if(n.tracked){if(t.properties.createdAt){if(!f(t.properties.createdAt))return s.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!f(t.properties.updatedAt))return s.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return n.has(i)?(s.push({id:i,valid:!1,reason:"Feature already exists with this id: "+i}),!1):(n.store[i]=t,a.push(t),s.push({id:i,valid:!0}),!0)}),this.spatialIndex.load(r);var d=a.map(function(t){return t.id});return d.length>0&&(this._onChange(d,"create",o),i&&a.forEach(function(t){i(t)})),s},e.search=function(t,e){var i=this,o=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?o.filter(e):o)},e.registerOnChange=function(t){this._onChange=function(e,i,o){t(e,i,o)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t,e){var i=this,o=[];t.forEach(function(t){var e=t.id,n=t.property,r=t.value,s=i.store[e];if(!s)throw new Error("No feature with this ("+e+"), can not update geometry");o.push(e),void 0===r?delete s.properties[n]:s.properties[n]=r,i.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(o,"update",e)},e.updateGeometry=function(t,e){var i=this,o=[];t.forEach(function(t){var e=t.id,n=t.geometry;o.push(e);var r=i.store[e];if(!r)throw new Error("No feature with this ("+e+"), can not update geometry");r.geometry=i.clone(n),i.spatialIndex.update(r),i.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(o,"update",e)},e.create=function(t,e){var i=this,o=[];return t.forEach(function(t){var e,n=t.geometry,s=t.properties,a=r({},s);i.tracked&&(e=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:e,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:e):a={createdAt:e,updatedAt:e});var d=i.getId(),l={id:d,type:"Feature",geometry:n,properties:a};i.store[d]=l,i.spatialIndex.insert(l),o.push(d)}),this._onChange&&this._onChange([].concat(o),"create",e),o},e.delete=function(t,e){var i=this;t.forEach(function(t){if(!i.store[t])throw new Error("No feature with id "+t+", can not delete");delete i.store[t],i.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete",e)},e.copy=function(t){return this.clone(this.store[t])},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.copyAllWhere=function(t){var e=this;return this.clone(Object.keys(this.store).map(function(t){return e.store[t]}).filter(function(e){return e.properties&&t(e.properties)}))},e.clear=function(){this.store={},this.spatialIndex.clear()},e.size=function(){return Object.keys(this.store).length},t}();function Me(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(we(e[0]));for(var o=1;o<e.length;o++)i-=Math.abs(we(e[o]))}return i}var Fe=20294876564838.72,De=Math.PI/180;function we(t){var e=t.length;if(e<=2)return 0;for(var i=0,o=0;o<e;)i+=(t[o+2>=e?(o+2)%e:o+2][0]*De-t[o][0]*De)*Math.sin(t[o+1===e?0:o+1][1]*De),o++;return i*Fe}var Oe="Feature is smaller than the minimum area",ke="Feature is not a Polygon or LineString",_e="Feature intersects itself";function be(t,e,i){var o=dt(t,e),n=dt(e,i)-o;return n<0&&(n+=360),180-Math.abs(n-90-90)}var Ne={cancel:"Escape",finish:"Enter"},Te={start:"crosshair",close:"pointer"},We=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Ne,i.cursors=Te,i.mouseMove=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents))},i.close=function(){if(void 0!==this.currentId){this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0}]);var t=this.currentId;this.currentCoordinate=0,this.currentId=void 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.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i,o,n,r,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var a=1/Math.pow(10,this.coordinatePrecision-1),d=Math.max(1e-6,a);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-d],s[0]]}else if(2===this.currentCoordinate){var c=s[0],h=s[1],u=Lt(c,h,this.coordinatePrecision,this.project,this.unproject),p=_(c[0],c[1]),g=_(u[0],u[1]),f=_(h[0],h[1]),y=_(t.lng,t.lat),v=q(y,p)<q(y,f),m=be(p,g,y),C=v?90-m:be(p,g,y)-90,P=q(g,y),I=Math.cos(S(C))*P,E=dt(p,f)+("right"==((r=((n=y).x-(o=f).x)*((i=p).y-o.y)-(n.y-o.y)*(i.x-o.x))>1e-10?"left":r<-1e-10?"right":"left")?-90:90),x=st(p,I,E),M=st(f,I,E),F=b(x.x,x.y),w=b(M.x,M.y);e=[s[0],s[1],[D(w.lng,this.coordinatePrecision),D(w.lat,this.coordinatePrecision)],[D(F.lng,this.coordinatePrecision),D(F.lat,this.coordinatePrecision)],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,l.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e)}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var o=this.store.getGeometryCopy(this.currentId);if(gt([t.lng,t.lat],o.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]],l.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){if(t.key===this.keyEvents.cancel)this.cleanUp();else if(t.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return K(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},e}(P);function je(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var Be={cancel:"Escape",finish:"Enter"},Ge={start:"crosshair",close:"pointer"},Re=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sector",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Be,i.direction=void 0,i.arcPoints=64,i.cursors=Ge,i.mouseMove=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.close=function(){if(void 0!==this.currentId){var t=Z(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}]),this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0}]);var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"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){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var o=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,o);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-n],i[0]]}else if(2===this.currentCoordinate){var r=i[0],s=i[1],a=[t.lng,t.lat],d=_(r[0],r[1]),c=_(s[0],s[1]),h=_(a[0],a[1]);if(void 0===this.direction){var u=je(d,c,h);this.direction=u?"clockwise":"anticlockwise"}var p,g=q(d,c),f=dt(d,c),y=dt(d,h),v=this.arcPoints,m=[r],C=lt(f),P=lt(y);"anticlockwise"===this.direction?(p=P-C)<0&&(p+=360):(p=C-P)<0&&(p+=360);var I=("anticlockwise"===this.direction?1:-1)*p/v;m.push(s);for(var E=0;E<=v;E++){var x=st(d,g,C+E*I),S=b(x.x,x.y),M=S.lat,F=[D(S.lng,this.coordinatePrecision),D(M,this.coordinatePrecision)];F[0]!==m[m.length-1][0]&&F[1]!==m[m.length-1][1]&&m.push(F)}m.push(r),e=[].concat(m)}e&&this.updatePolygonGeometry(this.currentId,e,l.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e)}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var o=this.store.getGeometryCopy(this.currentId);if(gt([t.lng,t.lat],o.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]],l.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return K(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},e}(P),Ue={cancel:"Escape",finish:"Enter"},Le={start:"crosshair",close:"pointer"},Ae=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=Ue,i.direction=void 0,i.arcPoints=64,i.cursors=Le,i.mouseMove=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.close=function(){if(void 0!==this.currentStartingPointId){var t=this.currentStartingPointId,e=this.currentInitialArcId,i=this.currentId;if(t&&this.store.delete([t]),e&&this.store.delete([e]),this.currentId){var o=Z(this.store.getGeometryCopy(this.currentId));o&&this.store.updateGeometry([{id:this.currentId,geometry:o}]),this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0}])}this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),i&&this.onFinish(i,{mode:this.mode,action:"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){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentInitialArcId&&void 0!==this.currentStartingPointId&&0!==this.currentCoordinate)if(2===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentInitialArcId).coordinates,i=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,o=e[0],n=[t.lng,t.lat],r=_(o[0],o[1]),s=_(n[0],n[1]),a=_(i[0],i[1]),d=q(a,r);if(void 0===this.direction){var c=je(a,r,s);this.direction=c?"clockwise":"anticlockwise"}var u,p=dt(a,r),g=dt(a,s),f=this.arcPoints,y=[o],v=lt(p),m=lt(g);"anticlockwise"===this.direction?(u=m-v)<0&&(u+=360):(u=v-m)<0&&(u+=360);for(var C=("anticlockwise"===this.direction?1:-1)*u/f,P=0;P<=f;P++){var I=st(a,d,v+P*C),E=b(I.x,I.y),x=E.lat,S=[D(E.lng,this.coordinatePrecision),D(x,this.coordinatePrecision)];S[0]!==y[y.length-1][0]&&S[1]!==y[y.length-1][1]&&y.push(S)}this.updateLineStringGeometry(this.currentInitialArcId,y,l.Provisional)}else if(3===this.currentCoordinate){var M=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(M.length<2)return;if(!this.direction)return;var F=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,w=M[0],O=M[M.length-1],k=_(t.lng,t.lat),N=_(w[0],w[1]),T=_(O[0],O[1]),W=_(F[0],F[1]),j=q(W,N),B=q(W,k)<j?N:k,G=dt(W,k),R=dt(W,N),U=dt(W,T),L=lt(R),A=lt(U),V=lt(G);if(this.notInSector({normalizedCursor:V,normalizedStart:L,normalizedEnd:A,direction:this.direction}))return;for(var Y=this.getDeltaBearing(this.direction,L,A),K=this.arcPoints,z=("anticlockwise"===this.direction?1:-1)*Y/K,H=q(W,B),X=[],Z=0;Z<=K;Z++){var J=st(W,H,L+Z*z),$=b(J.x,J.y),Q=$.lat,tt=[D($.lng,this.coordinatePrecision),D(Q,this.coordinatePrecision)];tt[0]!==M[M.length-1][0]&&tt[1]!==M[M.length-1][1]&&X.unshift(tt)}if(M.push.apply(M,X),M.push(M[0]),this.currentId)this.updatePolygonGeometry(this.currentId,M,l.Provisional);else{var et,it=this.store.create([{geometry:{type:"Polygon",coordinates:[M]},properties:(et={mode:this.mode},et[h.CURRENTLY_DRAWING]=!0,et)}]);this.currentId=it[0]}}},i.updateLineStringGeometry=function(t,e,i){var o={type:"LineString",coordinates:e};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.currentStartingPointId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:{mode:this.mode}}]);this.currentInitialArcId=i[0],this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&("Polygon"===t.geometry.type?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=u):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=u):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=20)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return K(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.getDeltaBearing=function(t,e,i){var o;return"anticlockwise"===t?(o=i-e)<0&&(o+=360):(o=e-i)<0&&(o+=360),o},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,o=t.normalizedEnd;return"clockwise"===t.direction?i<=o?e>=i&&e<=o:e>=i||e<=o:i>=o?e<=i&&e>=o:e<=i||e>=o},e}(P),Ve=function(t){var e=this,i=t.name,o=t.callback,n=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(o))},this.unregister=function(){e.register&&(e.registered=!1,n(o))},this.callback=o},Ye={__proto__:null,GeoJSONStore:Se,TerraDrawBaseDrawMode:P,TerraDrawBaseSelectMode:I,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(t){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._ignoreMismatchedPointerEvents="boolean"==typeof t.ignoreMismatchedPointerEvents&&t.ignoreMismatchedPointerEvents,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement().getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t,e){void 0===e&&(e=!1);var i=this.getLngLatFromEvent(t);if(!i)return null;var o=i.lng,n=i.lat,r=this.getMapElementXYPosition(t),s=r.containerX,a=r.containerY,d=this.getButton(t),l=Array.from(this._heldKeys);return{lng:D(o,this._coordinatePrecision),lat:D(n,this._coordinatePrecision),containerX:s,containerY:a,button:d,heldKeys:l,isContextMenu:e}},e.register=function(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(function(t){t.register()})},e.getCoordinatePrecision=function(){return this._coordinatePrecision},e.getAdapterListeners=function(){var t=this;return[new Ve({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i,t._lastPointerDownEventTarget=e.target?e.target:void 0)}},register:function(e){t.getMapEventElement().addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerdown",e)}}),new Ve({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var o={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},n={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=q(o,n);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._nextKeyUpIsContextMenu=!1,t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new Ve({name:"contextmenu",callback:function(e){t._currentModeCallbacks&&(e.preventDefault(),t._nextKeyUpIsContextMenu=!0)},register:function(e){t.getMapEventElement().addEventListener("contextmenu",e)},unregister:function(e){t.getMapEventElement().removeEventListener("contextmenu",e)}}),new Ve({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement()&&(!t._ignoreMismatchedPointerEvents||t._lastPointerDownEventTarget===e.target)&&(t._lastPointerDownEventTarget=void 0,e.isPrimary)){var i=t.getDrawEventFromEvent(e);i&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(i,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||(t._nextKeyUpIsContextMenu&&(i.isContextMenu=!0,t._nextKeyUpIsContextMenu=!1),t._currentModeCallbacks.onClick(i)),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement().addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerup",e)}}),new Ve({name:"keyup",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.delete(e.key),t._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement().addEventListener("keyup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("keyup",e)}}),new Ve({name:"keydown",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.add(e.key),t._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement().addEventListener("keydown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("keydown",e)}})]},e.unregister=function(){this._listeners.forEach(function(t){t.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1},t}(),getDefaultStyling:function(){return{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0}},SELECT_PROPERTIES:c},Ke={ValidationReasonFeatureNotPoint:St,ValidationReasonFeatureInvalidCoordinates:Mt,ValidationReasonFeatureInvalidCoordinatePrecision:Ft,ValidationReasonFeatureNotPolygon:v,ValidationReasonFeatureHasHoles:U,ValidationReasonFeatureLessThanFourCoordinates:L,ValidationReasonFeatureHasInvalidCoordinates:A,ValidationReasonFeatureCoordinatesNotClosed:V,ValidationReasonFeatureNotPolygonOrLineString:ke,ValidationReasonFeatureSelfIntersects:_e,ValidationReasonFeatureLessThanMinSize:Oe,ValidationReasonModeMismatch:m},ze={cancel:"Escape",finish:"Enter"},He={start:"crosshair",close:"pointer"},Xe=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand-linestring",i.startingClick=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=20,i.keyEvents=ze,i.cursors=He,i.preventNewFeature=!1,i.updateOptions(e),i}s(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),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors))},i.close=function(){if(void 0!==this.currentId){this.currentId&&this.store.updateProperty([{id:this.currentId,property:h.CURRENTLY_DRAWING,value:void 0}]);var t=this.currentId;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:l.Finish}).valid)return}this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 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.onMouseMove=function(t){if(void 0!==this.currentId&&!1!==this.startingClick){var e=this.store.getGeometryCopy(this.currentId),i=e.coordinates[e.coordinates.length-2],o=this.project(i[0],i[1]),n=q({x:o.x,y:o.y},{x:t.containerX,y:t.containerY}),r=e.coordinates[e.coordinates.length-1],s=this.project(r[0],r[1]),a=q({x:s.x,y:s.y},{x:t.containerX,y:t.containerY});if(this.setCursor(a<this.pointerDistance?this.cursors.close:this.cursors.start),!(n<this.minDistance)){var d={type:"LineString",coordinates:[].concat(e.coordinates,[[t.lng,t.lat]])};if(this.validate&&!this.validate({type:"Feature",id:this.currentId,geometry:d,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:d}]),this.closingPointId&&this.store.updateGeometry([{id:this.closingPointId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}])}}else this.setCursor(this.cursors.start)},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,o=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:(e={mode:this.mode},e[h.CURRENTLY_DRAWING]=!0,e)},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(i={mode:this.mode},i[h.CLOSING_POINT]=!0,i)}]),n=o[1];return this.currentId=o[0],this.closingPointId=n,this.startingClick=!0,void("drawing"!==this.state&&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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode?(e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=u,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 ft(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0)},e}(P);function qe(t){if(null===t)return!0;if("boolean"==typeof t)return!0;if("string"==typeof t)return!0;if(void 0===t)return!1;if("number"==typeof t)return Number.isFinite(t);if("bigint"==typeof t)return!1;if("symbol"==typeof t)return!1;if("function"==typeof t)return!1;if(t instanceof RegExp)return!1;if(t instanceof Map)return!1;if(t instanceof Set)return!1;if(t instanceof Date)return!1;if("object"==typeof t&&null!==t&&!Array.isArray(t)){var e=Object.getPrototypeOf(t);if(e!==Object.prototype&&null!==e)return!1}if(ArrayBuffer.isView(t)&&!(t instanceof DataView))return!1;if(Array.isArray(t))for(var i,o=n(t);!(i=o()).done;)if(!qe(i.value))return!1;return"object"==typeof t&&Object.keys(t).every(function(e){return"string"==typeof e&&qe(t[e])})}var Ze={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},Je=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="marker",i.cursors=Ze,i.editable=!1,i.editedFeatureId=void 0,i.markerUrl=void 0,i.markerHeight=void 0,i.markerWidth=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},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:l.Finish}).valid)return;this.store.updateGeometry([{id:this.editedFeatureId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:h.EDITED,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:h.EDITED,value:!1}]),this.editedFeatureId=void 0,e(!0))},i.registerBehaviors=function(t){this.pixelDistance=new ot(t),this.clickBoundingBox=new it(t)},i.styleFeature=function(t){var e,i,o,n=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(n.zIndex=30,n.markerHeight=this.getNumericStylingValue(null==(e=this.styles)?void 0:e.markerHeight,30,t),n.markerWidth=this.getNumericStylingValue(null==(i=this.styles)?void 0:i.markerWidth,30,t),n.markerUrl=this.getUrlStylingValue(null==(o=this.styles)?void 0:o.markerUrl,"",t)),n},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Dt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e={type:"Point",coordinates:[t.lng,t.lat]},i={mode:this.mode,markerUrl:this.markerUrl,markerHeight:this.markerHeight,markerWidth:this.markerWidth};if(!this.validate||this.validate({type:"Feature",geometry:e,properties:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.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},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(P);t.TerraDraw=/*#__PURE__*/function(){function t(t){var e=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectMode=void 0,this._adapter=t.adapter,this._mode=new ae;var i=new Set,o=t.modes.reduce(function(t,e){if(i.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return i.add(e.mode),t[e.mode]=e,t},{}),n=Object.keys(o);if(0===n.length)throw new Error("No modes provided");n.forEach(function(t){if(o[t].type===y.Select){if(e._instanceSelectMode)throw new Error("only one type of select mode can be provided");e._instanceSelectMode=t}}),this._modes=r({},o,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[]},this._store=new Se({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],o=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:o}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},d=function(t,i,o){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i,o)});var n=s(t),r=n.changed,a=n.unchanged;"create"===i?e._adapter.render({created:r,deletedIds:[],unchanged:a,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:a,updated:r},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:a,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:a,updated:[]},e.getModeStyles())}},l=function(t){if(e._enabled){e._eventListeners.select.forEach(function(e){e(t)});var i=s([t]);e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:i.changed},e.getModeStyles())}},c=function(t){if(e._enabled){e._eventListeners.deselect.forEach(function(t){t()});var i=s([t]),o=i.changed;o&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:o},e.getModeStyles())}};Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor.bind(e._adapter),project:e._adapter.project.bind(e._adapter),unproject:e._adapter.unproject.bind(e._adapter),setDoubleClickToZoom:e._adapter.setDoubleClickToZoom.bind(e._adapter),onChange:d,onSelect:l,onDeselect:c,onFinish:a,coordinatePrecision:e._adapter.getCoordinatePrecision()})})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(i){e[i]=function(e){return t._instanceSelectMode&&e.properties[c.SELECTED]?t._modes[t._instanceSelectMode].styleFeature.bind(t._modes[t._instanceSelectMode])(e):t._modes[i].styleFeature.bind(t._modes[i])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,r=e&&void 0!==e.pointerDistance?e.pointerDistance:30,s=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,a=!(!e||void 0===e.ignoreCoordinatePoints)&&e.ignoreCoordinatePoints,d=!(!e||void 0===e.ignoreCurrentlyDrawing)&&e.ignoreCurrentlyDrawing,l=!(!e||void 0===e.ignoreClosingPoints)&&e.ignoreClosingPoints,u=!(!e||void 0===e.ignoreSnappingPoints)&&e.ignoreSnappingPoints,p=this._adapter.unproject.bind(this._adapter),g=this._adapter.project.bind(this._adapter),f=g(i,o),y=et({unproject:p,point:f,pointerDistance:r});return this._store.search(y).filter(function(t){if(s&&(t.properties[c.MID_POINT]||t.properties[c.SELECTION_POINT]))return!1;if(a&&t.properties[h.COORDINATE_POINT])return!1;if(l&&t.properties[h.CLOSING_POINT])return!1;if(d&&t.properties[h.CURRENTLY_DRAWING])return!1;if(u&&t.properties[h.SNAPPING_POINT])return!1;if("Point"===t.geometry.type){var p=t.geometry.coordinates,y=g(p[0],p[1]);return q(f,y)<r}if("LineString"===t.geometry.type){for(var v=t.geometry.coordinates,m=0;m<v.length-1;m++){var C=v[m],P=v[m+1];if(Ht(f,g(C[0],C[1]),g(P[0],P[1]))<r)return!0}return!1}if(zt([i,o],t.geometry.coordinates))return!0;if(null!=e&&e.includePolygonsWithinPointerDistance)for(var I,E=n(t.geometry.coordinates);!(I=E()).done;)for(var x=I.value,S=0;S<x.length-1;S++){var M=x[S],F=x[S+1],D=g(M[0],M[1]),w=g(F[0],F[1]);if(Ht(f,D,w)<r)return!0}return!1}).map(function(t){if(null==e||!e.addClosestCoordinateInfoToProperties)return t;var n;if("Polygon"===t.geometry.type)n=t.geometry.coordinates[0].slice(0,-1);else{if("LineString"!==t.geometry.type)return t;n=t.geometry.coordinates}for(var r,s=-1,a=Infinity,d=0;d<n.length;d++){var l=n[d],c=q(g(l[0],l[1]),f);c<a&&(s=d,a=c,r=l)}return t.properties.closestCoordinateIndexToEvent=s,t.properties.closestCoordinatePixelDistanceToEvent=a,t.properties.closestCoordinateDistanceKmToEvent=E(r,[i,o]),t})},e.getSelectModeOrThrow=function(){var t=this.getSelectMode({switchToSelectMode:!0});if(!t)throw new Error("No select mode defined in instance");return t},e.getSelectMode=function(t){var e=t.switchToSelectMode;if(this.checkEnabled(),!this._instanceSelectMode)return null;var i=this.getMode();return e&&i!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},e.isGuidanceFeature=function(t){return Boolean(t.properties[c.MID_POINT]||t.properties[c.SELECTION_POINT]||t.properties[h.COORDINATE_POINT]||t.properties[h.SNAPPING_POINT])},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.updateModeOptions=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].updateOptions(e)},e.getSnapshot=function(){return this._store.copyAll()},e.getSnapshotFeature=function(t){if(this._store.has(t))return this._store.copy(t)},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},e.getModeState=function(){return this._mode.state},e.setMode=function(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},e.removeFeatures=function(t){var e=this;this.checkEnabled();var i=[];t.forEach(function(t){if(!e._store.has(t))throw new Error("No feature with id "+t+", can not delete");var o=e._store.copy(t);o.properties[c.SELECTED]&&e.deselectFeature(t),o.properties[h.COORDINATE_POINT_IDS]&&i.push.apply(i,o.properties[h.COORDINATE_POINT_IDS])}),this._store.delete([].concat(t,i),{origin:"api"})},e.selectFeature=function(t){this.getSelectModeOrThrow().selectFeature(t)},e.deselectFeature=function(t){this.getSelectModeOrThrow().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.checkIsReservedProperty=function(t){return![].concat(Object.values(c),Object.values(h)).includes(t)},e.updateFeatureProperties=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");var n=o.properties.mode;if(!this._modes[n])throw new Error("No mode with name "+n+" present in instance");var r=Object.entries(e);r.forEach(function(t){var e=t[0],o=t[1];if(!i.checkIsReservedProperty(e))throw new Error("You are trying to update a reserved property name: "+e+". Please choose another name.");if(void 0!==o&&!qe(o))throw new Error("Invalid JSON value provided for property "+e)}),this._store.updateProperty(r.map(function(t){return{id:o.id,property:t[0],value:t[1]}}),{origin:"api"})},e.updateFeatureGeometry=function(t,e){if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var i=this._store.copy(t);if(this.isGuidanceFeature(i))throw new Error("Guidance features are not allowed to be updated directly.");if(!(i&&e&&e.type&&e.coordinates))throw new Error("Invalid geometry provided");if(e.type!==i.geometry.type)throw new Error("Geometry type mismatch: expected "+i.geometry.type+", got "+e.type);var o=i.properties.mode,n=this._modes[o];if(!n)throw new Error("No mode with name "+o+" present in instance");var s=r({},i,{geometry:e}),a=n.validateFeature(s);if(!a.valid)throw new Error("Feature validation failed: "+(a.reason||"Unknown reason"));if(this._store.updateGeometry([{id:i.id,geometry:e}],{origin:"api"}),n.afterFeatureUpdated){n.afterFeatureUpdated(s);var d=s.properties[c.SELECTED],l=this.getSelectMode({switchToSelectMode:!1});l&&d&&l.afterFeatureUpdated(s)}},e.transformFeatureGeometry=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");var n,r=o.properties.mode,s=this._modes[r];if(!s)throw new Error("No mode with name "+r+" present in instance");if("Polygon"===o.geometry.type)n=o.geometry.coordinates[0];else{if("LineString"!==o.geometry.type)throw new Error("Feature geometry type "+o.geometry.type+" is not supported for transformation");n=o.geometry.coordinates}if("web-mercator"!=e.projection)throw new Error("Projection "+e.projection+" is not currently supported for transformation");if("scale"===e.type){var a=_(e.origin[0],e.origin[1]);ie({coordinates:n,originX:a.x,originY:a.y,xScale:e.options.xScale||1,yScale:e.options.yScale||1})}else"rotate"===e.type&&(n="Polygon"===(o=$t(o,e.options.angle||0)).geometry.type?o.geometry.coordinates[0]:o.geometry.coordinates);if(n=n.map(function(t){return[D(t[0],i._adapter.getCoordinatePrecision()),D(t[1],i._adapter.getCoordinatePrecision())]}),o.geometry.coordinates="Polygon"===o.geometry.type?[n]:n,this._store.updateGeometry([{id:o.id,geometry:o.geometry}],{origin:"api"}),s.afterFeatureUpdated){s.afterFeatureUpdated(o);var d=o.properties[c.SELECTED],l=this.getSelectMode({switchToSelectMode:!1});l&&d&&l.afterFeatureUpdated(o)}},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(g(t)){var i=t.properties.mode,o=e._modes[i];if(!o)return{id:t.id,valid:!1,reason:i+" mode is not in the list of instantiated modes"};var n=o.validateFeature.bind(o)(t);return{id:t.id,valid:n.valid,reason:n.reason?n.reason:n.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}},function(t){if(g(t)){var i=e._modes[t.properties.mode];i&&i.afterFeatureAdded&&i.afterFeatureAdded(t)}},{origin:"api"})},e.start=function(){var t=this;this._enabled||(this._enabled=!0,this._adapter.register({onReady:function(){t._eventListeners.ready.forEach(function(t){t()})},getState:function(){return t._mode.state},onClick:function(e){t._mode.onClick(e)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyDown:function(e){t._mode.onKeyDown(e)},onKeyUp:function(e){t._mode.onKeyUp(e)},onDragStart:function(e,i){t._mode.onDragStart(e,i)},onDrag:function(e,i){t._mode.onDrag(e,i)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)},onClear:function(){t._mode.cleanUp(),t._store.clear()}}))},e.getFeaturesAtLngLat=function(t,e){return this.featuresAtLocation({lng:t.lng,lat:t.lat},e)},e.getFeaturesAtPointerEvent=function(t,e){var i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)},e.stop=function(){this._enabled&&(this._enabled=!1,this._adapter.unregister())},e.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},e.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},o(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}])}(),t.TerraDrawAngledRectangleMode=We,t.TerraDrawCircleMode=X,t.TerraDrawExtend=Ye,t.TerraDrawFreehandLineStringMode=Xe,t.TerraDrawFreehandMode=Q,t.TerraDrawLineStringMode=xt,t.TerraDrawMarkerMode=Je,t.TerraDrawPointMode=Ot,t.TerraDrawPolygonMode=Tt,t.TerraDrawRectangleMode=Bt,t.TerraDrawRenderMode=Gt,t.TerraDrawSectorMode=Re,t.TerraDrawSelectMode=se,t.TerraDrawSensorMode=Ae,t.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:v}:Me(t.geometry)>e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0}},t.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:v}:Me(t.geometry)<e?{valid:!1,reason:Oe}:{valid:!0}},t.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:ke}:W(t)?{valid:!1,reason:_e}:{valid:!0}},t.ValidationReasons=Ke});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).terraDraw={})}(this,function(t){function e(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 i(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,d(o.key),o)}}function o(t,e,o){return e&&i(t.prototype,e),o&&i(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t,i){var o="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(o)return(o=o.call(t)).next.bind(o);if(Array.isArray(t)||(o=function(t,i){if(t){if("string"==typeof t)return e(t,i);var o={}.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(t,i):void 0}}(t))||i&&t&&"number"==typeof t.length){o&&(t=o);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[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 r(){return r=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},r.apply(null,arguments)}function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function d(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 l;!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(l||(l={}));var c="https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png",h={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},u={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"},p=10;function g(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function f(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function y(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var v,m="Feature is not a Polygon",C="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"}(v||(v={}));var P={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},I=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=P,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=v.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=r({},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.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(g(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(g(t.geometry))if(g(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:l.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:C}:{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.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?t(i):t},o(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}}])}(),E=/*#__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=v.Select,e}return s(e,t),e}(I);function x(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 S=6371008.8;function M(t){return t%360*Math.PI/180}function D(t){return t/6371.0088}function F(t){return t%(2*Math.PI)*180/Math.PI}function w(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var O=57.29577951308232,k=.017453292519943295,_=6378137,b=function(t,e){return{x:0===t?0:t*k*_,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*k/2))*_}},N=function(t,e){return{lng:0===t?0:O*(t/_),lat:0===e?0:(2*Math.atan(Math.exp(e/_))-Math.PI/2)*O}};function T(t,e,i){var o=M(t[0]),n=M(t[1]),r=M(i),s=D(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[F(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),F(a)]}function W(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=T(e,i,-360*s/n);r.push([w(a[0],o),w(a[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function j(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(B(t,i)||B(t,o)||B(e,i)||B(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 B(t,e){return t[0]===e[0]&&t[1]===e[1]}function G(t,e){return U(t[0])<=e&&U(t[1])<=e}function R(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 U(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var L="Feature has holes",A="Feature has less than 4 coordinates",V="Feature has invalid coordinates",Y="Feature coordinates are not closed";function K(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:L};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:A};for(var i=0;i<t.geometry.coordinates[0].length;i++){if(!R(t.geometry.coordinates[0][i]))return{valid:!1,reason:V};if(!G(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:Y}:{valid:!0};var o,n}function z(t,e){var i=K(t,e);return i.valid?j(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var H={cancel:"Escape",finish:"Enter"},X={start:"crosshair"},q=/*#__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=H,i.cursors=X,i.startingRadiusKilometers=1e-5,i.cursorMovedAfterInitialCursorDown=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers)},i.close=function(){if(void 0!==this.currentCircleId){this.store.updateProperty([{id:this.currentCircleId,property:u.CURRENTLY_DRAWING,value:void 0}]);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:l.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){var e;this.center=[t.lng,t.lat];var i=W({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.store.create([{geometry:i.geometry,properties:(e={mode:this.mode,radiusKilometers:this.startingRadiusKilometers},e[u.CURRENTLY_DRAWING]=!0,e)}]);this.currentCircleId=o[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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return z(t,e.coordinatePrecision)})},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=x(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var o=function(t,e){var i=1e3*x(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=N(s+h,a+u),g=p.lat;d.push([w(p.lng,i),w(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=W({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:l.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},i.afterFeatureUpdated=function(t){this.currentCircleId===t.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted())},e}(I),Z=function(t,e){var i=e.x-t.x,o=e.y-t.y;return Math.sqrt(o*o+i*i)};function J(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 $={cancel:"Escape",finish:"Enter"},Q={start:"crosshair",close:"pointer"},tt=/*#__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=$,i.cursors=Q,i.preventPointsNearClose=!0,i.autoClose=!1,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1,i.updateOptions(e),i}s(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=r({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors))},i.close=function(){if(void 0!==this.currentId){if(this.currentId){var t=J(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}]),this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0}])}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:l.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=Z({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(Z({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 d={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:d,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:d}])}}else this.setCursor(this.cursors.start)},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,o=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e)},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(i={mode:this.mode},i[u.CLOSING_POINT]=!0,i)}]),n=o[1];return this.currentId=o[0],this.closingPointId=n,this.startingClick=!0,void("drawing"!==this.state&&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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p,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 K(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)},e}(I),et=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 it(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 ot=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return s(e,t),e.prototype.create=function(t){return it({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(et),nt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return s(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return Z({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(et),rt=/*#__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 s(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}(et);function st(t,e,i){var o=M(t[0]),n=M(t[1]),r=M(i),s=D(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[F(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),F(a)]}function at(t,e,i){var o=t.x,n=t.y,r=M(i);return{x:o+e*Math.cos(r),y:n+e*Math.sin(r)}}function dt(t,e){var i=M(t[0]),o=M(e[0]),n=M(t[1]),r=M(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 F(Math.atan2(s,a))}function lt(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 ct(t){return(t+360)%360}function ht(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=dt(t[l],t[l-1])-180,r=st(t[l],o,n),s.push(r)}if(d>=i)return(o=i-d)?(n=dt(t[l],t[l-1])-180,r=st(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+=x(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 ut(t){return t*(Math.PI/180)}function pt(t){return t*(180/Math.PI)}var gt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}s(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+=x(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=ht(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=x(t,e),n=function(t,e,i){var o=[],n=ut(t[1]),r=ut(t[0]),s=ut(e[1]),a=ut(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([pt(v),pt(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[w(t[0],e.config.coordinatePrecision),w(t[1],e.config.coordinatePrecision)]})},e}(et);function ft(t,e){return t[0]===e[0]&&t[1]===e[1]}function yt(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(!R(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!G(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function vt(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function mt(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(vt(t)*vt(e));return Math.acos(Math.min(Math.max(i,-1),1))}function Ct(t){var e=M(t[1]),i=M(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function Pt(t){var e=t[0],i=t[1],o=F(Math.asin(t[2]));return[F(Math.atan2(i,e)),o]}var It=/*#__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){var e=n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)});return e.coordinate?[w(e.coordinate[0],n.config.coordinatePrecision),w(e.coordinate[1],n.config.coordinatePrecision)]:void 0},n.getSnappableCoordinate=function(t,e){var i=n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)});return i.coordinate?[w(i.coordinate[0],n.config.coordinatePrecision),w(i.coordinate[1],n.config.coordinatePrecision)]:void 0},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return s(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 l=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,o,r,s,a,d,l,c,h=[Infinity,Infinity],u=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=b(y[0],y[1]),I=b(v[0],v[1]),E=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 x=(l=(d={x:(s=E).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,c=Math.max(0,Math.min(1,l/(a.x*a.x+a.y*a.y))),{x:o.x+c*a.x,y:o.y+c*a.y}),S=N(x.x,x.y);m=[S.lng,S.lat]}m&&(C=Z(E,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,o=[Infinity,Infinity],r=Infinity,s=0,a=n(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,D=Ct(p),F=Ct(g),w=Ct(f),O=w[0],k=w[1],_=w[2],b=[(C=(y=D)[1])*(S=(v=F)[2])-(P=y[2])*(E=v[1]),P*(I=v[0])-(m=y[0])*S,m*E-C*I],N=b[0],T=b[1],W=b[2],j=T*_-W*k,B=W*O-N*_,G=N*k-T*O,R=G*T-B*W,U=j*W-G*N,L=B*N-j*T,A=1/Math.sqrt(Math.pow(R,2)+Math.pow(U,2)+Math.pow(L,2)),V=[R*A,U*A,L*A],Y=[-1*R*A,-1*U*A,-1*L*A],K=mt(D,F),z=mt(D,V),H=mt(F,V),X=mt(D,Y),q=mt(F,Y),mt(D,M=z<X&&z<q||H<X&&H<q?V:Y)>K||mt(F,M)>K?x(Pt(M),Pt(D))<=x(Pt(M),Pt(F))?[Pt(D),!0,!1]:[Pt(F),!1,!0]:[Pt(M),!1,!1])[0])&&(u=x(t,d))<r&&(o=d,r=u,s=e.indexOf(l))}var p,g,f,y,v,m,C,P,I,E,S,M,D,F,w,O,k,_,b,N,T,W,j,B,G,R,U,L,A,V,Y,K,z,H,X,q;return Infinity===r?void 0:{coordinate:o,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=[w(r.coordinate[0],i.config.coordinatePrecision),w(r.coordinate[1],i.config.coordinatePrecision)],s.featureCoordinateIndex=r.lineIndex,s.minDistance=c)}}),s},e}(et),Et={cancel:"Escape",finish:"Enter"},xt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},St=/*#__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=Et,i.snapping=void 0,i.cursors=xt,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommittedCoordinates=void 0,i.snappedPointId=void 0,i.lastMouseMoveEvent=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}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},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=r({},this.keyEvents,e.keyEvents)),null!=e&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable)},i.updateSnappedCoordinate=function(t){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.SNAPPING_POINT]=!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);return e},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,l.Commit),this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0}]);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.lastCommittedCoordinates=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.lastCommittedCoordinates=o.coordinates),this.store.updateGeometry(n)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=x(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,i=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e)}])[0];this.lastCommittedCoordinates=[t,t],this.currentId=i,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){var e;if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:(e={mode:this.mode},e[u.CLOSING_POINT]=!0,e)}]);this.closingPointId=o[0],this.setCursor(this.cursors.close);var n=[].concat(i,[t]);this.updateGeometries(n,void 0,l.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.lastCommittedCoordinates?this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1]:i[i.length-2],n=this.project(o[0],o[1]);if(Z({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],l.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.coordinateSnapping=new rt(t,new nt(t),new ot(t)),this.insertPoint=new gt(t),this.clickBoundingBox=new ot(t),this.pixelDistance=new nt(t),this.lineSnapping=new It(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new rt(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),this.lastMouseMoveEvent=t;var e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var i=this.store.getGeometryCopy(this.currentId).coordinates;if(i.pop(),this.closingPointId){var o=i[i.length-1],n=this.project(o[0],o[1]);Z({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var r=[].concat(i,[e]);if(this.insertCoordinates&&this.currentId&&this.lastCommittedCoordinates){var s=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1],a=e;if(!ft(s,a)){var d=this.generateInsertCoordinates(s,a);r=[].concat(this.lastCommittedCoordinates.slice(0,-1),d,[e])}}this.updateGeometries(r,void 0,l.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:l.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[u.EDITED]=!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:l.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:u.EDITED,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:u.EDITED,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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 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=p,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[u.CLOSING_POINT];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 yt(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},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&this.editedPointId&&(this.store.delete([this.editedPointId]),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.closingPointId&&(this.store.delete([this.closingPointId]),this.closingPointId=void 0),this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted())},e}(I),Mt="Feature is not a Point",Dt="Feature has invalid coordinates",Ft="Feature has coordinates with excessive precision";function wt(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:Mt}:R(t.geometry.coordinates)?G(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:Ft}:{valid:!1,reason:Dt}}var Ot={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},kt=/*#__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}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},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:l.Finish}).valid)return;this.store.updateGeometry([{id:this.editedFeatureId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:u.EDITED,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:u.EDITED,value:!1}]),this.editedFeatureId=void 0,e(!0))},i.registerBehaviors=function(t){this.pixelDistance=new nt(t),this.clickBoundingBox=new ot(t)},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 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 wt(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:l.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},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(I),_t=/*#__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}s(e,t);var i=e.prototype;return i.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[u.CLOSING_POINT]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(o={mode:e},o[u.CLOSING_POINT]=!0,o)}])},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},i.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]}}])},i.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}},o(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(et),bt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}s(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=n(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:r({},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[u.COORDINATE_POINT]=!0,n[u.COORDINATE_POINT_FEATURE_ID]=i,n.index=o,n)}}))},i.setFeatureCoordinatePoints=function(t,e){this.store.updateProperty([{id:t,property:u.COORDINATE_POINT_IDS,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}(et),Nt={cancel:"Escape",finish:"Enter"},Tt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Wt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Nt,i.cursors=Tt,i.mouseMove=!1,i.showCoordinatePoints=!1,i.lastMouseMoveEvent=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinatePoints=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.clickBoundingBox=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){var i=this;if(t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.snapping&&(this.snapping=e.snapping),void 0!==(null==e?void 0:e.editable)&&(this.editable=e.editable),void 0!==(null==e?void 0:e.pointerEvents)&&(this.pointerEvents=e.pointerEvents),void 0!==(null==e?void 0:e.showCoordinatePoints))if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(function(t){return t.mode===i.mode}).map(function(t){return t.id}).forEach(function(t){i.coordinatePoints.createOrUpdate(t)});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){var o=this.store.copyAllWhere(function(t){return t.mode===i.mode&&Boolean(t[u.COORDINATE_POINT_IDS])});this.coordinatePoints.deletePointsByFeatureIds(o.map(function(t){return t.id}))}},i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId).coordinates[0];if(!(t.length<5)&&this.updatePolygonGeometry([].concat(t.slice(0,-2),[t[0]]),l.Finish)){var e=this.currentId;if(this.currentId){var i=J(this.store.getGeometryCopy(this.currentId));i&&(this.store.updateGeometry([{id:this.currentId,geometry:i}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(this.currentId)),this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0},{id:this.currentId,property:u.COMMITTED_COORDINATE_COUNT,value:void 0},{id:this.currentId,property:u.PROVISIONAL_COORDINATE_COUNT,value:void 0}])}this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.snappedPointId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}}},i.registerBehaviors=function(t){this.clickBoundingBox=new ot(t),this.pixelDistance=new nt(t),this.lineSnapping=new It(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new rt(t,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new _t(t,this.pixelDistance),this.coordinatePoints=new bt(t)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.updateSnappedCoordinate=function(t){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.SNAPPING_POINT]=!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)},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var o=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,o);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-n],i[0]]}else if(2===this.currentCoordinate)e=[i[0],i[1],[t.lng,t.lat],i[0]];else{var r=this.closingPoints.isClosingPoint(t);r.isPreviousClosing||r.isClosing?(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.setCursor(this.cursors.close),e=[].concat(i.slice(0,-2),[i[0],i[0]])):e=[].concat(i.slice(0,-2),[[t.lng,t.lat],i[0]])}this.store.updateProperty([{id:this.currentId,property:u.PROVISIONAL_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.updatePolygonGeometry(e,l.Provisional)}},i.updatePolygonGeometry=function(t,e){if(!this.currentId)return!1;var i={type:"Polygon",coordinates:[t]};return!(this.validate&&!this.validate({type:"Feature",geometry:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid||(this.store.updateGeometry([{id:this.currentId,geometry:i}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(this.currentId),0))},i.snapCoordinate=function(t){var e,i,o,n,r,s=this,a=void 0;return null!=(e=this.snapping)&&e.toLine&&(n=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(a=n),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(a=r),null!=(o=this.snapping)&&o.toCustom&&(a=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})),a},i.polygonFilter=function(t){return Boolean("Polygon"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.polygonFilter(t)}),o=i.featureId,n=i.featureCoordinateIndex;if(o&&void 0!==n){var r,s=this.store.getGeometryCopy(o);if("Polygon"===s.type&&!((r=s.coordinates[0]).length<=4)){if("Polygon"!==s.type||0!==n&&n!==r.length-1?r.splice(n,1):(r.shift(),r.pop(),r.push([r[0][0],r[0][1]])),this.validate&&!this.validate({id:o,type:"Feature",geometry:s,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Commit}).valid)return;this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.store.updateGeometry([{id:o,geometry:s}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(o),this.onFinish(o,{mode:this.mode,action:"edit"})}}}},i.onLeftClick=function(t){if(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),0===this.currentCoordinate){var e,i=this.snapCoordinate(t);i&&(t.lng=i[0],t.lat=i[1]);var o=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e[u.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,e[u.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,e)}])[0];this.currentId=o,this.currentCoordinate++,this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(o),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.snapCoordinate(t);n&&(t.lng=n[0],t.lat=n[1]);var r=this.store.getGeometryCopy(this.currentId);if(ft([t.lng,t.lat],r.coordinates[0][0]))return;if(!this.updatePolygonGeometry([r.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],r.coordinates[0][0]],l.Commit))return;this.store.updateProperty([{id:this.currentId,property:u.COMMITTED_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var s=this.snapCoordinate(t);s&&(t.lng=s[0],t.lat=s[1]);var a=this.store.getGeometryCopy(this.currentId).coordinates[0];if(ft([t.lng,t.lat],a[1]))return;if(!this.updatePolygonGeometry([a[0],a[1],[t.lng,t.lat],[t.lng,t.lat],a[0]],l.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(a,"polygon"),this.store.updateProperty([{id:this.currentId,property:u.COMMITTED_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.currentCoordinate++}else if(this.currentId){var d=this.store.getGeometryCopy(this.currentId).coordinates[0],c=this.closingPoints.isClosingPoint(t);if(c.isPreviousClosing||c.isClosing)this.close();else{var h=this.snapCoordinate(t);if(h&&(t.lng=h[0],t.lat=h[1]),ft([t.lng,t.lat],d[this.currentCoordinate-1]))return;var p=(void 0===(g=[[].concat(d.slice(0,-1),[[t.lng,t.lat],d[0]])])&&(g=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:g},properties:{}});if(!this.updatePolygonGeometry(p.geometry.coordinates[0],l.Commit))return;this.store.updateProperty([{id:this.currentId,property:u.COMMITTED_COORDINATE_COUNT,value:this.currentCoordinate+1}]),this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(p.geometry.coordinates[0])}}var g},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var o=void 0;if("started"===this.state){var n=this.lineSnapping.getSnappable(t,function(t){return i.polygonFilter(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.polygonFilter(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[u.EDITED]=!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),o=i.coordinates[0];"coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex?0===this.editedFeatureCoordinateIndex||this.editedFeatureCoordinateIndex===i.coordinates[0].length-1?(o[0]=[t.lng,t.lat],o[o.length-1]=[t.lng,t.lat]):o[this.editedFeatureCoordinateIndex]=[t.lng,t.lat]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i.coordinates[0].splice(this.editedInsertIndex,0,[t.lng,t.lat]),this.editedFeatureCoordinateIndex++);var n={type:"Polygon",coordinates:i.coordinates};if(this.validate&&!this.validate({type:"Feature",geometry:n,properties:this.store.getPropertiesCopy(this.editedFeatureId)},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Provisional}).valid)return;this.snapping&&this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.store.updateGeometry([{id:this.editedFeatureId,geometry:n}]),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(this.editedFeatureId),this.editedPointId&&this.store.updateGeometry([{id:this.editedPointId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:u.EDITED,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:u.EDITED,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.snappedPointId,i=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{t&&this.coordinatePoints.deletePointsByFeatureIds([t]),void 0!==t&&this.store.delete([t]),void 0!==i&&this.store.delete([i]),void 0!==e&&this.store.delete([e]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p,e;if("Point"===t.geometry.type){var i=t.properties[u.EDITED],o=t.properties[u.COORDINATE_POINT],n=i?"editedPoint":t.properties[u.CLOSING_POINT]?"closingPoint":t.properties[u.SNAPPING_POINT]?"snappingPoint":o?"coordinatePoint":void 0;if(!n)return e;var s={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth}};return e.pointWidth=this.getNumericStylingValue(s[n].width,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(s[n].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(s[n].outlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(s[n].outlineWidth,2,t),e.zIndex=i?40:o?20:30,e}}return e},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(t.id)},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate(t.id),this.editedFeatureId===t.id&&this.editedPointId&&(this.store.delete([this.editedPointId]),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted())},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return K(t,e.coordinatePrecision)})},e}(I),jt={cancel:"Escape",finish:"Enter"},Bt={start:"crosshair"},Gt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="rectangle",i.center=void 0,i.clickCount=0,i.currentRectangleId=void 0,i.keyEvents=jt,i.cursors=Bt,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents))},i.updateRectangle=function(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){var i=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],o={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid)return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:o}])}},i.close=function(){var t=this.currentRectangleId;if(t){var e=J(this.store.getGeometryCopy(t));e&&this.store.updateGeometry([{id:t,geometry:e}]),this.store.updateProperty([{id:t,property:u.CURRENTLY_DRAWING,value:void 0}])}this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&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){var e;this.center=[t.lng,t.lat];var 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:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e)}]);this.currentRectangleId=i[0],this.clickCount++,this.setDrawing()}else this.updateRectangle(t,l.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,l.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(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&this.store.delete([t])},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth: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.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return z(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentRectangleId===t.id&&(this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted())},e}(I),Rt=/*#__PURE__*/function(t){function e(e){var i;if(!e.modeName)throw new Error("Mode name is required for TerraDrawRenderMode");return(i=t.call(this,e,!0)||this).type=v.Render,i.mode="render",i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.modeName&&(this.mode=e.modeName)},i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}},i.validateFeature=function(e){var i=t.prototype.validateFeature.call(this,e);if(i.valid){var o=e,n=wt(o,this.coordinatePrecision).valid||K(o,this.coordinatePrecision).valid||yt(o,this.coordinatePrecision).valid;return n?{valid:!0}:{valid:n,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(I);function Ut(t,e){var i=t,o=e,n=M(i[1]),r=M(o[1]),s=M(o[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=(F(Math.atan2(s,a))+360)%360;return d>180?-(360-d):d}function Lt(t,e,i){var o=e;e<0&&(o=-Math.abs(o));var n=o/S,r=t[0]*Math.PI/180,s=M(t[1]),a=M(i),d=n*Math.cos(a),l=s+d;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);var c=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),h=Math.abs(c)>1e-11?d/c:Math.cos(s),u=[(180*(r+n*Math.sin(a)/h)/Math.PI+540)%360-180,180*l/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function At(t,e,i,o,n){var r=o(t[0],t[1]),s=o(e[0],e[1]),a=n((r.x+s.x)/2,(r.y+s.y)/2),d=a.lat;return[w(a.lng,i),w(d,i)]}function Vt(t,e,i){var o=Lt(t,1e3*x(t,e)/2,Ut(t,e));return[w(o[0],i),w(o[1],i)]}function Yt(t){for(var e=t.featureCoords,i=t.precision,o=t.unproject,n=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var d=void 0;if("web-mercator"===r)d=At(e[a],e[a+1],i,n,o);else{if("globe"!==r)throw new Error("Invalid projection");d=Vt(e[a],e[a+1],i)}s.push(d)}return s}var Kt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n.coordinatePointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n.coordinatePointBehavior=o,n}s(e,t);var i=e.prototype;return i.insert=function(t,e,i){var o=this.store.getGeometryCopy(e),n=this.store.getPropertiesCopy(e),r=n.midPointFeatureId,s=n.midPointSegment,a=this.store.getGeometryCopy(r),d="Polygon"===a.type?a.coordinates[0]:a.coordinates;d.splice(s+1,0,o.coordinates),a.coordinates="Polygon"===a.type?[d]:d,this.store.updateGeometry([{id:r,geometry:a}]),this.store.getPropertiesCopy(t)[u.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate(t),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(d,r,i),this.selectionPointBehavior.create(d,a.type,r)},i.create=function(t,e,i){var o=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,o,n,r){return Yt({featureCoords:t,precision:i,project:o,unproject:n,projection:r}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:o.mode})[h.MID_POINT]=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i,this.config.project,this.config.unproject,this.projection))},i.delete=function(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])},i.getUpdated=function(t){var e=this;if(0!==this._midPoints.length)return Yt({featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}).map(function(t,i){return{id:e._midPoints[i],geometry:{type:"Point",coordinates:t}}})},o(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}])}(et),zt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}s(e,t);var i=e.prototype;return i.create=function(t,e,i){var o=this;this._selectionPoints=this.store.create(function(t,e,i){for(var o=[],n="Polygon"===e?t.length-1:t.length,r=0;r<n;r++)o.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return o}(t,e,function(t){var e;return(e={mode:o.mode,index:t})[h.SELECTION_POINT]=!0,e[h.SELECTION_POINT_FEATURE_ID]=i,e}))},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])},i.getUpdated=function(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map(function(e,i){return{id:e,geometry:{type:"Point",coordinates:t[i]}}})},i.getOneUpdated=function(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}},o(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}])}(et);function Ht(t,e){for(var i,o,n,r=!1,s=0,a=e.length;s<a;s++)for(var d=e[s],l=0,c=d.length,h=c-1;l<c;h=l++)(o=d[l])[1]>(i=t)[1]!=(n=d[h])[1]>i[1]&&i[0]<(n[0]-o[0])*(i[1]-o[1])/(n[1]-o[1])+o[0]&&(r=!r);return r}var Xt=function(t,e,i){var o=function(t){return t*t},n=function(t,e){return o(t.x-e.x)+o(t.y-e.y)};return Math.sqrt(function(t,e,i){var o=n(e,i);if(0===o)return n(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/o;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},qt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.createClickBoundingBox=void 0,n.pixelDistance=void 0,n.config=e,n.createClickBoundingBox=i,n.pixelDistance=o,n}return s(e,t),e.prototype.find=function(t,e){for(var i=void 0,o=Infinity,n=void 0,r=Infinity,s=void 0,a=Infinity,d=void 0,l=this.createClickBoundingBox.create(t),c=this.store.search(l),u=0;u<c.length;u++){var p=c[u],g=p.geometry;if("Point"===g.type){if(p.properties.selectionPoint||p.properties.coordinatePoint||!e&&p.properties[h.MID_POINT])continue;var f=this.pixelDistance.measure(t,g.coordinates);p.properties[h.MID_POINT]&&f<this.pointerDistance&&f<a?(a=f,s=p):!p.properties[h.MID_POINT]&&f<this.pointerDistance&&f<o&&(o=f,i=p)}else if("LineString"===g.type){if(i)continue;for(var y=0;y<g.coordinates.length-1;y++){var v=g.coordinates[y],m=g.coordinates[y+1],C=Xt({x:t.containerX,y:t.containerY},this.project(v[0],v[1]),this.project(m[0],m[1]));C<this.pointerDistance&&C<r&&(r=C,n=p)}}else if("Polygon"===g.type){if(i||n)continue;Ht([t.lng,t.lat],g.coordinates)&&(d=p)}}return{clickedFeature:i||n||d,clickedMidPoint:s}},e}(et),Zt=/*#__PURE__*/function(t){function e(e,i,o,n,r){var s;return(s=t.call(this,e)||this).config=void 0,s.featuresAtCursorEvent=void 0,s.selectionPoints=void 0,s.midPoints=void 0,s.coordinatePoints=void 0,s.draggedFeatureId=null,s.dragPosition=void 0,s.config=e,s.featuresAtCursorEvent=i,s.selectionPoints=o,s.midPoints=n,s.coordinatePoints=r,s}s(e,t);var i=e.prototype;return i.startDragging=function(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]},i.stopDragging=function(){this.draggedFeatureId=null,this.dragPosition=void 0},i.isDragging=function(){return null!==this.draggedFeatureId},i.canDrag=function(t,e){var i=this.featuresAtCursorEvent.find(t,!0).clickedFeature;return!(!i||i.id!==e)},i.drag=function(t,e){if(this.draggedFeatureId){var i=this.store.getGeometryCopy(this.draggedFeatureId),o=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var n,r;if(r="Polygon"===i.type?(n=i.coordinates[0]).length-1:(n=i.coordinates).length,!this.dragPosition)return!1;for(var s=0;s<r;s++){var a=n[s],d=void 0,c=void 0;if("web-mercator"===this.config.projection){var h=b(this.dragPosition[0],this.dragPosition[1]),u=b(o[0],o[1]),p=b(a[0],a[1]),g={x:h.x-u.x,y:h.y-u.y},f=N(p.x-g.x,p.y-g.y);d=f.lng,c=f.lat}else{var y=[this.dragPosition[0]-o[0],this.dragPosition[1]-o[1]];d=a[0]-y[0],c=a[1]-y[1]}if(d=w(d,this.config.coordinatePrecision),c=w(c,this.config.coordinatePrecision),d>180||d<-180||c>90||c<-90)return!1;n[s]=[d,c]}"Polygon"===i.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var v=this.selectionPoints.getUpdated(n)||[],m=this.midPoints.getUpdated(n)||[],C=this.coordinatePoints.getUpdated(this.draggedFeatureId,n)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}).valid)return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(v,m,C)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:o}}]),this.dragPosition=[t.lng,t.lat])}},e}(et),Jt=/*#__PURE__*/function(t){function e(e,i,o,n,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.pixelDistance=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.coordinateSnapping=void 0,d.lineSnapping=void 0,d.draggedCoordinate={id:null,index:-1},d.config=e,d.pixelDistance=i,d.selectionPoints=o,d.midPoints=n,d.coordinatePoints=r,d.coordinateSnapping=s,d.lineSnapping=a,d}s(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.snapCoordinate=function(t,e,i){var o,n,r,s=this,a=[t.lng,t.lat],d=function(t){return Boolean(t.properties&&t.properties.mode===i.properties.mode&&t.id!==s.draggedCoordinate.id)};return null!=e&&e.toLine&&(o=this.lineSnapping.getSnappable(t,d).coordinate)&&(a=o),e.toCoordinate&&(n=this.coordinateSnapping.getSnappable(t,d).coordinate)&&(a=n),null!=e&&e.toCustom&&(r=e.toCustom(t,{currentCoordinate:this.draggedCoordinate.index,currentId:i.id,getCurrentGeometrySnapshot:i.id?function(){return s.store.getGeometryCopy(i.id)}:function(){return null},project:this.project,unproject:this.unproject}))&&(a=r),a},i.drag=function(t,e,i,o){var n=this.draggedCoordinate.id;if(null===n)return!1;var r=this.draggedCoordinate.index,s=this.store.getGeometryCopy(n),a=this.store.getPropertiesCopy(n),d="LineString"===s.type?s.coordinates:s.coordinates[0],c="Polygon"===s.type&&(r===d.length-1||0===r),h={type:"Feature",id:n,geometry:s,properties:a},u=this.snapCoordinate(t,o,h);if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(c){var p=d.length-1;d[0]=u,d[p]=u}else d[r]=u;var g=this.selectionPoints.getOneUpdated(r,u),f=g?[g]:[],y=this.midPoints.getUpdated(d)||[],v=this.coordinatePoints.getUpdated(n,d)||[];return!("Point"!==s.type&&!e&&j({type:"Feature",geometry:s,properties:{}})||i&&!i(h,{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}).valid||(this.store.updateGeometry([{id:n,geometry:s}].concat(f,y,v)),0))},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(et);function $t(t){var e=0,i=0,o=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}var Qt=function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return b(t[0],t[1])}),n=o.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});n.x/=o.length,n.y/=o.length;var r=o.map(function(t){return{x:n.x+(t.x-n.x)*Math.cos(i)-(t.y-n.y)*Math.sin(i),y:n.y+(t.x-n.x)*Math.sin(i)+(t.y-n.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[N(e,i).lng,N(e,i).lat]});return"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r,t};function te(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=b(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,o=0,n=t.length,r=0;r<n-1;r++){var s=t[r],a=s[0],d=s[1],l=t[r+1],c=l[0],h=l[1],u=a*h-c*d;e+=u,i+=(a+c)*u,o+=(d+h)*u}return{x:i/=6*(e/=2),y:o/=6*e}}(e):function(t){for(var e=t.length,i=0,o=0,n=0;n<e;n++){var r=t[n];i+=r[0],o+=r[1]}return{x:i/e,y:o/e}}(e)}var ee=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.coordinatePoints=void 0,r.lastBearing=void 0,r.selectedGeometry=void 0,r.selectedGeometryCentroid=void 0,r.selectedGeometryWebMercatorCentroid=void 0,r.config=e,r.selectionPoints=i,r.midPoints=o,r.coordinatePoints=n,r}s(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0},i.rotate=function(t,e,i){var o=this;this.selectedGeometry||(this.selectedGeometry=this.store.getGeometryCopy(e));var n=this.selectedGeometry;if("Polygon"===n.type||"LineString"===n.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:n,properties:{}};if("web-mercator"===this.config.projection){this.selectedGeometryWebMercatorCentroid||(this.selectedGeometryWebMercatorCentroid=te(a));var d=b(t.lng,t.lat);if(0===(r=lt(this.selectedGeometryWebMercatorCentroid,d)))return;if(!this.lastBearing)return void(this.lastBearing=r);Qt(a,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(this.selectedGeometryCentroid||(this.selectedGeometryCentroid=$t({type:"Feature",geometry:n,properties:{}})),r=Ut(this.selectedGeometryCentroid,s),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=$t(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=Ut(i,t)+e,n=function(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=S,o=e[1]*Math.PI/180,n=t[1]*Math.PI/180,r=n-o,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(a)>1e-11?r/a:Math.cos(o);return Math.sqrt(r*r+d*d*s*s)*i}(i,t),r=Lt(i,n,o);t[0]=r[0],t[1]=r[1]})}(a,-(this.lastBearing-(r+180)))}var c="Polygon"===n.type?n.coordinates[0]:n.coordinates;c.forEach(function(t){t[0]=w(t[0],o.coordinatePrecision),t[1]=w(t[1],o.coordinatePrecision)});var h=this.midPoints.getUpdated(c)||[],u=this.selectionPoints.getUpdated(c)||[],p=this.coordinatePoints.getUpdated(e,c)||[];if(i&&!i({id:e,type:"Feature",geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:n}].concat(u,h,p)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}(et),ie=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.dragCoordinateResizeBehavior=void 0,o.config=e,o.dragCoordinateResizeBehavior=i,o}s(e,t);var i=e.prototype;return i.scale=function(t,e,i){if(!this.dragCoordinateResizeBehavior.isDragging()){var o=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,o)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed",i)},i.reset=function(){this.dragCoordinateResizeBehavior.stopDragging()},e}(et);function oe(t){var e=t.originX,i=t.originY,o=t.xScale,n=t.yScale;1===o&&1===n||t.coordinates.forEach(function(t){var r=b(t[0],t[1]),s=N(e+(r.x-e)*o,i+(r.y-i)*n),a=s.lat;t[0]=s.lng,t[1]=a})}var ne=/*#__PURE__*/function(t){function e(e,i,o,n,r){var s;return(s=t.call(this,e)||this).config=void 0,s.pixelDistance=void 0,s.selectionPoints=void 0,s.midPoints=void 0,s.coordinatePoints=void 0,s.minimumScale=1e-4,s.draggedCoordinate={id:null,index:-1},s.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},s.config=e,s.pixelDistance=i,s.selectionPoints=o,s.midPoints=n,s.coordinatePoints=r,s}s(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=te(e.feature);if(!r)return null;var s=b(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=b(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),o},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=te(e.feature);if(!r)return null;var s=b(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=b(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),o},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,o=t.webMercatorCursor,n=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-o.x,e.y-o.y))return null;var r=Z(e,o)/Z(e,i);return r<0&&(r=this.minimumScale),oe({coordinates:n,originX:e.x,originY:e.y,xScale:r,yScale:r}),n},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=b(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,l={x:i[a][0],y:i[a][1]},c=b(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:c,webMercatorSelected:r,webMercatorOrigin:l}),o},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=b(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,l={x:i[a][0],y:i[a][1]},c=b(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:o,webMercatorCursor:c,webMercatorSelected:r,webMercatorOrigin:l}),o},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,o=t.webMercatorSelected,n=t.webMercatorCursor,r=t.updatedCoords,s=i.x-n.x,a=i.y-n.y;if(!this.isValidDragWebMercator(e,s,a))return null;var d=1;0!==s&&1!==e&&5!==e&&(d=1-(i.x-o.x-s)/s);var l=1;return 0!==a&&3!==e&&7!==e&&(l=1-(i.y-o.y-a)/a),this.validateScale(d,l)?(d<0&&(d=this.minimumScale),l<0&&(l=this.minimumScale),this.performWebMercatorScale(r,i.x,i.y,d,l),r):null},i.getFeature=function(t){if(null===this.draggedCoordinate.id)return null;var e=this.store.getGeometryCopy(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{id:t,type:"Feature",geometry:e,properties:{}}},i.getNormalisedCoordinates=function(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates},i.validateScale=function(t,e){var i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,o=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&o},i.performWebMercatorScale=function(t,e,i,o,n){t.forEach(function(t){var r=b(t[0],t[1]),s=N(e+(r.x-e)*o,i+(r.y-i)*n),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=b(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],o=t[1];i<e[0]&&(e[0]=i),o<e[1]&&(e[1]=o),i>e[2]&&(e[2]=i),o>e[3]&&(e[3]=o)});var i=e[0],o=e[1],n=e[2],r=e[3];return[[i,r],[(i+n)/2,r],[n,r],[n,r+(o-r)/2],[n,o],[(i+n)/2,o],[i,o],[i,r+(o-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,o=Infinity,n=0;n<t.length;n++){var r=Z({x:e.x,y:e.y},{x:t[n][0],y:t[n][1]});r<o&&(i=n,o=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var o=this.getFeature(this.draggedCoordinate.id);if(!o)return!1;var n=null;if("center"===e?n=this.centerWebMercatorDrag(t):"opposite"===e?n=this.oppositeWebMercatorDrag(t):"center-fixed"===e?n=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(var r=0;r<n.length;r++){var s=n[r];if(s[0]=w(s[0],this.coordinatePrecision),s[1]=w(s[1],this.coordinatePrecision),!G(s,this.coordinatePrecision))return!1}var a=this.midPoints.getUpdated(n)||[],d=this.selectionPoints.getUpdated(n)||[],c=this.coordinatePoints.getUpdated(o.id,n)||[],h={type:o.geometry.type,coordinates:"Polygon"===o.geometry.type?[n]:n};return!(i&&!i({id:this.draggedCoordinate.id,type:"Feature",geometry:h,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:l.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:h}].concat(d,a,c)),0))},e}(et),re={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]},se={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"},ae=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="select",i.allowManualDeselection=!0,i.dragEventThrottle=5,i.dragEventCount=0,i.selected=[],i.flags={},i.keyEvents=re,i.cursors=se,i.validations={},i.selectionPoints=void 0,i.midPoints=void 0,i.coordinateSnap=void 0,i.featuresAtMouseEvent=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.dragFeature=void 0,i.dragCoordinate=void 0,i.rotateFeature=void 0,i.scaleFeature=void 0,i.dragCoordinateResizeFeature=void 0,i.coordinatePoints=void 0,i.lineSnap=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){if(t.prototype.updateOptions.call(this,e),this.cursors=e&&e.cursors?r({},this.cursors,e.cursors):se,null===(null==e?void 0:e.keyEvents)?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),void 0!==(null==e?void 0:e.dragEventThrottle)&&(this.dragEventThrottle=e.dragEventThrottle),void 0!==(null==e?void 0:e.allowManualDeselection)&&(this.allowManualDeselection=e.allowManualDeselection),null!=e&&e.flags)for(var i in this.flags=r({},this.flags,e.flags),this.validations={},this.flags){var o=this.flags[i].feature;o&&o.validation&&(this.validations[i]=o.validation)}},i.selectFeature=function(t){this.select(t,!1)},i.setSelecting=function(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"},i.registerBehaviors=function(t){this.pixelDistance=new nt(t),this.clickBoundingBox=new ot(t),this.featuresAtMouseEvent=new qt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new zt(t),this.coordinatePoints=new bt(t),this.midPoints=new Kt(t,this.selectionPoints,this.coordinatePoints),this.coordinateSnap=new rt(t,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new It(t,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new ee(t,this.selectionPoints,this.midPoints,this.coordinatePoints),this.dragFeature=new Zt(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints),this.dragCoordinate=new Jt(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap),this.dragCoordinateResizeFeature=new ne(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints),this.scaleFeature=new ie(t,this.dragCoordinateResizeFeature)},i.deselectFeature=function(){this.deselect()},i.deselect=function(){var t=this,e=this.selected.filter(function(e){return t.store.has(e)}).map(function(t){return{id:t,property:h.SELECTED,value:!1}});this.store.updateProperty(e),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},i.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,o=Infinity;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<o&&(o=s,i=e.store.getPropertiesCopy(n))}),i){var n=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(n),a=this.flags[s.mode],d=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var c,h=this.store.getGeometryCopy(n);if("Polygon"===h.type){if((c=h.coordinates[0]).length<=4)return}else if("LineString"===h.type&&(c=h.coordinates).length<=2)return;if(c){if("Polygon"!==h.type||0!==r&&r!==c.length-1?c.splice(r,1):(c.shift(),c.pop(),c.push([c[0][0],c[0][1]])),d&&!d({id:n,type:"Feature",geometry:h,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Commit}).valid)return;var u=[].concat(this.midPoints.ids,this.selectionPoints.ids);this.store.delete(u),this.store.updateGeometry([{id:n,geometry:h}]),s.coordinatePointIds&&this.coordinatePoints.createOrUpdate(n),this.selectionPoints.create(c,h.type,n),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(c,n,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),o=this.flags[i.mode];if(o&&o.feature){var n=this.selected[0];if(n){if(n===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:h.SELECTED,value:!0}]),this.onSelect(t);var r=this.store.getGeometryCopy(t),s=r.type,a=r.coordinates;if("LineString"===s||"Polygon"===s){var d="LineString"===s?a:a[0];d&&o&&o.feature.coordinates&&(this.selectionPoints.create(d,s,t),o.feature.coordinates.midpoints&&this.midPoints.create(d,t,this.coordinatePrecision))}}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,o=e.clickedMidPoint;if(this.selected.length&&o)this.midPoints.insert(this.selected[0],o.id,this.coordinatePrecision);else if(i&&i.id)this.select(i.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;var e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect()},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),o=this.flags[i.mode];if(o&&o.feature&&(o.feature.draggable||o.feature.coordinates&&o.feature.coordinates.draggable||o.feature.coordinates&&o.feature.coordinates.resizable||o.feature.coordinates&&"object"==typeof o.feature.coordinates.midpoints&&o.feature.coordinates.midpoints.draggable)){this.dragEventCount=0;var n=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,n);if(o&&o.feature&&o.feature.coordinates&&(o.feature.coordinates.draggable||o.feature.coordinates.resizable)&&-1!==r)return this.setCursor(this.cursors.dragStart),o.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(n,r):this.dragCoordinate.startDragging(n,r),void e(!1);if(o&&o.feature&&o.feature.coordinates&&"object"==typeof o.feature.coordinates.midpoints&&o.feature.coordinates.midpoints.draggable){var s=this.featuresAtMouseEvent.find(t,this.selected.length>0).clickedMidPoint;if(this.selected.length&&s){this.midPoints.insert(n,s.id,this.coordinatePrecision);var a=this.dragCoordinate.getDraggableIndex(t,n);return this.dragCoordinate.startDragging(n,a),void e(!1)}}return o&&o.feature&&o.feature.draggable&&this.dragFeature.canDrag(t,n)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,n),void e(!1)):void 0}}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)){var i=this.selected[0];if(i){var o=this.store.getPropertiesCopy(i),n=this.flags[o.mode],r=!0===(n&&n.feature&&n.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[o.mode];if(n&&n.feature&&n.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(n&&n.feature&&n.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&n.feature&&n.feature.coordinates&&n.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,n.feature.coordinates.resizable,s)}if(this.dragCoordinate.isDragging()){var a,d=null==(a=n.feature)||null==(a=a.coordinates)?void 0:a.snappable,l={toCoordinate:!1};return!0===d?l={toCoordinate:!0}:"object"==typeof d&&(l=d),void this.dragCoordinate.drag(t,r,s,l)}this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}}},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0))},i.onMouseMove=function(t){var e=this;if(this.selected.length){if(!this.dragFeature.isDragging()){var i=!1;this.midPoints.ids.forEach(function(o){if(!i){var n=e.store.getGeometryCopy(o);e.pixelDistance.measure(t,n.coordinates)<e.pointerDistance&&(i=!0)}});var o=!1;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!1,o=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var n=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(n&&n.id===this.selected[0]||o)?this.cursors.pointerOver:"unset")}}}else this.setCursor("unset")},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties[h.SELECTION_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties[h.MID_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=50,e}else if(t.properties[h.SELECTED]){if("Point"===t.geometry.type&&t.properties[u.MARKER])return e.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,c,t),e.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),e.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),e;if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=p,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=p,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=p,e}return e},i.afterFeatureUpdated=function(t){if(this.selected.length&&t.id===this.selected[0]){var e,i,o=this.flags[t.properties.mode];if(null==o||null==(e=o.feature)||!e.coordinates)return;var n,r=t.geometry.type,s=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),"Polygon"===r)n=t.geometry.coordinates[0];else{if("LineString"!==r)return;n=t.geometry.coordinates}this.selectionPoints.create(n,r,s),null!=o&&null!=(i=o.feature)&&null!=(i=i.coordinates)&&i.midpoints&&this.midPoints.create("Polygon"===r?t.geometry.coordinates[0]:t.geometry.coordinates,s,this.coordinatePrecision)}},e}(E),de=/*#__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=v.Static,e.mode="static",e}s(e,t);var i=e.prototype;return i.start=function(){},i.stop=function(){},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(){return r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0})},e}(I);function le(t,e,i,o,n){for(;o>i;){if(o-i>600){var r=o-i+1,s=e-i+1,a=Math.log(r),d=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*d*(r-d)/r)*(s-r/2<0?-1:1);le(t,e,Math.max(i,Math.floor(e-s*d/r+l)),Math.min(o,Math.floor(e+(r-s)*d/r+l)),n)}var c=t[e],h=i,u=o;for(ce(t,i,e),n(t[o],c)>0&&ce(t,i,o);h<u;){for(ce(t,h,u),h++,u--;n(t[h],c)<0;)h++;for(;n(t[u],c)>0;)u--}0===n(t[i],c)?ce(t,i,u):ce(t,++u,o),u<=e&&(i=u+1),e<=u&&(o=u-1)}}function ce(t,e,i){var o=t[e];t[e]=t[i],t[i]=o}function he(t,e){ue(t,0,t.children.length,e,t)}function ue(t,e,i,o,n){n||(n=Pe([])),n.minX=Infinity,n.minY=Infinity,n.maxX=-Infinity,n.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];pe(n,t.leaf?o(s):s)}return n}function pe(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function ge(t,e){return t.minX-e.minX}function fe(t,e){return t.minY-e.minY}function ye(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function ve(t){return t.maxX-t.minX+(t.maxY-t.minY)}function me(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Ce(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Pe(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function Ie(t,e,i,o,n){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=o)){var s=e+Math.ceil((i-e)/o/2)*o;le(t,s,e,i,n),r.push(e,s,s,i)}}var Ee=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!Ce(t,e))return i;for(var o=this.toBBox,n=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?o(s):s;Ce(t,a)&&(e.leaf?i.push(s):me(t,a)?this._all(s,i):n.push(s))}e=n.pop()}return i},e.collides=function(t){var e=this.data;if(Ce(t,e))for(var i=[];e;){for(var o=0;o<e.children.length;o++){var n=e.children[o],r=e.leaf?this.toBBox(n):n;if(Ce(t,r)){if(e.leaf||me(t,r))return!0;i.push(n)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var o=this.data;this.data=i,i=o}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=Pe([])},e.remove=function(t){for(var e,i,o=this.data,n=this.toBBox(t),r=[],s=[],a=!1;o||r.length;){if(o||(o=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),o.leaf){var d=o.children.indexOf(t);-1!==d&&(o.children.splice(d,1),r.push(o),this._condense(r))}a||o.leaf||!me(o,n)?i?(e++,o=i.children[e],a=!1):o=null:(r.push(o),s.push(e),e=0,i=o,o=o.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,o){var n,r=i-e+1,s=this._maxEntries;if(r<=s)return he(n=Pe(t.slice(e,i+1)),this.toBBox),n;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),(n=Pe([])).leaf=!1,n.height=o;var a=Math.ceil(r/s),d=a*Math.ceil(Math.sqrt(s));Ie(t,e,i,d,this.compareMinX);for(var l=e;l<=i;l+=d){var c=Math.min(l+d-1,i);Ie(t,l,c,a,this.compareMinY);for(var h=l;h<=c;h+=a){var u=Math.min(h+a-1,c);n.children.push(this._build(t,h,u,o-1))}}return he(n,this.toBBox),n},e._chooseSubtree=function(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){for(var n=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var d=e.children[a],l=ye(d),c=(h=t,u=d,(Math.max(u.maxX,h.maxX)-Math.min(u.minX,h.minX))*(Math.max(u.maxY,h.maxY)-Math.min(u.minY,h.minY))-l);c<r?(r=c,n=l<n?l:n,s=d):c===r&&l<n&&(n=l,s=d)}e=s||e.children[0]}var h,u;return e},e._insert=function(t,e,i){var o=i?t:this.toBBox(t),n=[],r=this._chooseSubtree(o,this.data,e,n);for(r.children.push(t),pe(r,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)},e._split=function(t,e){var i=t[e],o=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,o);var r=this._chooseSplitIndex(i,n,o),s=Pe(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,he(i,this.toBBox),he(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=Pe([t,e]),this.data.height=t.height+1,this.data.leaf=!1,he(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var o,n,r,s,a,d,l,c=Infinity,h=Infinity,u=e;u<=i-e;u++){var p=ue(t,0,u,this.toBBox),g=ue(t,u,i,this.toBBox),f=(n=p,r=g,s=Math.max(n.minX,r.minX),a=Math.max(n.minY,r.minY),d=Math.min(n.maxX,r.maxX),l=Math.min(n.maxY,r.maxY),Math.max(0,d-s)*Math.max(0,l-a)),y=ye(p)+ye(g);f<c?(c=f,o=u,h=y<h?y:h):f===c&&y<h&&(h=y,o=u)}return o||i-e},e._chooseSplitAxis=function(t,e,i){var o=t.leaf?this.compareMinX:ge,n=t.leaf?this.compareMinY:fe;this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,n)&&t.children.sort(o)},e._allDistMargin=function(t,e,i,o){t.children.sort(o);for(var n=this.toBBox,r=ue(t,0,e,n),s=ue(t,i-e,i,n),a=ve(r)+ve(s),d=e;d<i-e;d++){var l=t.children[d];pe(r,t.leaf?n(l):l),a+=ve(r)}for(var c=i-e-1;c>=e;c--){var h=t.children[c];pe(s,t.leaf?n(h):h),a+=ve(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var o=i;o>=0;o--)pe(e[o],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():he(t[i],this.toBBox)},t}(),xe=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Ee(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],o=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var n=0;n<e.length;n++)o.push(e[n][1]),i.push(e[n][0]);var r=Math.min.apply(Math,o),s=Math.max.apply(Math,o);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],o=new Set;t.forEach(function(t){var n=e.toBBox(t);if(e.setMaps(t,n),o.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);o.add(String(t.id)),i.push(n)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),Se={getId:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},isValidId:function(t){return"string"==typeof t&&36===t.length}},Me=/*#__PURE__*/function(){function t(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=function(){},this.store={},this.spatialIndex=new xe,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Se}var e=t.prototype;return e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.getId=function(){return this.idStrategy.getId()},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e,i,o){var n=this;if(0===t.length)return[];var r=this.clone(t),s=[],a=[];r=r.filter(function(t){null==t.id&&(t.id=n.idStrategy.getId());var i=t.id;if(e){var o=e(t);if(!o.valid)return s.push({id:i,valid:!1,reason:o.reason}),!1}if(n.tracked){if(t.properties.createdAt){if(!y(t.properties.createdAt))return s.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!y(t.properties.updatedAt))return s.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return n.has(i)?(s.push({id:i,valid:!1,reason:"Feature already exists with this id: "+i}),!1):(n.store[i]=t,a.push(t),s.push({id:i,valid:!0}),!0)}),this.spatialIndex.load(r);var d=a.map(function(t){return t.id});return d.length>0&&(this._onChange(d,"create",o),i&&a.forEach(function(t){i(t)})),s},e.search=function(t,e){var i=this,o=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?o.filter(e):o)},e.registerOnChange=function(t){this._onChange=function(e,i,o){t(e,i,o)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t,e){var i=this,o=[];t.forEach(function(t){var e=t.id,n=t.property,r=t.value,s=i.store[e];if(!s)throw new Error("No feature with this ("+e+"), can not update geometry");o.push(e),void 0===r?delete s.properties[n]:s.properties[n]=r,i.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(o,"update",e)},e.updateGeometry=function(t,e){var i=this,o=[];t.forEach(function(t){var e=t.id,n=t.geometry;o.push(e);var r=i.store[e];if(!r)throw new Error("No feature with this ("+e+"), can not update geometry");r.geometry=i.clone(n),i.spatialIndex.update(r),i.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(o,"update",e)},e.create=function(t,e){var i=this,o=[];return t.forEach(function(t){var e,n=t.geometry,s=t.properties,a=r({},s);i.tracked&&(e=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:e,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:e):a={createdAt:e,updatedAt:e});var d=i.getId(),l={id:d,type:"Feature",geometry:n,properties:a};i.store[d]=l,i.spatialIndex.insert(l),o.push(d)}),this._onChange&&this._onChange([].concat(o),"create",e),o},e.delete=function(t,e){var i=this;t.forEach(function(t){if(!i.store[t])throw new Error("No feature with id "+t+", can not delete");delete i.store[t],i.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete",e)},e.copy=function(t){return this.clone(this.store[t])},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.copyAllWhere=function(t){var e=this;return this.clone(Object.keys(this.store).map(function(t){return e.store[t]}).filter(function(e){return e.properties&&t(e.properties)}))},e.clear=function(){this.store={},this.spatialIndex.clear()},e.size=function(){return Object.keys(this.store).length},t}();function De(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Oe(e[0]));for(var o=1;o<e.length;o++)i-=Math.abs(Oe(e[o]))}return i}var Fe=20294876564838.72,we=Math.PI/180;function Oe(t){var e=t.length;if(e<=2)return 0;for(var i=0,o=0;o<e;)i+=(t[o+2>=e?(o+2)%e:o+2][0]*we-t[o][0]*we)*Math.sin(t[o+1===e?0:o+1][1]*we),o++;return i*Fe}var ke="Feature is smaller than the minimum area",_e="Feature is not a Polygon or LineString",be="Feature intersects itself";function Ne(t,e,i){var o=lt(t,e),n=lt(e,i)-o;return n<0&&(n+=360),180-Math.abs(n-90-90)}var Te={cancel:"Escape",finish:"Enter"},We={start:"crosshair",close:"pointer"},je=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Te,i.cursors=We,i.mouseMove=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents))},i.close=function(){if(void 0!==this.currentId){this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0}]);var t=this.currentId;this.currentCoordinate=0,this.currentId=void 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.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i,o,n,r,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var a=1/Math.pow(10,this.coordinatePrecision-1),d=Math.max(1e-6,a);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-d],s[0]]}else if(2===this.currentCoordinate){var c=s[0],h=s[1],u=At(c,h,this.coordinatePrecision,this.project,this.unproject),p=b(c[0],c[1]),g=b(u[0],u[1]),f=b(h[0],h[1]),y=b(t.lng,t.lat),v=Z(y,p)<Z(y,f),m=Ne(p,g,y),C=v?90-m:Ne(p,g,y)-90,P=Z(g,y),I=Math.cos(M(C))*P,E=lt(p,f)+("right"==((r=((n=y).x-(o=f).x)*((i=p).y-o.y)-(n.y-o.y)*(i.x-o.x))>1e-10?"left":r<-1e-10?"right":"left")?-90:90),x=at(p,I,E),S=at(f,I,E),D=N(x.x,x.y),F=N(S.x,S.y);e=[s[0],s[1],[w(F.lng,this.coordinatePrecision),w(F.lat,this.coordinatePrecision)],[w(D.lng,this.coordinatePrecision),w(D.lat,this.coordinatePrecision)],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,l.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e)}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var o=this.store.getGeometryCopy(this.currentId);if(ft([t.lng,t.lat],o.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]],l.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){if(t.key===this.keyEvents.cancel)this.cleanUp();else if(t.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return z(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},e}(I);function Be(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var Ge={cancel:"Escape",finish:"Enter"},Re={start:"crosshair",close:"pointer"},Ue=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sector",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Ge,i.direction=void 0,i.arcPoints=64,i.cursors=Re,i.mouseMove=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.close=function(){if(void 0!==this.currentId){var t=J(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}]),this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0}]);var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"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){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var o=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,o);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-n],i[0]]}else if(2===this.currentCoordinate){var r=i[0],s=i[1],a=[t.lng,t.lat],d=b(r[0],r[1]),c=b(s[0],s[1]),h=b(a[0],a[1]);if(void 0===this.direction){var u=Be(d,c,h);this.direction=u?"clockwise":"anticlockwise"}var p,g=Z(d,c),f=lt(d,c),y=lt(d,h),v=this.arcPoints,m=[r],C=ct(f),P=ct(y);"anticlockwise"===this.direction?(p=P-C)<0&&(p+=360):(p=C-P)<0&&(p+=360);var I=("anticlockwise"===this.direction?1:-1)*p/v;m.push(s);for(var E=0;E<=v;E++){var x=at(d,g,C+E*I),S=N(x.x,x.y),M=S.lat,D=[w(S.lng,this.coordinatePrecision),w(M,this.coordinatePrecision)];D[0]!==m[m.length-1][0]&&D[1]!==m[m.length-1][1]&&m.push(D)}m.push(r),e=[].concat(m)}e&&this.updatePolygonGeometry(this.currentId,e,l.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e)}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var o=this.store.getGeometryCopy(this.currentId);if(ft([t.lng,t.lat],o.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]],l.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return z(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},e}(I),Le={cancel:"Escape",finish:"Enter"},Ae={start:"crosshair",close:"pointer"},Ve=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=Le,i.direction=void 0,i.arcPoints=64,i.cursors=Ae,i.mouseMove=!1,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.close=function(){if(void 0!==this.currentStartingPointId){var t=this.currentStartingPointId,e=this.currentInitialArcId,i=this.currentId;if(t&&this.store.delete([t]),e&&this.store.delete([e]),this.currentId){var o=J(this.store.getGeometryCopy(this.currentId));o&&this.store.updateGeometry([{id:this.currentId,geometry:o}]),this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0}])}this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),i&&this.onFinish(i,{mode:this.mode,action:"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){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentInitialArcId&&void 0!==this.currentStartingPointId&&0!==this.currentCoordinate)if(2===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentInitialArcId).coordinates,i=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,o=e[0],n=[t.lng,t.lat],r=b(o[0],o[1]),s=b(n[0],n[1]),a=b(i[0],i[1]),d=Z(a,r);if(void 0===this.direction){var c=Be(a,r,s);this.direction=c?"clockwise":"anticlockwise"}var h,p=lt(a,r),g=lt(a,s),f=this.arcPoints,y=[o],v=ct(p),m=ct(g);"anticlockwise"===this.direction?(h=m-v)<0&&(h+=360):(h=v-m)<0&&(h+=360);for(var C=("anticlockwise"===this.direction?1:-1)*h/f,P=0;P<=f;P++){var I=at(a,d,v+P*C),E=N(I.x,I.y),x=E.lat,S=[w(E.lng,this.coordinatePrecision),w(x,this.coordinatePrecision)];S[0]!==y[y.length-1][0]&&S[1]!==y[y.length-1][1]&&y.push(S)}this.updateLineStringGeometry(this.currentInitialArcId,y,l.Provisional)}else if(3===this.currentCoordinate){var M=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(M.length<2)return;if(!this.direction)return;var D=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,F=M[0],O=M[M.length-1],k=b(t.lng,t.lat),_=b(F[0],F[1]),T=b(O[0],O[1]),W=b(D[0],D[1]),j=Z(W,_),B=Z(W,k)<j?_:k,G=lt(W,k),R=lt(W,_),U=lt(W,T),L=ct(R),A=ct(U),V=ct(G);if(this.notInSector({normalizedCursor:V,normalizedStart:L,normalizedEnd:A,direction:this.direction}))return;for(var Y=this.getDeltaBearing(this.direction,L,A),K=this.arcPoints,z=("anticlockwise"===this.direction?1:-1)*Y/K,H=Z(W,B),X=[],q=0;q<=K;q++){var J=at(W,H,L+q*z),$=N(J.x,J.y),Q=$.lat,tt=[w($.lng,this.coordinatePrecision),w(Q,this.coordinatePrecision)];tt[0]!==M[M.length-1][0]&&tt[1]!==M[M.length-1][1]&&X.unshift(tt)}if(M.push.apply(M,X),M.push(M[0]),this.currentId)this.updatePolygonGeometry(this.currentId,M,l.Provisional);else{var et,it=this.store.create([{geometry:{type:"Polygon",coordinates:[M]},properties:(et={mode:this.mode},et[u.CURRENTLY_DRAWING]=!0,et)}]);this.currentId=it[0]}}},i.updateLineStringGeometry=function(t,e,i){var o={type:"LineString",coordinates:e};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.currentStartingPointId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:{mode:this.mode}}]);this.currentInitialArcId=i[0],this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&("Polygon"===t.geometry.type?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=p):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=p):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=20)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return z(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.getDeltaBearing=function(t,e,i){var o;return"anticlockwise"===t?(o=i-e)<0&&(o+=360):(o=e-i)<0&&(o+=360),o},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,o=t.normalizedEnd;return"clockwise"===t.direction?i<=o?e>=i&&e<=o:e>=i||e<=o:i>=o?e<=i&&e>=o:e<=i||e>=o},e}(I),Ye=function(t){var e=this,i=t.name,o=t.callback,n=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(o))},this.unregister=function(){e.register&&(e.registered=!1,n(o))},this.callback=o},Ke={__proto__:null,GeoJSONStore:Me,TerraDrawBaseDrawMode:I,TerraDrawBaseSelectMode:E,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(t){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._ignoreMismatchedPointerEvents="boolean"==typeof t.ignoreMismatchedPointerEvents&&t.ignoreMismatchedPointerEvents,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement().getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t,e){void 0===e&&(e=!1);var i=this.getLngLatFromEvent(t);if(!i)return null;var o=i.lng,n=i.lat,r=this.getMapElementXYPosition(t),s=r.containerX,a=r.containerY,d=this.getButton(t),l=Array.from(this._heldKeys);return{lng:w(o,this._coordinatePrecision),lat:w(n,this._coordinatePrecision),containerX:s,containerY:a,button:d,heldKeys:l,isContextMenu:e}},e.register=function(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(function(t){t.register()})},e.getCoordinatePrecision=function(){return this._coordinatePrecision},e.getAdapterListeners=function(){var t=this;return[new Ye({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i,t._lastPointerDownEventTarget=e.target?e.target:void 0)}},register:function(e){t.getMapEventElement().addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerdown",e)}}),new Ye({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var o={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},n={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=Z(o,n);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._nextKeyUpIsContextMenu=!1,t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new Ye({name:"contextmenu",callback:function(e){t._currentModeCallbacks&&(e.preventDefault(),t._nextKeyUpIsContextMenu=!0)},register:function(e){t.getMapEventElement().addEventListener("contextmenu",e)},unregister:function(e){t.getMapEventElement().removeEventListener("contextmenu",e)}}),new Ye({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement()&&(!t._ignoreMismatchedPointerEvents||t._lastPointerDownEventTarget===e.target)&&(t._lastPointerDownEventTarget=void 0,e.isPrimary)){var i=t.getDrawEventFromEvent(e);i&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(i,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||(t._nextKeyUpIsContextMenu&&(i.isContextMenu=!0,t._nextKeyUpIsContextMenu=!1),t._currentModeCallbacks.onClick(i)),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement().addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerup",e)}}),new Ye({name:"keyup",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.delete(e.key),t._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement().addEventListener("keyup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("keyup",e)}}),new Ye({name:"keydown",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.add(e.key),t._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement().addEventListener("keydown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("keydown",e)}})]},e.unregister=function(){this._listeners.forEach(function(t){t.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1},t}(),getDefaultStyling:function(){return{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0}},SELECT_PROPERTIES:h},ze={ValidationReasonFeatureNotPoint:Mt,ValidationReasonFeatureInvalidCoordinates:Dt,ValidationReasonFeatureInvalidCoordinatePrecision:Ft,ValidationReasonFeatureNotPolygon:m,ValidationReasonFeatureHasHoles:L,ValidationReasonFeatureLessThanFourCoordinates:A,ValidationReasonFeatureHasInvalidCoordinates:V,ValidationReasonFeatureCoordinatesNotClosed:Y,ValidationReasonFeatureNotPolygonOrLineString:_e,ValidationReasonFeatureSelfIntersects:be,ValidationReasonFeatureLessThanMinSize:ke,ValidationReasonModeMismatch:C},He={cancel:"Escape",finish:"Enter"},Xe={start:"crosshair",close:"pointer"},qe=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand-linestring",i.startingClick=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=20,i.keyEvents=He,i.cursors=Xe,i.preventNewFeature=!1,i.updateOptions(e),i}s(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),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=r({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=r({},this.cursors,e.cursors))},i.close=function(){if(void 0!==this.currentId){this.currentId&&this.store.updateProperty([{id:this.currentId,property:u.CURRENTLY_DRAWING,value:void 0}]);var t=this.currentId;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:l.Finish}).valid)return}this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 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.onMouseMove=function(t){if(void 0!==this.currentId&&!1!==this.startingClick){var e=this.store.getGeometryCopy(this.currentId),i=e.coordinates[e.coordinates.length-2],o=this.project(i[0],i[1]),n=Z({x:o.x,y:o.y},{x:t.containerX,y:t.containerY}),r=e.coordinates[e.coordinates.length-1],s=this.project(r[0],r[1]),a=Z({x:s.x,y:s.y},{x:t.containerX,y:t.containerY});if(this.setCursor(a<this.pointerDistance?this.cursors.close:this.cursors.start),!(n<this.minDistance)){var d={type:"LineString",coordinates:[].concat(e.coordinates,[[t.lng,t.lat]])};if(this.validate&&!this.validate({type:"Feature",id:this.currentId,geometry:d,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:d}]),this.closingPointId&&this.store.updateGeometry([{id:this.closingPointId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}])}}else this.setCursor(this.cursors.start)},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,o=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:(e={mode:this.mode},e[u.CURRENTLY_DRAWING]=!0,e)},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(i={mode:this.mode},i[u.CLOSING_POINT]=!0,i)}]),n=o[1];return this.currentId=o[0],this.closingPointId=n,this.startingClick=!0,void("drawing"!==this.state&&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=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode?(e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=p,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 yt(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0)},e}(I);function Ze(t){if(null===t)return!0;if("boolean"==typeof t)return!0;if("string"==typeof t)return!0;if(void 0===t)return!1;if("number"==typeof t)return Number.isFinite(t);if("bigint"==typeof t)return!1;if("symbol"==typeof t)return!1;if("function"==typeof t)return!1;if(t instanceof RegExp)return!1;if(t instanceof Map)return!1;if(t instanceof Set)return!1;if(t instanceof Date)return!1;if("object"==typeof t&&null!==t&&!Array.isArray(t)){var e=Object.getPrototypeOf(t);if(e!==Object.prototype&&null!==e)return!1}if(ArrayBuffer.isView(t)&&!(t instanceof DataView))return!1;if(Array.isArray(t))for(var i,o=n(t);!(i=o()).done;)if(!Ze(i.value))return!1;return"object"==typeof t&&Object.keys(t).every(function(e){return"string"==typeof e&&Ze(t[e])})}var Je={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},$e=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="marker",i.cursors=Je,i.editable=!1,i.editedFeatureId=void 0,i.markerUrl=void 0,i.markerHeight=void 0,i.markerWidth=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.updateOptions(e),i}s(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=r({},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:l.Finish}).valid)return;this.store.updateGeometry([{id:this.editedFeatureId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:u.EDITED,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:u.EDITED,value:!1}]),this.editedFeatureId=void 0,e(!0))},i.registerBehaviors=function(t){this.pixelDistance=new nt(t),this.clickBoundingBox=new ot(t)},i.styleFeature=function(t){var e,i,o,n=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(n.zIndex=30,n.markerHeight=this.getNumericStylingValue(null==(e=this.styles)?void 0:e.markerHeight,40,t),n.markerWidth=this.getNumericStylingValue(null==(i=this.styles)?void 0:i.markerWidth,32,t),n.markerUrl=this.getUrlStylingValue(null==(o=this.styles)?void 0:o.markerUrl,c,t)),n},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return wt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e,i={type:"Point",coordinates:[t.lng,t.lat]},o=((e={mode:this.mode})[u.MARKER]=!0,e);if(!this.validate||this.validate({type:"Feature",geometry:i,properties:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:l.Finish}).valid){var n=this.store.create([{geometry:i,properties:o}]);this.onFinish(n[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},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(I);t.TerraDraw=/*#__PURE__*/function(){function t(t){var e=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectMode=void 0,this._adapter=t.adapter,this._mode=new de;var i=new Set,o=t.modes.reduce(function(t,e){if(i.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return i.add(e.mode),t[e.mode]=e,t},{}),n=Object.keys(o);if(0===n.length)throw new Error("No modes provided");n.forEach(function(t){if(o[t].type===v.Select){if(e._instanceSelectMode)throw new Error("only one type of select mode can be provided");e._instanceSelectMode=t}}),this._modes=r({},o,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[]},this._store=new Me({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],o=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:o}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},d=function(t,i,o){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i,o)});var n=s(t),r=n.changed,a=n.unchanged;"create"===i?e._adapter.render({created:r,deletedIds:[],unchanged:a,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:a,updated:r},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:a,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:a,updated:[]},e.getModeStyles())}},l=function(t){if(e._enabled){e._eventListeners.select.forEach(function(e){e(t)});var i=s([t]);e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:i.changed},e.getModeStyles())}},c=function(t){if(e._enabled){e._eventListeners.deselect.forEach(function(t){t()});var i=s([t]),o=i.changed;o&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:o},e.getModeStyles())}};Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor.bind(e._adapter),project:e._adapter.project.bind(e._adapter),unproject:e._adapter.unproject.bind(e._adapter),setDoubleClickToZoom:e._adapter.setDoubleClickToZoom.bind(e._adapter),onChange:d,onSelect:l,onDeselect:c,onFinish:a,coordinatePrecision:e._adapter.getCoordinatePrecision()})})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(i){e[i]=function(e){return t._instanceSelectMode&&e.properties[h.SELECTED]?t._modes[t._instanceSelectMode].styleFeature.bind(t._modes[t._instanceSelectMode])(e):t._modes[i].styleFeature.bind(t._modes[i])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,r=e&&void 0!==e.pointerDistance?e.pointerDistance:30,s=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,a=!(!e||void 0===e.ignoreCoordinatePoints)&&e.ignoreCoordinatePoints,d=!(!e||void 0===e.ignoreCurrentlyDrawing)&&e.ignoreCurrentlyDrawing,l=!(!e||void 0===e.ignoreClosingPoints)&&e.ignoreClosingPoints,c=!(!e||void 0===e.ignoreSnappingPoints)&&e.ignoreSnappingPoints,p=this._adapter.unproject.bind(this._adapter),g=this._adapter.project.bind(this._adapter),f=g(i,o),y=it({unproject:p,point:f,pointerDistance:r});return this._store.search(y).filter(function(t){if(s&&(t.properties[h.MID_POINT]||t.properties[h.SELECTION_POINT]))return!1;if(a&&t.properties[u.COORDINATE_POINT])return!1;if(l&&t.properties[u.CLOSING_POINT])return!1;if(d&&t.properties[u.CURRENTLY_DRAWING])return!1;if(c&&t.properties[u.SNAPPING_POINT])return!1;if("Point"===t.geometry.type){var p=t.geometry.coordinates,y=g(p[0],p[1]);return Z(f,y)<r}if("LineString"===t.geometry.type){for(var v=t.geometry.coordinates,m=0;m<v.length-1;m++){var C=v[m],P=v[m+1];if(Xt(f,g(C[0],C[1]),g(P[0],P[1]))<r)return!0}return!1}if(Ht([i,o],t.geometry.coordinates))return!0;if(null!=e&&e.includePolygonsWithinPointerDistance)for(var I,E=n(t.geometry.coordinates);!(I=E()).done;)for(var x=I.value,S=0;S<x.length-1;S++){var M=x[S],D=x[S+1],F=g(M[0],M[1]),w=g(D[0],D[1]);if(Xt(f,F,w)<r)return!0}return!1}).map(function(t){if(null==e||!e.addClosestCoordinateInfoToProperties)return t;var n;if("Polygon"===t.geometry.type)n=t.geometry.coordinates[0].slice(0,-1);else{if("LineString"!==t.geometry.type)return t;n=t.geometry.coordinates}for(var r,s=-1,a=Infinity,d=0;d<n.length;d++){var l=n[d],c=Z(g(l[0],l[1]),f);c<a&&(s=d,a=c,r=l)}return t.properties.closestCoordinateIndexToEvent=s,t.properties.closestCoordinatePixelDistanceToEvent=a,t.properties.closestCoordinateDistanceKmToEvent=x(r,[i,o]),t})},e.getSelectModeOrThrow=function(){var t=this.getSelectMode({switchToSelectMode:!0});if(!t)throw new Error("No select mode defined in instance");return t},e.getSelectMode=function(t){var e=t.switchToSelectMode;if(this.checkEnabled(),!this._instanceSelectMode)return null;var i=this.getMode();return e&&i!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},e.isGuidanceFeature=function(t){return Boolean(t.properties[h.MID_POINT]||t.properties[h.SELECTION_POINT]||t.properties[u.COORDINATE_POINT]||t.properties[u.SNAPPING_POINT])},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.updateModeOptions=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].updateOptions(e)},e.getSnapshot=function(){return this._store.copyAll()},e.getSnapshotFeature=function(t){if(this._store.has(t))return this._store.copy(t)},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},e.getModeState=function(){return this._mode.state},e.setMode=function(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},e.removeFeatures=function(t){var e=this;this.checkEnabled();var i=[];t.forEach(function(t){if(!e._store.has(t))throw new Error("No feature with id "+t+", can not delete");var o=e._store.copy(t);o.properties[h.SELECTED]&&e.deselectFeature(t),o.properties[u.COORDINATE_POINT_IDS]&&i.push.apply(i,o.properties[u.COORDINATE_POINT_IDS])}),this._store.delete([].concat(t,i),{origin:"api"})},e.selectFeature=function(t){this.getSelectModeOrThrow().selectFeature(t)},e.deselectFeature=function(t){this.getSelectModeOrThrow().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.checkIsReservedProperty=function(t){return![].concat(Object.values(h),Object.values(u)).includes(t)},e.updateFeatureProperties=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");var n=o.properties.mode;if(!this._modes[n])throw new Error("No mode with name "+n+" present in instance");var r=Object.entries(e);r.forEach(function(t){var e=t[0],o=t[1];if(!i.checkIsReservedProperty(e))throw new Error("You are trying to update a reserved property name: "+e+". Please choose another name.");if(void 0!==o&&!Ze(o))throw new Error("Invalid JSON value provided for property "+e)}),this._store.updateProperty(r.map(function(t){return{id:o.id,property:t[0],value:t[1]}}),{origin:"api"})},e.updateFeatureGeometry=function(t,e){if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var i=this._store.copy(t);if(this.isGuidanceFeature(i))throw new Error("Guidance features are not allowed to be updated directly.");if(!(i&&e&&e.type&&e.coordinates))throw new Error("Invalid geometry provided");if(e.type!==i.geometry.type)throw new Error("Geometry type mismatch: expected "+i.geometry.type+", got "+e.type);var o=i.properties.mode,n=this._modes[o];if(!n)throw new Error("No mode with name "+o+" present in instance");var s=r({},i,{geometry:e}),a=n.validateFeature(s);if(!a.valid)throw new Error("Feature validation failed: "+(a.reason||"Unknown reason"));if(this._store.updateGeometry([{id:i.id,geometry:e}],{origin:"api"}),n.afterFeatureUpdated){n.afterFeatureUpdated(s);var d=s.properties[h.SELECTED],l=this.getSelectMode({switchToSelectMode:!1});l&&d&&l.afterFeatureUpdated(s)}},e.transformFeatureGeometry=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var o=this._store.copy(t);if(this.isGuidanceFeature(o))throw new Error("Guidance features are not allowed to be updated directly.");var n,r=o.properties.mode,s=this._modes[r];if(!s)throw new Error("No mode with name "+r+" present in instance");if("Polygon"===o.geometry.type)n=o.geometry.coordinates[0];else{if("LineString"!==o.geometry.type)throw new Error("Feature geometry type "+o.geometry.type+" is not supported for transformation");n=o.geometry.coordinates}if("web-mercator"!=e.projection)throw new Error("Projection "+e.projection+" is not currently supported for transformation");if("scale"===e.type){var a=b(e.origin[0],e.origin[1]);oe({coordinates:n,originX:a.x,originY:a.y,xScale:e.options.xScale||1,yScale:e.options.yScale||1})}else"rotate"===e.type&&(n="Polygon"===(o=Qt(o,e.options.angle||0)).geometry.type?o.geometry.coordinates[0]:o.geometry.coordinates);if(n=n.map(function(t){return[w(t[0],i._adapter.getCoordinatePrecision()),w(t[1],i._adapter.getCoordinatePrecision())]}),o.geometry.coordinates="Polygon"===o.geometry.type?[n]:n,this._store.updateGeometry([{id:o.id,geometry:o.geometry}],{origin:"api"}),s.afterFeatureUpdated){s.afterFeatureUpdated(o);var d=o.properties[h.SELECTED],l=this.getSelectMode({switchToSelectMode:!1});l&&d&&l.afterFeatureUpdated(o)}},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(f(t)){var i=t.properties.mode,o=e._modes[i];if(!o)return{id:t.id,valid:!1,reason:i+" mode is not in the list of instantiated modes"};var n=o.validateFeature.bind(o)(t);return{id:t.id,valid:n.valid,reason:n.reason?n.reason:n.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}},function(t){if(f(t)){var i=e._modes[t.properties.mode];i&&i.afterFeatureAdded&&i.afterFeatureAdded(t)}},{origin:"api"})},e.start=function(){var t=this;this._enabled||(this._enabled=!0,this._adapter.register({onReady:function(){t._eventListeners.ready.forEach(function(t){t()})},getState:function(){return t._mode.state},onClick:function(e){t._mode.onClick(e)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyDown:function(e){t._mode.onKeyDown(e)},onKeyUp:function(e){t._mode.onKeyUp(e)},onDragStart:function(e,i){t._mode.onDragStart(e,i)},onDrag:function(e,i){t._mode.onDrag(e,i)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)},onClear:function(){t._mode.cleanUp(),t._store.clear()}}))},e.getFeaturesAtLngLat=function(t,e){return this.featuresAtLocation({lng:t.lng,lat:t.lat},e)},e.getFeaturesAtPointerEvent=function(t,e){var i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)},e.stop=function(){this._enabled&&(this._enabled=!1,this._adapter.unregister())},e.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},e.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},o(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}])}(),t.TerraDrawAngledRectangleMode=je,t.TerraDrawCircleMode=q,t.TerraDrawExtend=Ke,t.TerraDrawFreehandLineStringMode=qe,t.TerraDrawFreehandMode=tt,t.TerraDrawLineStringMode=St,t.TerraDrawMarkerMode=$e,t.TerraDrawPointMode=kt,t.TerraDrawPolygonMode=Wt,t.TerraDrawRectangleMode=Gt,t.TerraDrawRenderMode=Rt,t.TerraDrawSectorMode=Ue,t.TerraDrawSelectMode=ae,t.TerraDrawSensorMode=Ve,t.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:m}:De(t.geometry)>e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0}},t.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:m}:De(t.geometry)<e?{valid:!1,reason:ke}:{valid:!0}},t.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:_e}:j(t)?{valid:!1,reason:be}:{valid:!0}},t.ValidationReasons=ze});
2
2
  //# sourceMappingURL=terra-draw.umd.js.map