terra-draw-google-maps-adapter 1.0.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.
- package/.versionrc.cjs +9 -0
- package/README.md +7 -0
- package/dist/terra-draw-google-maps-adapter.cjs +2 -0
- package/dist/terra-draw-google-maps-adapter.cjs.map +1 -0
- package/dist/terra-draw-google-maps-adapter.d.ts +89 -0
- package/dist/terra-draw-google-maps-adapter.modern.js +2 -0
- package/dist/terra-draw-google-maps-adapter.modern.js.map +1 -0
- package/dist/terra-draw-google-maps-adapter.module.js +2 -0
- package/dist/terra-draw-google-maps-adapter.module.js.map +1 -0
- package/dist/terra-draw-google-maps-adapter.spec.d.ts +1 -0
- package/dist/terra-draw-google-maps-adapter.umd.js +2 -0
- package/dist/terra-draw-google-maps-adapter.umd.js.map +1 -0
- package/jest.nocheck.config.ts +8 -0
- package/package.json +52 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terra-draw-google-maps-adapter.module.js","sources":["../../terra-draw/dist/terra-draw.modern.js","../src/terra-draw-google-maps-adapter.ts"],"sourcesContent":["function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},t.apply(this,arguments)}var e;!function(t){t.Commit=\"commit\",t.Provisional=\"provisional\",t.Finish=\"finish\"}(e||(e={}));const i={SELECTED:\"selected\",MID_POINT:\"midPoint\",SELECTION_POINT:\"selectionPoint\"},o=\"closingPoint\",s=\"snappingPoint\";function n(t){return Boolean(t&&\"object\"==typeof t&&null!==t&&!Array.isArray(t))}function r(t){return!!function(t){return\"number\"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}const a=\"Feature is not a Polygon\",l=\"Feature mode property does not match the mode being added to\";var h;!function(t){t.Drawing=\"drawing\",t.Select=\"select\",t.Static=\"static\",t.Render=\"render\"}(h||(h={}));class d{get state(){return this._state}set state(t){throw new Error(\"Please use the modes lifecycle methods\")}get styles(){return this._styles}set styles(t){if(\"object\"!=typeof t)throw new Error(\"Styling must be an object\");this.onStyleChange([],\"styling\"),this._styles=t}registerBehaviors(t){}constructor(e){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=h.Drawing,this.mode=\"base\",this._state=\"unregistered\",this._styles=e&&e.styles?t({},e.styles):{},this.pointerDistance=e&&e.pointerDistance||40,this.validate=e&&e.validation,this.projection=e&&e.projection||\"web-mercator\"}setDrawing(){if(\"started\"!==this._state)throw new Error(\"Mode must be unregistered or stopped to start\");this._state=\"drawing\"}setStarted(){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)}setStopped(){if(\"started\"!==this._state)throw new Error(\"Mode must be started to be stopped\");this._state=\"stopped\",this.setDoubleClickToZoom(!0)}register(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})}validateFeature(t){return this.performFeatureValidation(t)}performFeatureValidation(t){if(\"unregistered\"===this._state)throw new Error(\"Mode must be registered\");const i=function(t,e){let i;if(n(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(n(t.geometry))if(n(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){const o=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.Provisional});return{valid:i.valid&&o.valid,reason:o.reason}}return{valid:i.valid,reason:i.reason}}validateModeFeature(t,e){const i=this.performFeatureValidation(t);return i.valid?t.properties.mode!==this.mode?{valid:!1,reason:l}:e(t):{valid:!1,reason:i.reason}}onFinish(t,e){}onDeselect(t){}onSelect(t){}onKeyDown(t){}onKeyUp(t){}onMouseMove(t){}onClick(t){}onDragStart(t,e){}onDrag(t,e){}onDragEnd(t,e){}getHexColorStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getNumericStylingValue(t,e,i){return this.getStylingValue(t,e,i)}getStylingValue(t,e,i){return void 0===t?e:\"function\"==typeof t?t(i):t}}class c extends d{constructor(...t){super(...t),this.type=h.Select}}function u(t,e){const i=t=>t*Math.PI/180,o=i(t[1]),s=i(t[0]),n=i(e[1]),r=n-o,a=i(e[0])-s,l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(o)*Math.cos(n)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}const g=6371008.8;function p(t){return t%360*Math.PI/180}function y(t){return t/(g/1e3)}function m(t){return t%(2*Math.PI)*180/Math.PI}function f(t,e=9){const i=Math.pow(10,e);return Math.round(t*i)/i}const v=57.29577951308232,C=.017453292519943295,P=6378137,x=(t,e)=>({x:0===t?0:t*C*P,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*C/2))*P}),M=(t,e)=>({lng:0===t?0:v*(t/P),lat:0===e?0:(2*Math.atan(Math.exp(e/P))-Math.PI/2)*v});function I(t,e,i){const o=p(t[0]),s=p(t[1]),n=p(i),r=y(e),a=Math.asin(Math.sin(s)*Math.cos(r)+Math.cos(s)*Math.sin(r)*Math.cos(n));return[m(o+Math.atan2(Math.sin(n)*Math.sin(r)*Math.cos(s),Math.cos(r)-Math.sin(s)*Math.sin(a))),m(a)]}function S(t){const{center:e,radiusKilometers:i,coordinatePrecision:o}=t,s=t.steps?t.steps:64,n=[];for(let t=0;t<s;t++){const r=I(e,i,-360*t/s);n.push([f(r[0],o),f(r[1],o)])}return n.push(n[0]),{type:\"Feature\",geometry:{type:\"Polygon\",coordinates:[n]},properties:{}}}function E(t){const e={epsilon:0};let i;if(\"Polygon\"===t.geometry.type)i=t.geometry.coordinates;else{if(\"LineString\"!==t.geometry.type)throw new Error(\"Self intersects only accepts Polygons and LineStrings\");i=[t.geometry.coordinates]}const o=[];for(let t=0;t<i.length;t++)for(let e=0;e<i[t].length-1;e++)for(let o=0;o<i.length;o++)for(let s=0;s<i[o].length-1;s++)n(t,e,o,s);return o.length>0;function s(t){return t<0-e.epsilon||t>1+e.epsilon}function n(t,e,n,r){const a=i[t][e],l=i[t][e+1],h=i[n][r],d=i[n][r+1],c=function(t,e,i,o){if(D(t,i)||D(t,o)||D(e,i)||D(o,i))return null;const s=t[0],n=t[1],r=e[0],a=e[1],l=i[0],h=i[1],d=o[0],c=o[1],u=(s-r)*(h-c)-(n-a)*(l-d);return 0===u?null:[((s*a-n*r)*(l-d)-(s-r)*(l*c-h*d))/u,((s*a-n*r)*(h-c)-(n-a)*(l*c-h*d))/u]}(a,l,h,d);if(null===c)return;let u,g;u=l[0]!==a[0]?(c[0]-a[0])/(l[0]-a[0]):(c[1]-a[1])/(l[1]-a[1]),g=d[0]!==h[0]?(c[0]-h[0])/(d[0]-h[0]):(c[1]-h[1])/(d[1]-h[1]),s(u)||s(g)||(c.toString(),o.push(c))}}function D(t,e){return t[0]===e[0]&&t[1]===e[1]}function F(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&&w(t[0])<=e&&w(t[1])<=e;var i,o}function w(t){let e=1,i=0;for(;Math.round(t*e)/e!==t;)e*=10,i++;return i}const b=\"Feature is not a Polygon\",_=\"Feature has holes\",k=\"Feature has less than 4 coordinates\",O=\"Feature has invalid coordinates\",j=\"Feature coordinates are not closed\";function W(t,e){return\"Polygon\"!==t.geometry.type?{valid:!1,reason:b}:1!==t.geometry.coordinates.length?{valid:!1,reason:_}:t.geometry.coordinates[0].length<4?{valid:!1,reason:k}:t.geometry.coordinates[0].every(t=>F(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:j}:{valid:!0}:{valid:!1,reason:O};var i,o}function B(t,e){const i=W(t,e);return i.valid?E(t)?{valid:!1,reason:\"Feature intersects itself\"}:{valid:!0}:i}class N extends d{constructor(e){var i;super(e),this.mode=\"circle\",this.center=void 0,this.clickCount=0,this.currentCircleId=void 0,this.keyEvents=void 0,this.cursors=void 0,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1;const o={start:\"crosshair\"};if(this.cursors=e&&e.cursors?t({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.startingRadiusKilometers=null!=(i=null==e?void 0:e.startingRadiusKilometers)?i:1e-5,this.validate=null==e?void 0:e.validation}close(){if(void 0===this.currentCircleId)return;const t=this.currentCircleId;if(this.validate&&t){const i=this.store.getGeometryCopy(t);if(!this.validate({type:\"Feature\",id:t,geometry:i,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.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\"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onClick(t){if(0===this.clickCount){this.center=[t.lng,t.lat];const e=S({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,this.clickCount++,this.cursorMovedAfterInitialCursorDown=!1,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.cursorMovedAfterInitialCursorDown&&this.updateCircle(t),this.close()}onMouseMove(t){this.cursorMovedAfterInitialCursorDown=!0,this.updateCircle(t)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const 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){}}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return\"Feature\"===e.type&&\"Polygon\"===e.geometry.type&&e.properties.mode===this.mode?(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i):i}validateFeature(t){return this.validateModeFeature(t,t=>B(t,this.coordinatePrecision))}updateCircle(t){if(1===this.clickCount&&this.center&&this.currentCircleId){const i=u(this.center,[t.lng,t.lat]);let o;if(\"web-mercator\"===this.projection){const e=function(t,e){const i=1e3*u(t,e);if(0===i)return 1;const{x:o,y:s}=x(t[0],t[1]),{x:n,y:r}=x(e[0],e[1]);return Math.sqrt(Math.pow(n-o,2)+Math.pow(r-s,2))/i}(this.center,[t.lng,t.lat]);o=function(t){const{center:e,radiusKilometers:i,coordinatePrecision:o}=t,s=t.steps?t.steps:64,n=1e3*i,[r,a]=e,{x:l,y:h}=x(r,a),d=[];for(let t=0;t<s;t++){const e=360*t/s*Math.PI/180,i=n*Math.cos(e),r=n*Math.sin(e),[a,c]=[l+i,h+r],{lng:u,lat:g}=M(a,c);d.push([f(u,o),f(g,o)])}return d.push(d[0]),{type:\"Feature\",geometry:{type:\"Polygon\",coordinates:[d]},properties:{}}}({center:this.center,radiusKilometers:i*e,coordinatePrecision:this.coordinatePrecision})}else{if(\"globe\"!==this.projection)throw new Error(\"Invalid projection\");o=S({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision})}if(this.validate&&!this.validate({type:\"Feature\",id:this.currentCircleId,geometry:o.geometry,properties:{radiusKilometers:i}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentCircleId,geometry:o.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:\"radiusKilometers\",value:i}])}}}const V=(t,e)=>{const{x:i,y:o}=t,{x:s,y:n}=e,r=s-i,a=n-o;return Math.sqrt(a*a+r*r)};class L extends d{constructor(e){super(e),this.mode=\"freehand\",this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=void 0,this.keyEvents=void 0,this.cursors=void 0,this.preventPointsNearClose=void 0,this.autoClose=void 0,this.autoCloseTimeout=500,this.hasLeftStartingPoint=!1,this.preventNewFeature=!1;const i={start:\"crosshair\",close:\"pointer\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.preventPointsNearClose=e&&e.preventPointsNearClose||!0,e&&e.autoCloseTimeout&&!e.autoClose)throw new Error(\"autoCloseTimeout is set, but autoClose is not enabled\");if(this.autoClose=e&&e.autoClose||!1,this.autoCloseTimeout=e&&e.autoCloseTimeout||500,this.minDistance=e&&e.minDistance||20,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.validate=null==e?void 0:e.validation}close(){if(void 0===this.currentId)return;const t=this.currentId;if(this.validate&&t){const i=this.store.getGeometryCopy(t);if(!this.validate({type:\"Feature\",id:t,geometry:i,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.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\"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onMouseMove(t){if(void 0===this.currentId||!1===this.startingClick)return;const i=this.store.getGeometryCopy(this.currentId),o=i.coordinates[0].length-2,[s,n]=i.coordinates[0][o],{x:r,y:a}=this.project(s,n),l=V({x:r,y:a},{x:t.containerX,y:t.containerY}),[h,d]=i.coordinates[0][0],{x:c,y:u}=this.project(h,d);if(V({x:c,y:u},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(()=>{this.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(l<this.minDistance)return;i.coordinates[0].pop();const g={type:\"Polygon\",coordinates:[[...i.coordinates[0],[t.lng,t.lat],i.coordinates[0][0]]]};this.validate&&!this.validate({type:\"Feature\",id:this.currentId,geometry:g,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.Provisional}).valid||this.store.updateGeometry([{id:this.currentId,geometry:g}])}onClick(t){if(!this.preventNewFeature){if(!1===this.startingClick){const[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:{mode:this.mode,[o]:!0}}]);return this.currentId=e,this.closingPointId=i,this.startingClick=!0,void this.setDrawing()}this.close()}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const 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){}}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return\"Feature\"===e.type&&\"Polygon\"===e.geometry.type&&e.properties.mode===this.mode?(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i):\"Feature\"===e.type&&\"Point\"===e.geometry.type&&e.properties.mode===this.mode?(i.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),i.zIndex=40,i):i}validateFeature(t){return this.validateModeFeature(t,t=>W(t,this.coordinatePrecision))}}class G{constructor({store:t,mode:e,project:i,unproject:o,pointerDistance:s,coordinatePrecision:n,projection:r}){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=t,this.mode=e,this.project=i,this.unproject=o,this.pointerDistance=s,this.coordinatePrecision=n,this.projection=r}}function T({unproject:t,point:e,pointerDistance:i}){const o=i/2,{x:s,y:n}=e;return{type:\"Feature\",properties:{},geometry:{type:\"Polygon\",coordinates:[[t(s-o,n-o),t(s+o,n-o),t(s+o,n+o),t(s-o,n+o),t(s-o,n-o)].map(t=>[t.lng,t.lat])]}}}class U extends G{constructor(t){super(t)}create(t){const{containerX:e,containerY:i}=t;return T({unproject:this.unproject,point:{x:e,y:i},pointerDistance:this.pointerDistance})}}class A extends G{constructor(t){super(t)}measure(t,e){const{x:i,y:o}=this.project(e[0],e[1]);return V({x:i,y:o},{x:t.containerX,y:t.containerY})}}class K extends G{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=t=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode)),this.getSnappableCoordinate=(t,e)=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode&&t.id!==e)),this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappable(t,e){const i=this.clickBoundingBox.create(t),o=this.store.search(i,e),s={coord:void 0,minDist:Infinity};return o.forEach(e=>{let i;if(\"Polygon\"===e.geometry.type)i=e.geometry.coordinates[0];else{if(\"LineString\"!==e.geometry.type)return;i=e.geometry.coordinates}i.forEach(e=>{const i=this.pixelDistance.measure(t,e);i<s.minDist&&i<this.pointerDistance&&(s.coord=e,s.minDist=i)})}),s.coord}}function X(t,e,i){const o=p(t[0]),s=p(t[1]),n=p(i),r=y(e),a=Math.asin(Math.sin(s)*Math.cos(r)+Math.cos(s)*Math.sin(r)*Math.cos(n));return[m(o+Math.atan2(Math.sin(n)*Math.sin(r)*Math.cos(s),Math.cos(r)-Math.sin(s)*Math.sin(a))),m(a)]}function R({x:t,y:e},i,o){const s=p(o);return{x:t+i*Math.cos(s),y:e+i*Math.sin(s)}}function Y(t,e){const i=p(t[0]),o=p(e[0]),s=p(t[1]),n=p(e[1]),r=Math.sin(o-i)*Math.cos(n),a=Math.cos(s)*Math.sin(n)-Math.sin(s)*Math.cos(n)*Math.cos(o-i);return m(Math.atan2(r,a))}function z({x:t,y:e},{x:i,y:o}){let s=Math.atan2(o-e,i-t);return s*=180/Math.PI,s>180?s-=360:s<-180&&(s+=360),s}function H(t){return(t+360)%360}function q(t,e,i){const o=[],s=t.length;let n,r,a,l=0;for(let s=0;s<t.length&&!(e>=l&&s===t.length-1);s++){if(l>e&&0===o.length){if(n=e-l,!n)return o.push(t[s]),o;r=Y(t[s],t[s-1])-180,a=X(t[s],n,r),o.push(a)}if(l>=i)return n=i-l,n?(r=Y(t[s],t[s-1])-180,a=X(t[s],n,r),o.push(a),o):(o.push(t[s]),o);if(l>=e&&o.push(t[s]),s===t.length-1)return o;l+=u(t[s],t[s+1])}if(l<e&&t.length===s)throw new Error(\"Start position is beyond line\");const h=t[t.length-1];return[h,h]}function $(t){return t*(Math.PI/180)}function Z(t){return t*(180/Math.PI)}class J extends G{constructor(t){super(t),this.config=void 0,this.config=t}generateInsertionCoordinates(t,e,i){const o=[t,e];let s=0;for(let t=0;t<o.length-1;t++)s+=u(o[0],o[1]);if(s<=i)return o;let n=s/i-1;Number.isInteger(n)||(n=Math.floor(n)+1);const r=[];for(let t=0;t<n;t++){const e=q(o,i*t,i*(t+1));r.push(e)}const a=[];for(let t=0;t<r.length;t++)a.push(r[t][1]);return this.limitCoordinates(a)}generateInsertionGeodesicCoordinates(t,e,i){const o=u(t,e),s=function(t,e,i){const o=[],s=$(t[1]),n=$(t[0]),r=$(e[1]),a=$(e[0]);i+=1;const l=2*Math.asin(Math.sqrt(Math.sin((r-s)/2)**2+Math.cos(s)*Math.cos(r)*Math.sin((a-n)/2)**2));if(0===l||isNaN(l))return o;for(let t=0;t<=i;t++){const e=t/i,h=Math.sin((1-e)*l)/Math.sin(l),d=Math.sin(e*l)/Math.sin(l),c=h*Math.cos(s)*Math.cos(n)+d*Math.cos(r)*Math.cos(a),u=h*Math.cos(s)*Math.sin(n)+d*Math.cos(r)*Math.sin(a),g=h*Math.sin(s)+d*Math.sin(r);if(isNaN(c)||isNaN(u)||isNaN(g))continue;const p=Math.atan2(g,Math.sqrt(c**2+u**2)),y=Math.atan2(u,c);isNaN(p)||isNaN(y)||o.push([Z(y),Z(p)])}return o.slice(1,-1)}(t,e,Math.floor(o/i));return this.limitCoordinates(s)}limitCoordinates(t){return t.map(t=>[f(t[0],this.config.coordinatePrecision),f(t[1],this.config.coordinatePrecision)])}}function Q(t,e){return t[0]===e[0]&&t[1]===e[1]}function tt(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(t=>F(t,e))?{valid:!0}:{valid:!1,reason:\"Feature has invalid coordinates\"}}class et extends d{constructor(e){super(e),this.mode=\"linestring\",this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.keyEvents=void 0,this.snapping=void 0,this.cursors=void 0,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommitedCoordinates=void 0,this.snappedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0;const i={start:\"crosshair\",close:\"pointer\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.snapping=e&&e.snapping?e.snapping:void 0,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.validate=null==e?void 0:e.validation,this.insertCoordinates=null==e?void 0:e.insertCoordinates}close(){if(void 0===this.currentId)return;const t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.updateGeometries([...t.coordinates],void 0,e.Commit);const i=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(i,{mode:this.mode,action:\"draw\"})}updateGeometries(t,e,i){if(!this.currentId)return;const 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;const s=[{id:this.currentId,geometry:o}];this.closingPointId&&e&&s.push({id:this.closingPointId,geometry:{type:\"Point\",coordinates:e}}),\"commit\"===i&&(this.lastCommitedCoordinates=o.coordinates),this.store.updateGeometry(s)}generateInsertCoordinates(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\");const i=u(t,e)/(this.insertCoordinates.value+1);let o=[];return\"globe\"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):\"web-mercator\"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o}createLine(t){const[e]=this.store.create([{geometry:{type:\"LineString\",coordinates:[t,t]},properties:{mode:this.mode}}]);this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()}firstUpdateToLine(t){if(!this.currentId)return;const i=this.store.getGeometryCopy(this.currentId).coordinates,[o]=this.store.create([{geometry:{type:\"Point\",coordinates:[...t]},properties:{mode:this.mode}}]);this.closingPointId=o,this.setCursor(this.cursors.close);const s=[...i,t];this.updateGeometries(s,void 0,e.Commit),this.currentCoordinate++}updateToLine(t,i){if(!this.currentId)return;const o=this.store.getGeometryCopy(this.currentId).coordinates,[s,n]=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:o[o.length-2],{x:r,y:a}=this.project(s,n);if(V({x:r,y:a},{x:i.x,y:i.y})<this.pointerDistance)return void this.close();this.setCursor(this.cursors.close);const l=[...o,t];this.updateGeometries(l,o[o.length-1],e.Commit),this.currentCoordinate++}registerBehaviors(t){this.coordinateSnapping=new K(t,new A(t),new U(t)),this.insertPoint=new J(t)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onMouseMove(t){this.mouseMove=!0,this.setCursor(this.cursors.start);const i=this.snapCoordinate(t);if(i){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:\"Point\",coordinates:i}}]);else{const[t]=this.store.create([{geometry:{type:\"Point\",coordinates:i},properties:{mode:this.mode,[s]:!0}}]);this.snappedPointId=t}t.lng=i[0],t.lat=i[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);const o=i||[t.lng,t.lat];if(void 0===this.currentId||0===this.currentCoordinate)return;const n=this.store.getGeometryCopy(this.currentId).coordinates;if(n.pop(),this.closingPointId){const[e,i]=n[n.length-1],{x:o,y:s}=this.project(e,i);V({x:o,y:s},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}let r=[...n,o];if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){const t=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],e=o;if(!Q(t,e)){const i=this.generateInsertCoordinates(t,e);r=[...this.lastCommitedCoordinates.slice(0,-1),...i,o]}}this.updateGeometries(r,void 0,e.Provisional)}onClick(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);const 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})}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const 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){}}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});if(\"Feature\"===e.type&&\"LineString\"===e.geometry.type&&e.properties.mode===this.mode)return i.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,i.lineStringColor,e),i.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,i.lineStringWidth,e),i.zIndex=10,i;if(\"Feature\"===e.type&&\"Point\"===e.geometry.type&&e.properties.mode===this.mode){const t=e.properties[o];return i.pointColor=this.getHexColorStylingValue(t?this.styles.closingPointColor:this.styles.snappingPointColor,i.pointColor,e),i.pointWidth=this.getNumericStylingValue(t?this.styles.closingPointWidth:this.styles.snappingPointWidth,i.pointWidth,e),i.pointOutlineColor=this.getHexColorStylingValue(t?this.styles.closingPointOutlineColor:this.styles.snappingPointOutlineColor,\"#ffffff\",e),i.pointOutlineWidth=this.getNumericStylingValue(t?this.styles.closingPointOutlineWidth:this.styles.snappingPointOutlineWidth,2,e),i.zIndex=40,i}return i}validateFeature(t){return this.validateModeFeature(t,t=>tt(t,this.coordinatePrecision))}snapCoordinate(t){var e,i;let 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}}const it=\"Feature is not a Point\",ot=\"Feature has invalid coordinates\";function st(t,e){return\"Point\"!==t.geometry.type?{valid:!1,reason:it}:F(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:ot}}class nt extends d{constructor(e){super(e),this.mode=\"point\",this.cursors=void 0;const i={create:\"crosshair\"};this.cursors=e&&e.cursors?t({},i,e.cursors):i}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onClick(t){if(!this.store)throw new Error(\"Mode must be registered first\");const i={type:\"Point\",coordinates:[t.lng,t.lat]},o={mode:this.mode};if(this.validate&&!this.validate({type:\"Feature\",geometry:i,properties:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.Finish}).valid)return;const[s]=this.store.create([{geometry:i,properties:o}]);this.onFinish(s,{mode:this.mode,action:\"draw\"})}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){}onDragStart(){}onDrag(){}onDragEnd(){}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return\"Feature\"===e.type&&\"Point\"===e.geometry.type&&e.properties.mode===this.mode&&(i.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(this.styles.pointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,e),i.zIndex=30),i}validateFeature(t){return this.validateModeFeature(t,t=>st(t,this.coordinatePrecision))}}class rt extends G{constructor(t,e){super(t),this.config=void 0,this.pixelDistance=void 0,this._startEndPoints=[],this.config=t,this.pixelDistance=e}get ids(){return this._startEndPoints.concat()}set ids(t){}create(t,e){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:{mode:e,[o]:!0}},{geometry:{type:\"Point\",coordinates:t[t.length-2]},properties:{mode:e,[o]:!0}}])}delete(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])}update(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]}}])}isClosingPoint(t){const e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),o=this.pixelDistance.measure(t,e.coordinates),s=this.pixelDistance.measure(t,i.coordinates);return{isClosing:o<this.pointerDistance,isPreviousClosing:s<this.pointerDistance}}}function at(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function lt(t,e){const i=function(t,e){const[i,o,s]=t,[n,r,a]=e;return i*n+o*r+s*a}(t,e)/(at(t)*at(e));return Math.acos(Math.min(Math.max(i,-1),1))}function ht(t){const e=p(t[1]),i=p(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function dt(t){const[e,i,o]=t,s=m(Math.asin(o));return[m(Math.atan2(i,e)),s]}function ct(t,e,i){const o=ht(t),s=ht(e),n=ht(i),[r,a,l]=n,[h,d,c]=function(t,e){const[i,o,s]=t,[n,r,a]=e;return[o*a-s*r,s*n-i*a,i*r-o*n]}(o,s),g=d*l-c*a,p=c*r-h*l,y=h*a-d*r,m=y*d-p*c,f=g*c-y*h,v=p*h-g*d,C=1/Math.sqrt(Math.pow(m,2)+Math.pow(f,2)+Math.pow(v,2)),P=[m*C,f*C,v*C],x=[-1*m*C,-1*f*C,-1*v*C],M=lt(o,s),I=lt(o,P),S=lt(s,P),E=lt(o,x),D=lt(s,x);let F;return F=I<E&&I<D||S<E&&S<D?P:x,lt(o,F)>M||lt(s,F)>M?u(dt(F),dt(o))<=u(dt(F),dt(s))?[dt(o),!0,!1]:[dt(s),!1,!0]:[dt(F),!1,!1]}function ut(t,e,i){const o=e.x-t.x,s=e.y-t.y,n=Math.max(0,Math.min(1,((i.x-t.x)*o+(i.y-t.y)*s)/(o*o+s*s)));return{x:t.x+n*o,y:t.y+n*s}}class gt extends G{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=t=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode)),this.getSnappableCoordinate=(t,e)=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode&&t.id!==e)),this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappable(t,e){const i=this.clickBoundingBox.create(t),o=this.store.search(i,e),s={coord:void 0,minDistance:Infinity};return o.forEach(e=>{let i;if(\"Polygon\"===e.geometry.type)i=e.geometry.coordinates[0];else{if(\"LineString\"!==e.geometry.type)return;i=e.geometry.coordinates}const o=[];for(let t=0;t<i.length-1;t++)o.push([i[t],i[t+1]]);let n;const r=[t.lng,t.lat];if(\"web-mercator\"===this.config.projection?n=function(t,e){let i=[Infinity,Infinity],o=Infinity;for(let s of e){const e=s[0],n=s[1];let r,a=Infinity;const l=x(e[0],e[1]),h=x(n[0],n[1]),d=x(t[0],t[1]);if(e[0]===t[0]&&e[1]===t[1])r=e;else if(n[0]===t[0]&&n[1]===t[1])r=n;else{const{x:t,y:e}=ut(l,h,d),{lng:i,lat:o}=M(t,e);r=[i,o]}r&&(a=V(d,x(r[0],r[1])),a<o&&(i=r,o=a))}return Infinity===o?void 0:{coordinate:i,distance:o}}(r,o):\"globe\"===this.config.projection&&(n=function(t,e){let i=[Infinity,Infinity],o=Infinity;for(let s of e){const e=s[0],n=s[1];let r,a=Infinity;e[0]===t[0]&&e[1]===t[1]?r=e:n[0]===t[0]&&n[1]===t[1]?r=n:[r]=ct(e,n,t),r&&(a=u(t,r),a<o&&(i=r,o=a))}return Infinity===o?void 0:{coordinate:i,distance:o}}(r,o)),!n)return;const a=this.pixelDistance.measure(t,n.coordinate);a<s.minDistance&&a<this.pointerDistance&&(s.coord=n.coordinate,s.minDistance=a)}),s.coord}}class pt extends d{constructor(e){super(e),this.mode=\"polygon\",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=void 0,this.snapping=void 0,this.snappedPointId=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.cursors=void 0,this.mouseMove=!1;const i={start:\"crosshair\",close:\"pointer\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,this.snapping=e&&e.snapping?e.snapping:void 0,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}}close(){if(void 0===this.currentId)return;const t=this.store.getGeometryCopy(this.currentId).coordinates[0];if(t.length<5)return;if(!this.updatePolygonGeometry([...t.slice(0,-2),t[0]],e.Finish))return;const i=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(i,{mode:this.mode,action:\"draw\"})}registerBehaviors(t){const e=new U(t);this.pixelDistance=new A(t),this.lineSnapping=new gt(t,this.pixelDistance,e),this.coordinateSnapping=new K(t,this.pixelDistance,e),this.closingPoints=new rt(t,this.pixelDistance)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onMouseMove(t){this.mouseMove=!0,this.setCursor(this.cursors.start);const i=this.snapCoordinate(t);if(i){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:\"Point\",coordinates:i}}]);else{const[t]=this.store.create([{geometry:{type:\"Point\",coordinates:i},properties:{mode:this.mode,[s]:!0}}]);this.snappedPointId=t}t.lng=i[0],t.lat=i[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);if(void 0===this.currentId||0===this.currentCoordinate)return;const o=this.store.getGeometryCopy(this.currentId).coordinates[0];let n;if(1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),i=Math.max(1e-6,e);n=[o[0],[t.lng,t.lat],[t.lng,t.lat-i],o[0]]}else if(2===this.currentCoordinate)n=[o[0],o[1],[t.lng,t.lat],o[0]];else{const{isClosing:e,isPreviousClosing:i}=this.closingPoints.isClosingPoint(t);i||e?(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.setCursor(this.cursors.close),n=[...o.slice(0,-2),o[0],o[0]]):n=[...o.slice(0,-2),[t.lng,t.lat],o[0]]}this.updatePolygonGeometry(n,e.Provisional)}updatePolygonGeometry(t,e){if(!this.currentId)return!1;const 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))}snapCoordinate(t){var e,i,o;let s;if(null!=(e=this.snapping)&&e.toLine){let e;e=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t),e&&(s=e)}if(null!=(i=this.snapping)&&i.toCoordinate){let e;e=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t),e&&(s=e)}return null!=(o=this.snapping)&&o.toCustom&&(s=this.snapping.toCustom(t)),s}onClick(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){const e=this.snapCoordinate(t);e&&(t.lng=e[0],t.lat=e[1]);const[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,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const i=this.snapCoordinate(t);i&&(t.lng=i[0],t.lat=i[1]);const o=this.store.getGeometryCopy(this.currentId);if(Q([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]],e.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){const i=this.snapCoordinate(t);i&&(t.lng=i[0],t.lat=i[1]);const o=this.store.getGeometryCopy(this.currentId).coordinates[0];if(Q([t.lng,t.lat],o[1]))return;if(!this.updatePolygonGeometry([o[0],o[1],[t.lng,t.lat],[t.lng,t.lat],o[0]],e.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(o,\"polygon\"),this.currentCoordinate++}else if(this.currentId){const i=this.store.getGeometryCopy(this.currentId).coordinates[0],{isClosing:o,isPreviousClosing:s}=this.closingPoints.isClosingPoint(t);if(s||o)this.close();else{const o=this.snapCoordinate(t);if(o&&(t.lng=o[0],t.lat=o[1]),Q([t.lng,t.lat],i[this.currentCoordinate-1]))return;const s=function(t=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]){return{type:\"Feature\",geometry:{type:\"Polygon\",coordinates:t},properties:{}}}([[...i.slice(0,-1),[t.lng,t.lat],i[0]]]);if(!this.updatePolygonGeometry(s.geometry.coordinates[0],e.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(s.geometry.coordinates[0])}}}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){this.setCursor(\"unset\")}onDrag(){}onDragEnd(){this.setCursor(this.cursors.start)}cleanUp(){const 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){}}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});if(e.properties.mode===this.mode){if(\"Polygon\"===e.geometry.type)return i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i;if(\"Point\"===e.geometry.type){const t=e.properties[o],n=e.properties[s];return i.pointWidth=this.getNumericStylingValue(t?this.styles.closingPointWidth:n?this.styles.snappingPointWidth:i.pointWidth,i.pointWidth,e),i.pointColor=this.getHexColorStylingValue(t?this.styles.closingPointColor:n?this.styles.snappingPointColor:i.pointColor,i.pointColor,e),i.pointOutlineColor=this.getHexColorStylingValue(t?this.styles.closingPointOutlineColor:n?this.styles.snappingPointOutlineColor:i.pointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(t?this.styles.closingPointOutlineWidth:n?this.styles.snappingPointOutlineWidth:2,2,e),i.zIndex=30,i}}return i}validateFeature(t){return this.validateModeFeature(t,t=>W(t,this.coordinatePrecision))}}class yt extends d{constructor(e){super(e),this.mode=\"rectangle\",this.center=void 0,this.clickCount=0,this.currentRectangleId=void 0,this.keyEvents=void 0,this.cursors=void 0;const i={start:\"crosshair\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}}updateRectangle(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){const 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}])}}close(){const 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\"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onClick(t){if(0===this.clickCount){this.center=[t.lng,t.lat];const[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,this.clickCount++,this.setDrawing()}else this.updateRectangle(t,e.Finish),this.close()}onMouseMove(t){this.updateRectangle(t,e.Provisional)}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){const 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])}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return\"Feature\"===e.type&&\"Polygon\"===e.geometry.type&&e.properties.mode===this.mode?(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10,i):i}validateFeature(t){return this.validateModeFeature(t,t=>B(t,this.coordinatePrecision))}}class mt extends d{constructor(t){super({styles:t.styles}),this.type=h.Render,this.mode=\"render\",this.mode=t.modeName}registerBehaviors(t){this.mode=t.mode}start(){this.setStarted()}stop(){this.setStopped()}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(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)}}validateFeature(t){const e=super.validateFeature(t);if(e.valid){const e=t,i=st(e,this.coordinatePrecision).valid||W(e,this.coordinatePrecision).valid||tt(e,this.coordinatePrecision).valid;return i?{valid:!0}:{valid:i,reason:\"Feature is not a valid Point, Polygon or LineString feature\"}}return e}}function ft(t,e){const i=t,o=e,s=p(i[1]),n=p(o[1]);let r=p(o[0]-i[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);const a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),l=(m(Math.atan2(r,a))+360)%360;return l>180?-(360-l):l}function vt(t,e,i){let o=e;e<0&&(o=-Math.abs(o));const s=o/g,n=t[0]*Math.PI/180,r=p(t[1]),a=p(i),l=s*Math.cos(a);let h=r+l;Math.abs(h)>Math.PI/2&&(h=h>0?Math.PI-h:-Math.PI-h);const d=Math.log(Math.tan(h/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(d)>1e-11?l/d:Math.cos(r),u=[(180*(n+s*Math.sin(a)/c)/Math.PI+540)%360-180,180*h/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function Ct(t,e,i,o,s){const n=o(t[0],t[1]),r=o(e[0],e[1]),{lng:a,lat:l}=s((n.x+r.x)/2,(n.y+r.y)/2);return[f(a,i),f(l,i)]}function Pt(t,e,i){const o=vt(t,1e3*u(t,e)/2,ft(t,e));return[f(o[0],i),f(o[1],i)]}function xt({featureCoords:t,precision:e,unproject:i,project:o,projection:s}){const n=[];for(let r=0;r<t.length-1;r++){let a;if(\"web-mercator\"===s)a=Ct(t[r],t[r+1],e,o,i);else{if(\"globe\"!==s)throw new Error(\"Invalid projection\");a=Pt(t[r],t[r+1],e)}n.push(a)}return n}class Mt extends G{constructor(t,e){super(t),this.config=void 0,this.selectionPointBehavior=void 0,this._midPoints=[],this.config=t,this.selectionPointBehavior=e}get ids(){return this._midPoints.concat()}set ids(t){}insert(t,e){const i=this.store.getGeometryCopy(t),{midPointFeatureId:o,midPointSegment:s}=this.store.getPropertiesCopy(t),n=this.store.getGeometryCopy(o),r=\"Polygon\"===n.type?n.coordinates[0]:n.coordinates;r.splice(s+1,0,i.coordinates),n.coordinates=\"Polygon\"===n.type?[r]:r,this.store.updateGeometry([{id:o,geometry:n}]),this.store.delete([...this._midPoints,...this.selectionPointBehavior.ids]),this.create(r,o,e),this.selectionPointBehavior.create(r,n.type,o)}create(t,e,o){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,s,n){return xt({featureCoords:t,precision:i,project:o,unproject:s,projection:n}).map((t,i)=>({geometry:{type:\"Point\",coordinates:t},properties:e(i)}))}(t,t=>({mode:this.mode,[i.MID_POINT]:!0,midPointSegment:t,midPointFeatureId:e}),o,this.config.project,this.config.unproject,this.projection))}delete(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])}getUpdated(t){if(0!==this._midPoints.length)return xt({featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}).map((t,e)=>({id:this._midPoints[e],geometry:{type:\"Point\",coordinates:t}}))}}class It extends G{constructor(t){super(t),this._selectionPoints=[]}get ids(){return this._selectionPoints.concat()}set ids(t){}create(t,e,i){this._selectionPoints=this.store.create(function(t,e,i){const o=[],s=\"Polygon\"===e?t.length-1:t.length;for(let e=0;e<s;e++)o.push({geometry:{type:\"Point\",coordinates:t[e]},properties:i(e)});return o}(t,e,t=>({mode:this.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t})))}delete(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])}getUpdated(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map((e,i)=>({id:e,geometry:{type:\"Point\",coordinates:t[i]}}))}getOneUpdated(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:\"Point\",coordinates:e}}}}function St(t,e){let i=!1;for(let r=0,a=e.length;r<a;r++){const a=e[r];for(let e=0,r=a.length,l=r-1;e<r;l=e++)(s=a[e])[1]>(o=t)[1]!=(n=a[l])[1]>o[1]&&o[0]<(n[0]-s[0])*(o[1]-s[1])/(n[1]-s[1])+s[0]&&(i=!i)}var o,s,n;return i}const Et=(t,e,i)=>{const o=t=>t*t,s=(t,e)=>o(t.x-e.x)+o(t.y-e.y);return Math.sqrt(((t,e,i)=>{const o=s(e,i);if(0===o)return s(t,e);let n=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/o;return n=Math.max(0,Math.min(1,n)),s(t,{x:e.x+n*(i.x-e.x),y:e.y+n*(i.y-e.y)})})(t,e,i))};class Dt extends G{constructor(t,e,i){super(t),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=t,this.createClickBoundingBox=e,this.pixelDistance=i}find(t,e){let o,s,n,r,a=Infinity,l=Infinity,h=Infinity;const d=this.createClickBoundingBox.create(t),c=this.store.search(d);for(let d=0;d<c.length;d++){const u=c[d],g=u.geometry;if(\"Point\"===g.type){if(u.properties.selectionPoint||!e&&u.properties[i.MID_POINT])continue;const s=this.pixelDistance.measure(t,g.coordinates);u.properties[i.MID_POINT]&&s<this.pointerDistance&&s<h?(h=s,n=u):!u.properties[i.MID_POINT]&&s<this.pointerDistance&&s<a&&(a=s,o=u)}else if(\"LineString\"===g.type){if(o)continue;for(let e=0;e<g.coordinates.length-1;e++){const i=g.coordinates[e],o=g.coordinates[e+1],n=Et({x:t.containerX,y:t.containerY},this.project(i[0],i[1]),this.project(o[0],o[1]));n<this.pointerDistance&&n<l&&(l=n,s=u)}}else if(\"Polygon\"===g.type){if(o||s)continue;St([t.lng,t.lat],g.coordinates)&&(r=u)}}return{clickedFeature:o||s||r,clickedMidPoint:n}}}class Ft extends G{constructor(t,e,i,o){super(t),this.config=void 0,this.featuresAtCursorEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=t,this.featuresAtCursorEvent=e,this.selectionPoints=i,this.midPoints=o}startDragging(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return null!==this.draggedFeatureId}canDrag(t,e){const{clickedFeature:i}=this.featuresAtCursorEvent.find(t,!0);return!(!i||i.id!==e)}drag(t,i){if(!this.draggedFeatureId)return;const o=this.store.getGeometryCopy(this.draggedFeatureId),s=[t.lng,t.lat];if(\"Polygon\"===o.type||\"LineString\"===o.type){let n,r;if(\"Polygon\"===o.type?(n=o.coordinates[0],r=n.length-1):(n=o.coordinates,r=n.length),!this.dragPosition)return!1;for(let t=0;t<r;t++){const e=n[t];let i,o;if(\"web-mercator\"===this.config.projection){const t=x(this.dragPosition[0],this.dragPosition[1]),n=x(s[0],s[1]),r=x(e[0],e[1]),a={x:t.x-n.x,y:t.y-n.y},l=r.x-a.x,h=r.y-a.y,{lng:d,lat:c}=M(l,h);i=d,o=c}else{const t=[this.dragPosition[0]-s[0],this.dragPosition[1]-s[1]];i=e[0]-t[0],o=e[1]-t[1]}if(i=f(i,this.config.coordinatePrecision),o=f(o,this.config.coordinatePrecision),i>180||i<-180||o>90||o<-90)return!1;n[t]=[i,o]}\"Polygon\"===o.type&&(n[n.length-1]=[n[0][0],n[0][1]]);const a=this.selectionPoints.getUpdated(n)||[],l=this.midPoints.getUpdated(n)||[];if(i&&!i({type:\"Feature\",id:this.draggedFeatureId,geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:e.Provisional}).valid)return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:o},...a,...l]),this.dragPosition=[t.lng,t.lat]}else\"Point\"===o.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:\"Point\",coordinates:s}}]),this.dragPosition=[t.lng,t.lat])}}class wt extends G{constructor(t,e,i,o){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.draggedCoordinate={id:null,index:-1},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=o}getClosestCoordinate(t,e){const i={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};let o;if(\"LineString\"===e.type)o=e.coordinates;else{if(\"Polygon\"!==e.type)return i;o=e.coordinates[0]}for(let s=0;s<o.length;s++){const n=this.pixelDistance.measure(t,o[s]);if(n<this.pointerDistance&&n<i.dist){const t=\"Polygon\"===e.type&&(s===o.length-1||0===s);i.dist=n,i.index=t?0:s,i.isFirstOrLastPolygonCoord=t}}return i}getDraggableIndex(t,e){const i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index}drag(t,i,o){if(!this.draggedCoordinate.id)return!1;const s=this.draggedCoordinate.index,n=this.store.getGeometryCopy(this.draggedCoordinate.id),r=\"LineString\"===n.type?n.coordinates:n.coordinates[0],a=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(\"Polygon\"!==n.type||s!==r.length-1&&0!==s)r[s]=a;else{const t=r.length-1;r[0]=a,r[t]=a}const l=this.selectionPoints.getOneUpdated(s,a),h=l?[l]:[],d=this.midPoints.getUpdated(r)||[];return!(\"Point\"!==n.type&&!i&&E({type:\"Feature\",geometry:n,properties:{}})||o&&!o({type:\"Feature\",id:this.draggedCoordinate.id,geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:e.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:n},...h,...d]),0))}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}}function bt(t){let e=0,i=0,o=0;return(\"Polygon\"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(t=>{e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}function _t(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;const i=g,o=e[1]*Math.PI/180,s=t[1]*Math.PI/180,n=s-o;let r=Math.abs(t[0]-e[0])*Math.PI/180;r>Math.PI&&(r-=2*Math.PI);const a=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=Math.abs(a)>1e-11?n/a:Math.cos(o);return Math.sqrt(n*n+l*l*r*r)*i}function kt(t){const e=(\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(t=>{const{x:e,y:i}=x(t[0],t[1]);return[e,i]});return\"Polygon\"===t.geometry.type?function(t){let e=0,i=0,o=0;const s=t.length;for(let n=0;n<s-1;n++){const[s,r]=t[n],[a,l]=t[n+1],h=s*l-a*r;e+=h,i+=(s+a)*h,o+=(r+l)*h}return e/=2,i/=6*e,o/=6*e,{x:i,y:o}}(e):function(t){const e=t.length;let i=0,o=0;for(let s=0;s<e;s++){const[e,n]=t[s];i+=e,o+=n}return{x:i/e,y:o/e}}(e)}class Ot extends G{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastBearing=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastBearing=void 0}rotate(t,i,o){const s=this.store.getGeometryCopy(i);if(\"Polygon\"!==s.type&&\"LineString\"!==s.type)return;const n=[t.lng,t.lat];let r;const a={type:\"Feature\",geometry:s,properties:{}};if(\"web-mercator\"===this.config.projection){if(r=z(kt(a),x(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=r);((t,e)=>{if(0===e||360===e||-360===e)return t;const i=.017453292519943295*e,o=(\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(([t,e])=>x(t,e)),s=o.reduce((t,e)=>({x:t.x+e.x,y:t.y+e.y}),{x:0,y:0});s.x/=o.length,s.y/=o.length;const n=o.map(t=>({x:s.x+(t.x-s.x)*Math.cos(i)-(t.y-s.y)*Math.sin(i),y:s.y+(t.x-s.x)*Math.sin(i)+(t.y-s.y)*Math.cos(i)})).map(({x:t,y:e})=>[M(t,e).lng,M(t,e).lat]);\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]=n:t.geometry.coordinates=n})(a,-(this.lastBearing-r))}else{if(\"globe\"!==this.config.projection)throw new Error(\"Unsupported projection\");if(r=ft(bt({type:\"Feature\",geometry:s,properties:{}}),n),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;const i=bt(t);(\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const o=ft(i,t)+e,s=_t(i,t),n=vt(i,s,o);t[0]=n[0],t[1]=n[1]})}(a,-(this.lastBearing-(r+180)))}const l=\"Polygon\"===s.type?s.coordinates[0]:s.coordinates;l.forEach(t=>{t[0]=f(t[0],this.coordinatePrecision),t[1]=f(t[1],this.coordinatePrecision)});const h=this.midPoints.getUpdated(l)||[],d=this.selectionPoints.getUpdated(l)||[];if(o&&!o({id:i,type:\"Feature\",geometry:s,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:e.Provisional}))return!1;this.store.updateGeometry([{id:i,geometry:s},...d,...h]),\"web-mercator\"===this.projection?this.lastBearing=r:\"globe\"===this.projection&&(this.lastBearing=r+180)}}class jt extends G{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastDistance=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastDistance=void 0}scale(t,i,o){const s=this.store.getGeometryCopy(i);if(\"Polygon\"!==s.type&&\"LineString\"!==s.type)return;const n=[t.lng,t.lat],r={type:\"Feature\",geometry:s,properties:{}};let a;const l=kt(r);if(\"web-mercator\"===this.config.projection){const e=x(t.lng,t.lat);a=V(l,e)}else{if(\"globe\"!==this.config.projection)throw new Error(\"Invalid projection\");a=u(bt({type:\"Feature\",geometry:s,properties:{}}),n)}if(!this.lastDistance)return void(this.lastDistance=a);const h=1-(this.lastDistance-a)/a;if(\"web-mercator\"===this.config.projection){const{lng:t,lat:e}=M(l.x,l.y);!function(t,e,i){if(1===e)return t;const o=(\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(([t,e])=>x(t,e)),s=x(i[0],i[1]),n=o.map(t=>({x:s.x+(t.x-s.x)*e,y:s.y+(t.y-s.y)*e})).map(({x:t,y:e})=>[M(t,e).lng,M(t,e).lat]);\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]=n:t.geometry.coordinates=n}(r,h,[t,e])}else\"globe\"===this.config.projection&&function(t,e,i,o=\"xy\"){1===e||(\"Polygon\"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const s=_t(i,t),n=ft(i,t),r=vt(i,s*e,n);\"x\"!==o&&\"xy\"!==o||(t[0]=r[0]),\"y\"!==o&&\"xy\"!==o||(t[1]=r[1])})}(r,h,bt(r));const d=\"Polygon\"===s.type?s.coordinates[0]:s.coordinates;d.forEach(t=>{t[0]=f(t[0],this.coordinatePrecision),t[1]=f(t[1],this.coordinatePrecision)});const c=this.midPoints.getUpdated(d)||[],g=this.selectionPoints.getUpdated(d)||[];if(o&&!o({id:i,type:\"Feature\",geometry:s,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:e.Provisional}))return!1;this.store.updateGeometry([{id:i,geometry:s},...g,...c]),this.lastDistance=a}}class Wt extends G{constructor(t,e,i,o){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=o}getClosestCoordinate(t,e){const i={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};let o;if(\"LineString\"===e.type)o=e.coordinates;else{if(\"Polygon\"!==e.type)return i;o=e.coordinates[0]}for(let s=0;s<o.length;s++){const n=this.pixelDistance.measure(t,o[s]);if(n<this.pointerDistance&&n<i.dist){const t=\"Polygon\"===e.type&&(s===o.length-1||0===s);i.dist=n,i.index=t?0:s,i.isFirstOrLastPolygonCoord=t}}return i}isValidDragWebMercator(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}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;const t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;const e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}}centerWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{feature:i,boundingBox:o,updatedCoords:s,selectedCoordinate:n}=e,r=kt(i);if(!r)return null;const a=x(n[0],n[1]),{closestBBoxIndex:l}=this.getIndexesWebMercator(o,a),h=x(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:l,updatedCoords:s,webMercatorCursor:h,webMercatorSelected:a,webMercatorOrigin:r}),s}centerFixedWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{feature:i,boundingBox:o,updatedCoords:s,selectedCoordinate:n}=e,r=kt(i);if(!r)return null;const a=x(n[0],n[1]),{closestBBoxIndex:l}=this.getIndexesWebMercator(o,a),h=x(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:l,updatedCoords:s,webMercatorCursor:h,webMercatorSelected:a,webMercatorOrigin:r}),s}scaleFixedWebMercator({closestBBoxIndex:t,webMercatorOrigin:e,webMercatorSelected:i,webMercatorCursor:o,updatedCoords:s}){if(!this.isValidDragWebMercator(t,e.x-o.x,e.y-o.y))return null;let n=V(e,o)/V(e,i);return n<0&&(n=this.minimumScale),this.performWebMercatorScale(s,e.x,e.y,n,n),s}oppositeFixedWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{boundingBox:i,updatedCoords:o,selectedCoordinate:s}=e,n=x(s[0],s[1]),{oppositeBboxIndex:r,closestBBoxIndex:a}=this.getIndexesWebMercator(i,n),l={x:i[r][0],y:i[r][1]},h=x(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:h,webMercatorSelected:n,webMercatorOrigin:l}),o}oppositeWebMercatorDrag(t){const e=this.getSelectedFeatureDataWebMercator();if(!e)return null;const{boundingBox:i,updatedCoords:o,selectedCoordinate:s}=e,n=x(s[0],s[1]),{oppositeBboxIndex:r,closestBBoxIndex:a}=this.getIndexesWebMercator(i,n),l={x:i[r][0],y:i[r][1]},h=x(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:h,webMercatorSelected:n,webMercatorOrigin:l}),o}scaleWebMercator({closestBBoxIndex:t,webMercatorOrigin:e,webMercatorSelected:i,webMercatorCursor:o,updatedCoords:s}){const n=e.x-o.x,r=e.y-o.y;if(!this.isValidDragWebMercator(t,n,r))return null;let a=1;0!==n&&1!==t&&5!==t&&(a=1-(e.x-i.x-n)/n);let l=1;return 0!==r&&3!==t&&7!==t&&(l=1-(e.y-i.y-r)/r),this.validateScale(a,l)?(a<0&&(a=this.minimumScale),l<0&&(l=this.minimumScale),this.performWebMercatorScale(s,e.x,e.y,a,l),s):null}getFeature(t){if(null===this.draggedCoordinate.id)return null;const e=this.store.getGeometryCopy(t);return\"Polygon\"!==e.type&&\"LineString\"!==e.type?null:{type:\"Feature\",geometry:e,properties:{}}}getNormalisedCoordinates(t){return\"Polygon\"===t.type?t.coordinates[0]:t.coordinates}validateScale(t,e){const i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,o=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&o}performWebMercatorScale(t,e,i,o,s){t.forEach(t=>{const{x:n,y:r}=x(t[0],t[1]),a=e+(n-e)*o,l=i+(r-i)*s,{lng:h,lat:d}=M(a,l);t[0]=h,t[1]=d})}getBBoxWebMercator(t){const e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(t=>{const{x:e,y:i}=x(t[0],t[1]);return[e,i]})).forEach(([t,i])=>{t<e[0]&&(e[0]=t),i<e[1]&&(e[1]=i),t>e[2]&&(e[2]=t),i>e[3]&&(e[3]=i)});const[i,o,s,n]=e;return[[i,n],[(i+s)/2,n],[s,n],[s,n+(o-n)/2],[s,o],[(i+s)/2,o],[i,o],[i,n+(o-n)/2]]}getIndexesWebMercator(t,e){let i,o=Infinity;for(let s=0;s<t.length;s++){const n=V({x:e.x,y:e.y},{x:t[s][0],y:t[s][1]});n<o&&(i=s,o=n)}if(void 0===i)throw new Error(\"No closest coordinate found\");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}}isDragging(){return null!==this.draggedCoordinate.id}startDragging(t,e){this.draggedCoordinate={id:t,index:e}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}getDraggableIndex(t,e){const i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index}drag(t,i,o){if(!this.draggedCoordinate.id)return!1;const s=this.getFeature(this.draggedCoordinate.id);if(!s)return!1;let n=null;if(\"center\"===i?n=this.centerWebMercatorDrag(t):\"opposite\"===i?n=this.oppositeWebMercatorDrag(t):\"center-fixed\"===i?n=this.centerFixedWebMercatorDrag(t):\"opposite-fixed\"===i&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(let t=0;t<n.length;t++){const e=n[t];if(e[0]=f(e[0],this.coordinatePrecision),e[1]=f(e[1],this.coordinatePrecision),!F(e,this.coordinatePrecision))return!1}const r=this.midPoints.getUpdated(n)||[],a=this.selectionPoints.getUpdated(n)||[],l={type:s.geometry.type,coordinates:\"Polygon\"===s.geometry.type?[n]:n};return!(o&&!o({id:this.draggedCoordinate.id,type:\"Feature\",geometry:l,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:e.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:l},...a,...r]),0))}}class Bt extends c{constructor(e){var i;super(e),this.mode=\"select\",this.allowManualDeselection=!0,this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags=void 0,this.keyEvents=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.dragCoordinateResizeFeature=void 0,this.cursors=void 0,this.validations={},this.flags=e&&e.flags?e.flags:{};const o={pointerOver:\"move\",dragStart:\"move\",dragEnd:\"move\",insertMidpoint:\"crosshair\"};if(this.cursors=e&&e.cursors?t({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))this.keyEvents={deselect:null,delete:null,rotate:null,scale:null};else{const i={deselect:\"Escape\",delete:\"Delete\",rotate:[\"Control\",\"r\"],scale:[\"Control\",\"s\"]};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}if(this.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,this.allowManualDeselection=null==(i=null==e?void 0:e.allowManualDeselection)||i,e&&e.flags&&e.flags)for(const t in e.flags){const i=e.flags[t].feature;i&&i.validation&&(this.validations[t]=i.validation)}}selectFeature(t){this.select(t,!1)}setSelecting(){if(\"started\"!==this._state)throw new Error(\"Mode must be started to move to selecting state\");this._state=\"selecting\"}registerBehaviors(t){this.pixelDistance=new A(t),this.clickBoundingBox=new U(t),this.featuresAtMouseEvent=new Dt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new It(t),this.midPoints=new Mt(t,this.selectionPoints),this.rotateFeature=new Ot(t,this.selectionPoints,this.midPoints),this.scaleFeature=new jt(t,this.selectionPoints,this.midPoints),this.dragFeature=new Ft(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new wt(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new Wt(t,this.pixelDistance,this.selectionPoints,this.midPoints)}deselectFeature(){this.deselect()}deselect(){const t=this.selected.filter(t=>this.store.has(t)).map(t=>({id:t,property:i.SELECTED,value:!1}));this.store.updateProperty(t),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()}deleteSelected(){this.store.delete(this.selected),this.selected=[]}onRightClick(t){if(!this.selectionPoints.ids.length)return;let i,o=Infinity;if(this.selectionPoints.ids.forEach(e=>{const s=this.store.getGeometryCopy(e),n=this.pixelDistance.measure(t,s.coordinates);n<this.pointerDistance&&n<o&&(o=n,i=this.store.getPropertiesCopy(e))}),!i)return;const s=i.selectionPointFeatureId,n=i.index,r=this.store.getPropertiesCopy(s),a=this.flags[r.mode],l=this.validations[r.mode];if(!(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable))return;const h=this.store.getGeometryCopy(s);let d;if(\"Polygon\"===h.type){if(d=h.coordinates[0],d.length<=4)return}else if(\"LineString\"===h.type&&(d=h.coordinates,d.length<=3))return;if(d){if(\"Polygon\"===h.type&&0===n||n===d.length-1?(d.shift(),d.pop(),d.push([d[0][0],d[0][1]])):d.splice(n,1),l&&!l({id:s,type:\"Feature\",geometry:h,properties:r},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e.Commit}).valid)return;this.store.delete([...this.midPoints.ids,...this.selectionPoints.ids]),this.store.updateGeometry([{id:s,geometry:h}]),this.selectionPoints.create(d,h.type,s),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(d,s,this.coordinatePrecision)}}select(t,e=!0){if(this.selected[0]===t)return;const{mode:i}=this.store.getPropertiesCopy(t),o=this.flags[i];if(!o||!o.feature)return;const s=this.selected[0];if(s){if(s===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);const{type:n,coordinates:r}=this.store.getGeometryCopy(t);if(\"LineString\"!==n&&\"Polygon\"!==n)return;const a=\"LineString\"===n?r:r[0];a&&o&&o.feature.coordinates&&(this.selectionPoints.create(a,n,t),o.feature.coordinates.midpoints&&this.midPoints.create(a,t,this.coordinatePrecision))}onLeftClick(t){const{clickedFeature:e,clickedMidPoint:i}=this.featuresAtMouseEvent.find(t,this.selected.length>0);if(this.selected.length&&i)this.midPoints.insert(i.id,this.coordinatePrecision);else if(e&&e.id)this.select(e.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(t){\"right\"!==t.button?\"left\"===t.button&&this.onLeftClick(t):this.onRightClick(t)}canScale(t){return this.keyEvents.scale&&this.keyEvents.scale.every(e=>t.heldKeys.includes(e))}canRotate(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(e=>t.heldKeys.includes(e))}preventDefaultKeyEvent(t){const e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()}onKeyDown(t){this.preventDefaultKeyEvent(t)}onKeyUp(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()}cleanUp(){this.selected.length&&this.deselect()}onDragStart(t,e){if(!this.selected.length)return;const 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)))return;this.dragEventCount=0;const s=this.selected[0],n=this.dragCoordinate.getDraggableIndex(t,s);return o&&o.feature&&o.feature.coordinates&&(o.feature.coordinates.draggable||o.feature.coordinates.resizable)&&-1!==n?(this.setCursor(this.cursors.dragStart),o.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(s,n):this.dragCoordinate.startDragging(s,n),void e(!1)):o&&o.feature&&o.feature.draggable&&this.dragFeature.canDrag(t,s)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,s),void e(!1)):void 0}onDrag(t,e){const i=this.selected[0];if(!i)return;const o=this.store.getPropertiesCopy(i),s=this.flags[o.mode],n=!0===(s&&s.feature&&s.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle==0)return;const r=this.validations[o.mode];if(s&&s.feature&&s.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,r);if(s&&s.feature&&s.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,r);if(this.dragCoordinateResizeFeature.isDragging()&&s.feature&&s.feature.coordinates&&s.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,s.feature.coordinates.resizable,r)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,n,r):this.dragFeature.isDragging()?this.dragFeature.drag(t,r):e(!0)}onDragEnd(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)}onMouseMove(t){if(!this.selected.length)return void this.setCursor(\"unset\");if(this.dragFeature.isDragging())return;let e=!1;this.midPoints.ids.forEach(i=>{if(e)return;const o=this.store.getGeometryCopy(i);this.pixelDistance.measure(t,o.coordinates)<this.pointerDistance&&(e=!0)});let i=!1;if(this.selectionPoints.ids.forEach(o=>{const s=this.store.getGeometryCopy(o);this.pixelDistance.measure(t,s.coordinates)<this.pointerDistance&&(e=!1,i=!0)}),e)return void this.setCursor(this.cursors.insertMidpoint);const{clickedFeature:o}=this.featuresAtMouseEvent.find(t,!0);this.setCursor(this.selected.length>0&&(o&&o.id===this.selected[0]||i)?this.cursors.pointerOver:\"unset\")}styleFeature(e){const o=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});if(e.properties.mode===this.mode&&\"Point\"===e.geometry.type){if(e.properties.selectionPoint)return o.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,o.pointColor,e),o.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,o.pointOutlineColor,e),o.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,o.pointWidth,e),o.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,e),o.zIndex=30,o;if(e.properties.midPoint)return o.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,o.pointColor,e),o.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,o.pointOutlineColor,e),o.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,e),o.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,e),o.zIndex=40,o}else if(e.properties[i.SELECTED]){if(\"Polygon\"===e.geometry.type)return o.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,o.polygonFillColor,e),o.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,o.polygonOutlineWidth,e),o.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,o.polygonOutlineColor,e),o.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,o.polygonFillOpacity,e),o.zIndex=10,o;if(\"LineString\"===e.geometry.type)return o.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,o.lineStringColor,e),o.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,o.lineStringWidth,e),o.zIndex=10,o;if(\"Point\"===e.geometry.type)return o.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,o.pointWidth,e),o.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,o.pointColor,e),o.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,o.pointOutlineColor,e),o.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,o.pointOutlineWidth,e),o.zIndex=10,o}return o}}class Nt extends d{constructor(...t){super(...t),this.type=h.Static,this.mode=\"static\"}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0})}}function Vt(t,e,i,o,s){for(;o>i;){if(o-i>600){const n=o-i+1,r=e-i+1,a=Math.log(n),l=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*l*(n-l)/n)*(r-n/2<0?-1:1);Vt(t,e,Math.max(i,Math.floor(e-r*l/n+h)),Math.min(o,Math.floor(e+(n-r)*l/n+h)),s)}const n=t[e];let r=i,a=o;for(Lt(t,i,e),s(t[o],n)>0&&Lt(t,i,o);r<a;){for(Lt(t,r,a),r++,a--;s(t[r],n)<0;)r++;for(;s(t[a],n)>0;)a--}0===s(t[i],n)?Lt(t,i,a):(a++,Lt(t,a,o)),a<=e&&(i=a+1),e<=a&&(o=a-1)}}function Lt(t,e,i){const o=t[e];t[e]=t[i],t[i]=o}function Gt(t,e){Tt(t,0,t.children.length,e,t)}function Tt(t,e,i,o,s){s||(s=qt([])),s.minX=Infinity,s.minY=Infinity,s.maxX=-Infinity,s.maxY=-Infinity;for(let n=e;n<i;n++){const e=t.children[n];Ut(s,t.leaf?o(e):e)}return s}function Ut(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 At(t,e){return t.minX-e.minX}function Kt(t,e){return t.minY-e.minY}function Xt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Rt(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Yt(t,e){const i=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY),s=Math.min(t.maxX,e.maxX),n=Math.min(t.maxY,e.maxY);return Math.max(0,s-i)*Math.max(0,n-o)}function zt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Ht(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 $t(t,e,i,o,s){const n=[e,i];for(;n.length;){if((i=n.pop())-(e=n.pop())<=o)continue;const r=e+Math.ceil((i-e)/o/2)*o;Vt(t,r,e,i,s),n.push(e,r,r,i)}}class Zt{constructor(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()}search(t){let e=this.data;const i=[];if(!Ht(t,e))return i;const o=this.toBBox,s=[];for(;e;){for(let n=0;n<e.children.length;n++){const r=e.children[n],a=e.leaf?o(r):r;Ht(t,a)&&(e.leaf?i.push(r):zt(t,a)?this._all(r,i):s.push(r))}e=s.pop()}return i}collides(t){let e=this.data;if(Ht(t,e)){const i=[];for(;e;){for(let o=0;o<e.children.length;o++){const s=e.children[o],n=e.leaf?this.toBBox(s):s;if(Ht(t,n)){if(e.leaf||zt(t,n))return!0;i.push(s)}}e=i.pop()}}return!1}load(t){if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e}insert(t){this._insert(t,this.data.height-1)}clear(){this.data=qt([])}remove(t){let e=this.data;const i=this.toBBox(t),o=[],s=[];let n,r,a=!1;for(;e||o.length;){if(e||(e=o.pop(),r=o[o.length-1],n=s.pop(),a=!0),e.leaf){const i=e.children.indexOf(t);-1!==i&&(e.children.splice(i,1),o.push(e),this._condense(o))}a||e.leaf||!zt(e,i)?r?(n++,e=r.children[n],a=!1):e=null:(o.push(e),s.push(n),n=0,r=e,e=e.children[0])}}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,o){const s=i-e+1;let n,r=this._maxEntries;if(s<=r)return n=qt(t.slice(e,i+1)),Gt(n,this.toBBox),n;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),n=qt([]),n.leaf=!1,n.height=o;const a=Math.ceil(s/r),l=a*Math.ceil(Math.sqrt(r));$t(t,e,i,l,this.compareMinX);for(let s=e;s<=i;s+=l){const e=Math.min(s+l-1,i);$t(t,s,e,a,this.compareMinY);for(let i=s;i<=e;i+=a){const s=Math.min(i+a-1,e);n.children.push(this._build(t,i,s,o-1))}}return Gt(n,this.toBBox),n}_chooseSubtree(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){let i,o=Infinity,r=Infinity;for(let a=0;a<e.children.length;a++){const l=e.children[a],h=Xt(l),d=(s=t,n=l,(Math.max(n.maxX,s.maxX)-Math.min(n.minX,s.minX))*(Math.max(n.maxY,s.maxY)-Math.min(n.minY,s.minY))-h);d<r?(r=d,o=h<o?h:o,i=l):d===r&&h<o&&(o=h,i=l)}e=i||e.children[0]}var s,n;return e}_insert(t,e,i){const o=i?t:this.toBBox(t),s=[],n=this._chooseSubtree(o,this.data,e,s);for(n.children.push(t),Ut(n,o);e>=0&&s[e].children.length>this._maxEntries;)this._split(s,e),e--;this._adjustParentBBoxes(o,s,e)}_split(t,e){const i=t[e],o=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,o);const n=this._chooseSplitIndex(i,s,o),r=qt(i.children.splice(n,i.children.length-n));r.height=i.height,r.leaf=i.leaf,Gt(i,this.toBBox),Gt(r,this.toBBox),e?t[e-1].children.push(r):this._splitRoot(i,r)}_splitRoot(t,e){this.data=qt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Gt(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let o,s=Infinity,n=Infinity;for(let r=e;r<=i-e;r++){const e=Tt(t,0,r,this.toBBox),a=Tt(t,r,i,this.toBBox),l=Yt(e,a),h=Xt(e)+Xt(a);l<s?(s=l,o=r,n=h<n?h:n):l===s&&h<n&&(n=h,o=r)}return o||i-e}_chooseSplitAxis(t,e,i){const o=t.leaf?this.compareMinX:At,s=t.leaf?this.compareMinY:Kt;this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,s)&&t.children.sort(o)}_allDistMargin(t,e,i,o){t.children.sort(o);const s=this.toBBox,n=Tt(t,0,e,s),r=Tt(t,i-e,i,s);let a=Rt(n)+Rt(r);for(let o=e;o<i-e;o++){const e=t.children[o];Ut(n,t.leaf?s(e):e),a+=Rt(n)}for(let o=i-e-1;o>=e;o--){const e=t.children[o];Ut(r,t.leaf?s(e):e),a+=Rt(r)}return a}_adjustParentBBoxes(t,e,i){for(let o=i;o>=0;o--)Ut(e[o],t)}_condense(t){for(let e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children,e.splice(e.indexOf(t[i]),1)):this.clear():Gt(t[i],this.toBBox)}}class Jt{constructor(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Zt(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)}toBBox(t){const e=[],i=[];let o;if(\"Polygon\"===t.geometry.type)o=t.geometry.coordinates[0];else if(\"LineString\"===t.geometry.type)o=t.geometry.coordinates;else{if(\"Point\"!==t.geometry.type)throw new Error(\"Not a valid feature to turn into a bounding box\");o=[t.geometry.coordinates]}for(let t=0;t<o.length;t++)i.push(o[t][1]),e.push(o[t][0]);const s=Math.min(...i),n=Math.max(...i);return{minX:Math.min(...e),minY:s,maxX:Math.max(...e),maxY:n}}insert(t){if(this.idToNode.get(String(t.id)))throw new Error(\"Feature already exists\");const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}load(t){const e=[],i=new Set;t.forEach(t=>{const o=this.toBBox(t);if(this.setMaps(t,o),i.has(String(t.id)))throw new Error(`Duplicate feature ID found ${t.id}`);i.add(String(t.id)),e.push(o)}),this.tree.load(e)}update(t){this.remove(t.id);const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}remove(t){const e=this.idToNode.get(t);if(!e)throw new Error(`${t} not inserted into the spatial index`);this.tree.remove(e)}clear(){this.tree.clear()}search(t){return this.tree.search(this.toBBox(t)).map(t=>this.nodeToId.get(t))}collides(t){return this.tree.collides(this.toBBox(t))}}const Qt={getId:()=>\"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g,function(t){const e=16*Math.random()|0;return(\"x\"==t?e:3&e|8).toString(16)}),isValidId:t=>\"string\"==typeof t&&36===t.length};class te{constructor(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new Jt,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Qt}clone(t){return JSON.parse(JSON.stringify(t))}getId(){return this.idStrategy.getId()}has(t){return Boolean(this.store[t])}load(t,e){if(0===t.length)return[];let i=this.clone(t);const o=[],s=[];return i=i.filter(t=>{null==t.id&&(t.id=this.idStrategy.getId());const i=t.id;if(e){const o=e(t);if(!o.valid)return s.push({id:i,valid:!1,reason:o.reason}),!1}if(this.tracked){if(t.properties.createdAt){if(!r(t.properties.createdAt))return s.push({id:t.id,valid:!1,reason:\"createdAt is not a valid numeric timestamp\"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!r(t.properties.updatedAt))return s.push({id:t.id,valid:!1,reason:\"updatedAt is not a valid numeric timestamp\"}),!1}else t.properties.updatedAt=+new Date}return this.has(i)?(s.push({id:i,valid:!1,reason:`Feature already exists with this id: ${i}`}),!1):(this.store[i]=t,o.push(i),s.push({id:i,valid:!0}),!0)}),this.spatialIndex.load(i),this._onChange(o,\"create\"),s}search(t,e){const i=this.spatialIndex.search(t).map(t=>this.store[t]);return this.clone(e?i.filter(e):i)}registerOnChange(t){this._onChange=(e,i)=>{t(e,i)}}getGeometryCopy(t){const 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)}getPropertiesCopy(t){const 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)}updateProperty(t){const e=[];t.forEach(({id:t,property:i,value:o})=>{const s=this.store[t];if(!s)throw new Error(`No feature with this (${t}), can not update geometry`);e.push(t),s.properties[i]=o,this.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,\"update\")}updateGeometry(t){const e=[];t.forEach(({id:t,geometry:i})=>{e.push(t);const o=this.store[t];if(!o)throw new Error(`No feature with this (${t}), can not update geometry`);o.geometry=this.clone(i),this.spatialIndex.update(o),this.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,\"update\")}create(e){const i=[];return e.forEach(({geometry:e,properties:o})=>{let s,n=t({},o);this.tracked&&(s=+new Date,o?(n.createdAt=\"number\"==typeof o.createdAt?o.createdAt:s,n.updatedAt=\"number\"==typeof o.updatedAt?o.updatedAt:s):n={createdAt:s,updatedAt:s});const r=this.getId(),a={id:r,type:\"Feature\",geometry:e,properties:n};this.store[r]=a,this.spatialIndex.insert(a),i.push(r)}),this._onChange&&this._onChange([...i],\"create\"),i}delete(t){t.forEach(t=>{if(!this.store[t])throw new Error(\"No feature with this id, can not delete\");delete this.store[t],this.spatialIndex.remove(t)}),this._onChange&&this._onChange([...t],\"delete\")}copyAll(){return this.clone(Object.keys(this.store).map(t=>this.store[t]))}clear(){this.store={},this.spatialIndex.clear()}size(){return Object.keys(this.store).length}}function ee(t){const e=t.coordinates;let i=0;if(e&&e.length>0){i+=Math.abs(se(e[0]));for(let t=1;t<e.length;t++)i-=Math.abs(se(e[t]))}return i}const ie=g*g/2,oe=Math.PI/180;function se(t){const e=t.length;if(e<=2)return 0;let i=0,o=0;for(;o<e;)i+=(t[o+2>=e?(o+2)%e:o+2][0]*oe-t[o][0]*oe)*Math.sin(t[o+1===e?0:o+1][1]*oe),o++;return i*ie}const ne=\"Feature is smaller than the minimum area\",re=(t,e)=>\"Polygon\"!==t.geometry.type?{valid:!1,reason:a}:ee(t.geometry)<e?{valid:!1,reason:ne}:{valid:!0},ae=(t,e)=>\"Polygon\"!==t.geometry.type?{valid:!1,reason:a}:ee(t.geometry)>e?{valid:!1,reason:\"Feature is larger than the maximum area\"}:{valid:!0},le=\"Feature is not a Polygon or LineString\",he=\"Feature intersects itself\",de=t=>\"Polygon\"!==t.geometry.type&&\"LineString\"!==t.geometry.type?{valid:!1,reason:le}:E(t)?{valid:!1,reason:he}:{valid:!0};function ce(t,e,i){const o=z(t,e);let s=z(e,i)-o;return s<0&&(s+=360),180-Math.abs(s-90-90)}class ue extends d{constructor(e){super(e),this.mode=\"angled-rectangle\",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=void 0,this.cursors=void 0,this.mouseMove=!1;const i={start:\"crosshair\",close:\"pointer\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}}close(){if(void 0===this.currentId)return;const t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,\"drawing\"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:\"draw\"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const i=this.store.getGeometryCopy(this.currentId).coordinates[0];let o;if(1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),s=Math.max(1e-6,e);o=[i[0],[t.lng,t.lat],[t.lng,t.lat-s],i[0]]}else if(2===this.currentCoordinate){const e=i[0],s=i[1],n=Ct(e,s,this.coordinatePrecision,this.project,this.unproject),r=x(e[0],e[1]),a=x(n[0],n[1]),l=x(s[0],s[1]),h=x(t.lng,t.lat),d=V(h,r)<V(h,l),c=ce(r,a,h),u=d?90-c:ce(r,a,h)-90,g=V(a,h),y=Math.cos(p(u))*g,m=z(r,l)+(\"right\"===function(t,e,i){const o=(i.x-e.x)*(t.y-e.y)-(i.y-e.y)*(t.x-e.x);return o>1e-10?\"left\":o<-1e-10?\"right\":\"left\"}(r,l,h)?-90:90),f=R(r,y,m),v=R(l,y,m),C=M(f.x,f.y),P=M(v.x,v.y);o=[i[0],i[1],[P.lng,P.lat],[C.lng,C.lat],i[0]]}o&&this.updatePolygonGeometry(this.currentId,o,e.Provisional)}updatePolygonGeometry(t,e,i){const 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))}onClick(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){const[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,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const i=this.store.getGeometryCopy(this.currentId);if(Q([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]],e.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.currentCoordinate=0,\"drawing\"===this.state&&this.setStarted()}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return e.properties.mode===this.mode&&\"Polygon\"===e.geometry.type&&(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10),i}validateFeature(t){return this.validateModeFeature(t,t=>B(t,this.coordinatePrecision))}}function ge(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}class pe extends d{constructor(e){super(e),this.mode=\"sector\",this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=void 0,this.direction=void 0,this.arcPoints=void 0,this.cursors=void 0,this.mouseMove=!1;const i={start:\"crosshair\",close:\"pointer\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.arcPoints=(null==e?void 0:e.arcPoints)||64}close(){if(void 0===this.currentId)return;const 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\"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onMouseMove(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0===this.currentId||0===this.currentCoordinate)return;const i=this.store.getGeometryCopy(this.currentId).coordinates[0];let o;if(1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),s=Math.max(1e-6,e);o=[i[0],[t.lng,t.lat],[t.lng,t.lat-s],i[0]]}else if(2===this.currentCoordinate){const e=i[0],s=i[1],n=[t.lng,t.lat],r=x(e[0],e[1]),a=x(s[0],s[1]),l=x(n[0],n[1]);if(void 0===this.direction){const t=ge(r,a,l);this.direction=t?\"clockwise\":\"anticlockwise\"}const h=V(r,a),d=z(r,a),c=z(r,l),u=this.arcPoints,g=[e],p=H(d),y=H(c);let m;\"anticlockwise\"===this.direction?(m=y-p,m<0&&(m+=360)):(m=p-y,m<0&&(m+=360));const v=(\"anticlockwise\"===this.direction?1:-1)*m/u;g.push(s);for(let t=0;t<=u;t++){const e=R(r,h,p+t*v),{lng:i,lat:o}=M(e.x,e.y),s=[f(i,this.coordinatePrecision),f(o,this.coordinatePrecision)];s[0]!==g[g.length-1][0]&&s[1]!==g[g.length-1][1]&&g.push(s)}g.push(e),o=[...g]}o&&this.updatePolygonGeometry(this.currentId,o,e.Provisional)}updatePolygonGeometry(t,e,i){const 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))}onClick(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){const[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,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){const i=this.store.getGeometryCopy(this.currentId);if(Q([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]],e.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){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()}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return e.properties.mode===this.mode&&\"Polygon\"===e.geometry.type&&(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10),i}validateFeature(t){return this.validateModeFeature(t,t=>B(t,this.coordinatePrecision))}}class ye extends d{constructor(e){super(e),this.mode=\"sensor\",this.currentCoordinate=0,this.currentId=void 0,this.currentInitialArcId=void 0,this.currentStartingPointId=void 0,this.keyEvents=void 0,this.direction=void 0,this.arcPoints=void 0,this.cursors=void 0,this.mouseMove=!1;const i={start:\"crosshair\",close:\"pointer\"};if(this.cursors=e&&e.cursors?t({},i,e.cursors):i,null===(null==e?void 0:e.keyEvents))this.keyEvents={cancel:null,finish:null};else{const i={cancel:\"Escape\",finish:\"Enter\"};this.keyEvents=e&&e.keyEvents?t({},i,e.keyEvents):i}this.arcPoints=(null==e?void 0:e.arcPoints)||64}close(){if(void 0===this.currentStartingPointId)return;const 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\"})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(\"unset\")}onMouseMove(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){const i=this.store.getGeometryCopy(this.currentInitialArcId).coordinates,o=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,s=i[0],n=[t.lng,t.lat],r=x(s[0],s[1]),a=x(n[0],n[1]),l=x(o[0],o[1]),h=V(l,r);if(void 0===this.direction){const t=ge(l,r,a);this.direction=t?\"clockwise\":\"anticlockwise\"}const d=z(l,r),c=z(l,a),u=this.arcPoints,g=[s],p=H(d),y=H(c);let m;\"anticlockwise\"===this.direction?(m=y-p,m<0&&(m+=360)):(m=p-y,m<0&&(m+=360));const v=(\"anticlockwise\"===this.direction?1:-1)*m/u;for(let t=0;t<=u;t++){const e=R(l,h,p+t*v),{lng:i,lat:o}=M(e.x,e.y),s=[f(i,this.coordinatePrecision),f(o,this.coordinatePrecision)];s[0]!==g[g.length-1][0]&&s[1]!==g[g.length-1][1]&&g.push(s)}this.updateLineStringGeometry(this.currentInitialArcId,g,e.Provisional)}else if(3===this.currentCoordinate){const i=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(i.length<2)return;if(!this.direction)return;const o=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,s=i[0],n=i[i.length-1],r=x(t.lng,t.lat),a=x(s[0],s[1]),l=x(n[0],n[1]),h=x(o[0],o[1]),d=V(h,a),c=V(h,r)<d?a:r,u=z(h,r),g=z(h,a),p=z(h,l),y=H(g),m=H(p),v=H(u);if(this.notInSector({normalizedCursor:v,normalizedStart:y,normalizedEnd:m,direction:this.direction}))return;const C=this.getDeltaBearing(this.direction,y,m),P=this.arcPoints,I=(\"anticlockwise\"===this.direction?1:-1)*C/P,S=V(h,c),E=[];for(let t=0;t<=P;t++){const e=R(h,S,y+t*I),{lng:o,lat:s}=M(e.x,e.y),n=[f(o,this.coordinatePrecision),f(s,this.coordinatePrecision)];n[0]!==i[i.length-1][0]&&n[1]!==i[i.length-1][1]&&E.unshift(n)}i.push(...E),i.push(i[0]),this.currentId?this.updatePolygonGeometry(this.currentId,i,e.Provisional):[this.currentId]=this.store.create([{geometry:{type:\"Polygon\",coordinates:[i]},properties:{mode:this.mode}}])}}updateLineStringGeometry(t,e,i){const 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))}updatePolygonGeometry(t,e,i){const 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))}onClick(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){const[e]=this.store.create([{geometry:{type:\"Point\",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.currentStartingPointId=e,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){const[e]=this.store.create([{geometry:{type:\"LineString\",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:{mode:this.mode}}]);this.currentInitialArcId=e,this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()}onKeyUp(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){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()}styleFeature(e){const i=t({},{polygonFillColor:\"#3f97e0\",polygonOutlineColor:\"#3f97e0\",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:\"#3f97e0\",pointOutlineColor:\"#ffffff\",pointOutlineWidth:0,pointWidth:6,lineStringColor:\"#3f97e0\",lineStringWidth:4,zIndex:0});return e.properties.mode===this.mode&&(\"Polygon\"===e.geometry.type?(i.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,i.polygonFillColor,e),i.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,i.polygonFillOpacity,e),i.zIndex=10):\"LineString\"===e.geometry.type?(i.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,i.polygonOutlineColor,e),i.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,i.polygonOutlineWidth,e),i.zIndex=10):\"Point\"===e.geometry.type&&(i.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,i.pointColor,e),i.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,i.pointWidth,e),i.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,i.pointOutlineColor,e),i.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,i.pointOutlineWidth,e),i.zIndex=20)),i}validateFeature(t){return this.validateModeFeature(t,t=>B(t,this.coordinatePrecision))}getDeltaBearing(t,e,i){let o;return\"anticlockwise\"===t?(o=i-e,o<0&&(o+=360)):(o=e-i,o<0&&(o+=360)),o}notInSector({normalizedCursor:t,normalizedStart:e,normalizedEnd:i,direction:o}){return\"clockwise\"===o?e<=i?t>=e&&t<=i:t>=e||t<=i:e>=i?t<=e&&t>=i:t<=e||t>=i}}class me{constructor({name:t,callback:e,unregister:i,register:o}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=t,this.register=()=>{this.registered||(this.registered=!0,o(e))},this.unregister=()=>{this.register&&(this.registered=!1,i(e))},this.callback=e}}var fe={__proto__:null,GeoJSONStore:te,TerraDrawBaseDrawMode:d,TerraDrawBaseAdapter:class{constructor(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}getButton(t){return-1===t.button?\"neither\":0===t.button?\"left\":1===t.button?\"middle\":2===t.button?\"right\":\"neither\"}getMapElementXYPosition(t){const e=this.getMapEventElement(),{left:i,top:o}=e.getBoundingClientRect();return{containerX:t.clientX-i,containerY:t.clientY-o}}getDrawEventFromEvent(t){const e=this.getLngLatFromEvent(t);if(!e)return null;const{lng:i,lat:o}=e,{containerX:s,containerY:n}=this.getMapElementXYPosition(t),r=this.getButton(t),a=Array.from(this._heldKeys);return{lng:f(i,this._coordinatePrecision),lat:f(o,this._coordinatePrecision),containerX:s,containerY:n,button:r,heldKeys:a}}register(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(t=>{t.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new me({name:\"pointerdown\",callback:t=>{if(!this._currentModeCallbacks)return;if(!t.isPrimary)return;const e=this.getDrawEventFromEvent(t);e&&(this._dragState=\"pre-dragging\",this._lastDrawEvent=e)},register:t=>{this.getMapEventElement().addEventListener(\"pointerdown\",t)},unregister:t=>{this.getMapEventElement().removeEventListener(\"pointerdown\",t)}}),new me({name:\"pointermove\",callback:t=>{if(!this._currentModeCallbacks)return;if(!t.isPrimary)return;t.preventDefault();const e=this.getDrawEventFromEvent(t);if(e)if(\"not-dragging\"===this._dragState)this._currentModeCallbacks.onMouseMove(e),this._lastDrawEvent=e;else if(\"pre-dragging\"===this._dragState){if(!this._lastDrawEvent)return;const t={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},i={x:e.containerX,y:e.containerY},o=this._currentModeCallbacks.getState(),s=V(t,i);let n=!1;if(n=\"drawing\"===o?s<this._minPixelDragDistanceDrawing:\"selecting\"===o?s<this._minPixelDragDistanceSelecting:s<this._minPixelDragDistance,n)return;this._dragState=\"dragging\",this._currentModeCallbacks.onDragStart(e,t=>{this.setDraggability.bind(this)(t)})}else\"dragging\"===this._dragState&&this._currentModeCallbacks.onDrag(e,t=>{this.setDraggability.bind(this)(t)})},register:t=>{this.getMapEventElement().addEventListener(\"pointermove\",t)},unregister:t=>{this.getMapEventElement().removeEventListener(\"pointermove\",t)}}),new me({name:\"contextmenu\",callback:t=>{this._currentModeCallbacks&&t.preventDefault()},register:t=>{this.getMapEventElement().addEventListener(\"contextmenu\",t)},unregister:t=>{this.getMapEventElement().removeEventListener(\"contextmenu\",t)}}),new me({name:\"pointerup\",callback:t=>{if(!this._currentModeCallbacks)return;if(t.target!==this.getMapEventElement())return;if(!t.isPrimary)return;const e=this.getDrawEventFromEvent(t);e&&(\"dragging\"===this._dragState?this._currentModeCallbacks.onDragEnd(e,t=>{this.setDraggability.bind(this)(t)}):\"not-dragging\"!==this._dragState&&\"pre-dragging\"!==this._dragState||this._currentModeCallbacks.onClick(e),this._dragState=\"not-dragging\",this.setDraggability(!0))},register:t=>{this.getMapEventElement().addEventListener(\"pointerup\",t)},unregister:t=>{this.getMapEventElement().removeEventListener(\"pointerup\",t)}}),new me({name:\"keyup\",callback:t=>{this._currentModeCallbacks&&(this._heldKeys.delete(t.key),this._currentModeCallbacks.onKeyUp({key:t.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>t.preventDefault()}))},register:t=>{this.getMapEventElement().addEventListener(\"keyup\",t)},unregister:t=>{this.getMapEventElement().removeEventListener(\"keyup\",t)}}),new me({name:\"keydown\",callback:t=>{this._currentModeCallbacks&&(this._heldKeys.add(t.key),this._currentModeCallbacks.onKeyDown({key:t.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>t.preventDefault()}))},register:t=>{this.getMapEventElement().addEventListener(\"keydown\",t)},unregister:t=>{this.getMapEventElement().removeEventListener(\"keydown\",t)}})]}unregister(){this._listeners.forEach(t=>{t.unregister()}),this.clear()}},SELECT_PROPERTIES:i};const ve={ValidationReasonFeatureNotPoint:it,ValidationReasonFeatureInvalidCoordinates:ot,ValidationReasonFeatureNotPolygon:a,ValidationReasonFeatureHasHoles:_,ValidationReasonFeatureLessThanFourCoordinates:k,ValidationReasonFeatureHasInvalidCoordinates:O,ValidationReasonFeatureCoordinatesNotClosed:j,ValidationReasonFeatureNotPolygonOrLineString:le,ValidationReasonFeatureSelfIntersects:he,ValidationReasonFeatureLessThanMinSize:ne,ValidationReasonModeMismatch:l};class Ce{constructor(e){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=e.adapter,this._mode=new Nt;const i=new Set,o=e.modes.reduce((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},{}),s=Object.keys(o);if(0===s.length)throw new Error(\"No modes provided\");s.forEach(t=>{if(o[t].type===h.Select){if(this._instanceSelectMode)throw new Error(\"only one type of select mode can be provided\");this._instanceSelectMode=t}}),this._modes=t({},o,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[]},this._store=new te({tracked:!!e.tracked,idStrategy:e.idStrategy?e.idStrategy:void 0});const n=t=>{const e=[],i=this._store.copyAll().filter(i=>!t.includes(i.id)||(e.push(i),!1));return{changed:e,unchanged:i}},r=(t,e)=>{this._enabled&&this._eventListeners.finish.forEach(i=>{i(t,e)})},a=(t,e)=>{if(!this._enabled)return;this._eventListeners.change.forEach(i=>{i(t,e)});const{changed:i,unchanged:o}=n(t);\"create\"===e?this._adapter.render({created:i,deletedIds:[],unchanged:o,updated:[]},this.getModeStyles()):\"update\"===e?this._adapter.render({created:[],deletedIds:[],unchanged:o,updated:i},this.getModeStyles()):\"delete\"===e?this._adapter.render({created:[],deletedIds:t,unchanged:o,updated:[]},this.getModeStyles()):\"styling\"===e&&this._adapter.render({created:[],deletedIds:[],unchanged:o,updated:[]},this.getModeStyles())},l=t=>{if(!this._enabled)return;this._eventListeners.select.forEach(e=>{e(t)});const{changed:e,unchanged:i}=n([t]);this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())},d=t=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t()});const{changed:e,unchanged:i}=n([t]);e&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:e},this.getModeStyles())};Object.keys(this._modes).forEach(t=>{this._modes[t].register({mode:t,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:a,onSelect:l,onDeselect:d,onFinish:r,coordinatePrecision:this._adapter.getCoordinatePrecision()})})}checkEnabled(){if(!this._enabled)throw new Error(\"Terra Draw is not enabled\")}getModeStyles(){const t={};return Object.keys(this._modes).forEach(e=>{t[e]=t=>this._instanceSelectMode&&t.properties[i.SELECTED]?this._modes[this._instanceSelectMode].styleFeature.bind(this._modes[this._instanceSelectMode])(t):this._modes[e].styleFeature.bind(this._modes[e])(t)}),t}featuresAtLocation({lng:t,lat:e},o){const s=o&&void 0!==o.pointerDistance?o.pointerDistance:30,n=!o||void 0===o.ignoreSelectFeatures||o.ignoreSelectFeatures,r=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),l=a(t,e),h=T({unproject:r,point:l,pointerDistance:s});return this._store.search(h).filter(o=>{if(n&&(o.properties[i.MID_POINT]||o.properties[i.SELECTION_POINT]))return!1;if(\"Point\"===o.geometry.type){const t=o.geometry.coordinates,e=a(t[0],t[1]);return V(l,e)<s}if(\"LineString\"===o.geometry.type){const t=o.geometry.coordinates;for(let e=0;e<t.length-1;e++){const i=t[e],o=t[e+1];if(Et(l,a(i[0],i[1]),a(o[0],o[1]))<s)return!0}return!1}return!!St([t,e],o.geometry.coordinates)||void 0})}getSelectMode(){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]}setModeStyles(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error(\"No mode with this name present\");this._modes[t].styles=e}getSnapshot(){return this._store.copyAll()}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(t){throw new Error(\"Enabled is read only\")}getMode(){return this._mode.mode}setMode(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()}removeFeatures(t){this.checkEnabled(),this._store.delete(t)}selectFeature(t){this.getSelectMode().selectFeature(t)}deselectFeature(t){this.getSelectMode().deselectFeature(t)}getFeatureId(){return this._store.getId()}hasFeature(t){return this._store.has(t)}addFeatures(t){return this.checkEnabled(),0===t.length?[]:this._store.load(t,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)){const e=t.properties.mode,i=this._modes[e];if(!i)return{id:t.id,valid:!1,reason:`${e} mode is not in the list of instantiated modes`};const o=i.validateFeature.bind(i)(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\"}})}start(){this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(t=>{t()})},getState:()=>this._mode.state,onClick:t=>{this._mode.onClick(t)},onMouseMove:t=>{this._mode.onMouseMove(t)},onKeyDown:t=>{this._mode.onKeyDown(t)},onKeyUp:t=>{this._mode.onKeyUp(t)},onDragStart:(t,e)=>{this._mode.onDragStart(t,e)},onDrag:(t,e)=>{this._mode.onDrag(t,e)},onDragEnd:(t,e)=>{this._mode.onDragEnd(t,e)},onClear:()=>{this._mode.cleanUp(),this._store.clear()}})}getFeaturesAtLngLat(t,e){const{lng:i,lat:o}=t;return this.featuresAtLocation({lng:i,lat:o},e)}getFeaturesAtPointerEvent(t,e){const i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)}stop(){this._enabled=!1,this._adapter.unregister()}on(t,e){const i=this._eventListeners[t];i.includes(e)||i.push(e)}off(t,e){const i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)}}const Pe={MockCallbacks:e=>t({getState:jest.fn(),onKeyUp:jest.fn(),onKeyDown:jest.fn(),onClick:jest.fn(),onMouseMove:jest.fn(),onDragStart:jest.fn(),onDrag:jest.fn(),onDragEnd:jest.fn(),onClear:jest.fn(),onReady:jest.fn()},e),MockPointerEvent:()=>({bubbles:!0,cancelable:!0,clientX:0,clientY:0,button:0,buttons:1,pointerId:1,pointerType:\"mouse\",isPrimary:!0})};export{Ce as TerraDraw,ue as TerraDrawAngledRectangleMode,N as TerraDrawCircleMode,fe as TerraDrawExtend,L as TerraDrawFreehandMode,et as TerraDrawLineStringMode,nt as TerraDrawPointMode,pt as TerraDrawPolygonMode,yt as TerraDrawRectangleMode,mt as TerraDrawRenderMode,pe as TerraDrawSectorMode,Bt as TerraDrawSelectMode,ye as TerraDrawSensorMode,Pe as Testing,ae as ValidateMaxAreaSquareMeters,re as ValidateMinAreaSquareMeters,de as ValidateNotSelfIntersecting,ve as ValidationReasons};\n//# sourceMappingURL=terra-draw.modern.js.map\n","import {\n\tTerraDrawChanges,\n\tSetCursor,\n\tTerraDrawStylingFunction,\n\tTerraDrawExtend\n\t// TerraDrawBaseAdapter,\n\t// TerraDrawCallbacks,\n\t// BaseAdapterConfig,\n\t// FeatureId\n} from \"terra-draw\";\nimport { GeoJsonObject } from \"geojson\";\n// import { BaseAdapterConfig, TerraDrawBaseAdapter } from \"./common/base.adapter\";\n// import { FeatureId } from \"../store/store\";\n\nexport class TerraDrawGoogleMapsAdapter extends TerraDrawExtend.TerraDrawBaseAdapter {\n\tconstructor(\n\t\tconfig: {\n\t\t\tlib: typeof google.maps;\n\t\t\tmap: google.maps.Map;\n\t\t} & TerraDrawExtend.BaseAdapterConfig,\n\t) {\n\t\tsuper(config);\n\t\tthis._lib = config.lib;\n\t\tthis._map = config.map;\n\n\t\t// In order for the internals of the adapter to work we require an ID to\n\t\t// allow query selectors to work\n\t\tif (!this._map.getDiv().id) {\n\t\t\tthrow new Error(\"Google Map container div requires and id to be set\");\n\t\t}\n\n\t\tthis._coordinatePrecision =\n\t\t\ttypeof config.coordinatePrecision === \"number\"\n\t\t\t\t? config.coordinatePrecision\n\t\t\t\t: 9;\n\t}\n\n\tprivate _cursor: string | undefined;\n\tprivate _cursorStyleSheet: HTMLStyleElement | undefined;\n\tprivate _lib: typeof google.maps;\n\tprivate _map: google.maps.Map;\n\tprivate _overlay: google.maps.OverlayView | undefined;\n\tprivate _clickEventListener: google.maps.MapsEventListener | undefined;\n\tprivate _mouseMoveEventListener: google.maps.MapsEventListener | undefined;\n\n\tprivate get _layers(): boolean {\n\t\treturn Boolean(this.renderedFeatureIds?.size > 0);\n\t}\n\n\t/**\n\t * Generates an SVG path string for a circle with the given center coordinates and radius.\n\t * Based off this StackOverflow answer: https://stackoverflow.com/a/27905268/1363484\n\t * @param cx The x-coordinate of the circle's center.\n\t * @param cy The y-coordinate of the circle's center.\n\t * @param r The radius of the circle.\n\t * @returns The SVG path string representing the circle.\n\t */\n\tprivate circlePath(cx: number, cy: number, r: number) {\n\t\tconst d = r * 2;\n\t\treturn `M ${cx} ${cy} m -${r}, 0 a ${r},${r} 0 1,0 ${d},0 a ${r},${r} 0 1,0 -${d},0`;\n\t}\n\n\tpublic register(callbacks: TerraDrawExtend.TerraDrawCallbacks) {\n\t\tsuper.register(callbacks);\n\n\t\t// The overlay is responsible for allow us to\n\t\t// get the projection, which in turn allows us to\n\t\t// go through lng/lat to pixel space and vice versa\n\t\tthis._overlay = new this._lib.OverlayView();\n\t\tthis._overlay.draw = function () { };\n\n\t\t// Unforunately it is only ready after the onAdd\n\t\t// method is called, which is why we need to use the 'ready'\n\t\t// listener with the Google Maps adapter\n\t\tthis._overlay.onAdd = () => {\n\t\t\tif (this._currentModeCallbacks?.onReady) {\n\t\t\t\tthis._currentModeCallbacks.onReady();\n\t\t\t}\n\t\t};\n\t\tthis._overlay.setMap(this._map);\n\n\t\t// Clicking on data geometries triggers\n\t\t// swallows the map onclick event,\n\t\t// so we need to forward it to the click callback handler\n\t\tthis._clickEventListener = this._map.data.addListener(\n\t\t\t\"click\",\n\t\t\t(\n\t\t\t\tevent: google.maps.MapMouseEvent & {\n\t\t\t\t\tdomEvent: MouseEvent;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst clickListener = this._listeners.find(\n\t\t\t\t\t({ name }) => name === \"click\",\n\t\t\t\t);\n\t\t\t\tif (clickListener) {\n\t\t\t\t\tclickListener.callback(event);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tthis._mouseMoveEventListener = this._map.data.addListener(\n\t\t\t\"mousemove\",\n\t\t\t(\n\t\t\t\tevent: google.maps.MapMouseEvent & {\n\t\t\t\t\tdomEvent: MouseEvent;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst mouseMoveListener = this._listeners.find(\n\t\t\t\t\t({ name }) => name === \"mousemove\",\n\t\t\t\t);\n\t\t\t\tif (mouseMoveListener) {\n\t\t\t\t\tmouseMoveListener.callback(event);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic unregister(): void {\n\t\tsuper.unregister();\n\t\tthis._clickEventListener?.remove();\n\t\tthis._mouseMoveEventListener?.remove();\n\t\tthis._overlay?.setMap(null);\n\t\tthis._overlay = undefined;\n\t}\n\n\t/**\n\t * Returns the longitude and latitude coordinates from a given PointerEvent on the map.\n\t * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.\n\t * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.\n\t */\n\tgetLngLatFromEvent(event: PointerEvent | MouseEvent) {\n\t\tif (!this._overlay) {\n\t\t\tthrow new Error(\"cannot get overlay\");\n\t\t}\n\n\t\tconst bounds = this._map.getBounds();\n\n\t\tif (!bounds) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst ne = bounds.getNorthEast();\n\t\tconst sw = bounds.getSouthWest();\n\t\tconst latLngBounds = new this._lib.LatLngBounds(sw, ne);\n\n\t\tconst mapCanvas = this._map.getDiv();\n\t\tconst offsetX = event.clientX - mapCanvas.getBoundingClientRect().left;\n\t\tconst offsetY = event.clientY - mapCanvas.getBoundingClientRect().top;\n\t\tconst screenCoord = new this._lib.Point(offsetX, offsetY);\n\n\t\tconst projection = this._overlay.getProjection();\n\t\tif (!projection) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst latLng = projection.fromContainerPixelToLatLng(screenCoord);\n\n\t\tif (latLng && latLngBounds.contains(latLng)) {\n\t\t\treturn { lng: latLng.lng(), lat: latLng.lat() };\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the HTML element of the Google Map element that handles interaction events\n\t * @returns The HTMLElement representing the map container.\n\t */\n\tpublic getMapEventElement() {\n\t\t// TODO: This is a bit hacky, maybe there is a better solution here\n\t\tconst selector = 'div[style*=\"z-index: 3;\"]';\n\t\treturn this._map.getDiv().querySelector(selector) as HTMLDivElement;\n\t}\n\n\t/**\n\t * Converts longitude and latitude coordinates to pixel coordinates in the map container.\n\t * @param lng The longitude coordinate to project.\n\t * @param lat The latitude coordinate to project.\n\t * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.\n\t */\n\tproject(lng: number, lat: number) {\n\t\tif (!this._overlay) {\n\t\t\tthrow new Error(\"cannot get overlay\");\n\t\t}\n\n\t\tconst bounds = this._map.getBounds();\n\n\t\tif (bounds === undefined) {\n\t\t\tthrow new Error(\"cannot get bounds\");\n\t\t}\n\n\t\tconst projection = this._overlay.getProjection();\n\t\tif (projection === undefined) {\n\t\t\tthrow new Error(\"cannot get projection\");\n\t\t}\n\n\t\tconst point = projection.fromLatLngToContainerPixel(\n\t\t\tnew this._lib.LatLng(lat, lng),\n\t\t);\n\n\t\tif (point === null) {\n\t\t\tthrow new Error(\"cannot project coordinates\");\n\t\t}\n\n\t\treturn { x: point.x, y: point.y };\n\t}\n\n\t/**\n\t * Converts pixel coordinates in the map container to longitude and latitude coordinates.\n\t * @param x The x-coordinate in the map container to unproject.\n\t * @param y The y-coordinate in the map container to unproject.\n\t * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.\n\t */\n\tunproject(x: number, y: number) {\n\t\tif (!this._overlay) {\n\t\t\tthrow new Error(\"cannot get overlay\");\n\t\t}\n\n\t\tconst projection = this._overlay.getProjection();\n\t\tif (projection === undefined) {\n\t\t\tthrow new Error(\"cannot get projection\");\n\t\t}\n\n\t\tconst latLng = projection.fromContainerPixelToLatLng(\n\t\t\tnew this._lib.Point(x, y),\n\t\t);\n\n\t\tif (latLng === null) {\n\t\t\tthrow new Error(\"cannot unproject coordinates\");\n\t\t}\n\n\t\treturn { lng: latLng.lng(), lat: latLng.lat() };\n\t}\n\n\t/**\n\t * Sets the cursor style for the map container.\n\t * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.\n\t */\n\tsetCursor(cursor: Parameters<SetCursor>[0]) {\n\t\tif (cursor === this._cursor) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this._cursorStyleSheet) {\n\t\t\tthis._cursorStyleSheet.remove();\n\t\t\tthis._cursorStyleSheet = undefined;\n\t\t}\n\n\t\tif (cursor !== \"unset\") {\n\t\t\t// TODO: We could cache these individually per cursor\n\n\t\t\tconst div = this._map.getDiv();\n\t\t\tconst styleDivSelector = `#${div.id} .gm-style > div`;\n\t\t\tconst styleDiv = document.querySelector(styleDivSelector);\n\n\t\t\tif (styleDiv) {\n\t\t\t\tstyleDiv.classList.add(\"terra-draw-google-maps\");\n\n\t\t\t\tconst style = document.createElement(\"style\");\n\t\t\t\tstyle.innerHTML = `.terra-draw-google-maps { cursor: ${cursor} !important; }`;\n\t\t\t\tdocument.getElementsByTagName(\"head\")[0].appendChild(style);\n\t\t\t\tthis._cursorStyleSheet = style;\n\t\t\t}\n\t\t}\n\n\t\tthis._cursor = cursor;\n\t}\n\n\t/**\n\t * Enables or disables the double-click to zoom functionality on the map.\n\t * @param enabled Set to true to enable double-click to zoom, or false to disable it.\n\t */\n\tsetDoubleClickToZoom(enabled: boolean) {\n\t\tif (enabled) {\n\t\t\tthis._map.setOptions({ disableDoubleClickZoom: false });\n\t\t} else {\n\t\t\tthis._map.setOptions({ disableDoubleClickZoom: true });\n\t\t}\n\t}\n\n\t/**\n\t * Enables or disables the draggable functionality of the map.\n\t * @param enabled Set to true to enable map dragging, or false to disable it.\n\t */\n\tsetDraggability(enabled: boolean) {\n\t\tthis._map.setOptions({ draggable: enabled });\n\t}\n\n\tprivate renderedFeatureIds: Set<TerraDrawExtend.FeatureId> = new Set();\n\n\t/**\n\t * Renders GeoJSON features on the map using the provided styling configuration.\n\t * @param changes An object containing arrays of created, updated, and unchanged features to render.\n\t * @param styling An object mapping draw modes to feature styling functions\n\t */\n\trender(changes: TerraDrawChanges, styling: TerraDrawStylingFunction) {\n\t\tif (this._layers) {\n\t\t\tchanges.deletedIds.forEach((deletedId) => {\n\t\t\t\tconst featureToDelete = this._map.data.getFeatureById(deletedId);\n\t\t\t\tif (featureToDelete) {\n\t\t\t\t\tthis._map.data.remove(featureToDelete);\n\t\t\t\t\tthis.renderedFeatureIds.delete(deletedId);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tchanges.updated.forEach((updatedFeature) => {\n\t\t\t\tif (!updatedFeature || !updatedFeature.id) {\n\t\t\t\t\tthrow new Error(\"Feature is not valid\");\n\t\t\t\t}\n\n\t\t\t\tconst featureToUpdate = this._map.data.getFeatureById(\n\t\t\t\t\tupdatedFeature.id,\n\t\t\t\t);\n\n\t\t\t\tif (!featureToUpdate) {\n\t\t\t\t\tthrow new Error(\"Feature could not be found by Google Maps API\");\n\t\t\t\t}\n\n\t\t\t\t// Remove all keys\n\t\t\t\tfeatureToUpdate.forEachProperty((property, name) => {\n\t\t\t\t\tfeatureToUpdate.setProperty(name, undefined);\n\t\t\t\t});\n\n\t\t\t\t// Update all keys\n\t\t\t\tObject.keys(updatedFeature.properties).forEach((property) => {\n\t\t\t\t\tfeatureToUpdate.setProperty(\n\t\t\t\t\t\tproperty,\n\t\t\t\t\t\tupdatedFeature.properties[property],\n\t\t\t\t\t);\n\t\t\t\t});\n\n\t\t\t\tswitch (updatedFeature.geometry.type) {\n\t\t\t\t\tcase \"Point\":\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tconst coordinates = updatedFeature.geometry.coordinates;\n\n\t\t\t\t\t\t\tfeatureToUpdate.setGeometry(\n\t\t\t\t\t\t\t\tnew this._lib.Data.Point(\n\t\t\t\t\t\t\t\t\tnew this._lib.LatLng(coordinates[1], coordinates[0]),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"LineString\":\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tconst coordinates = updatedFeature.geometry.coordinates;\n\n\t\t\t\t\t\t\tconst path: google.maps.LatLng[] = [];\n\t\t\t\t\t\t\tfor (let i = 0; i < coordinates.length; i++) {\n\t\t\t\t\t\t\t\tconst coordinate = coordinates[i];\n\t\t\t\t\t\t\t\tconst latLng = new this._lib.LatLng(\n\t\t\t\t\t\t\t\t\tcoordinate[1],\n\t\t\t\t\t\t\t\t\tcoordinate[0],\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tpath.push(latLng);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfeatureToUpdate.setGeometry(new this._lib.Data.LineString(path));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Polygon\":\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tconst coordinates = updatedFeature.geometry.coordinates;\n\n\t\t\t\t\t\t\tconst paths: google.maps.LatLng[][] = [];\n\t\t\t\t\t\t\tfor (let i = 0; i < coordinates.length; i++) {\n\t\t\t\t\t\t\t\tconst path: google.maps.LatLng[] = [];\n\t\t\t\t\t\t\t\tfor (let j = 0; j < coordinates[i].length; j++) {\n\t\t\t\t\t\t\t\t\tconst latLng = new this._lib.LatLng(\n\t\t\t\t\t\t\t\t\t\tcoordinates[i][j][1],\n\t\t\t\t\t\t\t\t\t\tcoordinates[i][j][0],\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tpath.push(latLng);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpaths.push(path);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfeatureToUpdate.setGeometry(new this._lib.Data.Polygon(paths));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// Create new features\n\t\t\tchanges.created.forEach((createdFeature) => {\n\t\t\t\tthis.renderedFeatureIds.add(createdFeature.id as string);\n\t\t\t\tthis._map.data.addGeoJson(createdFeature);\n\t\t\t});\n\t\t}\n\n\t\tchanges.created.forEach((feature) => {\n\t\t\tthis.renderedFeatureIds.add(feature.id as string);\n\t\t});\n\n\t\tconst featureCollection = {\n\t\t\ttype: \"FeatureCollection\",\n\t\t\tfeatures: [...changes.created],\n\t\t} as GeoJsonObject;\n\n\t\tthis._map.data.addGeoJson(featureCollection);\n\n\t\tthis._map.data.setStyle((feature) => {\n\t\t\tconst mode = feature.getProperty(\"mode\");\n\t\t\tconst gmGeometry = feature.getGeometry();\n\t\t\tif (!gmGeometry) {\n\t\t\t\tthrow new Error(\"Google Maps geometry not found\");\n\t\t\t}\n\t\t\tconst type = gmGeometry.getType();\n\t\t\tconst properties: Record<string, any> = {};\n\n\t\t\tfeature.forEachProperty((value, property) => {\n\t\t\t\tproperties[property] = value;\n\t\t\t});\n\n\t\t\tconst calculatedStyles = styling[mode]({\n\t\t\t\ttype: \"Feature\",\n\t\t\t\tgeometry: {\n\t\t\t\t\ttype: type as \"Point\" | \"LineString\" | \"Polygon\",\n\t\t\t\t\tcoordinates: [],\n\t\t\t\t},\n\t\t\t\tproperties,\n\t\t\t});\n\n\t\t\tswitch (type) {\n\t\t\t\tcase \"Point\":\n\t\t\t\t\tconst path = this.circlePath(0, 0, calculatedStyles.pointWidth);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclickable: false,\n\t\t\t\t\t\ticon: {\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tfillColor: calculatedStyles.pointColor,\n\t\t\t\t\t\t\tfillOpacity: 1,\n\t\t\t\t\t\t\tstrokeColor: calculatedStyles.pointOutlineColor,\n\t\t\t\t\t\t\tstrokeWeight: calculatedStyles.pointOutlineWidth,\n\t\t\t\t\t\t\trotation: 0,\n\t\t\t\t\t\t\tscale: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\n\t\t\t\tcase \"LineString\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstrokeColor: calculatedStyles.lineStringColor,\n\t\t\t\t\t\tstrokeWeight: calculatedStyles.lineStringWidth,\n\t\t\t\t\t};\n\t\t\t\tcase \"Polygon\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstrokeColor: calculatedStyles.polygonOutlineColor,\n\t\t\t\t\t\tstrokeWeight: calculatedStyles.polygonOutlineWidth,\n\t\t\t\t\t\tfillOpacity: calculatedStyles.polygonFillOpacity,\n\t\t\t\t\t\tfillColor: calculatedStyles.polygonFillColor,\n\t\t\t\t\t};\n\t\t\t}\n\n\t\t\tthrow Error(\"Unknown feature type\");\n\t\t});\n\t}\n\n\tprivate clearLayers() {\n\t\tif (this._layers) {\n\t\t\tthis._map.data.forEach((feature) => {\n\t\t\t\tconst id = feature.getId() as string;\n\t\t\t\tconst hasFeature = this.renderedFeatureIds.has(id);\n\t\t\t\tif (hasFeature) {\n\t\t\t\t\tthis._map.data.remove(feature);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.renderedFeatureIds = new Set();\n\t\t}\n\t}\n\n\t/**\n\t * Clears the map and store of all rendered data layers\n\t * @returns void\n\t * */\n\tpublic clear() {\n\t\tif (this._currentModeCallbacks) {\n\t\t\t// Clean up state first\n\t\t\tthis._currentModeCallbacks.onClear();\n\n\t\t\t// Then clean up rendering\n\t\t\tthis.clearLayers();\n\t\t}\n\t}\n\n\tpublic getCoordinatePrecision(): number {\n\t\t// TODO: It seems this shouldn't be necessary as extends BaseAdapter which as this method\n\t\treturn super.getCoordinatePrecision();\n\t}\n}\n"],"names":["t","Object","assign","bind","e","arguments","length","i","o","prototype","hasOwnProperty","call","apply","this","Commit","Provisional","Finish","SELECTED","MID_POINT","SELECTION_POINT","TerraDrawGoogleMapsAdapter","_TerraDrawExtend$Terr","config","_this","_cursor","_cursorStyleSheet","_lib","_map","_overlay","_clickEventListener","_mouseMoveEventListener","renderedFeatureIds","Set","lib","map","getDiv","id","Error","_coordinatePrecision","coordinatePrecision","_proto","circlePath","cx","cy","r","d","register","callbacks","_this2","OverlayView","draw","onAdd","_this2$_currentModeCa","_currentModeCallbacks","onReady","setMap","data","addListener","event","clickListener","_listeners","find","_ref","name","callback","mouseMoveListener","_ref2","unregister","_this$_clickEventList","_this$_mouseMoveEvent","_this$_overlay","remove","undefined","getLngLatFromEvent","bounds","getBounds","ne","getNorthEast","sw","getSouthWest","latLngBounds","LatLngBounds","mapCanvas","offsetX","clientX","getBoundingClientRect","left","offsetY","clientY","top","screenCoord","Point","projection","getProjection","latLng","fromContainerPixelToLatLng","contains","lng","lat","getMapEventElement","querySelector","project","point","fromLatLngToContainerPixel","LatLng","x","y","unproject","setCursor","cursor","div","styleDiv","document","classList","add","style","createElement","innerHTML","getElementsByTagName","appendChild","setDoubleClickToZoom","enabled","setOptions","disableDoubleClickZoom","setDraggability","draggable","render","changes","styling","_this3","_layers","deletedIds","forEach","deletedId","featureToDelete","getFeatureById","updated","updatedFeature","featureToUpdate","forEachProperty","property","setProperty","keys","properties","geometry","type","coordinates","setGeometry","Data","path","coordinate","push","LineString","paths","j","Polygon","created","createdFeature","addGeoJson","feature","featureCollection","features","concat","setStyle","mode","getProperty","gmGeometry","getGeometry","getType","value","calculatedStyles","clickable","icon","pointWidth","fillColor","pointColor","fillOpacity","strokeColor","pointOutlineColor","strokeWeight","pointOutlineWidth","rotation","scale","lineStringColor","lineStringWidth","polygonOutlineColor","polygonOutlineWidth","polygonFillOpacity","polygonFillColor","clearLayers","_this4","getId","has","clear","onClear","getCoordinatePrecision","_createClass","key","get","_this$renderedFeature","Boolean","size","TerraDrawExtend","TerraDrawBaseAdapter"],"mappings":"+qBA2FY,SAAAA,IAAA,OAAAA,EAAAC,OAAAC,OAAAD,OAAAC,OAAAC,OAAA,SAAAH,GAAA,IAAA,IAAAI,EAAA,EAAAA,EAAAC,UAAAC,OAAAF,IAAA,CAAA,IAAAG,EAAAF,UAAAD,GAAA,IAAA,IAAAI,KAAAD,EAAAN,OAAAQ,UAAAC,eAAAC,KAAAJ,EAAAC,KAAAR,EAAAQ,GAAAD,EAAAC,GAAA,CAAA,OAAAR,CAAA,EAAAA,EAAAY,MAAAC,KAAAR,UAAA,CAAA,IAAAD,oLAAZ,SAAYJ,GACXA,EAAAc,OAAA,SACAd,EAAAe,YAAA,cACAf,EAAAgB,OACA,QAAA,CAJD,CAAYZ,IAAAA,EAIX,CAAA,m+nBAwEgC,CAChCa,SAAU,WACVC,UAAW,WACXC,gBAAiB,mBC5JLC,eAA2B,SAAAC,WACvC,SAAAD,EACCE,GAGqCC,IAAAA,EAQrC,IANAA,EAAAF,EAAAV,KAAMW,KAAAA,IAAOT,MAgBNW,aAAO,EAAAD,EACPE,uBAAiB,EAAAF,EACjBG,UAAI,EAAAH,EACJI,UAAI,EAAAJ,EACJK,cAAQ,EAAAL,EACRM,yBAAmB,EAAAN,EACnBO,6BAAuB,EAAAP,EAqPvBQ,mBAAqD,IAAIC,IA1QhET,EAAKG,KAAOJ,EAAOW,IACnBV,EAAKI,KAAOL,EAAOY,KAIdX,EAAKI,KAAKQ,SAASC,GACvB,MAAM,IAAIC,MAAM,sDAMX,OAHNd,EAAKe,qBACkC,iBAA/BhB,EAAOiB,oBACXjB,EAAOiB,oBACP,EAAEhB,CACP,GArBuCF,KAAAD,yEAqBtC,IAAAoB,EAAApB,EAAAX,UAYAW,OAZAoB,EAsBOC,WAAA,SAAWC,EAAYC,EAAYC,GAC1C,IAAMC,EAAQ,EAAJD,EACV,MAAYF,KAAAA,EAAMC,IAAAA,EAASC,OAAAA,EAAUA,SAAAA,EAAKA,IAAAA,EAAWC,UAAAA,EAASD,QAAAA,EAAKA,IAAAA,EAAYC,WAAAA,EAChF,IAAA,EAACL,EAEMM,SAAA,SAASC,GAA6C,IAAAC,EAAAnC,KAC5DQ,EAAAZ,UAAMqC,SAAQnC,KAACoC,KAAAA,GAKflC,KAAKe,SAAW,IAAQf,KAACa,KAAKuB,YAC9BpC,KAAKe,SAASsB,KAAO,WAAA,EAKrBrC,KAAKe,SAASuB,MAAQ,WAAK,IAAAC,EACtBA,OAAJA,EAAIJ,EAAKK,wBAALD,EAA4BE,SAC/BN,EAAKK,sBAAsBC,SAE7B,EACAzC,KAAKe,SAAS2B,OAAO1C,KAAKc,MAK1Bd,KAAKgB,oBAAsBhB,KAAKc,KAAK6B,KAAKC,YACzC,QACA,SACCC,GAIA,IAAMC,EAAgBX,EAAKY,WAAWC,KACrC,SAAAC,GAAO,MAAgB,UAAhBA,EAAJC,IAA2B,GAE3BJ,GACHA,EAAcK,SAASN,EAEzB,GAGD7C,KAAKiB,wBAA0BjB,KAAKc,KAAK6B,KAAKC,YAC7C,YACA,SACCC,GAIA,IAAMO,EAAoBjB,EAAKY,WAAWC,KACzC,SAAAK,GAAc,MAAS,cAAhBA,EAAJH,IAA+B,GAE/BE,GACHA,EAAkBD,SAASN,EAE7B,EAEF,EAAClB,EAEM2B,WAAA,WAAU,IAAAC,EAAAC,EAAAC,EAChBjD,EAAAZ,UAAM0D,WAAUxD,KAChBE,MAAAuD,OAAAA,EAAAvD,KAAKgB,sBAALuC,EAA0BG,SAC1BF,OAAAA,EAAAxD,KAAKiB,0BAALuC,EAA8BE,SAC9BD,OAAAA,EAAAzD,KAAKe,WAAL0C,EAAef,OAAO,MACtB1C,KAAKe,cAAW4C,CACjB,EAAChC,EAODiC,mBAAA,SAAmBf,GAClB,IAAK7C,KAAKe,SACT,MAAM,IAAIS,MAAM,sBAGjB,IAAMqC,EAAS7D,KAAKc,KAAKgD,YAEzB,IAAKD,EACJ,OACD,KAEA,IAAME,EAAKF,EAAOG,eACZC,EAAKJ,EAAOK,eACZC,EAAe,IAAInE,KAAKa,KAAKuD,aAAaH,EAAIF,GAE9CM,EAAYrE,KAAKc,KAAKQ,SACtBgD,EAAUzB,EAAM0B,QAAUF,EAAUG,wBAAwBC,KAC5DC,EAAU7B,EAAM8B,QAAUN,EAAUG,wBAAwBI,IAC5DC,EAAc,IAAQ7E,KAACa,KAAKiE,MAAMR,EAASI,GAE3CK,EAAa/E,KAAKe,SAASiE,gBACjC,IAAKD,EACJ,OACD,KAEA,IAAME,EAASF,EAAWG,2BAA2BL,GAErD,OAAII,GAAUd,EAAagB,SAASF,GAC5B,CAAEG,IAAKH,EAAOG,MAAOC,IAAKJ,EAAOI,OAEjC,IAET,EAAC1D,EAMM2D,mBAAA,WAGN,OAAWtF,KAACc,KAAKQ,SAASiE,cADT,4BAElB,EAAC5D,EAQD6D,QAAA,SAAQJ,EAAaC,GACpB,IAAKrF,KAAKe,SACT,MAAM,IAAIS,MAAM,sBAKjB,QAAemC,IAFA3D,KAAKc,KAAKgD,YAGxB,MAAU,IAAAtC,MAAM,qBAGjB,IAAMuD,EAAa/E,KAAKe,SAASiE,gBACjC,QAAmBrB,IAAfoB,EACH,MAAU,IAAAvD,MAAM,yBAGjB,IAAMiE,EAAQV,EAAWW,2BACxB,IAAQ1F,KAACa,KAAK8E,OAAON,EAAKD,IAG3B,GAAc,OAAVK,EACH,MAAU,IAAAjE,MAAM,8BAGjB,MAAO,CAAEoE,EAAGH,EAAMG,EAAGC,EAAGJ,EAAMI,EAC/B,EAAClE,EAQDmE,UAAA,SAAUF,EAAWC,GACpB,IAAK7F,KAAKe,SACT,MAAU,IAAAS,MAAM,sBAGjB,IAAMuD,EAAa/E,KAAKe,SAASiE,gBACjC,QAAmBrB,IAAfoB,EACH,MAAM,IAAIvD,MAAM,yBAGjB,IAAMyD,EAASF,EAAWG,2BACzB,IAAIlF,KAAKa,KAAKiE,MAAMc,EAAGC,IAGxB,GAAe,OAAXZ,EACH,MAAU,IAAAzD,MAAM,gCAGjB,MAAO,CAAE4D,IAAKH,EAAOG,MAAOC,IAAKJ,EAAOI,MACzC,EAAC1D,EAMDoE,UAAA,SAAUC,GACT,GAAIA,IAAWhG,KAAKW,QAApB,CASA,GALIX,KAAKY,oBACRZ,KAAKY,kBAAkB8C,SACvB1D,KAAKY,uBAAoB+C,GAGX,UAAXqC,EAAoB,CAGvB,IAAMC,EAAMjG,KAAKc,KAAKQ,SAEhB4E,EAAWC,SAASZ,cADJ,IAAOU,EAAI1E,GAAE,oBAGnC,GAAI2E,EAAU,CACbA,EAASE,UAAUC,IAAI,0BAEvB,IAAMC,EAAQH,SAASI,cAAc,SACrCD,EAAME,UAAS,qCAAwCR,EAAM,iBAC7DG,SAASM,qBAAqB,QAAQ,GAAGC,YAAYJ,GACrDtG,KAAKY,kBAAoB0F,CAC1B,CACD,CAEAtG,KAAKW,QAAUqF,CAxBf,CAyBD,EAACrE,EAMDgF,qBAAA,SAAqBC,GAEnB5G,KAAKc,KAAK+F,WADPD,EACkB,CAAEE,wBAAwB,GAE1B,CAAEA,wBAAwB,GAEjD,EAACnF,EAMDoF,gBAAA,SAAgBH,GACf5G,KAAKc,KAAK+F,WAAW,CAAEG,UAAWJ,GACnC,EAACjF,EASDsF,OAAA,SAAOC,EAA2BC,GAAiCC,IAAAA,EAClEpH,KAAIA,KAAKqH,UACRH,EAAQI,WAAWC,QAAQ,SAACC,GAC3B,IAAMC,EAAkBL,EAAKtG,KAAK6B,KAAK+E,eAAeF,GAClDC,IACHL,EAAKtG,KAAK6B,KAAKe,OAAO+D,GACtBL,EAAKlG,mBAAkB,OAAQsG,GAEjC,GAEAN,EAAQS,QAAQJ,QAAQ,SAACK,GACxB,IAAKA,IAAmBA,EAAerG,GACtC,MAAU,IAAAC,MAAM,wBAGjB,IAAMqG,EAAkBT,EAAKtG,KAAK6B,KAAK+E,eACtCE,EAAerG,IAGhB,IAAKsG,EACJ,MAAM,IAAIrG,MAAM,iDAgBjB,OAZAqG,EAAgBC,gBAAgB,SAACC,EAAU7E,GAC1C2E,EAAgBG,YAAY9E,OAAMS,EACnC,GAGAvE,OAAO6I,KAAKL,EAAeM,YAAYX,QAAQ,SAACQ,GAC/CF,EAAgBG,YACfD,EACAH,EAAeM,WAAWH,GAE5B,GAEQH,EAAeO,SAASC,MAC/B,IAAK,QAEH,IAAMC,EAAcT,EAAeO,SAASE,YAE5CR,EAAgBS,YACf,IAAIlB,EAAKvG,KAAK0H,KAAKzD,MAClB,IAAIsC,EAAKvG,KAAK8E,OAAO0C,EAAY,GAAIA,EAAY,MAIpD,MACD,IAAK,aAKH,IAHA,IAAMA,EAAcT,EAAeO,SAASE,YAEtCG,EAA6B,GAC1B9I,EAAI,EAAGA,EAAI2I,EAAY5I,OAAQC,IAAK,CAC5C,IAAM+I,EAAaJ,EAAY3I,GACzBuF,EAAS,IAAImC,EAAKvG,KAAK8E,OAC5B8C,EAAW,GACXA,EAAW,IAEZD,EAAKE,KAAKzD,EACX,CAEA4C,EAAgBS,YAAY,IAAIlB,EAAKvG,KAAK0H,KAAKI,WAAWH,IAE3D,MACD,IAAK,UAKH,IAHA,IAAMH,EAAcT,EAAeO,SAASE,YAEtCO,EAAgC,GAC7BlJ,EAAI,EAAGA,EAAI2I,EAAY5I,OAAQC,IAAK,CAE5C,IADA,IAAM8I,EAA6B,GAC1BK,EAAI,EAAGA,EAAIR,EAAY3I,GAAGD,OAAQoJ,IAAK,CAC/C,IAAM5D,EAAS,IAAImC,EAAKvG,KAAK8E,OAC5B0C,EAAY3I,GAAGmJ,GAAG,GAClBR,EAAY3I,GAAGmJ,GAAG,IAEnBL,EAAKE,KAAKzD,EACX,CACA2D,EAAMF,KAAKF,EACZ,CAEAX,EAAgBS,YAAY,IAAIlB,EAAKvG,KAAK0H,KAAKO,QAAQF,IAK3D,GAGA1B,EAAQ6B,QAAQxB,QAAQ,SAACyB,GACxB5B,EAAKlG,mBAAmBmF,IAAI2C,EAAezH,IAC3C6F,EAAKtG,KAAK6B,KAAKsG,WAAWD,EAC3B,IAGD9B,EAAQ6B,QAAQxB,QAAQ,SAAC2B,GACxB9B,EAAKlG,mBAAmBmF,IAAI6C,EAAQ3H,GACrC,GAEA,IAAM4H,EAAoB,CACzBf,KAAM,oBACNgB,SAAQC,GAAAA,OAAMnC,EAAQ6B,UAGvB/I,KAAKc,KAAK6B,KAAKsG,WAAWE,GAE1BnJ,KAAKc,KAAK6B,KAAK2G,SAAS,SAACJ,GACxB,IAAMK,EAAOL,EAAQM,YAAY,QAC3BC,EAAaP,EAAQQ,cAC3B,IAAKD,EACJ,MAAU,IAAAjI,MAAM,kCAEjB,IAAM4G,EAAOqB,EAAWE,UAClBzB,EAAkC,CAAE,EAE1CgB,EAAQpB,gBAAgB,SAAC8B,EAAO7B,GAC/BG,EAAWH,GAAY6B,CACxB,GAEA,IAAMC,EAAmB1C,EAAQoC,GAAM,CACtCnB,KAAM,UACND,SAAU,CACTC,KAAMA,EACNC,YAAa,IAEdH,WAAAA,IAGD,OAAQE,GACP,IAAK,QAGJ,MAAO,CACN0B,WAAW,EACXC,KAAM,CACLvB,KALWpB,EAAKxF,WAAW,EAAG,EAAGiI,EAAiBG,YAMlDC,UAAWJ,EAAiBK,WAC5BC,YAAa,EACbC,YAAaP,EAAiBQ,kBAC9BC,aAAcT,EAAiBU,kBAC/BC,SAAU,EACVC,MAAO,IAIV,IAAK,aACJ,MAAO,CACNL,YAAaP,EAAiBa,gBAC9BJ,aAAcT,EAAiBc,iBAEjC,IAAK,UACJ,MAAO,CACNP,YAAaP,EAAiBe,oBAC9BN,aAAcT,EAAiBgB,oBAC/BV,YAAaN,EAAiBiB,mBAC9Bb,UAAWJ,EAAiBkB,kBAI/B,MAAMvJ,MAAM,uBACb,EACD,EAACG,EAEOqJ,YAAA,WAAW,IAAAC,EAAAjL,KACdA,KAAKqH,UACRrH,KAAKc,KAAK6B,KAAK4E,QAAQ,SAAC2B,GACvB,IAAM3H,EAAK2H,EAAQgC,QACAD,EAAK/J,mBAAmBiK,IAAI5J,IAE9C0J,EAAKnK,KAAK6B,KAAKe,OAAOwF,EAExB,GACAlJ,KAAKkB,mBAAqB,IAAIC,IAEhC,EAACQ,EAMMyJ,MAAA,WACFpL,KAAKwC,wBAERxC,KAAKwC,sBAAsB6I,UAG3BrL,KAAKgL,cAEP,EAACrJ,EAEM2J,uBAAA,WAEN,OAAA9K,EAAAZ,UAAa0L,uBAAsBxL,KAAAE,KACpC,EAACuL,EAAAhL,EAAAiL,CAAAA,CAAAA,IAAAC,UAAAA,IA5bD,WAAmBC,IAAAA,EAClB,OAAOC,SAAQD,OAAAA,EAAA1L,KAAKkB,yBAALwK,EAAAA,EAAyBE,MAAO,EAChD,KAACrL,CAAA,CAjCsC,CAAQsL,EAAgBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +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).terraDrawGoogleMapsAdapter={})}(this,function(t){function e(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function n(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,e(i.key),i)}}function r(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},o.apply(this,arguments)}var a,s;function c(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function l(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(a||(a={})),function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(s||(s={}));var h=/*#__PURE__*/function(){var t=e.prototype;function e(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=s.Drawing,this.mode="base",this._state="unregistered",this._styles=t&&t.styles?o({},t.styles):{},this.pointerDistance=t&&t.pointerDistance||40,this.validate=t&&t.validation,this.projection=t&&t.projection||"web-mercator"}return t.registerBehaviors=function(t){},t.setDrawing=function(){if("started"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="drawing"},t.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)},t.setStopped=function(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped",this.setDoubleClickToZoom(!0)},t.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})},t.validateFeature=function(t){return this.performFeatureValidation(t)},t.performFeatureValidation=function(t){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var n;if(c(t))if(null==t.id)n="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)n="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(c(t.geometry))if(c(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)return{valid:!1,reason:"Feature does not have a valid mode property"}}else n="Feature coordinates is not an array";else n="Feature is not Point, LineString or Polygon";else n="Feature has no properties";else n="Feature has no geometry";else n="Feature must match the id strategy (default is UUID4)";else n="Feature is not object";return n?{valid:!1,reason:n}:{valid:!0}}(t,this.store.idStrategy.isValidId);if(this.validate){var n=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:a.Provisional});return{valid:e.valid&&n.valid,reason:n.reason}}return{valid:e.valid,reason:e.reason}},t.validateModeFeature=function(t,e){var n=this.performFeatureValidation(t);return n.valid?t.properties.mode!==this.mode?{valid:!1,reason:"Feature mode property does not match the mode being added to"}:e(t):{valid:!1,reason:n.reason}},t.onFinish=function(t,e){},t.onDeselect=function(t){},t.onSelect=function(t){},t.onKeyDown=function(t){},t.onKeyUp=function(t){},t.onMouseMove=function(t){},t.onClick=function(t){},t.onDragStart=function(t,e){},t.onDrag=function(t,e){},t.onDragEnd=function(t,e){},t.getHexColorStylingValue=function(t,e,n){return this.getStylingValue(t,e,n)},t.getNumericStylingValue=function(t,e,n){return this.getStylingValue(t,e,n)},t.getStylingValue=function(t,e,n){return void 0===t?e:"function"==typeof t?t(n):t},r(e,[{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}}]),e}();function u(t,e){void 0===e&&(e=9);var n=Math.pow(10,e);return Math.round(t*n)/n}function d(t,e,n,r,i){for(;r>n;){if(r-n>600){var o=r-n+1,a=e-n+1,s=Math.log(o),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(o-c)/o)*(a-o/2<0?-1:1);d(t,e,Math.max(n,Math.floor(e-a*c/o+l)),Math.min(r,Math.floor(e+(o-a)*c/o+l)),i)}var h=t[e],u=n,p=r;for(f(t,n,e),i(t[r],h)>0&&f(t,n,r);u<p;){for(f(t,u,p),u++,p--;i(t[u],h)<0;)u++;for(;i(t[p],h)>0;)p--}0===i(t[n],h)?f(t,n,p):f(t,++p,r),p<=e&&(n=p+1),e<=p&&(r=p-1)}}function f(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function p(t,e){g(t,0,t.children.length,e,t)}function g(t,e,n,r,i){i||(i=M([])),i.minX=Infinity,i.minY=Infinity,i.maxX=-Infinity,i.maxY=-Infinity;for(var o=e;o<n;o++){var a=t.children[o];m(i,t.leaf?r(a):a)}return i}function m(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 v(t,e){return t.minX-e.minX}function y(t,e){return t.minY-e.minY}function _(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function x(t){return t.maxX-t.minX+(t.maxY-t.minY)}function w(t,e){var n=Math.max(t.minX,e.minX),r=Math.max(t.minY,e.minY),i=Math.min(t.maxX,e.maxX),o=Math.min(t.maxY,e.maxY);return Math.max(0,i-n)*Math.max(0,o-r)}function E(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function b(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function M(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function D(t,e,n,r,i){for(var o=[e,n];o.length;)if(!((n=o.pop())-(e=o.pop())<=r)){var a=e+Math.ceil((n-e)/r/2)*r;d(t,a,e,n,i),o.push(e,a,a,n)}}var P=/*#__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,n=[];if(!b(t,e))return n;for(var r=this.toBBox,i=[];e;){for(var o=0;o<e.children.length;o++){var a=e.children[o],s=e.leaf?r(a):a;b(t,s)&&(e.leaf?n.push(a):E(t,s)?this._all(a,n):i.push(a))}e=i.pop()}return n},e.collides=function(t){var e=this.data;if(b(t,e))for(var n=[];e;){for(var r=0;r<e.children.length;r++){var i=e.children[r],o=e.leaf?this.toBBox(i):i;if(b(t,o)){if(e.leaf||E(t,o))return!0;n.push(i)}}e=n.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 n=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=M([])},e.remove=function(t){for(var e,n,r=this.data,i=this.toBBox(t),o=[],a=[],s=!1;r||o.length;){if(r||(r=o.pop(),n=o[o.length-1],e=a.pop(),s=!0),r.leaf){var c=r.children.indexOf(t);-1!==c&&(r.children.splice(c,1),o.push(r),this._condense(o))}s||r.leaf||!E(r,i)?n?(e++,r=n.children[e],s=!1):r=null:(o.push(r),a.push(e),e=0,n=r,r=r.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 n=[];t;)t.leaf?e.push.apply(e,t.children):n.push.apply(n,t.children),t=n.pop();return e},e._build=function(t,e,n,r){var i,o=n-e+1,a=this._maxEntries;if(o<=a)return p(i=M(t.slice(e,n+1)),this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,r-1))),(i=M([])).leaf=!1,i.height=r;var s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));D(t,e,n,c,this.compareMinX);for(var l=e;l<=n;l+=c){var h=Math.min(l+c-1,n);D(t,l,h,s,this.compareMinY);for(var u=l;u<=h;u+=s){var d=Math.min(u+s-1,h);i.children.push(this._build(t,u,d,r-1))}}return p(i,this.toBBox),i},e._chooseSubtree=function(t,e,n,r){for(;r.push(e),!e.leaf&&r.length-1!==n;){for(var i=void 0,o=Infinity,a=Infinity,s=0;s<e.children.length;s++){var c=e.children[s],l=_(c),h=(u=t,d=c,(Math.max(d.maxX,u.maxX)-Math.min(d.minX,u.minX))*(Math.max(d.maxY,u.maxY)-Math.min(d.minY,u.minY))-l);h<a?(a=h,o=l<o?l:o,i=c):h===a&&l<o&&(o=l,i=c)}e=i||e.children[0]}var u,d;return e},e._insert=function(t,e,n){var r=n?t:this.toBBox(t),i=[],o=this._chooseSubtree(r,this.data,e,i);for(o.children.push(t),m(o,r);e>=0&&i[e].children.length>this._maxEntries;)this._split(i,e),e--;this._adjustParentBBoxes(r,i,e)},e._split=function(t,e){var n=t[e],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);var o=this._chooseSplitIndex(n,i,r),a=M(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,p(n,this.toBBox),p(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(n,a)},e._splitRoot=function(t,e){this.data=M([t,e]),this.data.height=t.height+1,this.data.leaf=!1,p(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,n){for(var r,i=Infinity,o=Infinity,a=e;a<=n-e;a++){var s=g(t,0,a,this.toBBox),c=g(t,a,n,this.toBBox),l=w(s,c),h=_(s)+_(c);l<i?(i=l,r=a,o=h<o?h:o):l===i&&h<o&&(o=h,r=a)}return r||n-e},e._chooseSplitAxis=function(t,e,n){var r=t.leaf?this.compareMinX:v,i=t.leaf?this.compareMinY:y;this._allDistMargin(t,e,n,r)<this._allDistMargin(t,e,n,i)&&t.children.sort(r)},e._allDistMargin=function(t,e,n,r){t.children.sort(r);for(var i=this.toBBox,o=g(t,0,e,i),a=g(t,n-e,n,i),s=x(o)+x(a),c=e;c<n-e;c++){var l=t.children[c];m(o,t.leaf?i(l):l),s+=x(o)}for(var h=n-e-1;h>=e;h--){var u=t.children[h];m(a,t.leaf?i(u):u),s+=x(a)}return s},e._adjustParentBBoxes=function(t,e,n){for(var r=n;r>=0;r--)m(e[r],t)},e._condense=function(t){for(var e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children).splice(e.indexOf(t[n]),1):this.clear():p(t[n],this.toBBox)},t}(),S=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new P(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,n=[],r=[];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 i=0;i<e.length;i++)r.push(e[i][1]),n.push(e[i][0]);var o=Math.min.apply(Math,r),a=Math.max.apply(Math,r);return{minX:Math.min.apply(Math,n),minY:o,maxX:Math.max.apply(Math,n),maxY:a}},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,n=[],r=new Set;t.forEach(function(t){var i=e.toBBox(t);if(e.setMaps(t,i),r.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);r.add(String(t.id)),n.push(i)}),this.tree.load(n)},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}(),k={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}},C=/*#__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 S,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:k}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 n=this;if(0===t.length)return[];var r=this.clone(t),i=[],o=[];return r=r.filter(function(t){null==t.id&&(t.id=n.idStrategy.getId());var r=t.id;if(e){var a=e(t);if(!a.valid)return o.push({id:r,valid:!1,reason:a.reason}),!1}if(n.tracked){if(t.properties.createdAt){if(!l(t.properties.createdAt))return o.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(!l(t.properties.updatedAt))return o.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return n.has(r)?(o.push({id:r,valid:!1,reason:"Feature already exists with this id: "+r}),!1):(n.store[r]=t,i.push(r),o.push({id:r,valid:!0}),!0)}),this.spatialIndex.load(r),this._onChange(i,"create"),o},e.search=function(t,e){var n=this,r=this.spatialIndex.search(t).map(function(t){return n.store[t]});return this.clone(e?r.filter(e):r)},e.registerOnChange=function(t){this._onChange=function(e,n){t(e,n)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,n=[];t.forEach(function(t){var r=t.id,i=t.property,o=t.value,a=e.store[r];if(!a)throw new Error("No feature with this ("+r+"), can not update geometry");n.push(r),a.properties[i]=o,e.tracked&&(a.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(n,"update")},e.updateGeometry=function(t){var e=this,n=[];t.forEach(function(t){var r=t.id,i=t.geometry;n.push(r);var o=e.store[r];if(!o)throw new Error("No feature with this ("+r+"), can not update geometry");o.geometry=e.clone(i),e.spatialIndex.update(o),e.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(n,"update")},e.create=function(t){var e=this,n=[];return t.forEach(function(t){var r,i=t.geometry,a=t.properties,s=o({},a);e.tracked&&(r=+new Date,a?(s.createdAt="number"==typeof a.createdAt?a.createdAt:r,s.updatedAt="number"==typeof a.updatedAt?a.updatedAt:r):s={createdAt:r,updatedAt:r});var c=e.getId(),l={id:c,type:"Feature",geometry:i,properties:s};e.store[c]=l,e.spatialIndex.insert(l),n.push(c)}),this._onChange&&this._onChange([].concat(n),"create"),n},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}(),B=function(t){var e=this,n=t.name,r=t.callback,i=t.unregister,o=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=n,this.register=function(){e.registered||(e.registered=!0,o(r))},this.unregister=function(){e.register&&(e.registered=!1,i(r))},this.callback=r},L={__proto__:null,GeoJSONStore:C,TerraDrawBaseDrawMode:h,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 n=e.lng,r=e.lat,i=this.getMapElementXYPosition(t),o=i.containerX,a=i.containerY,s=this.getButton(t),c=Array.from(this._heldKeys);return{lng:u(n,this._coordinatePrecision),lat:u(r,this._coordinatePrecision),containerX:o,containerY:a,button:s,heldKeys:c}},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 B({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var n=t.getDrawEventFromEvent(e);n&&(t._dragState="pre-dragging",t._lastDrawEvent=n)}},register:function(e){t.getMapEventElement().addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerdown",e)}}),new B({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var n=t.getDrawEventFromEvent(e);if(n)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(n),t._lastDrawEvent=n;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var r={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},i={x:n.containerX,y:n.containerY},o=t._currentModeCallbacks.getState(),a=function(t,e){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(r*r+n*n)}(r,i);if("drawing"===o?a<t._minPixelDragDistanceDrawing:"selecting"===o?a<t._minPixelDragDistanceSelecting:a<t._minPixelDragDistance)return;t._dragState="dragging",t._currentModeCallbacks.onDragStart(n,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(n,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new B({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 B({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement()&&e.isPrimary){var n=t.getDrawEventFromEvent(e);n&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(n,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||t._currentModeCallbacks.onClick(n),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement().addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerup",e)}}),new B({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 B({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:{SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT:"selectionPoint"}},I=/*#__PURE__*/function(t){var e,n;function o(e){var n;if((n=t.call(this,e)||this)._cursor=void 0,n._cursorStyleSheet=void 0,n._lib=void 0,n._map=void 0,n._overlay=void 0,n._clickEventListener=void 0,n._mouseMoveEventListener=void 0,n.renderedFeatureIds=new Set,n._lib=e.lib,n._map=e.map,!n._map.getDiv().id)throw new Error("Google Map container div requires and id to be set");return n._coordinatePrecision="number"==typeof e.coordinatePrecision?e.coordinatePrecision:9,n}n=t,(e=o).prototype=Object.create(n.prototype),e.prototype.constructor=e,i(e,n);var a=o.prototype;return a.circlePath=function(t,e,n){var r=2*n;return"M "+t+" "+e+" m -"+n+", 0 a "+n+","+n+" 0 1,0 "+r+",0 a "+n+","+n+" 0 1,0 -"+r+",0"},a.register=function(e){var n=this;t.prototype.register.call(this,e),this._overlay=new this._lib.OverlayView,this._overlay.draw=function(){},this._overlay.onAdd=function(){var t;null!=(t=n._currentModeCallbacks)&&t.onReady&&n._currentModeCallbacks.onReady()},this._overlay.setMap(this._map),this._clickEventListener=this._map.data.addListener("click",function(t){var e=n._listeners.find(function(t){return"click"===t.name});e&&e.callback(t)}),this._mouseMoveEventListener=this._map.data.addListener("mousemove",function(t){var e=n._listeners.find(function(t){return"mousemove"===t.name});e&&e.callback(t)})},a.unregister=function(){var e,n,r;t.prototype.unregister.call(this),null==(e=this._clickEventListener)||e.remove(),null==(n=this._mouseMoveEventListener)||n.remove(),null==(r=this._overlay)||r.setMap(null),this._overlay=void 0},a.getLngLatFromEvent=function(t){if(!this._overlay)throw new Error("cannot get overlay");var e=this._map.getBounds();if(!e)return null;var n=e.getNorthEast(),r=e.getSouthWest(),i=new this._lib.LatLngBounds(r,n),o=this._map.getDiv(),a=t.clientX-o.getBoundingClientRect().left,s=t.clientY-o.getBoundingClientRect().top,c=new this._lib.Point(a,s),l=this._overlay.getProjection();if(!l)return null;var h=l.fromContainerPixelToLatLng(c);return h&&i.contains(h)?{lng:h.lng(),lat:h.lat()}:null},a.getMapEventElement=function(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')},a.project=function(t,e){if(!this._overlay)throw new Error("cannot get overlay");if(void 0===this._map.getBounds())throw new Error("cannot get bounds");var n=this._overlay.getProjection();if(void 0===n)throw new Error("cannot get projection");var r=n.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===r)throw new Error("cannot project coordinates");return{x:r.x,y:r.y}},a.unproject=function(t,e){if(!this._overlay)throw new Error("cannot get overlay");var n=this._overlay.getProjection();if(void 0===n)throw new Error("cannot get projection");var r=n.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===r)throw new Error("cannot unproject coordinates");return{lng:r.lng(),lat:r.lat()}},a.setCursor=function(t){if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),"unset"!==t){var e=this._map.getDiv(),n=document.querySelector("#"+e.id+" .gm-style > div");if(n){n.classList.add("terra-draw-google-maps");var r=document.createElement("style");r.innerHTML=".terra-draw-google-maps { cursor: "+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(r),this._cursorStyleSheet=r}}this._cursor=t}},a.setDoubleClickToZoom=function(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})},a.setDraggability=function(t){this._map.setOptions({draggable:t})},a.render=function(t,e){var n=this;this._layers&&(t.deletedIds.forEach(function(t){var e=n._map.data.getFeatureById(t);e&&(n._map.data.remove(e),n.renderedFeatureIds.delete(t))}),t.updated.forEach(function(t){if(!t||!t.id)throw new Error("Feature is not valid");var e=n._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty(function(t,n){e.setProperty(n,void 0)}),Object.keys(t.properties).forEach(function(n){e.setProperty(n,t.properties[n])}),t.geometry.type){case"Point":var r=t.geometry.coordinates;e.setGeometry(new n._lib.Data.Point(new n._lib.LatLng(r[1],r[0])));break;case"LineString":for(var i=t.geometry.coordinates,o=[],a=0;a<i.length;a++){var s=i[a],c=new n._lib.LatLng(s[1],s[0]);o.push(c)}e.setGeometry(new n._lib.Data.LineString(o));break;case"Polygon":for(var l=t.geometry.coordinates,h=[],u=0;u<l.length;u++){for(var d=[],f=0;f<l[u].length;f++){var p=new n._lib.LatLng(l[u][f][1],l[u][f][0]);d.push(p)}h.push(d)}e.setGeometry(new n._lib.Data.Polygon(h))}}),t.created.forEach(function(t){n.renderedFeatureIds.add(t.id),n._map.data.addGeoJson(t)})),t.created.forEach(function(t){n.renderedFeatureIds.add(t.id)});var r={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(r),this._map.data.setStyle(function(t){var r=t.getProperty("mode"),i=t.getGeometry();if(!i)throw new Error("Google Maps geometry not found");var o=i.getType(),a={};t.forEachProperty(function(t,e){a[e]=t});var s=e[r]({type:"Feature",geometry:{type:o,coordinates:[]},properties:a});switch(o){case"Point":return{clickable:!1,icon:{path:n.circlePath(0,0,s.pointWidth),fillColor:s.pointColor,fillOpacity:1,strokeColor:s.pointOutlineColor,strokeWeight:s.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:s.lineStringColor,strokeWeight:s.lineStringWidth};case"Polygon":return{strokeColor:s.polygonOutlineColor,strokeWeight:s.polygonOutlineWidth,fillOpacity:s.polygonFillOpacity,fillColor:s.polygonFillColor}}throw Error("Unknown feature type")})},a.clearLayers=function(){var t=this;this._layers&&(this._map.data.forEach(function(e){var n=e.getId();t.renderedFeatureIds.has(n)&&t._map.data.remove(e)}),this.renderedFeatureIds=new Set)},a.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},a.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},r(o,[{key:"_layers",get:function(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}}]),o}(L.TerraDrawBaseAdapter);t.TerraDrawGoogleMapsAdapter=I});
|
|
2
|
+
//# sourceMappingURL=terra-draw-google-maps-adapter.umd.js.map
|