terra-draw 1.0.0 → 1.2.0

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.
Files changed (37) hide show
  1. package/README.md +33 -4
  2. package/dist/common.d.ts +1 -0
  3. package/dist/geometry/boolean/right-hand-rule.d.ts +7 -0
  4. package/dist/geometry/boolean/right-hand-rule.spec.d.ts +1 -0
  5. package/dist/geometry/ensure-right-hand-rule.d.ts +2 -0
  6. package/dist/geometry/ensure-right-hand-rule.spec.d.ts +1 -0
  7. package/dist/geometry/point-on-line.d.ts +1 -0
  8. package/dist/geometry/web-mercator-point-on-line.d.ts +1 -0
  9. package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +2 -1
  10. package/dist/modes/base.mode.d.ts +10 -9
  11. package/dist/modes/circle/circle.mode.d.ts +2 -1
  12. package/dist/modes/coordinate-snapping.behavior.d.ts +7 -2
  13. package/dist/modes/freehand/freehand.mode.d.ts +2 -1
  14. package/dist/modes/line-snapping.behavior.d.ts +7 -2
  15. package/dist/modes/linestring/linestring.mode.d.ts +19 -4
  16. package/dist/modes/point/point.mode.d.ts +21 -5
  17. package/dist/modes/polygon/polygon.mode.d.ts +23 -7
  18. package/dist/modes/rectangle/rectangle.mode.d.ts +2 -1
  19. package/dist/modes/render/render.mode.d.ts +2 -1
  20. package/dist/modes/sector/sector.mode.d.ts +2 -1
  21. package/dist/modes/select/select.mode.d.ts +4 -3
  22. package/dist/modes/sensor/sensor.mode.d.ts +2 -1
  23. package/dist/modes/static/static.mode.d.ts +1 -1
  24. package/dist/store/store.d.ts +1 -0
  25. package/dist/terra-draw.cjs +1 -1
  26. package/dist/terra-draw.cjs.map +1 -1
  27. package/dist/terra-draw.d.ts +25 -40
  28. package/dist/terra-draw.modern.js +1 -1
  29. package/dist/terra-draw.modern.js.map +1 -1
  30. package/dist/terra-draw.module.js +1 -1
  31. package/dist/terra-draw.module.js.map +1 -1
  32. package/dist/terra-draw.umd.js +1 -1
  33. package/dist/terra-draw.umd.js.map +1 -1
  34. package/package.json +3 -3
  35. package/dist/test/jest.matchers.d.ts +0 -1
  36. package/dist/test/mock-callbacks.d.ts +0 -2
  37. package/dist/test/mock-pointer-event.d.ts +0 -1
@@ -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,n=Array(e);i<e;i++)n[i]=t[i];return n}function i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,l(n.key),n)}}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,i){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,i){if(t){if("string"==typeof t)return e(t,i);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,i):void 0}}(t))||i&&t&&"number"==typeof t.length){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},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 l(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 c;!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(c||(c={}));var d={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT:"selectionPoint"},h="closingPoint",u="snappingPoint";function g(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function p(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var f,y="Feature is not a Polygon",v="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"}(f||(f={}));var m=/*#__PURE__*/function(){function t(t){this._state=void 0,this._styles=void 0,this.behaviors=[],this.validate=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.projection=void 0,this.type=f.Drawing,this.mode="base",this._state="unregistered",this._styles=t&&t.styles?r({},t.styles):{},this.pointerDistance=t&&t.pointerDistance||40,this.validate=t&&t.validation,this.projection=t&&t.projection||"web-mercator"}var e=t.prototype;return e.registerBehaviors=function(t){},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.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:c.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:v}:{valid:!1,reason:i.reason}},e.onFinish=function(t,e){},e.onDeselect=function(t){},e.onSelect=function(t){},e.onKeyDown=function(t){},e.onKeyUp=function(t){},e.onMouseMove=function(t){},e.onClick=function(t){},e.onDragStart=function(t,e){},e.onDrag=function(t,e){},e.onDragEnd=function(t,e){},e.getHexColorStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getNumericStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?t(i):t},n(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([],"styling"),this._styles=t}}])}(),C=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=f.Select,e}return s(e,t),e}(m);function P(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}var M=6371008.8;function x(t){return t%360*Math.PI/180}function S(t){return t/6371.0088}function I(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 E=57.29577951308232,w=.017453292519943295,F=6378137,b=function(t,e){return{x:0===t?0:t*w*F,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*w/2))*F}},_=function(t,e){return{lng:0===t?0:E*(t/F),lat:0===e?0:(2*Math.atan(Math.exp(e/F))-Math.PI/2)*E}};function k(t,e,i){var n=x(t[0]),o=x(t[1]),r=x(i),s=S(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[I(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),I(a)]}function O(t){for(var e=t.center,i=t.radiusKilometers,n=t.coordinatePrecision,o=t.steps?t.steps:64,r=[],s=0;s<o;s++){var a=k(e,i,-360*s/o);r.push([D(a[0],n),D(a[1],n)])}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=[],n=0;n<e.length;n++)for(var o=0;o<e[n].length-1;o++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)l(n,o,r,s);return i.length>0;function a(t){return t<0||t>1}function l(t,n,o,r){var s,l=e[t][n],c=e[t][n+1],d=e[o][r],h=e[o][r+1],u=function(t,e,i,n){if(W(t,i)||W(t,n)||W(e,i)||W(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],l=i[0],c=i[1],d=n[0],h=n[1],u=(o-s)*(c-h)-(r-a)*(l-d);return 0===u?null:[((o*a-r*s)*(l-d)-(o-s)*(l*h-c*d))/u,((o*a-r*s)*(c-h)-(r-a)*(l*h-c*d))/u]}(l,c,d,h);null!==u&&(s=h[0]!==d[0]?(u[0]-d[0])/(h[0]-d[0]):(u[1]-d[1])/(h[1]-d[1]),a(c[0]!==l[0]?(u[0]-l[0])/(c[0]-l[0]):(u[1]-l[1])/(c[1]-l[1]))||a(s)||(u.toString(),i.push(u)))}}function W(t,e){return t[0]===e[0]&&t[1]===e[1]}function B(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(n=t[0])>=-180&&n<=180&&(i=t[1])>=-90&&i<=90&&N(t[0])<=e&&N(t[1])<=e;var i,n}function N(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var V="Feature has holes",L="Feature has less than 4 coordinates",T="Feature has invalid coordinates",G="Feature coordinates are not closed";function A(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:"Feature is not a Polygon"}:1!==t.geometry.coordinates.length?{valid:!1,reason:V}:t.geometry.coordinates[0].length<4?{valid:!1,reason:L}:t.geometry.coordinates[0].every(function(t){return B(t,e)})?(i=t.geometry.coordinates[0][0])[0]!==(n=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||i[1]!==n[1]?{valid:!1,reason:G}:{valid:!0}:{valid:!1,reason:T};var i,n}function U(t,e){var i=A(t,e);return i.valid?j(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var K=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).mode="circle",n.center=void 0,n.clickCount=0,n.currentCircleId=void 0,n.keyEvents=void 0,n.cursors=void 0,n.startingRadiusKilometers=1e-5,n.cursorMovedAfterInitialCursorDown=!1;var o={start:"crosshair"};if(n.cursors=e&&e.cursors?r({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))n.keyEvents={cancel:null,finish:null};else{var s={cancel:"Escape",finish:"Enter"};n.keyEvents=e&&e.keyEvents?r({},s,e.keyEvents):s}return n.startingRadiusKilometers=null!=(i=null==e?void 0:e.startingRadiusKilometers)?i:1e-5,n.validate=null==e?void 0:e.validation,n}s(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentCircleId){var t=this.currentCircleId;if(this.validate&&t){var e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:c.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(0===this.clickCount){this.center=[t.lng,t.lat];var e=O({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=i[0],this.clickCount++,this.cursorMovedAfterInitialCursorDown=!1,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.cursorMovedAfterInitialCursorDown&&this.updateCircle(t),this.close()},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.updateCircle(t)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t])}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return U(t,e.coordinatePrecision)})},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=P(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var n=function(t,e){var i=1e3*P(t,e);if(0===i)return 1;var n=b(t[0],t[1]),o=n.x,r=n.y,s=b(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-o,2)+Math.pow(a-r,2))/i}(this.center,[t.lng,t.lat]);e=function(t){for(var e=t.center,i=t.coordinatePrecision,n=t.steps?t.steps:64,o=1e3*t.radiusKilometers,r=b(e[0],e[1]),s=r.x,a=r.y,l=[],c=0;c<n;c++){var d=360*c/n*Math.PI/180,h=o*Math.cos(d),u=o*Math.sin(d),g=_(s+h,a+u),p=g.lat;l.push([D(g.lng,i),D(p,i)])}return l.push(l[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[l]},properties:{}}}({center:this.center,radiusKilometers:i*n,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");e=O({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:c.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},e}(m),R=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)},X=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="freehand",i.startingClick=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=void 0,i.keyEvents=void 0,i.cursors=void 0,i.preventPointsNearClose=void 0,i.autoClose=void 0,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,i.preventPointsNearClose=e&&e.preventPointsNearClose||!0,e&&e.autoCloseTimeout&&!e.autoClose)throw new Error("autoCloseTimeout is set, but autoClose is not enabled");if(i.autoClose=e&&e.autoClose||!1,i.autoCloseTimeout=e&&e.autoCloseTimeout||500,i.minDistance=e&&e.minDistance||20,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i.validate=null==e?void 0:e.validation,i}s(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){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:c.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(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){var e=this;if(void 0!==this.currentId&&!1!==this.startingClick){var i=this.store.getGeometryCopy(this.currentId),n=i.coordinates[0][i.coordinates[0].length-2],o=this.project(n[0],n[1]),r=R({x:o.x,y:o.y},{x:t.containerX,y:t.containerY}),s=i.coordinates[0][0],a=this.project(s[0],s[1]);if(R({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(function(){e.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(!(r<this.minDistance)){i.coordinates[0].pop();var l={type:"Polygon",coordinates:[[].concat(i.coordinates[0],[[t.lng,t.lat],i.coordinates[0][0]])]};if(this.validate&&!this.validate({type:"Feature",id:this.currentId,geometry:l,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:c.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:l}])}}},i.onClick=function(t){if(!this.preventNewFeature){if(!1===this.startingClick){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(e={mode:this.mode},e[h]=!0,e)}]),n=i[1];return this.currentId=i[0],this.closingPointId=n,this.startingClick=!0,void this.setDrawing()}this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&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});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=10,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=40,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return A(t,e.coordinatePrecision)})},e}(m),z=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection;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=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a};function Y(t){var e=t.unproject,i=t.point,n=t.pointerDistance/2,o=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(o-n,r-n),e(o+n,r-n),e(o+n,r+n),e(o-n,r+n),e(o-n,r-n)].map(function(t){return[t.lng,t.lat]})]}}}var H=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return s(e,t),e.prototype.create=function(t){return Y({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(z),q=/*#__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 R({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(z),Z=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)})},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)})},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return s(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={coord:void 0,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(e){var n=i.pixelDistance.measure(t,e);n<r.minDist&&n<i.pointerDistance&&(r.coord=e,r.minDist=n)})}),r.coord},e}(z);function J(t,e,i){var n=x(t[0]),o=x(t[1]),r=x(i),s=S(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[I(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),I(a)]}function $(t,e,i){var n=t.x,o=t.y,r=x(i);return{x:n+e*Math.cos(r),y:o+e*Math.sin(r)}}function Q(t,e){var i=x(t[0]),n=x(e[0]),o=x(t[1]),r=x(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return I(Math.atan2(s,a))}function tt(t,e){var i=Math.atan2(e.y-t.y,e.x-t.x);return(i*=180/Math.PI)>180?i-=360:i<-180&&(i+=360),i}function et(t){return(t+360)%360}function it(t,e,i){for(var n,o,r,s=[],a=t.length,l=0,c=0;c<t.length&&!(e>=l&&c===t.length-1);c++){if(l>e&&0===s.length){if(!(n=e-l))return s.push(t[c]),s;o=Q(t[c],t[c-1])-180,r=J(t[c],n,o),s.push(r)}if(l>=i)return(n=i-l)?(o=Q(t[c],t[c-1])-180,r=J(t[c],n,o),s.push(r),s):(s.push(t[c]),s);if(l>=e&&s.push(t[c]),c===t.length-1)return s;l+=P(t[c],t[c+1])}if(l<e&&t.length===a)throw new Error("Start position is beyond line");var d=t[t.length-1];return[d,d]}function nt(t){return t*(Math.PI/180)}function ot(t){return t*(180/Math.PI)}var rt=/*#__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 n=[t,e],o=0,r=0;r<n.length-1;r++)o+=P(n[0],n[1]);if(o<=i)return n;var s=o/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],l=0;l<s;l++){var c=it(n,i*l,i*(l+1));a.push(c)}for(var d=[],h=0;h<a.length;h++)d.push(a[h][1]);return this.limitCoordinates(d)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var n=P(t,e),o=function(t,e,i){var n=[],o=nt(t[1]),r=nt(t[0]),s=nt(e[1]),a=nt(e[0]);i+=1;var l=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-o)/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===l||isNaN(l))return n;for(var c=0;c<=i;c++){var d=c/i,h=Math.sin((1-d)*l)/Math.sin(l),u=Math.sin(d*l)/Math.sin(l),g=h*Math.cos(o)*Math.cos(r)+u*Math.cos(s)*Math.cos(a),p=h*Math.cos(o)*Math.sin(r)+u*Math.cos(s)*Math.sin(a),f=h*Math.sin(o)+u*Math.sin(s);if(!(isNaN(g)||isNaN(p)||isNaN(f))){var y=Math.atan2(f,Math.sqrt(Math.pow(g,2)+Math.pow(p,2))),v=Math.atan2(p,g);isNaN(y)||isNaN(v)||n.push([ot(v),ot(y)])}}return n.slice(1,-1)}(t,e,Math.floor(n/i));return this.limitCoordinates(o)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[D(t[0],e.config.coordinatePrecision),D(t[1],e.config.coordinatePrecision)]})},e}(z);function st(t,e){return t[0]===e[0]&&t[1]===e[1]}function at(t,e){return"LineString"!==t.geometry.type?{valid:!1,reason:"Feature is not a LineString"}:t.geometry.coordinates.length<2?{valid:!1,reason:"Feature has less than 2 coordinates"}:t.geometry.coordinates.every(function(t){return B(t,e)})?{valid:!0}:{valid:!1,reason:"Feature has invalid coordinates"}}var lt=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.closingPointId=void 0,i.keyEvents=void 0,i.snapping=void 0,i.cursors=void 0,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommitedCoordinates=void 0,i.snappedPointId=void 0,i.coordinateSnapping=void 0,i.insertPoint=void 0;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,i.snapping=e&&e.snapping?e.snapping:void 0,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i.validate=null==e?void 0:e.validation,i.insertCoordinates=null==e?void 0:e.insertCoordinates,i}s(e,t);var i=e.prototype;return 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,c.Commit);var e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.snappedPointId=void 0,this.lastCommitedCoordinates=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}},i.updateGeometries=function(t,e,i){if(this.currentId){var n={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid)return;var o=[{id:this.currentId,geometry:n}];this.closingPointId&&e&&o.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=n.coordinates),this.store.updateGeometry(o)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=P(t,e)/(this.insertCoordinates.value+1),n=[];return"globe"===this.projection?n=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(n=this.insertPoint.generateInsertionCoordinates(t,e,i)),n},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var n=[].concat(e,[t]);this.updateGeometries(n,void 0,c.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,n=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],o=this.project(n[0],n[1]);if(R({x:o.x,y:o.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],c.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.coordinateSnapping=new Z(t,new q(t),new H(t)),this.insertPoint=new rt(t)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,n=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[u]=!0,i)}]);this.snappedPointId=n[0]}t.lng=e[0],t.lat=e[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);var o=e||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var r=this.store.getGeometryCopy(this.currentId).coordinates;if(r.pop(),this.closingPointId){var s=r[r.length-1],a=this.project(s[0],s[1]);R({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var l=[].concat(r,[o]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var d=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],h=o;if(!st(d,h)){var g=this.generateInsertCoordinates(d,h);l=[].concat(this.lastCommitedCoordinates.slice(0,-1),g,[o])}}this.updateGeometries(l,void 0,c.Provisional)}},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,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.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.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});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=10,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[h];return e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:this.styles.snappingPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:this.styles.snappingPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:this.styles.snappingPointOutlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:this.styles.snappingPointOutlineWidth,2,t),e.zIndex=40,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return at(t,e.coordinatePrecision)})},i.snapCoordinate=function(t){var e,i,n;return null!=(e=this.snapping)&&e.toCoordinate&&(n=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t)),null!=(i=this.snapping)&&i.toCustom&&(n=this.snapping.toCustom(t)),n},e}(m),ct="Feature is not a Point",dt="Feature has invalid coordinates";function ht(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:ct}:B(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:dt}}var ut=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="point",i.cursors=void 0;var n={create:"crosshair"};return i.cursors=e&&e.cursors?r({},n,e.cursors):n,i}s(e,t);var i=e.prototype;return i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");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:c.Finish}).valid){var n=this.store.create([{geometry:e,properties:i}]);this.onFinish(n[0],{mode:this.mode,action:"draw"})}},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},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});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(e.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,t),e.zIndex=30),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return ht(t,e.coordinatePrecision)})},e}(m),gt=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n._startEndPoints=[],n.config=e,n.pixelDistance=i,n}s(e,t);var i=e.prototype;return i.create=function(t,e){var i,n;if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i[h]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(n={mode:e},n[h]=!0,n)}])},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]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},n(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(z);function pt(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function ft(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(pt(t)*pt(e));return Math.acos(Math.min(Math.max(i,-1),1))}function yt(t){var e=x(t[1]),i=x(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function vt(t){var e=t[0],i=t[1],n=I(Math.asin(t[2]));return[I(Math.atan2(i,e)),n]}var mt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)})},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)})},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return s(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),r=this.store.search(n,e),s={coord:void 0,minDistance:Infinity};return r.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}for(var r,a=[],l=0;l<n.length-1;l++)a.push([n[l],n[l+1]]);var c=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,n,r,s,a,l,c,d,h=[Infinity,Infinity],u=Infinity,g=o(e);!(i=g()).done;){var p=i.value,f=p[0],y=p[1],v=void 0,m=Infinity,C=b(f[0],f[1]),P=b(y[0],y[1]),M=b(t[0],t[1]);if(f[0]===t[0]&&f[1]===t[1])v=f;else if(y[0]===t[0]&&y[1]===t[1])v=y;else{var x=(c=(l={x:(s=M).x-(n=C).x,y:s.y-n.y}).x*(a={x:(r=P).x-n.x,y:r.y-n.y}).x+l.y*a.y,d=Math.max(0,Math.min(1,c/(a.x*a.x+a.y*a.y))),{x:n.x+d*a.x,y:n.y+d*a.y}),S=_(x.x,x.y);v=[S.lng,S.lat]}v&&(m=R(M,b(v[0],v[1])))<u&&(h=v,u=m)}return Infinity===u?void 0:{coordinate:h,distance:u}}(c,a):"globe"===i.config.projection&&(r=function(t,e){for(var i,n=[Infinity,Infinity],r=Infinity,s=o(e);!(i=s()).done;){var a,l=i.value,c=l[0],d=l[1],h=Infinity;(a=c[0]===t[0]&&c[1]===t[1]?c:d[0]===t[0]&&d[1]===t[1]?d:(u=c,g=d,p=t,D=yt(u),E=yt(g),w=yt(p),F=w[0],b=w[1],_=w[2],k=[(m=(f=D)[1])*(S=(y=E)[2])-(C=f[2])*(x=y[1]),C*(M=y[0])-(v=f[0])*S,v*x-m*M],O=k[0],j=k[1],W=k[2],B=j*_-W*b,N=W*F-O*_,V=O*b-j*F,L=V*j-N*W,T=B*W-V*O,G=N*O-B*j,A=1/Math.sqrt(Math.pow(L,2)+Math.pow(T,2)+Math.pow(G,2)),U=[L*A,T*A,G*A],K=[-1*L*A,-1*T*A,-1*G*A],R=ft(D,E),X=ft(D,U),z=ft(E,U),Y=ft(D,K),H=ft(E,K),ft(D,I=X<Y&&X<H||z<Y&&z<H?U:K)>R||ft(E,I)>R?P(vt(I),vt(D))<=P(vt(I),vt(E))?[vt(D),!0,!1]:[vt(E),!1,!0]:[vt(I),!1,!1])[0])&&(h=P(t,a))<r&&(n=a,r=h)}var u,g,p,f,y,v,m,C,M,x,S,I,D,E,w,F,b,_,k,O,j,W,B,N,V,L,T,G,A,U,K,R,X,z,Y,H;return Infinity===r?void 0:{coordinate:n,distance:r}}(c,a)),r){var d=i.pixelDistance.measure(t,r.coordinate);d<s.minDistance&&d<i.pointerDistance&&(s.coord=r.coordinate,s.minDistance=d)}}),s.coord},e}(z),Ct=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,i.snapping=e&&e.snapping?e.snapping:void 0,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i}s(e,t);var i=e.prototype;return 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]]),c.Finish)){var e=this.currentId;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){var e=new H(t);this.pixelDistance=new q(t),this.lineSnapping=new mt(t,this.pixelDistance,e),this.coordinateSnapping=new Z(t,this.pixelDistance,e),this.closingPoints=new gt(t,this.pixelDistance)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,n=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[u]=!0,i)}]);this.snappedPointId=n[0]}t.lng=e[0],t.lat=e[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);if(void 0!==this.currentId&&0!==this.currentCoordinate){var o,r=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var s=1/Math.pow(10,this.coordinatePrecision-1),a=Math.max(1e-6,s);o=[r[0],[t.lng,t.lat],[t.lng,t.lat-a],r[0]]}else if(2===this.currentCoordinate)o=[r[0],r[1],[t.lng,t.lat],r[0]];else{var l=this.closingPoints.isClosingPoint(t);l.isPreviousClosing||l.isClosing?(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.setCursor(this.cursors.close),o=[].concat(r.slice(0,-2),[r[0],r[0]])):o=[].concat(r.slice(0,-2),[[t.lng,t.lat],r[0]])}this.updatePolygonGeometry(o,c.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}]),0))},i.snapCoordinate=function(t){var e,i,n,o,r,s=void 0;return null!=(e=this.snapping)&&e.toLine&&(o=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(s=o),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(s=r),null!=(n=this.snapping)&&n.toCustom&&(s=this.snapping.toCustom(t)),s},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),0===this.currentCoordinate){var e=this.snapCoordinate(t);e&&(t.lng=e[0],t.lat=e[1]);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:{mode:this.mode}}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.snapCoordinate(t);n&&(t.lng=n[0],t.lat=n[1]);var o=this.store.getGeometryCopy(this.currentId);if(st([t.lng,t.lat],o.coordinates[0][0]))return;if(!this.updatePolygonGeometry([o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]],c.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var r=this.snapCoordinate(t);r&&(t.lng=r[0],t.lat=r[1]);var s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(st([t.lng,t.lat],s[1]))return;if(!this.updatePolygonGeometry([s[0],s[1],[t.lng,t.lat],[t.lng,t.lat],s[0]],c.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(s,"polygon"),this.currentCoordinate++}else if(this.currentId){var a=this.store.getGeometryCopy(this.currentId).coordinates[0],l=this.closingPoints.isClosingPoint(t);if(l.isPreviousClosing||l.isClosing)this.close();else{var d=this.snapCoordinate(t);if(d&&(t.lng=d[0],t.lat=d[1]),st([t.lng,t.lat],a[this.currentCoordinate-1]))return;var h=(void 0===(u=[[].concat(a.slice(0,-1),[[t.lng,t.lat],a[0]])])&&(u=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:u},properties:{}});if(!this.updatePolygonGeometry(h.geometry.coordinates[0],c.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(h.geometry.coordinates[0])}}var u},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){this.setCursor("unset")},i.onDrag=function(){},i.onDragEnd=function(){this.setCursor(this.cursors.start)},i.cleanUp=function(){var t=this.currentId,e=this.snappedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),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});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=10,e;if("Point"===t.geometry.type){var i=t.properties[h],n=t.properties[u];return e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:n?this.styles.snappingPointWidth:e.pointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:n?this.styles.snappingPointColor:e.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:n?this.styles.snappingPointOutlineColor:e.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:n?this.styles.snappingPointOutlineWidth:2,2,t),e.zIndex=30,e}}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return A(t,e.coordinatePrecision)})},e}(m),Pt=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="rectangle",i.center=void 0,i.clickCount=0,i.currentRectangleId=void 0,i.keyEvents=void 0,i.cursors=void 0;var n={start:"crosshair"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i}s(e,t);var i=e.prototype;return i.updateRectangle=function(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){var i=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],n={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:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid)return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:n}])}},i.close=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.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(0===this.clickCount){this.center=[t.lng,t.lat];var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentRectangleId=e[0],this.clickCount++,this.setDrawing()}else this.updateRectangle(t,c.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,c.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});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=10,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return U(t,e.coordinatePrecision)})},e}(m),Mt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).type=f.Render,i.mode="render",i.mode=e.modeName,i}s(e,t);var i=e.prototype;return 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 n=e,o=ht(n,this.coordinatePrecision).valid||A(n,this.coordinatePrecision).valid||at(n,this.coordinatePrecision).valid;return o?{valid:!0}:{valid:o,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(m);function xt(t,e){var i=t,n=e,o=x(i[1]),r=x(n[1]),s=x(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=(I(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function St(t,e,i){var n=e;e<0&&(n=-Math.abs(n));var o=n/M,r=t[0]*Math.PI/180,s=x(t[1]),a=x(i),l=o*Math.cos(a),c=s+l;Math.abs(c)>Math.PI/2&&(c=c>0?Math.PI-c:-Math.PI-c);var d=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),h=Math.abs(d)>1e-11?l/d:Math.cos(s),u=[(180*(r+o*Math.sin(a)/h)/Math.PI+540)%360-180,180*c/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function It(t,e,i,n,o){var r=n(t[0],t[1]),s=n(e[0],e[1]),a=o((r.x+s.x)/2,(r.y+s.y)/2),l=a.lat;return[D(a.lng,i),D(l,i)]}function Dt(t,e,i){var n=St(t,1e3*P(t,e)/2,xt(t,e));return[D(n[0],i),D(n[1],i)]}function Et(t){for(var e=t.featureCoords,i=t.precision,n=t.unproject,o=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var l=void 0;if("web-mercator"===r)l=It(e[a],e[a+1],i,o,n);else{if("globe"!==r)throw new Error("Invalid projection");l=Dt(e[a],e[a+1],i)}s.push(l)}return s}var wt=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n}s(e,t);var i=e.prototype;return i.insert=function(t,e){var i=this.store.getGeometryCopy(t),n=this.store.getPropertiesCopy(t),o=n.midPointFeatureId,r=n.midPointSegment,s=this.store.getGeometryCopy(o),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:o,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,o,e),this.selectionPointBehavior.create(a,s.type,o)},i.create=function(t,e,i){var n=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,n,o,r){return Et({featureCoords:t,precision:i,project:n,unproject:o,projection:r}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:n.mode})[d.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 Et({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}}})},n(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}])}(z),Ft=/*#__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 n=this;this._selectionPoints=this.store.create(function(t,e,i){for(var n=[],o="Polygon"===e?t.length-1:t.length,r=0;r<o;r++)n.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return n}(t,e,function(t){return{mode:n.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},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}}},n(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}])}(z);function bt(t,e){for(var i,n,o,r=!1,s=0,a=e.length;s<a;s++)for(var l=e[s],c=0,d=l.length,h=d-1;c<d;h=c++)(n=l[c])[1]>(i=t)[1]!=(o=l[h])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var _t=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},kt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return s(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=void 0,a=Infinity,l=void 0,c=this.createClickBoundingBox.create(t),h=this.store.search(c),u=0;u<h.length;u++){var g=h[u],p=g.geometry;if("Point"===p.type){if(g.properties.selectionPoint||!e&&g.properties[d.MID_POINT])continue;var f=this.pixelDistance.measure(t,p.coordinates);g.properties[d.MID_POINT]&&f<this.pointerDistance&&f<a?(a=f,s=g):!g.properties[d.MID_POINT]&&f<this.pointerDistance&&f<n&&(n=f,i=g)}else if("LineString"===p.type){if(i)continue;for(var y=0;y<p.coordinates.length-1;y++){var v=p.coordinates[y],m=p.coordinates[y+1],C=_t({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,o=g)}}else if("Polygon"===p.type){if(i||o)continue;bt([t.lng,t.lat],p.coordinates)&&(l=g)}}return{clickedFeature:i||o||l,clickedMidPoint:s}},e}(z),Ot=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.featuresAtCursorEvent=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedFeatureId=null,r.dragPosition=void 0,r.config=e,r.featuresAtCursorEvent=i,r.selectionPoints=n,r.midPoints=o,r}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),n=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var o,r;if(r="Polygon"===i.type?(o=i.coordinates[0]).length-1:(o=i.coordinates).length,!this.dragPosition)return!1;for(var s=0;s<r;s++){var a=o[s],l=void 0,d=void 0;if("web-mercator"===this.config.projection){var h=b(this.dragPosition[0],this.dragPosition[1]),u=b(n[0],n[1]),g=b(a[0],a[1]),p={x:h.x-u.x,y:h.y-u.y},f=_(g.x-p.x,g.y-p.y);l=f.lng,d=f.lat}else{var y=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]];l=a[0]-y[0],d=a[1]-y[1]}if(l=D(l,this.config.coordinatePrecision),d=D(d,this.config.coordinatePrecision),l>180||l<-180||d>90||d<-90)return!1;o[s]=[l,d]}"Polygon"===i.type&&(o[o.length-1]=[o[0][0],o[0][1]]);var v=this.selectionPoints.getUpdated(o)||[],m=this.midPoints.getUpdated(o)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:c.Provisional}).valid)return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(v,m)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:n}}]),this.dragPosition=[t.lng,t.lat])}},e}(z),jt=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedCoordinate={id:null,index:-1},r.config=e,r.pixelDistance=i,r.selectionPoints=n,r.midPoints=o,r}s(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var n=this.draggedCoordinate.index,o=this.store.getGeometryCopy(this.draggedCoordinate.id),r="LineString"===o.type?o.coordinates:o.coordinates[0],s=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==o.type||n!==r.length-1&&0!==n)r[n]=s;else{var a=r.length-1;r[0]=s,r[a]=s}var l=this.selectionPoints.getOneUpdated(n,s),d=l?[l]:[],h=this.midPoints.getUpdated(r)||[];return!("Point"!==o.type&&!e&&j({type:"Feature",geometry:o,properties:{}})||i&&!i({type:"Feature",id:this.draggedCoordinate.id,geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:c.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:o}].concat(d,h)),0))},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(z);function Wt(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}function Bt(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=M,n=e[1]*Math.PI/180,o=t[1]*Math.PI/180,r=o-n,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),l=Math.abs(a)>1e-11?r/a:Math.cos(n);return Math.sqrt(r*r+l*l*s*s)*i}function Nt(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,n=0,o=t.length,r=0;r<o-1;r++){var s=t[r],a=s[0],l=s[1],c=t[r+1],d=c[0],h=c[1],u=a*h-d*l;e+=u,i+=(a+d)*u,n+=(l+h)*u}return{x:i/=6*(e/=2),y:n/=6*e}}(e):function(t){for(var e=t.length,i=0,n=0,o=0;o<e;o++){var r=t[o];i+=r[0],n+=r[1]}return{x:i/e,y:n/e}}(e)}var Vt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastBearing=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}s(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e,i){var n=this,o=this.store.getGeometryCopy(e);if("Polygon"===o.type||"LineString"===o.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:o,properties:{}};if("web-mercator"===this.config.projection){if(r=tt(Nt(a),b(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=r);!function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return b(t[0],t[1])}),o=n.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});o.x/=n.length,o.y/=n.length;var r=n.map(function(t){return{x:o.x+(t.x-o.x)*Math.cos(i)-(t.y-o.y)*Math.sin(i),y:o.y+(t.x-o.x)*Math.sin(i)+(t.y-o.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[_(e,i).lng,_(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(a,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(r=xt(Wt({type:"Feature",geometry:o,properties:{}}),s),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=Wt(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=xt(i,t)+e,o=Bt(i,t),r=St(i,o,n);t[0]=r[0],t[1]=r[1]})}(a,-(this.lastBearing-(r+180)))}var l="Polygon"===o.type?o.coordinates[0]:o.coordinates;l.forEach(function(t){t[0]=D(t[0],n.coordinatePrecision),t[1]=D(t[1],n.coordinatePrecision)});var d=this.midPoints.getUpdated(l)||[],h=this.selectionPoints.getUpdated(l)||[];if(i&&!i({id:e,type:"Feature",geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:c.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:o}].concat(h,d)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}(z),Lt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastDistance=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}s(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e,i){var n=this,o=this.store.getGeometryCopy(e);if("Polygon"===o.type||"LineString"===o.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:o,properties:{}},l=Nt(a);if("web-mercator"===this.config.projection){var d=b(t.lng,t.lat);r=R(l,d)}else{if("globe"!==this.config.projection)throw new Error("Invalid projection");r=P(Wt({type:"Feature",geometry:o,properties:{}}),s)}if(this.lastDistance){var h=1-(this.lastDistance-r)/r;if("web-mercator"===this.config.projection){var u=_(l.x,l.y);!function(t,e,i){if(1===e)return t;var n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return b(t[0],t[1])}),o=b(i[0],i[1]),r=n.map(function(t){return{x:o.x+(t.x-o.x)*e,y:o.y+(t.y-o.y)*e}}).map(function(t){var e=t.x,i=t.y;return[_(e,i).lng,_(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(a,h,[u.lng,u.lat])}else"globe"===this.config.projection&&function(t,e,i,n){void 0===n&&(n="xy"),1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=Bt(i,t),r=xt(i,t),s=St(i,o*e,r);"x"!==n&&"xy"!==n||(t[0]=s[0]),"y"!==n&&"xy"!==n||(t[1]=s[1])})}(a,h,Wt(a));var g="Polygon"===o.type?o.coordinates[0]:o.coordinates;g.forEach(function(t){t[0]=D(t[0],n.coordinatePrecision),t[1]=D(t[1],n.coordinatePrecision)});var p=this.midPoints.getUpdated(g)||[],f=this.selectionPoints.getUpdated(g)||[];if(i&&!i({id:e,type:"Feature",geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:c.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:o}].concat(f,p)),this.lastDistance=r}else this.lastDistance=r}},e}(z),Tt=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.minimumScale=1e-4,r.draggedCoordinate={id:null,index:-1},r.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},r.config=e,r.pixelDistance=i,r.selectionPoints=n,r.midPoints=o,r}s(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},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,n=e.updatedCoords,o=e.selectedCoordinate,r=Nt(e.feature);if(!r)return null;var s=b(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=b(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),n},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=Nt(e.feature);if(!r)return null;var s=b(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=b(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),n},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,n=t.webMercatorCursor,o=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-n.x,e.y-n.y))return null;var r=R(e,n)/R(e,i);return r<0&&(r=this.minimumScale),this.performWebMercatorScale(o,e.x,e.y,r,r),o},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=b(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=b(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:l,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),n},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=b(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=b(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:l,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),n},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,n=t.webMercatorSelected,o=t.webMercatorCursor,r=t.updatedCoords,s=i.x-o.x,a=i.y-o.y;if(!this.isValidDragWebMercator(e,s,a))return null;var l=1;0!==s&&1!==e&&5!==e&&(l=1-(i.x-n.x-s)/s);var c=1;return 0!==a&&3!==e&&7!==e&&(c=1-(i.y-n.y-a)/a),this.validateScale(l,c)?(l<0&&(l=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(r,i.x,i.y,l,c),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:{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,n=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&n},i.performWebMercatorScale=function(t,e,i,n,o){t.forEach(function(t){var r=b(t[0],t[1]),s=_(e+(r.x-e)*n,i+(r.y-i)*o),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],n=t[1];i<e[0]&&(e[0]=i),n<e[1]&&(e[1]=n),i>e[2]&&(e[2]=i),n>e[3]&&(e[3]=n)});var i=e[0],n=e[1],o=e[2],r=e[3];return[[i,r],[(i+o)/2,r],[o,r],[o,r+(n-r)/2],[o,n],[(i+o)/2,n],[i,n],[i,r+(n-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,n=Infinity,o=0;o<t.length;o++){var r=R({x:e.x,y:e.y},{x:t[o][0],y:t[o][1]});r<n&&(i=o,n=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),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var n=this.getFeature(this.draggedCoordinate.id);if(!n)return!1;var o=null;if("center"===e?o=this.centerWebMercatorDrag(t):"opposite"===e?o=this.oppositeWebMercatorDrag(t):"center-fixed"===e?o=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(o=this.oppositeFixedWebMercatorDrag(t)),!o)return!1;for(var r=0;r<o.length;r++){var s=o[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(o)||[],l=this.selectionPoints.getUpdated(o)||[],d={type:n.geometry.type,coordinates:"Polygon"===n.geometry.type?[o]:o};return!(i&&!i({id:this.draggedCoordinate.id,type:"Feature",geometry:d,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:c.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:d}].concat(l,a)),0))},e}(z),Gt=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).mode="select",n.allowManualDeselection=!0,n.dragEventThrottle=5,n.dragEventCount=0,n.selected=[],n.flags=void 0,n.keyEvents=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.featuresAtMouseEvent=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.dragFeature=void 0,n.dragCoordinate=void 0,n.rotateFeature=void 0,n.scaleFeature=void 0,n.dragCoordinateResizeFeature=void 0,n.cursors=void 0,n.validations={},n.flags=e&&e.flags?e.flags:{};var o={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"};if(n.cursors=e&&e.cursors?r({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))n.keyEvents={deselect:null,delete:null,rotate:null,scale:null};else{var s={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]};n.keyEvents=e&&e.keyEvents?r({},s,e.keyEvents):s}if(n.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,n.allowManualDeselection=null==(i=null==e?void 0:e.allowManualDeselection)||i,e&&e.flags&&e.flags)for(var a in e.flags){var l=e.flags[a].feature;l&&l.validation&&(n.validations[a]=l.validation)}return n}s(e,t);var i=e.prototype;return 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 q(t),this.clickBoundingBox=new H(t),this.featuresAtMouseEvent=new kt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Ft(t),this.midPoints=new wt(t,this.selectionPoints),this.rotateFeature=new Vt(t,this.selectionPoints,this.midPoints),this.scaleFeature=new Lt(t,this.selectionPoints,this.midPoints),this.dragFeature=new Ot(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new jt(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new Tt(t,this.pixelDistance,this.selectionPoints,this.midPoints)},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:d.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,n=Infinity;if(this.selectionPoints.ids.forEach(function(o){var r=e.store.getGeometryCopy(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.store.getPropertiesCopy(o))}),i){var o=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(o),a=this.flags[s.mode],l=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var d,h=this.store.getGeometryCopy(o);if("Polygon"===h.type){if((d=h.coordinates[0]).length<=4)return}else if("LineString"===h.type&&(d=h.coordinates).length<=3)return;if(d){if("Polygon"===h.type&&0===r||r===d.length-1?(d.shift(),d.pop(),d.push([d[0][0],d[0][1]])):d.splice(r,1),l&&!l({id:o,type:"Feature",geometry:h,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:c.Commit}).valid)return;this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:o,geometry:h}]),this.selectionPoints.create(d,h.type,o),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(d,o,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),n=this.flags[i.mode];if(n&&n.feature){var o=this.selected[0];if(o){if(o===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:"selected",value:!0}]),this.onSelect(t);var r=this.store.getGeometryCopy(t),s=r.type,a=r.coordinates;if("LineString"===s||"Polygon"===s){var l="LineString"===s?a:a[0];l&&n&&n.feature.coordinates&&(this.selectionPoints.create(l,s,t),n.feature.coordinates.midpoints&&this.midPoints.create(l,t,this.coordinatePrecision))}}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,n=e.clickedMidPoint;if(this.selected.length&&n)this.midPoints.insert(n.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?"left"===t.button&&this.onLeftClick(t):this.onRightClick(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;this.onDeselect(this.selected[0]),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.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),n=this.flags[i.mode];if(n&&n.feature&&(n.feature.draggable||n.feature.coordinates&&n.feature.coordinates.draggable||n.feature.coordinates&&n.feature.coordinates.resizable)){this.dragEventCount=0;var o=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,o);return n&&n.feature&&n.feature.coordinates&&(n.feature.coordinates.draggable||n.feature.coordinates.resizable)&&-1!==r?(this.setCursor(this.cursors.dragStart),n.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(o,r):this.dragCoordinate.startDragging(o,r),void e(!1)):n&&n.feature&&n.feature.draggable&&this.dragFeature.canDrag(t,o)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,o),void e(!1)):void 0}}},i.onDrag=function(t,e){var i=this.selected[0];if(i){var n=this.store.getPropertiesCopy(i),o=this.flags[n.mode],r=!0===(o&&o.feature&&o.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[n.mode];if(o&&o.feature&&o.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(o&&o.feature&&o.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,o.feature.coordinates.resizable,s)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,r,s):this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}},i.onDragEnd=function(t,e){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(n){if(!i){var o=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!0)}});var n=!1;if(this.selectionPoints.ids.forEach(function(o){var r=e.store.getGeometryCopy(o);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!1,n=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var o=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(o&&o.id===this.selected[0]||n)?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});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=40,e}else if(t.properties[d.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=10,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=10,e}return e},e}(C),At=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=f.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})},e}(m);function Ut(t,e,i,n,o){for(;n>i;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(r-l)/r)*(s-r/2<0?-1:1);Ut(t,e,Math.max(i,Math.floor(e-s*l/r+c)),Math.min(n,Math.floor(e+(r-s)*l/r+c)),o)}var d=t[e],h=i,u=n;for(Kt(t,i,e),o(t[n],d)>0&&Kt(t,i,n);h<u;){for(Kt(t,h,u),h++,u--;o(t[h],d)<0;)h++;for(;o(t[u],d)>0;)u--}0===o(t[i],d)?Kt(t,i,u):Kt(t,++u,n),u<=e&&(i=u+1),e<=u&&(n=u-1)}}function Kt(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function Rt(t,e){Xt(t,0,t.children.length,e,t)}function Xt(t,e,i,n,o){o||(o=Qt([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];zt(o,t.leaf?n(s):s)}return o}function zt(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 Yt(t,e){return t.minX-e.minX}function Ht(t,e){return t.minY-e.minY}function qt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Zt(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Jt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function $t(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Qt(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function te(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;Ut(t,s,e,i,o),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(!$t(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?n(s):s;$t(t,a)&&(e.leaf?i.push(s):Jt(t,a)?this._all(s,i):o.push(s))}e=o.pop()}return i},e.collides=function(t){var e=this.data;if($t(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var o=e.children[n],r=e.leaf?this.toBBox(o):o;if($t(t,r)){if(e.leaf||Jt(t,r))return!0;i.push(o)}}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 n=this.data;this.data=i,i=n}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=Qt([])},e.remove=function(t){for(var e,i,n=this.data,o=this.toBBox(t),r=[],s=[],a=!1;n||r.length;){if(n||(n=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),n.leaf){var l=n.children.indexOf(t);-1!==l&&(n.children.splice(l,1),r.push(n),this._condense(r))}a||n.leaf||!Jt(n,o)?i?(e++,n=i.children[e],a=!1):n=null:(r.push(n),s.push(e),e=0,i=n,n=n.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,n){var o,r=i-e+1,s=this._maxEntries;if(r<=s)return Rt(o=Qt(t.slice(e,i+1)),this.toBBox),o;n||(n=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,n-1))),(o=Qt([])).leaf=!1,o.height=n;var a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));te(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var d=Math.min(c+l-1,i);te(t,c,d,a,this.compareMinY);for(var h=c;h<=d;h+=a){var u=Math.min(h+a-1,d);o.children.push(this._build(t,h,u,n-1))}}return Rt(o,this.toBBox),o},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var o=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=qt(l),d=(h=t,u=l,(Math.max(u.maxX,h.maxX)-Math.min(u.minX,h.minX))*(Math.max(u.maxY,h.maxY)-Math.min(u.minY,h.minY))-c);d<r?(r=d,o=c<o?c:o,s=l):d===r&&c<o&&(o=c,s=l)}e=s||e.children[0]}var h,u;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),zt(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=Qt(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,Rt(i,this.toBBox),Rt(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=Qt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Rt(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,l,c,d=Infinity,h=Infinity,u=e;u<=i-e;u++){var g=Xt(t,0,u,this.toBBox),p=Xt(t,u,i,this.toBBox),f=(o=g,r=p,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),l=Math.min(o.maxX,r.maxX),c=Math.min(o.maxY,r.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=qt(g)+qt(p);f<d?(d=f,n=u,h=y<h?y:h):f===d&&y<h&&(h=y,n=u)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:Yt,o=t.leaf?this.compareMinY:Ht;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,o)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var o=this.toBBox,r=Xt(t,0,e,o),s=Xt(t,i-e,i,o),a=Zt(r)+Zt(s),l=e;l<i-e;l++){var c=t.children[l];zt(r,t.leaf?o(c):c),a+=Zt(r)}for(var d=i-e-1;d>=e;d--){var h=t.children[d];zt(s,t.leaf?o(h):h),a+=Zt(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)zt(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():Rt(t[i],this.toBBox)},t}(),ie=/*#__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=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o<e.length;o++)n.push(e[o][1]),i.push(e[o][0]);var r=Math.min.apply(Math,n),s=Math.max.apply(Math,n);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=[],n=new Set;t.forEach(function(t){var o=e.toBBox(t);if(e.setMaps(t,o),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(o)}),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}(),ne={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}},oe=/*#__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 ie,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:ne}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){var i=this;if(0===t.length)return[];var n=this.clone(t),o=[],r=[];return n=n.filter(function(t){null==t.id&&(t.id=i.idStrategy.getId());var n=t.id;if(e){var s=e(t);if(!s.valid)return r.push({id:n,valid:!1,reason:s.reason}),!1}if(i.tracked){if(t.properties.createdAt){if(!p(t.properties.createdAt))return r.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!p(t.properties.updatedAt))return r.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return i.has(n)?(r.push({id:n,valid:!1,reason:"Feature already exists with this id: "+n}),!1):(i.store[n]=t,o.push(n),r.push({id:n,valid:!0}),!0)}),this.spatialIndex.load(n),this._onChange(o,"create"),r},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},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){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.property,r=t.value,s=e.store[n];if(!s)throw new Error("No feature with this ("+n+"), can not update geometry");i.push(n),s.properties[o]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.geometry;i.push(n);var r=e.store[n];if(!r)throw new Error("No feature with this ("+n+"), can not update geometry");r.geometry=e.clone(o),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,i=[];return t.forEach(function(t){var n,o=t.geometry,s=t.properties,a=r({},s);e.tracked&&(n=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:n,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:n):a={createdAt:n,updatedAt:n});var l=e.getId(),c={id:l,type:"Feature",geometry:o,properties:a};e.store[l]=c,e.spatialIndex.insert(c),i.push(l)}),this._onChange&&this._onChange([].concat(i),"create"),i},e.delete=function(t){var e=this;t.forEach(function(t){if(!e.store[t])throw new Error("No feature with this id, can not delete");delete e.store[t],e.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete")},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.clear=function(){this.store={},this.spatialIndex.clear()},e.size=function(){return Object.keys(this.store).length},t}();function re(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(le(e[0]));for(var n=1;n<e.length;n++)i-=Math.abs(le(e[n]))}return i}var se=20294876564838.72,ae=Math.PI/180;function le(t){var e=t.length;if(e<=2)return 0;for(var i=0,n=0;n<e;)i+=(t[n+2>=e?(n+2)%e:n+2][0]*ae-t[n][0]*ae)*Math.sin(t[n+1===e?0:n+1][1]*ae),n++;return i*se}var ce="Feature is smaller than the minimum area",de="Feature is not a Polygon or LineString",he="Feature intersects itself";function ue(t,e,i){var n=tt(t,e),o=tt(e,i)-n;return o<0&&(o+=360),180-Math.abs(o-90-90)}var ge=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i}s(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){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,n,o,r,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var a=1/Math.pow(10,this.coordinatePrecision-1),l=Math.max(1e-6,a);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-l],s[0]]}else if(2===this.currentCoordinate){var d=s[0],h=s[1],u=It(d,h,this.coordinatePrecision,this.project,this.unproject),g=b(d[0],d[1]),p=b(u[0],u[1]),f=b(h[0],h[1]),y=b(t.lng,t.lat),v=R(y,g)<R(y,f),m=ue(g,p,y),C=v?90-m:ue(g,p,y)-90,P=R(p,y),M=Math.cos(x(C))*P,S=tt(g,f)+("right"==((r=((o=y).x-(n=f).x)*((i=g).y-n.y)-(o.y-n.y)*(i.x-n.x))>1e-10?"left":r<-1e-10?"right":"left")?-90:90),I=$(g,M,S),D=$(f,M,S),E=_(I.x,I.y),w=_(D.x,D.y);e=[s[0],s[1],[w.lng,w.lat],[E.lng,E.lat],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,c.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(st([t.lng,t.lat],i.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]],c.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.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});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=10),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return U(t,e.coordinatePrecision)})},e}(m);function pe(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var fe=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="sector",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.direction=void 0,i.arcPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i.arcPoints=(null==e?void 0:e.arcPoints)||64,i}s(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"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 n=1/Math.pow(10,this.coordinatePrecision-1),o=Math.max(1e-6,n);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-o],i[0]]}else if(2===this.currentCoordinate){var r=i[0],s=i[1],a=[t.lng,t.lat],l=b(r[0],r[1]),d=b(s[0],s[1]),h=b(a[0],a[1]);if(void 0===this.direction){var u=pe(l,d,h);this.direction=u?"clockwise":"anticlockwise"}var g,p=R(l,d),f=tt(l,d),y=tt(l,h),v=this.arcPoints,m=[r],C=et(f),P=et(y);"anticlockwise"===this.direction?(g=P-C)<0&&(g+=360):(g=C-P)<0&&(g+=360);var M=("anticlockwise"===this.direction?1:-1)*g/v;m.push(s);for(var x=0;x<=v;x++){var S=$(l,p,C+x*M),I=_(S.x,S.y),E=I.lat,w=[D(I.lng,this.coordinatePrecision),D(E,this.coordinatePrecision)];w[0]!==m[m.length-1][0]&&w[1]!==m[m.length-1][1]&&m.push(w)}m.push(r),e=[].concat(m)}e&&this.updatePolygonGeometry(this.currentId,e,c.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(st([t.lng,t.lat],i.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]],c.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});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=10),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return U(t,e.coordinatePrecision)})},e}(m),ye=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=void 0,i.direction=void 0,i.arcPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i.arcPoints=(null==e?void 0:e.arcPoints)||64,i}s(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentStartingPointId){var t=this.currentStartingPointId,e=this.currentInitialArcId,i=this.currentId;t&&this.store.delete([t]),e&&this.store.delete([e]),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),i&&this.onFinish(i,{mode:this.mode,action:"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,n=e[0],o=[t.lng,t.lat],r=b(n[0],n[1]),s=b(o[0],o[1]),a=b(i[0],i[1]),l=R(a,r);if(void 0===this.direction){var d=pe(a,r,s);this.direction=d?"clockwise":"anticlockwise"}var h,u=tt(a,r),g=tt(a,s),p=this.arcPoints,f=[n],y=et(u),v=et(g);"anticlockwise"===this.direction?(h=v-y)<0&&(h+=360):(h=y-v)<0&&(h+=360);for(var m=("anticlockwise"===this.direction?1:-1)*h/p,C=0;C<=p;C++){var P=$(a,l,y+C*m),M=_(P.x,P.y),x=M.lat,S=[D(M.lng,this.coordinatePrecision),D(x,this.coordinatePrecision)];S[0]!==f[f.length-1][0]&&S[1]!==f[f.length-1][1]&&f.push(S)}this.updateLineStringGeometry(this.currentInitialArcId,f,c.Provisional)}else if(3===this.currentCoordinate){var I=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(I.length<2)return;if(!this.direction)return;var E=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,w=I[0],F=I[I.length-1],k=b(t.lng,t.lat),O=b(w[0],w[1]),j=b(F[0],F[1]),W=b(E[0],E[1]),B=R(W,O),N=R(W,k)<B?O:k,V=tt(W,k),L=tt(W,O),T=tt(W,j),G=et(L),A=et(T),U=et(V);if(this.notInSector({normalizedCursor:U,normalizedStart:G,normalizedEnd:A,direction:this.direction}))return;for(var K=this.getDeltaBearing(this.direction,G,A),X=this.arcPoints,z=("anticlockwise"===this.direction?1:-1)*K/X,Y=R(W,N),H=[],q=0;q<=X;q++){var Z=$(W,Y,G+q*z),J=_(Z.x,Z.y),Q=J.lat,it=[D(J.lng,this.coordinatePrecision),D(Q,this.coordinatePrecision)];it[0]!==I[I.length-1][0]&&it[1]!==I[I.length-1][1]&&H.unshift(it)}if(I.push.apply(I,H),I.push(I[0]),this.currentId)this.updatePolygonGeometry(this.currentId,I,c.Provisional);else{var nt=this.store.create([{geometry:{type:"Polygon",coordinates:[I]},properties:{mode:this.mode}}]);this.currentId=nt[0]}}},i.updateLineStringGeometry=function(t,e,i){var n={type:"LineString",coordinates:e};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(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});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=10):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=10):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.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 U(t,e.coordinatePrecision)})},i.getDeltaBearing=function(t,e,i){var n;return"anticlockwise"===t?(n=i-e)<0&&(n+=360):(n=e-i)<0&&(n+=360),n},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,n=t.normalizedEnd;return"clockwise"===t.direction?i<=n?e>=i&&e<=n:e>=i||e<=n:i>=n?e<=i&&e>=n:e<=i||e>=n},e}(m),ve=function(t){var e=this,i=t.name,n=t.callback,o=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(n))},this.unregister=function(){e.register&&(e.registered=!1,o(n))},this.callback=n},me={__proto__:null,GeoJSONStore:oe,TerraDrawBaseDrawMode:m,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(t){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._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){var e=this.getLngLatFromEvent(t);if(!e)return null;var i=e.lng,n=e.lat,o=this.getMapElementXYPosition(t),r=o.containerX,s=o.containerY,a=this.getButton(t),l=Array.from(this._heldKeys);return{lng:D(i,this._coordinatePrecision),lat:D(n,this._coordinatePrecision),containerX:r,containerY:s,button:a,heldKeys:l}},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)}},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 n={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},o={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=R(n,o);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;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()},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()&&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._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()},t}(),SELECT_PROPERTIES:d},Ce={ValidationReasonFeatureNotPoint:ct,ValidationReasonFeatureInvalidCoordinates:dt,ValidationReasonFeatureNotPolygon:y,ValidationReasonFeatureHasHoles:V,ValidationReasonFeatureLessThanFourCoordinates:L,ValidationReasonFeatureHasInvalidCoordinates:T,ValidationReasonFeatureCoordinatesNotClosed:G,ValidationReasonFeatureNotPolygonOrLineString:de,ValidationReasonFeatureSelfIntersects:he,ValidationReasonFeatureLessThanMinSize:ce,ValidationReasonModeMismatch:v},Pe=/*#__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 At;var i=new Set,n=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},{}),o=Object.keys(n);if(0===o.length)throw new Error("No modes provided");o.forEach(function(t){if(n[t].type===f.Select){if(e._instanceSelectMode)throw new Error("only one type of select mode can be provided");e._instanceSelectMode=t}}),this._modes=r({},n,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[]},this._store=new oe({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],n=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:n}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},l=function(t,i){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i)});var n=s(t),o=n.changed,r=n.unchanged;"create"===i?e._adapter.render({created:o,deletedIds:[],unchanged:r,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:o},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},e.getModeStyles())}},c=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())}},d=function(t){if(e._enabled){e._eventListeners.deselect.forEach(function(t){t()});var i=s([t]),n=i.changed;n&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:n},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:l,onSelect:c,onDeselect:d,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[d.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,n=t.lat,o=e&&void 0!==e.pointerDistance?e.pointerDistance:30,r=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,s=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),l=a(i,n),c=Y({unproject:s,point:l,pointerDistance:o});return this._store.search(c).filter(function(t){if(r&&(t.properties[d.MID_POINT]||t.properties[d.SELECTION_POINT]))return!1;if("Point"===t.geometry.type){var e=t.geometry.coordinates,s=a(e[0],e[1]);return R(l,s)<o}if("LineString"===t.geometry.type){for(var c=t.geometry.coordinates,h=0;h<c.length-1;h++){var u=c[h],g=c[h+1];if(_t(l,a(u[0],u[1]),a(g[0],g[1]))<o)return!0}return!1}return!!bt([i,n],t.geometry.coordinates)||void 0})},e.getSelectMode=function(){if(this.checkEnabled(),!this._instanceSelectMode)throw new Error("No select mode defined in instance");return this.getMode()!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},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.getSnapshot=function(){return this._store.copyAll()},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},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){this.checkEnabled(),this._store.delete(t)},e.selectFeature=function(t){this.getSelectMode().selectFeature(t)},e.deselectFeature=function(t){this.getSelectMode().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(function(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}(t)){var i=t.properties.mode,n=e._modes[i];if(!n)return{id:t.id,valid:!1,reason:i+" mode is not in the list of instantiated modes"};var o=n.validateFeature.bind(n)(t);return{id:t.id,valid:o.valid,reason:o.reason?o.reason:o.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}})},e.start=function(){var t=this;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=!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)},n(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}])}();t.HELLO="HELLO",t.TerraDraw=Pe,t.TerraDrawAngledRectangleMode=ge,t.TerraDrawCircleMode=K,t.TerraDrawExtend=me,t.TerraDrawFreehandMode=X,t.TerraDrawLineStringMode=lt,t.TerraDrawPointMode=ut,t.TerraDrawPolygonMode=Ct,t.TerraDrawRectangleMode=Pt,t.TerraDrawRenderMode=Mt,t.TerraDrawSectorMode=fe,t.TerraDrawSelectMode=Gt,t.TerraDrawSensorMode=ye,t.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:y}:re(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:y}:re(t.geometry)<e?{valid:!1,reason:ce}:{valid:!0}},t.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:de}:j(t)?{valid:!1,reason:he}:{valid:!0}},t.ValidationReasons=Ce});
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:"selectionPoint"},h="edited",u="closingPoint",p="snappingPoint";function g(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}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=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},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)},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.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: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.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}}])}(),P=/*#__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}(C);function I(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 M(t){return t%360*Math.PI/180}function S(t){return t/6371.0088}function F(t){return t%(2*Math.PI)*180/Math.PI}function E(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var D=57.29577951308232,w=.017453292519943295,b=6378137,k=function(t,e){return{x:0===t?0:t*w*b,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*w/2))*b}},O=function(t,e){return{lng:0===t?0:D*(t/b),lat:0===e?0:(2*Math.atan(Math.exp(e/b))-Math.PI/2)*D}};function _(t,e,i){var o=M(t[0]),n=M(t[1]),r=M(i),s=S(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 j(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=_(e,i,-360*s/n);r.push([E(a[0],o),E(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(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 N(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(o=t[0])>=-180&&o<=180&&(i=t[1])>=-90&&i<=90&&T(t[0])<=e&&T(t[1])<=e;var i,o}function T(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var V="Feature has holes",G="Feature has less than 4 coordinates",L="Feature has invalid coordinates",A="Feature coordinates are not closed";function U(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:"Feature is not a Polygon"}:1!==t.geometry.coordinates.length?{valid:!1,reason:V}:t.geometry.coordinates[0].length<4?{valid:!1,reason:G}:t.geometry.coordinates[0].every(function(t){return N(t,e)})?(i=t.geometry.coordinates[0][0])[0]!==(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||i[1]!==o[1]?{valid:!1,reason:A}:{valid:!0}:{valid:!1,reason:L};var i,o}function R(t,e){var i=U(t,e);return i.valid?W(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var K={cancel:"Escape",finish:"Enter"},X={start:"crosshair"},z=/*#__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=K,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){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(0===this.clickCount){this.center=[t.lng,t.lat];var e=j({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=i[0],this.clickCount++,this.cursorMovedAfterInitialCursorDown=!1,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.cursorMovedAfterInitialCursorDown&&this.updateCircle(t),this.close()},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.updateCircle(t)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t])}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return R(t,e.coordinatePrecision)})},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=I(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var o=function(t,e){var i=1e3*I(t,e);if(0===i)return 1;var o=k(t[0],t[1]),n=o.x,r=o.y,s=k(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=k(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=O(s+h,a+u),g=p.lat;d.push([E(p.lng,i),E(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=j({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}])}},e}(C),Y=function(t,e){var i=e.x-t.x,o=e.y-t.y;return Math.sqrt(o*o+i*i)};function H(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 q={cancel:"Escape",finish:"Enter"},Z={start:"crosshair",close:"pointer"},J=/*#__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=q,i.cursors=Z,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=H(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}])}var e=this.currentId;if(this.validate&&e){var i=this.store.getGeometryCopy(e);if(!this.validate({type:"Feature",id:e,geometry:i,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType: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=Y({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(Y({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}])}}},i.onClick=function(t){if(!this.preventNewFeature){if(!1===this.startingClick){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(e={mode:this.mode},e[u]=!0,e)}]),o=i[1];return this.currentId=i[0],this.closingPointId=o,this.startingClick=!0,void this.setDrawing()}this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.startingClick&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==e&&this.store.delete([e])}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,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=40,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return U(t,e.coordinatePrecision)})},e}(C),$=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 Q(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 tt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return s(e,t),e.prototype.create=function(t){return Q({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}($),et=/*#__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 Y({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}($),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){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}($);function ot(t,e,i){var o=M(t[0]),n=M(t[1]),r=M(i),s=S(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 nt(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 rt(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 st(t,e){var i=Math.atan2(e.y-t.y,e.x-t.x);return(i*=180/Math.PI)>180?i-=360:i<-180&&(i+=360),i}function at(t){return(t+360)%360}function dt(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=rt(t[l],t[l-1])-180,r=ot(t[l],o,n),s.push(r)}if(d>=i)return(o=i-d)?(n=rt(t[l],t[l-1])-180,r=ot(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+=I(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 lt(t){return t*(Math.PI/180)}function ct(t){return t*(180/Math.PI)}var ht=/*#__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+=I(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=dt(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=I(t,e),n=function(t,e,i){var o=[],n=lt(t[1]),r=lt(t[0]),s=lt(e[1]),a=lt(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([ct(v),ct(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[E(t[0],e.config.coordinatePrecision),E(t[1],e.config.coordinatePrecision)]})},e}($);function ut(t,e){return t[0]===e[0]&&t[1]===e[1]}function pt(t,e){return"LineString"!==t.geometry.type?{valid:!1,reason:"Feature is not a LineString"}:t.geometry.coordinates.length<2?{valid:!1,reason:"Feature has less than 2 coordinates"}:t.geometry.coordinates.every(function(t){return N(t,e)})?{valid:!0}:{valid:!1,reason:"Feature has invalid coordinates"}}function gt(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function ft(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(gt(t)*gt(e));return Math.acos(Math.min(Math.max(i,-1),1))}function yt(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 vt(t){var e=t[0],i=t[1],o=F(Math.asin(t[2]));return[F(Math.atan2(i,e)),o]}var mt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.getSnappableCoordinateFirstClick=function(t){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)}).coordinate},n.getSnappableCoordinate=function(t,e){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)}).coordinate},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return 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=k(y[0],y[1]),I=k(v[0],v[1]),x=k(t[0],t[1]);if(y[0]===t[0]&&y[1]===t[1])m=y;else if(v[0]===t[0]&&v[1]===t[1])m=v;else{var M=(l=(d={x:(s=x).x-(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=O(M.x,M.y);m=[S.lng,S.lat]}m&&(C=Y(x,k(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,E=yt(p),D=yt(g),w=yt(f),b=w[0],k=w[1],O=w[2],_=[(C=(y=E)[1])*(S=(v=D)[2])-(P=y[2])*(M=v[1]),P*(x=v[0])-(m=y[0])*S,m*M-C*x],j=_[0],W=_[1],B=_[2],N=W*O-B*k,T=B*b-j*O,V=j*k-W*b,G=V*W-T*B,L=N*B-V*j,A=T*j-N*W,U=1/Math.sqrt(Math.pow(G,2)+Math.pow(L,2)+Math.pow(A,2)),R=[G*U,L*U,A*U],K=[-1*G*U,-1*L*U,-1*A*U],X=ft(E,D),z=ft(E,R),Y=ft(D,R),H=ft(E,K),q=ft(D,K),ft(E,F=z<H&&z<q||Y<H&&Y<q?R:K)>X||ft(D,F)>X?I(vt(F),vt(E))<=I(vt(F),vt(D))?[vt(E),!0,!1]:[vt(D),!1,!0]:[vt(F),!1,!1])[0])&&(u=I(t,d))<r&&(o=d,r=u,s=e.indexOf(l))}var p,g,f,y,v,m,C,P,x,M,S,F,E,D,w,b,k,O,_,j,W,B,N,T,V,G,L,A,U,R,K,X,z,Y,H,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=r.coordinate,s.featureCoordinateIndex=r.lineIndex,s.minDistance=c)}}),s},e}($),Ct={cancel:"Escape",finish:"Enter"},Pt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},It=/*#__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=Ct,i.snapping=void 0,i.cursors=Pt,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommitedCoordinates=void 0,i.snappedPointId=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinateSnapping=void 0,i.insertPoint=void 0,i.lineSnapping=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.updateOptions(e),i}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.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);var e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.snappedPointId=void 0,this.lastCommitedCoordinates=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}},i.updateGeometries=function(t,e,i){if(this.currentId){var o={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid)return;var n=[{id:this.currentId,geometry:o}];this.closingPointId&&e&&n.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=o.coordinates),this.store.updateGeometry(n)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=I(t,e)/(this.insertCoordinates.value+1),o=[];return"globe"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var o=[].concat(e,[t]);this.updateGeometries(o,void 0,l.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],n=this.project(o[0],o[1]);if(Y({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 it(t,new et(t),new tt(t)),this.insertPoint=new ht(t),this.clickBoundingBox=new tt(t),this.pixelDistance=new et(t),this.lineSnapping=new mt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new it(t,this.pixelDistance,this.clickBoundingBox)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,o=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[p]=!0,i)}]);this.snappedPointId=o[0]}t.lng=e[0],t.lat=e[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);var n=e||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var r=this.store.getGeometryCopy(this.currentId).coordinates;if(r.pop(),this.closingPointId){var s=r[r.length-1],a=this.project(s[0],s[1]);Y({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var d=[].concat(r,[n]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var c=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],h=n;if(!ut(c,h)){var u=this.generateInsertCoordinates(c,h);d=[].concat(this.lastCommitedCoordinates.slice(0,-1),u,[n])}}this.updateGeometries(d,void 0,l.Provisional)}},i.onRightClick=function(t){if(this.editable&&"started"===this.state){var e=this.coordinateSnapping.getSnappable(t,function(t){return"LineString"===t.geometry.type}),i=e.featureId,o=e.featureCoordinateIndex;if(i&&void 0!==o){var n,r=this.store.getGeometryCopy(i);if("LineString"===r.type&&!((n=r.coordinates).length<=2)){if(n.splice(o,1),this.validate&&!this.validate({id:i,type:"Feature",geometry:r,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:i,geometry:r}])}}}},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){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){if(this.editable){var i=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t);o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,i=o.coordinate);var n=this.coordinateSnapping.getSnappable(t);n.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=n.featureCoordinateIndex,this.editedFeatureId=n.featureId,i=n.coordinate)}if(this.editedFeatureId&&i){if(!this.editedPointId){var r,s=this.store.create([{geometry:{type:"Point",coordinates:i},properties:(r={mode:this.mode},r[h]=!0,r)}]);this.editedPointId=s[0]}this.setCursor(this.cursors.dragStart),e(!1)}}},i.onDrag=function(t,e){if(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,value:!0}]),e(!0)}},i.onDragEnd=function(t,e){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,value:!1}]),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});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=10,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[u];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=40,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return pt(t,e.coordinatePrecision)})},i.snapCoordinate=function(t){var e,i,o;return null!=(e=this.snapping)&&e.toCoordinate&&(o=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t)),null!=(i=this.snapping)&&i.toCustom&&(o=this.snapping.toCustom(t)),o},e}(C),xt="Feature is not a Point",Mt="Feature has invalid coordinates";function St(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:xt}:N(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:Mt}}var Ft={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},Et=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="point",i.cursors=Ft,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){if(!this.store)throw new Error("Mode must be registered first");"right"===t.button?this.onRightClick(t):"left"===t.button&&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.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(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,value:!0}]),e(!0)}},i.onDragEnd=function(t,e){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,value:!1}]),this.editedFeatureId=void 0,e(!0))},i.registerBehaviors=function(t){this.pixelDistance=new et(t),this.clickBoundingBox=new tt(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});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 St(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},e}(C),Dt=/*#__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]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(o={mode:e},o[u]=!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){}}])}($),wt={cancel:"Escape",finish:"Enter"},bt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},kt=/*#__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=wt,i.cursors=bt,i.mouseMove=!1,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.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){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),null!=e&&e.editable&&(this.editable=e.editable)},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=H(this.store.getGeometryCopy(this.currentId));i&&this.store.updateGeometry([{id:this.currentId,geometry:i}])}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 tt(t),this.pixelDistance=new et(t),this.lineSnapping=new mt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new it(t,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new Dt(t,this.pixelDistance)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,o=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[p]=!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);if(void 0!==this.currentId&&0!==this.currentCoordinate){var n,r=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var s=1/Math.pow(10,this.coordinatePrecision-1),a=Math.max(1e-6,s);n=[r[0],[t.lng,t.lat],[t.lng,t.lat-a],r[0]]}else if(2===this.currentCoordinate)n=[r[0],r[1],[t.lng,t.lat],r[0]];else{var d=this.closingPoints.isClosingPoint(t);d.isPreviousClosing||d.isClosing?(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.setCursor(this.cursors.close),n=[].concat(r.slice(0,-2),[r[0],r[0]])):n=[].concat(r.slice(0,-2),[[t.lng,t.lat],r[0]])}this.updatePolygonGeometry(n,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}]),0))},i.snapCoordinate=function(t){var e,i,o,n,r,s=void 0;return null!=(e=this.snapping)&&e.toLine&&(n=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(s=n),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(s=r),null!=(o=this.snapping)&&o.toCustom&&(s=this.snapping.toCustom(t)),s},i.onRightClick=function(t){if(this.editable){var e=this.coordinateSnapping.getSnappable(t,function(t){return"Polygon"===t.geometry.type}),i=e.featureId,o=e.featureCoordinateIndex;if(i&&void 0!==o){var n,r=this.store.getGeometryCopy(i);if("Polygon"===r.type&&!((n=r.coordinates[0]).length<=4)){if("Polygon"!==r.type||0!==o&&o!==n.length-1?n.splice(o,1):(n.shift(),n.pop(),n.push([n[0][0],n[0][1]])),this.validate&&!this.validate({id:i,type:"Feature",geometry:r,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:i,geometry:r}])}}}},i.onLeftClick=function(t){if(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),0===this.currentCoordinate){var e=this.snapCoordinate(t);e&&(t.lng=e[0],t.lat=e[1]);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:{mode:this.mode}}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var o=this.snapCoordinate(t);o&&(t.lng=o[0],t.lat=o[1]);var n=this.store.getGeometryCopy(this.currentId);if(ut([t.lng,t.lat],n.coordinates[0][0]))return;if(!this.updatePolygonGeometry([n.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],n.coordinates[0][0]],l.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var r=this.snapCoordinate(t);r&&(t.lng=r[0],t.lat=r[1]);var s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(ut([t.lng,t.lat],s[1]))return;if(!this.updatePolygonGeometry([s[0],s[1],[t.lng,t.lat],[t.lng,t.lat],s[0]],l.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(s,"polygon"),this.currentCoordinate++}else if(this.currentId){var a=this.store.getGeometryCopy(this.currentId).coordinates[0],d=this.closingPoints.isClosingPoint(t);if(d.isPreviousClosing||d.isClosing)this.close();else{var c=this.snapCoordinate(t);if(c&&(t.lng=c[0],t.lat=c[1]),ut([t.lng,t.lat],a[this.currentCoordinate-1]))return;var h=(void 0===(u=[[].concat(a.slice(0,-1),[[t.lng,t.lat],a[0]])])&&(u=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:u},properties:{}});if(!this.updatePolygonGeometry(h.geometry.coordinates[0],l.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(h.geometry.coordinates[0])}}var u},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"!==t.button?"left"!==t.button||this.onLeftClick(t):this.onRightClick(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){if(this.editable){var i=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t);o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,i=o.coordinate);var n=this.coordinateSnapping.getSnappable(t);n.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=n.featureCoordinateIndex,this.editedFeatureId=n.featureId,i=n.coordinate)}if(this.editedFeatureId&&i){if(!this.editedPointId){var r,s=this.store.create([{geometry:{type:"Point",coordinates:i},properties:(r={mode:this.mode},r[h]=!0,r)}]);this.editedPointId=s[0]}this.setCursor(this.cursors.dragStart),e(!1)}}},i.onDrag=function(t,e){if(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.editedPointId&&this.store.updateGeometry([{id:this.editedPointId,geometry:{type:"Point",coordinates:[t.lng,t.lat]}}]),this.store.updateProperty([{id:this.editedFeatureId,property:h,value:!0}]),e(!0)}},i.onDragEnd=function(t,e){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,value:!1}]),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{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});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=10,e;if("Point"===t.geometry.type){var i=t.properties[h],o=i?"editedPoint":t.properties[u]?"closingPoint":t.properties[p]?"snappingPoint":void 0;if(!o)return e;var n={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}};return e.pointWidth=this.getNumericStylingValue(n[o].width,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(n[o].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(n[o].outlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(n[o].outlineWidth,2,t),e.zIndex=i?35:30,e}}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return U(t,e.coordinatePrecision)})},e}(C),Ot={cancel:"Escape",finish:"Enter"},_t={start:"crosshair"},jt=/*#__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=Ot,i.cursors=_t,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=H(this.store.getGeometryCopy(t));e&&this.store.updateGeometry([{id:t,geometry:e}])}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(0===this.clickCount){this.center=[t.lng,t.lat];var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentRectangleId=e[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});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=10,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return R(t,e.coordinatePrecision)})},e}(C),Wt=/*#__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=St(o,this.coordinatePrecision).valid||U(o,this.coordinatePrecision).valid||pt(o,this.coordinatePrecision).valid;return n?{valid:!0}:{valid:n,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(C);function Bt(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 Nt(t,e,i){var o=e;e<0&&(o=-Math.abs(o));var n=o/x,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 Tt(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[E(a.lng,i),E(d,i)]}function Vt(t,e,i){var o=Nt(t,1e3*I(t,e)/2,Bt(t,e));return[E(o[0],i),E(o[1],i)]}function Gt(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=Tt(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 Lt=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPointBehavior=void 0,o._midPoints=[],o.config=e,o.selectionPointBehavior=i,o}s(e,t);var i=e.prototype;return i.insert=function(t,e){var i=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t),n=o.midPointFeatureId,r=o.midPointSegment,s=this.store.getGeometryCopy(n),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:n,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,n,e),this.selectionPointBehavior.create(a,s.type,n)},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 Gt({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 Gt({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){}}])}($),At=/*#__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){return{mode:o.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},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){}}])}($);function Ut(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 Rt=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))},Kt=/*#__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||!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=Rt({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;Ut([t.lng,t.lat],g.coordinates)&&(d=p)}}return{clickedFeature:i||n||d,clickedMidPoint:s}},e}($),Xt=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.featuresAtCursorEvent=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedFeatureId=null,r.dragPosition=void 0,r.config=e,r.featuresAtCursorEvent=i,r.selectionPoints=o,r.midPoints=n,r}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=k(this.dragPosition[0],this.dragPosition[1]),u=k(o[0],o[1]),p=k(a[0],a[1]),g={x:h.x-u.x,y:h.y-u.y},f=O(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=E(d,this.config.coordinatePrecision),c=E(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)||[];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)),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}($),zt=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedCoordinate={id:null,index:-1},r.config=e,r.pixelDistance=i,r.selectionPoints=o,r.midPoints=n,r}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.drag=function(t,e,i){if(null===this.draggedCoordinate.id)return!1;var o=this.draggedCoordinate.index,n=this.store.getGeometryCopy(this.draggedCoordinate.id),r="LineString"===n.type?n.coordinates:n.coordinates[0],s=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==n.type||o!==r.length-1&&0!==o)r[o]=s;else{var a=r.length-1;r[0]=s,r[a]=s}var d=this.selectionPoints.getOneUpdated(o,s),c=d?[d]:[],h=this.midPoints.getUpdated(r)||[];return!("Point"!==n.type&&!e&&W({type:"Feature",geometry:n,properties:{}})||i&&!i({type:"Feature",id:this.draggedCoordinate.id,geometry:n,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:n}].concat(c,h)),0))},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}($);function Yt(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]}function Ht(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}function qt(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=k(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 Zt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.lastBearing=void 0,n.config=e,n.selectionPoints=i,n.midPoints=o,n}s(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e,i){var o=this,n=this.store.getGeometryCopy(e);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){if(r=st(qt(a),k(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=r);!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 k(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[O(e,i).lng,O(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(a,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(r=Bt(Yt({type:"Feature",geometry:n,properties:{}}),s),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=Yt(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=Bt(i,t)+e,n=Ht(i,t),r=Nt(i,n,o);t[0]=r[0],t[1]=r[1]})}(a,-(this.lastBearing-(r+180)))}var d="Polygon"===n.type?n.coordinates[0]:n.coordinates;d.forEach(function(t){t[0]=E(t[0],o.coordinatePrecision),t[1]=E(t[1],o.coordinatePrecision)});var c=this.midPoints.getUpdated(d)||[],h=this.selectionPoints.getUpdated(d)||[];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(h,c)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}($),Jt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.lastDistance=void 0,n.config=e,n.selectionPoints=i,n.midPoints=o,n}s(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e,i){var o=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:n,properties:{}},d=qt(a);if("web-mercator"===this.config.projection){var c=k(t.lng,t.lat);r=Y(d,c)}else{if("globe"!==this.config.projection)throw new Error("Invalid projection");r=I(Yt({type:"Feature",geometry:n,properties:{}}),s)}if(this.lastDistance){var h=1-(this.lastDistance-r)/r;if("web-mercator"===this.config.projection){var u=O(d.x,d.y);!function(t,e,i){if(1===e)return t;var o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return k(t[0],t[1])}),n=k(i[0],i[1]),r=o.map(function(t){return{x:n.x+(t.x-n.x)*e,y:n.y+(t.y-n.y)*e}}).map(function(t){var e=t.x,i=t.y;return[O(e,i).lng,O(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(a,h,[u.lng,u.lat])}else"globe"===this.config.projection&&function(t,e,i,o){void 0===o&&(o="xy"),1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=Ht(i,t),r=Bt(i,t),s=Nt(i,n*e,r);"x"!==o&&"xy"!==o||(t[0]=s[0]),"y"!==o&&"xy"!==o||(t[1]=s[1])})}(a,h,Yt(a));var p="Polygon"===n.type?n.coordinates[0]:n.coordinates;p.forEach(function(t){t[0]=E(t[0],o.coordinatePrecision),t[1]=E(t[1],o.coordinatePrecision)});var g=this.midPoints.getUpdated(p)||[],f=this.selectionPoints.getUpdated(p)||[];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(f,g)),this.lastDistance=r}else this.lastDistance=r}},e}($),$t=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.minimumScale=1e-4,r.draggedCoordinate={id:null,index:-1},r.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},r.config=e,r.pixelDistance=i,r.selectionPoints=o,r.midPoints=n,r}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=k(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=k(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=k(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=k(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=Y(e,o)/Y(e,i);return r<0&&(r=this.minimumScale),this.performWebMercatorScale(n,e.x,e.y,r,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=k(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=k(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=k(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=k(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:{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=k(t[0],t[1]),s=O(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=k(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=Y({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]=E(s[0],this.coordinatePrecision),s[1]=E(s[1],this.coordinatePrecision),!N(s,this.coordinatePrecision))return!1}var a=this.midPoints.getUpdated(n)||[],d=this.selectionPoints.getUpdated(n)||[],c={type:o.geometry.type,coordinates:"Polygon"===o.geometry.type?[n]:n};return!(i&&!i({id:this.draggedCoordinate.id,type:"Feature",geometry:c,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:c}].concat(d,a)),0))},e}($),Qt={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]},te={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"},ee=/*#__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=Qt,i.cursors=te,i.validations={},i.selectionPoints=void 0,i.midPoints=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.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):te,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 et(t),this.clickBoundingBox=new tt(t),this.featuresAtMouseEvent=new Kt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new At(t),this.midPoints=new Lt(t,this.selectionPoints),this.rotateFeature=new Zt(t,this.selectionPoints,this.midPoints),this.scaleFeature=new Jt(t,this.selectionPoints,this.midPoints),this.dragFeature=new Xt(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new zt(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new $t(t,this.pixelDistance,this.selectionPoints,this.midPoints)},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;this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:n,geometry:h}]),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:"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(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?"left"===t.button&&this.onLeftClick(t):this.onRightClick(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;this.onDeselect(this.selected[0]),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.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)){this.dragEventCount=0;var n=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,n);return o&&o.feature&&o.feature.coordinates&&(o.feature.coordinates.draggable||o.feature.coordinates.resizable)&&-1!==r?(this.setCursor(this.cursors.dragStart),o.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(n,r):this.dragCoordinate.startDragging(n,r),void e(!1)):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){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)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,r,s):this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}},i.onDragEnd=function(t,e){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});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=40,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=10,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=10,e}return e},e}(P),ie=/*#__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})},e}(C);function oe(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);oe(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(ne(t,i,e),n(t[o],c)>0&&ne(t,i,o);h<u;){for(ne(t,h,u),h++,u--;n(t[h],c)<0;)h++;for(;n(t[u],c)>0;)u--}0===n(t[i],c)?ne(t,i,u):ne(t,++u,o),u<=e&&(i=u+1),e<=u&&(o=u-1)}}function ne(t,e,i){var o=t[e];t[e]=t[i],t[i]=o}function re(t,e){se(t,0,t.children.length,e,t)}function se(t,e,i,o,n){n||(n=ge([])),n.minX=Infinity,n.minY=Infinity,n.maxX=-Infinity,n.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];ae(n,t.leaf?o(s):s)}return n}function ae(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 de(t,e){return t.minX-e.minX}function le(t,e){return t.minY-e.minY}function ce(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function he(t){return t.maxX-t.minX+(t.maxY-t.minY)}function ue(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function pe(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ge(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function fe(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;oe(t,s,e,i,n),r.push(e,s,s,i)}}var ye=/*#__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(!pe(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;pe(t,a)&&(e.leaf?i.push(s):ue(t,a)?this._all(s,i):n.push(s))}e=n.pop()}return i},e.collides=function(t){var e=this.data;if(pe(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(pe(t,r)){if(e.leaf||ue(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=ge([])},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||!ue(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 re(n=ge(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=ge([])).leaf=!1,n.height=o;var a=Math.ceil(r/s),d=a*Math.ceil(Math.sqrt(s));fe(t,e,i,d,this.compareMinX);for(var l=e;l<=i;l+=d){var c=Math.min(l+d-1,i);fe(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 re(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=ce(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),ae(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=ge(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,re(i,this.toBBox),re(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=ge([t,e]),this.data.height=t.height+1,this.data.leaf=!1,re(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=se(t,0,u,this.toBBox),g=se(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=ce(p)+ce(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:de,n=t.leaf?this.compareMinY:le;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=se(t,0,e,n),s=se(t,i-e,i,n),a=he(r)+he(s),d=e;d<i-e;d++){var l=t.children[d];ae(r,t.leaf?n(l):l),a+=he(r)}for(var c=i-e-1;c>=e;c--){var h=t.children[c];ae(s,t.leaf?n(h):h),a+=he(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var o=i;o>=0;o--)ae(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():re(t[i],this.toBBox)},t}(),ve=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new ye(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}(),me={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}},Ce=/*#__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 ve,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:me}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){var i=this;if(0===t.length)return[];var o=this.clone(t),n=[],r=[];return o=o.filter(function(t){null==t.id&&(t.id=i.idStrategy.getId());var o=t.id;if(e){var s=e(t);if(!s.valid)return r.push({id:o,valid:!1,reason:s.reason}),!1}if(i.tracked){if(t.properties.createdAt){if(!f(t.properties.createdAt))return r.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 r.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return i.has(o)?(r.push({id:o,valid:!1,reason:"Feature already exists with this id: "+o}),!1):(i.store[o]=t,n.push(o),r.push({id:o,valid:!0}),!0)}),this.spatialIndex.load(o),this._onChange(n,"create"),r},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){t(e,i)}},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){var e=this,i=[];t.forEach(function(t){var o=t.id,n=t.property,r=t.value,s=e.store[o];if(!s)throw new Error("No feature with this ("+o+"), can not update geometry");i.push(o),s.properties[n]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var o=t.id,n=t.geometry;i.push(o);var r=e.store[o];if(!r)throw new Error("No feature with this ("+o+"), can not update geometry");r.geometry=e.clone(n),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,i=[];return t.forEach(function(t){var o,n=t.geometry,s=t.properties,a=r({},s);e.tracked&&(o=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:o,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:o):a={createdAt:o,updatedAt:o});var d=e.getId(),l={id:d,type:"Feature",geometry:n,properties:a};e.store[d]=l,e.spatialIndex.insert(l),i.push(d)}),this._onChange&&this._onChange([].concat(i),"create"),i},e.delete=function(t){var e=this;t.forEach(function(t){if(!e.store[t])throw new Error("No feature with this id, can not delete");delete e.store[t],e.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete")},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.clear=function(){this.store={},this.spatialIndex.clear()},e.size=function(){return Object.keys(this.store).length},t}();function Pe(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Me(e[0]));for(var o=1;o<e.length;o++)i-=Math.abs(Me(e[o]))}return i}var Ie=20294876564838.72,xe=Math.PI/180;function Me(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]*xe-t[o][0]*xe)*Math.sin(t[o+1===e?0:o+1][1]*xe),o++;return i*Ie}var Se="Feature is smaller than the minimum area",Fe="Feature is not a Polygon or LineString",Ee="Feature intersects itself";function De(t,e,i){var o=st(t,e),n=st(e,i)-o;return n<0&&(n+=360),180-Math.abs(n-90-90)}var we={cancel:"Escape",finish:"Enter"},be={start:"crosshair",close:"pointer"},ke=/*#__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=we,i.cursors=be,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){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=Tt(c,h,this.coordinatePrecision,this.project,this.unproject),p=k(c[0],c[1]),g=k(u[0],u[1]),f=k(h[0],h[1]),y=k(t.lng,t.lat),v=Y(y,p)<Y(y,f),m=De(p,g,y),C=v?90-m:De(p,g,y)-90,P=Y(g,y),I=Math.cos(M(C))*P,x=st(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),S=nt(p,I,x),F=nt(f,I,x),E=O(S.x,S.y),D=O(F.x,F.y);e=[s[0],s[1],[D.lng,D.lat],[E.lng,E.lat],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(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(ut([t.lng,t.lat],i.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.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});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=10),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return R(t,e.coordinatePrecision)})},e}(C);function Oe(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var _e={cancel:"Escape",finish:"Enter"},je={start:"crosshair",close:"pointer"},We=/*#__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=_e,i.direction=void 0,i.arcPoints=64,i.cursors=je,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=H(this.store.getGeometryCopy(this.currentId));t&&this.store.updateGeometry([{id:this.currentId,geometry:t}]);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=k(r[0],r[1]),c=k(s[0],s[1]),h=k(a[0],a[1]);if(void 0===this.direction){var u=Oe(d,c,h);this.direction=u?"clockwise":"anticlockwise"}var p,g=Y(d,c),f=st(d,c),y=st(d,h),v=this.arcPoints,m=[r],C=at(f),P=at(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 x=0;x<=v;x++){var M=nt(d,g,C+x*I),S=O(M.x,M.y),F=S.lat,D=[E(S.lng,this.coordinatePrecision),E(F,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(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(ut([t.lng,t.lat],i.coordinates[0][0]))return;if(!this.updatePolygonGeometry(this.currentId,[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.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});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=10),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return R(t,e.coordinatePrecision)})},e}(C),Be={cancel:"Escape",finish:"Enter"},Ne={start:"crosshair",close:"pointer"},Te=/*#__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=Be,i.direction=void 0,i.arcPoints=64,i.cursors=Ne,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=H(this.store.getGeometryCopy(this.currentId));o&&this.store.updateGeometry([{id:this.currentId,geometry:o}])}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=k(o[0],o[1]),s=k(n[0],n[1]),a=k(i[0],i[1]),d=Y(a,r);if(void 0===this.direction){var c=Oe(a,r,s);this.direction=c?"clockwise":"anticlockwise"}var h,u=st(a,r),p=st(a,s),g=this.arcPoints,f=[o],y=at(u),v=at(p);"anticlockwise"===this.direction?(h=v-y)<0&&(h+=360):(h=y-v)<0&&(h+=360);for(var m=("anticlockwise"===this.direction?1:-1)*h/g,C=0;C<=g;C++){var P=nt(a,d,y+C*m),I=O(P.x,P.y),x=I.lat,M=[E(I.lng,this.coordinatePrecision),E(x,this.coordinatePrecision)];M[0]!==f[f.length-1][0]&&M[1]!==f[f.length-1][1]&&f.push(M)}this.updateLineStringGeometry(this.currentInitialArcId,f,l.Provisional)}else if(3===this.currentCoordinate){var S=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(S.length<2)return;if(!this.direction)return;var F=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,D=S[0],w=S[S.length-1],b=k(t.lng,t.lat),_=k(D[0],D[1]),j=k(w[0],w[1]),W=k(F[0],F[1]),B=Y(W,_),N=Y(W,b)<B?_:b,T=st(W,b),V=st(W,_),G=st(W,j),L=at(V),A=at(G),U=at(T);if(this.notInSector({normalizedCursor:U,normalizedStart:L,normalizedEnd:A,direction:this.direction}))return;for(var R=this.getDeltaBearing(this.direction,L,A),K=this.arcPoints,X=("anticlockwise"===this.direction?1:-1)*R/K,z=Y(W,N),H=[],q=0;q<=K;q++){var Z=nt(W,z,L+q*X),J=O(Z.x,Z.y),$=J.lat,Q=[E(J.lng,this.coordinatePrecision),E($,this.coordinatePrecision)];Q[0]!==S[S.length-1][0]&&Q[1]!==S[S.length-1][1]&&H.unshift(Q)}if(S.push.apply(S,H),S.push(S[0]),this.currentId)this.updatePolygonGeometry(this.currentId,S,l.Provisional);else{var tt=this.store.create([{geometry:{type:"Polygon",coordinates:[S]},properties:{mode:this.mode}}]);this.currentId=tt[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(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});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=10):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=10):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.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 R(t,e.coordinatePrecision)})},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}(C),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},Ge={__proto__:null,GeoJSONStore:Ce,TerraDrawBaseDrawMode:C,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(t){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._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){var e=this.getLngLatFromEvent(t);if(!e)return null;var i=e.lng,o=e.lat,n=this.getMapElementXYPosition(t),r=n.containerX,s=n.containerY,a=this.getButton(t),d=Array.from(this._heldKeys);return{lng:E(i,this._coordinatePrecision),lat:E(o,this._coordinatePrecision),containerX:r,containerY:s,button:a,heldKeys:d}},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)}},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=Y(o,n);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;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()},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()&&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._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()},t}(),SELECT_PROPERTIES:c},Le={ValidationReasonFeatureNotPoint:xt,ValidationReasonFeatureInvalidCoordinates:Mt,ValidationReasonFeatureNotPolygon:v,ValidationReasonFeatureHasHoles:V,ValidationReasonFeatureLessThanFourCoordinates:G,ValidationReasonFeatureHasInvalidCoordinates:L,ValidationReasonFeatureCoordinatesNotClosed:A,ValidationReasonFeatureNotPolygonOrLineString:Fe,ValidationReasonFeatureSelfIntersects:Ee,ValidationReasonFeatureLessThanMinSize:Se,ValidationReasonModeMismatch:m};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 ie;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 Ce({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){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i)});var o=s(t),n=o.changed,r=o.unchanged;"create"===i?e._adapter.render({created:n,deletedIds:[],unchanged:r,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:n},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:r,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,n=e&&void 0!==e.pointerDistance?e.pointerDistance:30,r=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,s=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),d=a(i,o),l=Q({unproject:s,point:d,pointerDistance:n});return this._store.search(l).filter(function(t){if(r&&(t.properties[c.MID_POINT]||t.properties[c.SELECTION_POINT]))return!1;if("Point"===t.geometry.type){var e=t.geometry.coordinates,s=a(e[0],e[1]);return Y(d,s)<n}if("LineString"===t.geometry.type){for(var l=t.geometry.coordinates,h=0;h<l.length-1;h++){var u=l[h],p=l[h+1];if(Rt(d,a(u[0],u[1]),a(p[0],p[1]))<n)return!0}return!1}return!!Ut([i,o],t.geometry.coordinates)||void 0})},e.getSelectMode=function(){if(this.checkEnabled(),!this._instanceSelectMode)throw new Error("No select mode defined in instance");return this.getMode()!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},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.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){this.checkEnabled(),this._store.delete(t)},e.selectFeature=function(t){this.getSelectMode().selectFeature(t)},e.deselectFeature=function(t){this.getSelectMode().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(function(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}(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"}})},e.start=function(){var t=this;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=!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=ke,t.TerraDrawCircleMode=z,t.TerraDrawExtend=Ge,t.TerraDrawFreehandMode=J,t.TerraDrawLineStringMode=It,t.TerraDrawPointMode=Et,t.TerraDrawPolygonMode=kt,t.TerraDrawRectangleMode=jt,t.TerraDrawRenderMode=Wt,t.TerraDrawSectorMode=We,t.TerraDrawSelectMode=ee,t.TerraDrawSensorMode=Te,t.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:v}:Pe(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}:Pe(t.geometry)<e?{valid:!1,reason:Se}:{valid:!0}},t.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:Fe}:W(t)?{valid:!1,reason:Ee}:{valid:!0}},t.ValidationReasons=Le});
2
2
  //# sourceMappingURL=terra-draw.umd.js.map