terra-draw 1.0.0-beta.1 → 1.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +9 -2
  2. package/dist/adapters/common/adapter-listener.d.ts +22 -0
  3. package/dist/adapters/common/base.adapter.d.ts +59 -0
  4. package/dist/adapters/mapbox-gl.adapter.d.ts +0 -1
  5. package/dist/adapters/openlayers.adapter.d.ts +14 -13
  6. package/dist/common.d.ts +11 -9
  7. package/dist/extend.d.ts +4 -0
  8. package/dist/geometry/calculate-relative-angle.d.ts +2 -10
  9. package/dist/geometry/clockwise.d.ts +2 -0
  10. package/dist/geometry/determine-halfplane.d.ts +2 -10
  11. package/dist/geometry/measure/bearing.d.ts +3 -7
  12. package/dist/geometry/measure/destination.d.ts +2 -7
  13. package/dist/geometry/measure/pixel-distance-to-line.d.ts +2 -10
  14. package/dist/geometry/measure/pixel-distance.d.ts +2 -7
  15. package/dist/geometry/point-on-line.d.ts +5 -0
  16. package/dist/geometry/project/web-mercator.d.ts +2 -4
  17. package/dist/geometry/web-mercator-centroid.d.ts +2 -4
  18. package/dist/geometry/web-mercator-point-on-line.d.ts +11 -0
  19. package/dist/modes/angled-rectangle/angled-rectangle.mode.d.ts +2 -7
  20. package/dist/modes/base.mode.d.ts +3 -1
  21. package/dist/modes/circle/circle.mode.d.ts +3 -2
  22. package/dist/modes/coordinate-snapping.behavior.d.ts +16 -0
  23. package/dist/modes/freehand/freehand.mode.d.ts +8 -2
  24. package/dist/modes/{snapping.behavior.d.ts → line-snapping.behavior.d.ts} +1 -1
  25. package/dist/modes/linestring/linestring.mode.d.ts +16 -5
  26. package/dist/modes/point/point.mode.d.ts +2 -2
  27. package/dist/modes/polygon/polygon.mode.d.ts +17 -4
  28. package/dist/modes/rectangle/rectangle.mode.d.ts +2 -2
  29. package/dist/modes/render/render.mode.d.ts +2 -1
  30. package/dist/modes/sector/sector.mode.d.ts +60 -0
  31. package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +2 -2
  32. package/dist/modes/sensor/sensor.mode.d.ts +69 -0
  33. package/dist/store/store-feature-validation.d.ts +8 -2
  34. package/dist/store/store.d.ts +7 -3
  35. package/dist/terra-draw.cjs +1 -1
  36. package/dist/terra-draw.cjs.map +1 -1
  37. package/dist/terra-draw.d.ts +12 -13
  38. package/dist/terra-draw.modern.js +1 -1
  39. package/dist/terra-draw.modern.js.map +1 -1
  40. package/dist/terra-draw.module.js +1 -1
  41. package/dist/terra-draw.module.js.map +1 -1
  42. package/dist/terra-draw.umd.js +1 -1
  43. package/dist/terra-draw.umd.js.map +1 -1
  44. package/dist/validation-reasons.d.ts +13 -0
  45. package/dist/validations/common-validations.d.ts +2 -0
  46. package/dist/validations/linestring.validation.d.ts +4 -1
  47. package/dist/validations/max-size.validation.d.ts +3 -1
  48. package/dist/validations/min-size.validation.d.ts +3 -1
  49. package/dist/validations/not-self-intersecting.validation.d.ts +4 -1
  50. package/dist/validations/point.validation.d.ts +4 -1
  51. package/dist/validations/polygon.validation.d.ts +8 -2
  52. package/e2e/package-lock.json +5 -4
  53. package/e2e/package.json +1 -1
  54. package/e2e/public/index.html +2 -0
  55. package/e2e/tests/leaflet.spec.ts +414 -18
  56. package/e2e/tests/setup.ts +16 -5
  57. package/eslint.config.js +32 -0
  58. package/package.json +29 -28
  59. package/tsconfig.json +2 -1
  60. package/readme.gif +0 -0
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).terraDraw={})}(this,function(t){function e(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function i(t,i){for(var n=0;n<i.length;n++){var r=i[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,e(r.key),r)}}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},r.apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var l=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)},c=function(t){var e=this,i=t.name,n=t.callback,r=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=i,this.register=function(){e.registered||(e.registered=!0,o(n))},this.unregister=function(){e.register&&(e.registered=!1,r(n))},this.callback=n},h=/*#__PURE__*/function(){function t(t){this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement().getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t){var e=this.getLngLatFromEvent(t);if(!e)return null;var i=e.lng,n=e.lat,r=this.getMapElementXYPosition(t),o=r.containerX,s=r.containerY,l=this.getButton(t),c=Array.from(this._heldKeys);return{lng:a(i,this._coordinatePrecision),lat:a(n,this._coordinatePrecision),containerX:o,containerY:s,button:l,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 c({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i)}},register:function(e){t.getMapEventElement().addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerdown",e)}}),new c({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var n={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},r={x:i.containerX,y:i.containerY},o=t._currentModeCallbacks.getState(),s=l(n,r);if("drawing"===o?s<t._minPixelDragDistanceDrawing:"selecting"===o?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new c({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 c({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement()&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(i,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||t._currentModeCallbacks.onClick(i),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement().addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerup",e)}}),new c({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 c({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}(),d=/*#__PURE__*/function(t){function e(e){var i;if((i=t.call(this,e)||this)._cursor=void 0,i._cursorStyleSheet=void 0,i._lib=void 0,i._map=void 0,i._overlay=void 0,i._clickEventListener=void 0,i._mouseMoveEventListener=void 0,i.renderedFeatureIds=new Set,i._lib=e.lib,i._map=e.map,!i._map.getDiv().id)throw new Error("Google Map container div requires and id to be set");return i._coordinatePrecision="number"==typeof e.coordinatePrecision?e.coordinatePrecision:9,i}o(e,t);var i=e.prototype;return i.circlePath=function(t,e,i){var n=2*i;return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+n+",0 a "+i+","+i+" 0 1,0 -"+n+",0"},i.register=function(e){var i=this;t.prototype.register.call(this,e),this._overlay=new this._lib.OverlayView,this._overlay.draw=function(){},this._overlay.onAdd=function(){i._currentModeCallbacks&&i._currentModeCallbacks.onReady&&i._currentModeCallbacks.onReady()},this._overlay.setMap(this._map),this._clickEventListener=this._map.data.addListener("click",function(t){var e=i._listeners.find(function(t){return"click"===t.name});e&&e.callback(t)}),this._mouseMoveEventListener=this._map.data.addListener("mousemove",function(t){var e=i._listeners.find(function(t){return"mousemove"===t.name});e&&e.callback(t)})},i.unregister=function(){var e,i,n;t.prototype.unregister.call(this),null==(e=this._clickEventListener)||e.remove(),null==(i=this._mouseMoveEventListener)||i.remove(),null==(n=this._overlay)||n.setMap(null),this._overlay=void 0},i.getLngLatFromEvent=function(t){if(!this._overlay)throw new Error("cannot get overlay");var e=this._map.getBounds();if(!e)return null;var i=e.getNorthEast(),n=e.getSouthWest(),r=new this._lib.LatLngBounds(n,i),o=this._map.getDiv(),s=t.clientX-o.getBoundingClientRect().left,a=t.clientY-o.getBoundingClientRect().top,l=new this._lib.Point(s,a),c=this._overlay.getProjection();if(!c)return null;var h=c.fromContainerPixelToLatLng(l);return h&&r.contains(h)?{lng:h.lng(),lat:h.lat()}:null},i.getMapEventElement=function(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')},i.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 i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");var n=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===n)throw new Error("cannot project coordinates");return{x:n.x,y:n.y}},i.unproject=function(t,e){if(!this._overlay)throw new Error("cannot get overlay");var i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");var n=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===n)throw new Error("cannot unproject coordinates");return{lng:n.lng(),lat:n.lat()}},i.setCursor=function(t){if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),"unset"!==t){var e=this._map.getDiv(),i=document.querySelector("#"+e.id+" .gm-style > div");if(i){i.classList.add("terra-draw-google-maps");var n=document.createElement("style");n.innerHTML=".terra-draw-google-maps { cursor: "+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(n),this._cursorStyleSheet=n}}this._cursor=t}},i.setDoubleClickToZoom=function(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})},i.setDraggability=function(t){this._map.setOptions({draggable:t})},i.render=function(t,e){var i=this;this._layers&&(t.deletedIds.forEach(function(t){var e=i._map.data.getFeatureById(t);e&&(i._map.data.remove(e),i.renderedFeatureIds.delete(t))}),t.updated.forEach(function(t){if(!t||!t.id)throw new Error("Feature is not valid");var e=i._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty(function(t,i){e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(function(i){e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":var n=t.geometry.coordinates;e.setGeometry(new i._lib.Data.Point(new i._lib.LatLng(n[1],n[0])));break;case"LineString":for(var r=t.geometry.coordinates,o=[],s=0;s<r.length;s++){var a=r[s],l=new i._lib.LatLng(a[1],a[0]);o.push(l)}e.setGeometry(new i._lib.Data.LineString(o));break;case"Polygon":for(var c=t.geometry.coordinates,h=[],d=0;d<c.length;d++){for(var u=[],g=0;g<c[d].length;g++){var p=new i._lib.LatLng(c[d][g][1],c[d][g][0]);u.push(p)}h.push(u)}e.setGeometry(new i._lib.Data.Polygon(h))}}),t.created.forEach(function(t){i.renderedFeatureIds.add(t.id),i._map.data.addGeoJson(t)})),t.created.forEach(function(t){i.renderedFeatureIds.add(t.id)});var n={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(n),this._map.data.setStyle(function(t){var n=t.getProperty("mode"),r=t.getGeometry();if(!r)throw new Error("Google Maps geometry not found");var o=r.getType(),s={};t.forEachProperty(function(t,e){s[e]=t});var a=e[n]({type:"Feature",geometry:{type:o,coordinates:[]},properties:s});switch(o){case"Point":return{clickable:!1,icon:{path:i.circlePath(0,0,a.pointWidth),fillColor:a.pointColor,fillOpacity:1,strokeColor:a.pointOutlineColor,strokeWeight:a.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:a.lineStringColor,strokeWeight:a.lineStringWidth};case"Polygon":return{strokeColor:a.polygonOutlineColor,strokeWeight:a.polygonOutlineWidth,fillOpacity:a.polygonFillOpacity,fillColor:a.polygonFillColor}}throw Error("Unknown feature type")})},i.clearLayers=function(){var t=this;this._layers&&(this._map.data.forEach(function(e){var i=e.getId();t.renderedFeatureIds.has(i)&&t._map.data.remove(e)}),this.renderedFeatureIds=new Set)},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},n(e,[{key:"_layers",get:function(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}}]),e}(h),u=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._lib=void 0,i._map=void 0,i._panes={},i._container=void 0,i._layers={},i._lib=e.lib,i._map=e.map,i._container=i._map.getContainer(),i}o(e,t);var i=e.prototype;return i.createPaneStyleSheet=function(t,e){var i=document.createElement("style");return i.innerHTML=".leaflet-"+t+"-pane {z-index: "+(e+600)+";}",document.getElementsByTagName("head")[0].appendChild(i),this._map.createPane(t),i},i.clearPanes=function(){Object.values(this._panes).forEach(function(t){t&&t.remove()}),this._panes={}},i.clearLayers=function(){var t=this;Object.values(this._layers).forEach(function(e){t._map.removeLayer(e)}),this._layers={}},i.styleGeoJSONLayer=function(t){var e=this;return{pointToLayer:function(i,n){if(!i.properties)throw new Error("Feature has no properties");if("string"!=typeof i.properties.mode)throw new Error("Feature mode is not a string");var r=(0,t[i.properties.mode])(i),o=String(r.zIndex);return e._panes[o]||(e._panes[o]=e.createPaneStyleSheet(o,r.zIndex)),e._lib.circleMarker(n,{radius:r.pointWidth,stroke:r.pointOutlineWidth||!1,color:r.pointOutlineColor,weight:r.pointOutlineWidth,fillOpacity:.8,fillColor:r.pointColor,pane:o,interactive:!1})},style:function(i){if(!i||!i.properties)return{};var n=i,r=(0,t[n.properties.mode])(n),o=String(r.zIndex);return e._panes[o]||(e._panes[o]=e.createPaneStyleSheet(o,r.zIndex)),"LineString"===n.geometry.type?{interactive:!1,color:r.lineStringColor,weight:r.lineStringWidth,pane:o}:"Polygon"===n.geometry.type?{interactive:!1,fillOpacity:r.polygonFillOpacity,fillColor:r.polygonFillColor,weight:r.polygonOutlineWidth,stroke:!0,color:r.polygonFillColor,pane:o}:{}}}},i.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t),i={x:e.containerX,y:e.containerY};if(null===i.x||isNaN(i.x)||null===i.y||isNaN(i.y))return null;var n=this._map.containerPointToLatLng(i);return null===n.lng||isNaN(n.lng)||null===n.lat||isNaN(n.lat)?null:{lng:n.lng,lat:n.lat}},i.getMapEventElement=function(){return this._container},i.setDraggability=function(t){t?this._map.dragging.enable():this._map.dragging.disable()},i.project=function(t,e){var i=this._map.latLngToContainerPoint({lng:t,lat:e});return{x:i.x,y:i.y}},i.unproject=function(t,e){var i=this._map.containerPointToLatLng({x:t,y:e});return{lng:i.lng,lat:i.lat}},i.setCursor=function(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t},i.setDoubleClickToZoom=function(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()},i.render=function(t,e){var i=this;t.created.forEach(function(t){i._layers[t.id]=i._lib.geoJSON(t,i.styleGeoJSONLayer(e)),i._map.addLayer(i._layers[t.id])}),t.deletedIds.forEach(function(t){i._map.removeLayer(i._layers[t])}),t.updated.forEach(function(t){i._map.removeLayer(i._layers[t.id]),i._layers[t.id]=i._lib.geoJSON(t,i.styleGeoJSONLayer(e)),i._map.addLayer(i._layers[t.id])})},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers(),this.clearPanes())},i.register=function(e){t.prototype.register.call(this,e),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.unregister=function(){return t.prototype.unregister.call(this)},e}(h),g=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._nextRender=void 0,i._map=void 0,i._container=void 0,i._rendered=!1,i.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},i._map=e.map,i._container=i._map.getContainer(),i}o(e,t);var i=e.prototype;return i.clearLayers=function(){var t=this;this._rendered&&(["point","linestring","polygon"].forEach(function(e){var i="td-"+e.toLowerCase();t._map.removeLayer(i),"polygon"===e&&t._map.removeLayer(i+"-outline"),t._map.removeSource(i)}),this._rendered=!1,this._nextRender&&(cancelAnimationFrame(this._nextRender),this._nextRender=void 0))},i._addGeoJSONSource=function(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e},tolerance:0})},i._addFillLayer=function(t){return this._map.addLayer({id:t,source:t,type:"fill",paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})},i._addFillOutlineLayer=function(t,e){var i=this._map.addLayer({id:t+"-outline",source:t,type:"line",paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}});return e&&this._map.moveLayer(t,e),i},i._addLineLayer=function(t,e){var i=this._map.addLayer({id:t,source:t,type:"line",paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}});return e&&this._map.moveLayer(t,e),i},i._addPointLayer=function(t,e){var i=this._map.addLayer({id:t,source:t,type:"circle",paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return e&&this._map.moveLayer(t,e),i},i._addLayer=function(t,e,i){"Point"===e&&this._addPointLayer(t,i),"LineString"===e&&this._addLineLayer(t,i),"Polygon"===e&&(this._addFillLayer(t),this._addFillOutlineLayer(t,i))},i._addGeoJSONLayer=function(t,e){var i="td-"+t.toLowerCase();return this._addGeoJSONSource(i,e),this._addLayer(i,t),i},i._setGeoJSONLayerData=function(t,e){var i="td-"+t.toLowerCase();return this._map.getSource(i).setData({type:"FeatureCollection",features:e}),i},i.getEmptyGeometries=function(){return{points:[],linestrings:[],polygons:[]}},i.updateChangedIds=function(t){var e=this;[].concat(t.updated,t.created).forEach(function(t){"Point"===t.geometry.type?e.changedIds.points=!0:"LineString"===t.geometry.type?e.changedIds.linestrings=!0:"Polygon"===t.geometry.type&&(e.changedIds.polygons=!0)}),t.deletedIds.length>0&&(this.changedIds.deletion=!0),0===t.created.length&&0===t.updated.length&&0===t.deletedIds.length&&(this.changedIds.styling=!0)},i.getLngLatFromEvent=function(t){var e=this._container.getBoundingClientRect();return this.unproject(t.clientX-e.left,t.clientY-e.top)},i.getMapEventElement=function(){return this._map.getCanvas()},i.setDraggability=function(t){t?(this._map.dragRotate.enable(),this._map.dragPan.enable()):(this._map.dragRotate.disable(),this._map.dragPan.disable())},i.project=function(t,e){var i=this._map.project({lng:t,lat:e});return{x:i.x,y:i.y}},i.unproject=function(t,e){var i=this._map.unproject({x:t,y:e});return{lng:i.lng,lat:i.lat}},i.setCursor=function(t){var e=this._map.getCanvas();"unset"===t?e.style.removeProperty("cursor"):e.style.cursor=t},i.setDoubleClickToZoom=function(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()},i.render=function(t,e){var i=this;this.updateChangedIds(t),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(function(){for(var n=[].concat(t.created,t.updated,t.unchanged),r=i.getEmptyGeometries(),o=function(t){var i=n[t];Object.keys(e).forEach(function(t){var n=i.properties;if(n.mode===t){var o=e[t](i);"Point"===i.geometry.type?(n.pointColor=o.pointColor,n.pointOutlineColor=o.pointOutlineColor,n.pointOutlineWidth=o.pointOutlineWidth,n.pointWidth=o.pointWidth,r.points.push(i)):"LineString"===i.geometry.type?(n.lineStringColor=o.lineStringColor,n.lineStringWidth=o.lineStringWidth,r.linestrings.push(i)):"Polygon"===i.geometry.type&&(n.polygonFillColor=o.polygonFillColor,n.polygonFillOpacity=o.polygonFillOpacity,n.polygonOutlineColor=o.polygonOutlineColor,n.polygonOutlineWidth=o.polygonOutlineWidth,r.polygons.push(i))}})},s=0;s<n.length;s++)o(s);var a=r.points,l=r.linestrings,c=r.polygons;if(i._rendered){var h,d=i.changedIds.deletion||i.changedIds.styling,u=d||i.changedIds.linestrings,g=d||i.changedIds.polygons;(d||i.changedIds.points)&&(h=i._setGeoJSONLayerData("Point",a)),u&&i._setGeoJSONLayerData("LineString",l),g&&i._setGeoJSONLayerData("Polygon",c),h&&i._map.moveLayer(h)}else{var p=i._addGeoJSONLayer("Point",a);i._addGeoJSONLayer("LineString",l),i._addGeoJSONLayer("Polygon",c),i._rendered=!0,p&&i._map.moveLayer(p)}i.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.unregister=function(){return t.prototype.unregister.call(this)},i.register=function(e){t.prototype.register.call(this,e),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()},e}(h),p=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mapboxglAdapter=void 0,i.mapboxglAdapter=new g(e),i}o(e,t);var i=e.prototype;return i.register=function(t){this.mapboxglAdapter.register(t)},i.unregister=function(){this.mapboxglAdapter.unregister()},i.getCoordinatePrecision=function(){return this.mapboxglAdapter.getCoordinatePrecision()},i.getLngLatFromEvent=function(t){return this.mapboxglAdapter.getLngLatFromEvent(t)},i.getMapEventElement=function(){return this.mapboxglAdapter.getMapEventElement()},i.setDraggability=function(t){this.mapboxglAdapter.setDraggability(t)},i.project=function(t,e){return this.mapboxglAdapter.project(t,e)},i.unproject=function(t,e){return this.mapboxglAdapter.unproject(t,e)},i.setCursor=function(t){this.mapboxglAdapter.setCursor(t)},i.setDoubleClickToZoom=function(t){this.mapboxglAdapter.setDoubleClickToZoom(t)},i.render=function(t,e){this.mapboxglAdapter.render(t,e)},i.clear=function(){this.mapboxglAdapter.clear()},e}(h);function f(){throw new Error("Unimplemented abstract method.")}let y=0;function v(t,e){return Array.isArray(t)?t:(void 0===e?e=[t,t]:(e[0]=t,e[1]=t),e)}class m{constructor(t){this.opacity_=t.opacity,this.rotateWithView_=t.rotateWithView,this.rotation_=t.rotation,this.scale_=t.scale,this.scaleArray_=v(t.scale),this.displacement_=t.displacement,this.declutterMode_=t.declutterMode}clone(){const t=this.getScale();return new m({opacity:this.getOpacity(),scale:Array.isArray(t)?t.slice():t,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()})}getOpacity(){return this.opacity_}getRotateWithView(){return this.rotateWithView_}getRotation(){return this.rotation_}getScale(){return this.scale_}getScaleArray(){return this.scaleArray_}getDisplacement(){return this.displacement_}getDeclutterMode(){return this.declutterMode_}getAnchor(){return f()}getImage(t){return f()}getHitDetectionImage(){return f()}getPixelRatio(t){return 1}getImageState(){return f()}getImageSize(){return f()}getOrigin(){return f()}getSize(){return f()}setDisplacement(t){this.displacement_=t}setOpacity(t){this.opacity_=t}setRotateWithView(t){this.rotateWithView_=t}setRotation(t){this.rotation_=t}setScale(t){this.scale_=t,this.scaleArray_=v(t)}listenImageChange(t){f()}load(){f()}unlistenImageChange(t){f()}ready(){return Promise.resolve()}}var _=m,C={name:"rgb",min:[0,0,0],max:[255,255,255],channel:["red","green","blue"],alias:["RGB"]},P={name:"xyz",min:[0,0,0],channel:["X","Y","Z"],alias:["XYZ","ciexyz","cie1931"],whitepoint:{2:{A:[109.85,100,35.585],C:[98.074,100,118.232],D50:[96.422,100,82.521],D55:[95.682,100,92.149],D65:[95.045592705167,100,108.9057750759878],D75:[94.972,100,122.638],F2:[99.187,100,67.395],F7:[95.044,100,108.755],F11:[100.966,100,64.37],E:[100,100,100]},10:{A:[111.144,100,35.2],C:[97.285,100,116.145],D50:[96.72,100,81.427],D55:[95.799,100,90.926],D65:[94.811,100,107.304],D75:[94.416,100,120.641],F2:[103.28,100,69.026],F7:[95.792,100,107.687],F11:[103.866,100,65.627],E:[100,100,100]}}};P.max=P.whitepoint[2].D65,P.rgb=function(t,e){var i,n,r,o=t[0]/(e=e||P.whitepoint[2].E)[0],s=t[1]/e[1],a=t[2]/e[2];return n=-.96924363628087*o+1.87596750150772*s+.041555057407175*a,r=.055630079696993*o+-.20397695888897*s+1.056971514242878*a,i=(i=3.240969941904521*o+-1.537383177570093*s+-.498610760293*a)>.0031308?1.055*Math.pow(i,1/2.4)-.055:i*=12.92,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:n*=12.92,r=r>.0031308?1.055*Math.pow(r,1/2.4)-.055:r*=12.92,[255*(i=Math.min(Math.max(0,i),1)),255*(n=Math.min(Math.max(0,n),1)),255*(r=Math.min(Math.max(0,r),1))]},C.xyz=function(t,e){var i=t[0]/255,n=t[1]/255,r=t[2]/255;return[(.41239079926595*(i=i>.04045?Math.pow((i+.055)/1.055,2.4):i/12.92)+.35758433938387*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.18048078840183*(r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92))*(e=e||P.whitepoint[2].E)[0],(.21263900587151*i+.71516867876775*n+.072192315360733*r)*e[1],(.019330818715591*i+.11919477979462*n+.95053215224966*r)*e[2]]};var x={name:"luv",min:[0,-134,-140],max:[100,224,122],channel:["lightness","u","v"],alias:["LUV","cieluv","cie1976"],xyz:function(t,e,i){var n,r,o,s,a,l,c;return 0===(o=t[0])?[0,0,0]:(n=t[1]/(13*o)+4*(a=P.whitepoint[i=i||2][e=e||"D65"][0])/(a+15*(l=P.whitepoint[i][e][1])+3*(c=P.whitepoint[i][e][2]))||0,r=t[2]/(13*o)+9*l/(a+15*l+3*c)||0,[9*(s=o>8?l*Math.pow((o+16)/116,3):l*o*.0011070564598794539)*n/(4*r)||0,s,s*(12-3*n-20*r)/(4*r)||0])}};P.luv=function(t,e,i){var n,r,o,s,a,l,c,h,d,u,g;u=4*(c=P.whitepoint[i=i||2][e=e||"D65"][0])/(c+15*(h=P.whitepoint[i][e][1])+3*(d=P.whitepoint[i][e][2])),g=9*h/(c+15*h+3*d),n=4*(s=t[0])/(s+15*(a=t[1])+3*(l=t[2]))||0,r=9*a/(s+15*a+3*l)||0;var p=a/h;return[o=p<=.008856451679035631?903.2962962962961*p:116*Math.pow(p,1/3)-16,13*o*(n-u),13*o*(r-g)]},x.lchuv=function(t){var e=t[0],i=t[1],n=t[2],r=Math.sqrt(i*i+n*n),o=360*Math.atan2(n,i)/2/Math.PI;return o<0&&(o+=360),[e,r,o]},P.lchuv=function(t){return x.lchuv(P.luv(t))};var M={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},w={red:0,orange:60,yellow:120,green:180,blue:240,purple:300},b={name:"hsl",min:[0,0,0],max:[360,100,100],channel:["hue","saturation","lightness"],alias:["HSL"],rgb:function(t){var e,i,n,r,o,s=t[0]/360,a=t[1]/100,l=t[2]/100,c=0;if(0===a)return[o=255*l,o,o];for(e=2*l-(i=l<.5?l*(1+a):l+a-l*a),r=[0,0,0];c<3;)(n=s+1/3*-(c-1))<0?n++:n>1&&n--,r[c++]=255*(o=6*n<1?e+6*(i-e)*n:2*n<1?i:3*n<2?e+(i-e)*(2/3-n)*6:e);return r}};function S(t,e,i){return Math.min(Math.max(t,e),i)}C.hsl=function(t){var e,i,n=t[0]/255,r=t[1]/255,o=t[2]/255,s=Math.min(n,r,o),a=Math.max(n,r,o),l=a-s;return a===s?e=0:n===a?e=(r-o)/l:r===a?e=2+(o-n)/l:o===a&&(e=4+(n-r)/l),(e=Math.min(60*e,360))<0&&(e+=360),i=(s+a)/2,[e,100*(a===s?0:i<=.5?l/(a+s):l/(2-a-s)),100*i]};const E=1024,I={};let D=0;function k(t){return Array.isArray(t)?t:function(t){if(I.hasOwnProperty(t))return I[t];if(D>=E){let t=0;for(const e in I)3&t++||(delete I[e],--D)}const e=function(t){var e;Array.isArray(t)&&t.raw&&(t=String.raw(...arguments)),t instanceof Number&&(t=+t);var i=function(t){var e,i,n=[],r=1;if("number"==typeof t)return{space:"rgb",values:[t>>>16,(65280&t)>>>8,255&t],alpha:1};if("number"==typeof t)return{space:"rgb",values:[t>>>16,(65280&t)>>>8,255&t],alpha:1};if(t=String(t).toLowerCase(),M[t])n=M[t].slice(),i="rgb";else if("transparent"===t)r=0,i="rgb",n=[0,0,0];else if("#"===t[0]){var o=t.slice(1),s=o.length;r=1,s<=4?(n=[parseInt(o[0]+o[0],16),parseInt(o[1]+o[1],16),parseInt(o[2]+o[2],16)],4===s&&(r=parseInt(o[3]+o[3],16)/255)):(n=[parseInt(o[0]+o[1],16),parseInt(o[2]+o[3],16),parseInt(o[4]+o[5],16)],8===s&&(r=parseInt(o[6]+o[7],16)/255)),n[0]||(n[0]=0),n[1]||(n[1]=0),n[2]||(n[2]=0),i="rgb"}else if(e=/^((?:rgba?|hs[lvb]a?|hwba?|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms|oklch|oklab|color))\s*\(([^\)]*)\)/.exec(t)){var a="cmyk"===(i=e[1].replace(/a$/,""))?4:"gray"===i?1:3;n=e[2].trim().split(/\s*[,\/]\s*|\s+/),"color"===i&&(i=n.shift()),r=(n=n.map(function(t,e){if("%"===t[t.length-1])return t=parseFloat(t)/100,3===e?t:"rgb"===i?255*t:"h"===i[0]?100*t:"l"!==i[0]||e?"lab"===i?125*t:"lch"===i?e<2?150*t:360*t:"o"!==i[0]||e?"oklab"===i?.4*t:"oklch"===i?e<2?.4*t:360*t:t:t:100*t;if("h"===i[e]||2===e&&"h"===i[i.length-1]){if(void 0!==w[t])return w[t];if(t.endsWith("deg"))return parseFloat(t);if(t.endsWith("turn"))return 360*parseFloat(t);if(t.endsWith("grad"))return 360*parseFloat(t)/400;if(t.endsWith("rad"))return 180*parseFloat(t)/Math.PI}return"none"===t?0:parseFloat(t)})).length>a?n.pop():1}else/[0-9](?:\s|\/|,)/.test(t)&&(n=t.match(/([0-9]+)/g).map(function(t){return parseFloat(t)}),i=t.match(/([a-z])/gi)?.join("")?.toLowerCase()||"rgb");return{space:i,values:n,alpha:r}}(t);if(!i.space)return[];const n="h"===i.space[0]?b.min:C.min,r="h"===i.space[0]?b.max:C.max;return(e=Array(3))[0]=Math.min(Math.max(i.values[0],n[0]),r[0]),e[1]=Math.min(Math.max(i.values[1],n[1]),r[1]),e[2]=Math.min(Math.max(i.values[2],n[2]),r[2]),"h"===i.space[0]&&(e=b.rgb(e)),e.push(Math.min(Math.max(i.alpha,0),1)),e}(t);if(4!==e.length)throw new Error('failed to parse "'+t+'" as color');for(const i of e)if(isNaN(i))throw new Error('failed to parse "'+t+'" as color');return function(t){t[0]=S(t[0]+.5|0,0,255),t[1]=S(t[1]+.5|0,0,255),t[2]=S(t[2]+.5|0,0,255),t[3]=S(t[3],0,1)}(e),I[t]=e,++D,e}(t)}function F(t){let e=t[0];e!=(0|e)&&(e=e+.5|0);let i=t[1];i!=(0|i)&&(i=i+.5|0);let n=t[2];return n!=(0|n)&&(n=n+.5|0),"rgba("+e+","+i+","+n+","+(void 0===t[3]?1:Math.round(1e3*t[3])/1e3)+")"}const O="undefined"!=typeof navigator&&void 0!==navigator.userAgent?navigator.userAgent.toLowerCase():"";O.includes("firefox"),O.includes("safari")&&!O.includes("chrom")&&(O.includes("version/15.4")||/cpu (os|iphone os) 15_4 like mac os x/.test(O)),O.includes("webkit")&&O.includes("edge"),O.includes("macintosh");const L="undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof OffscreenCanvas&&self instanceof WorkerGlobalScope,j="undefined"!=typeof Image&&Image.prototype.decode;function W(t,e,i,n){let r;return r=i&&i.length?i.shift():L?new OffscreenCanvas(t||300,e||300):document.createElement("canvas"),t&&(r.width=t),e&&(r.height=e),r.getContext("2d",n)}let B;function A(){return B||(B=W(1,1)),B}!function(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("_",null,e),window.removeEventListener("_",null,e)}catch(t){}}();var G=class{constructor(){this.disposed=!1}dispose(){this.disposed||(this.disposed=!0,this.disposeInternal())}disposeInternal(){}},N=class{constructor(t){this.type=t,this.target=null}preventDefault(){this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0}};function R(){}function V(t){for(const e in t)delete t[e]}var z=class extends G{constructor(t){super(),this.eventTarget_=t,this.pendingRemovals_=null,this.dispatching_=null,this.listeners_=null}addEventListener(t,e){if(!t||!e)return;const i=this.listeners_||(this.listeners_={}),n=i[t]||(i[t]=[]);n.includes(e)||n.push(e)}dispatchEvent(t){const e="string"==typeof t,i=e?t:t.type,n=this.listeners_&&this.listeners_[i];if(!n)return;const r=e?new N(t):t;r.target||(r.target=this.eventTarget_||this);const o=this.dispatching_||(this.dispatching_={}),s=this.pendingRemovals_||(this.pendingRemovals_={});let a;i in o||(o[i]=0,s[i]=0),++o[i];for(let t=0,e=n.length;t<e;++t)if(a="handleEvent"in n[t]?n[t].handleEvent(r):n[t].call(this,r),!1===a||r.propagationStopped){a=!1;break}if(0==--o[i]){let t=s[i];for(delete s[i];t--;)this.removeEventListener(i,R);delete o[i]}return a}disposeInternal(){this.listeners_&&V(this.listeners_)}getListeners(t){return this.listeners_&&this.listeners_[t]||void 0}hasListener(t){return!!this.listeners_&&(t?t in this.listeners_:Object.keys(this.listeners_).length>0)}removeEventListener(t,e){if(!this.listeners_)return;const i=this.listeners_[t];if(!i)return;const n=i.indexOf(e);-1!==n&&(this.pendingRemovals_&&t in this.pendingRemovals_?(i[n]=R,++this.pendingRemovals_[t]):(i.splice(n,1),0===i.length&&delete this.listeners_[t]))}},T="change";function X(t,e,i,n,r){if(r){const r=i;i=function(){t.removeEventListener(e,i),r.apply(n??this,arguments)}}else n&&n!==t&&(i=i.bind(n));const o={target:t,type:e,listener:i};return t.addEventListener(e,i),o}function U(t,e,i,n){return X(t,e,i,n,!0)}function Y(t){t&&t.target&&(t.target.removeEventListener(t.type,t.listener),V(t))}function H(t,e,i){return e+":"+t+":"+(i?k(i):"null")}const K=new class{constructor(){this.cache_={},this.patternCache_={},this.cacheSize_=0,this.maxCacheSize_=32}clear(){this.cache_={},this.patternCache_={},this.cacheSize_=0}canExpireCache(){return this.cacheSize_>this.maxCacheSize_}expire(){if(this.canExpireCache()){let t=0;for(const e in this.cache_)3&t++||this.cache_[e].hasListener()||(delete this.cache_[e],delete this.patternCache_[e],--this.cacheSize_)}}get(t,e,i){const n=H(t,e,i);return n in this.cache_?this.cache_[n]:null}getPattern(t,e,i){const n=H(t,e,i);return n in this.patternCache_?this.patternCache_[n]:null}set(t,e,i,n,r){const o=H(t,e,i),s=o in this.cache_;this.cache_[o]=n,r&&(0===n.getImageState()&&n.load(),1===n.getImageState()?n.ready().then(()=>{this.patternCache_[o]=A().createPattern(n.getImage(1),"repeat")}):this.patternCache_[o]=A().createPattern(n.getImage(1),"repeat")),s||++this.cacheSize_}setSize(t){this.maxCacheSize_=t,this.expire()}};let J=null;class q extends z{constructor(t,e,i,n,r){super(),this.hitDetectionImage_=null,this.image_=t,this.crossOrigin_=i,this.canvas_={},this.color_=r,this.imageState_=void 0===n?0:n,this.size_=t&&t.width&&t.height?[t.width,t.height]:null,this.src_=e,this.ready_=null}initializeImage_(){this.image_=new Image,null!==this.crossOrigin_&&(this.image_.crossOrigin=this.crossOrigin_)}isTainted_(){if(void 0===this.tainted_&&2===this.imageState_){J||(J=W(1,1,void 0,{willReadFrequently:!0})),J.drawImage(this.image_,0,0);try{J.getImageData(0,0,1,1),this.tainted_=!1}catch(t){J=null,this.tainted_=!0}}return!0===this.tainted_}dispatchChangeEvent_(){this.dispatchEvent(T)}handleImageError_(){this.imageState_=3,this.dispatchChangeEvent_()}handleImageLoad_(){this.imageState_=2,this.size_=[this.image_.width,this.image_.height],this.dispatchChangeEvent_()}getImage(t){return this.image_||this.initializeImage_(),this.replaceColor_(t),this.canvas_[t]?this.canvas_[t]:this.image_}getPixelRatio(t){return this.replaceColor_(t),this.canvas_[t]?t:1}getImageState(){return this.imageState_}getHitDetectionImage(){if(this.image_||this.initializeImage_(),!this.hitDetectionImage_)if(this.isTainted_()){const t=this.size_[0],e=this.size_[1],i=W(t,e);i.fillRect(0,0,t,e),this.hitDetectionImage_=i.canvas}else this.hitDetectionImage_=this.image_;return this.hitDetectionImage_}getSize(){return this.size_}getSrc(){return this.src_}load(){if(0===this.imageState_){this.image_||this.initializeImage_(),this.imageState_=1;try{void 0!==this.src_&&(this.image_.src=this.src_)}catch(t){this.handleImageError_()}this.image_ instanceof HTMLImageElement&&(t=this.image_,e=this.src_,e&&(t.src=e),t.src&&j?new Promise((e,i)=>t.decode().then(()=>e(t)).catch(n=>t.complete&&t.width?e(t):i(n))):function(t,e){return new Promise((e,i)=>{function n(){o(),e(t)}function r(){o(),i(new Error("Image load error"))}function o(){t.removeEventListener("load",n),t.removeEventListener("error",r)}t.addEventListener("load",n),t.addEventListener("error",r)})}(t)).then(t=>{this.image_=t,this.handleImageLoad_()}).catch(this.handleImageError_.bind(this))}var t,e}replaceColor_(t){if(!this.color_||this.canvas_[t]||2!==this.imageState_)return;const e=this.image_,i=document.createElement("canvas");i.width=Math.ceil(e.width*t),i.height=Math.ceil(e.height*t);const n=i.getContext("2d");var r;n.scale(t,t),n.drawImage(e,0,0),n.globalCompositeOperation="multiply",n.fillStyle="string"==typeof(r=this.color_)?r:F(r),n.fillRect(0,0,i.width/t,i.height/t),n.globalCompositeOperation="destination-in",n.drawImage(e,0,0),this.canvas_[t]=i}ready(){return this.ready_||(this.ready_=new Promise(t=>{if(2===this.imageState_||3===this.imageState_)t();else{const e=()=>{2!==this.imageState_&&3!==this.imageState_||(this.removeEventListener(T,e),t())};this.addEventListener(T,e)}})),this.ready_}}function Z(t,e,i,n,r,o){let s=void 0===e?void 0:K.get(e,i,r);return s||(s=new q(t,t&&"src"in t?t.src||void 0:e,i,n,r),K.set(e,i,r,s,o)),o&&s&&!K.getPattern(e,i,r)&&K.set(e,i,r,s,o),s}function $(t){return t?Array.isArray(t)?F(t):"object"==typeof t&&"src"in t?function(t){if(!t.offset||!t.size)return K.getPattern(t.src,"anonymous",t.color);const e=t.src+":"+t.offset,i=K.getPattern(e,void 0,t.color);if(i)return i;const n=K.get(t.src,"anonymous",null);if(2!==n.getImageState())return null;const r=W(t.size[0],t.size[1]);return r.drawImage(n.getImage(1),t.offset[0],t.offset[1],t.size[0],t.size[1],0,0,t.size[0],t.size[1]),Z(r.canvas,e,void 0,2,t.color,!0),K.getPattern(e,void 0,t.color)}(t):t:null}var Q=class extends z{constructor(){super(),this.on=this.onInternal,this.once=this.onceInternal,this.un=this.unInternal,this.revision_=0}changed(){++this.revision_,this.dispatchEvent(T)}getRevision(){return this.revision_}onInternal(t,e){if(Array.isArray(t)){const i=t.length,n=new Array(i);for(let r=0;r<i;++r)n[r]=X(this,t[r],e);return n}return X(this,t,e)}onceInternal(t,e){let i;if(Array.isArray(t)){const n=t.length;i=new Array(n);for(let r=0;r<n;++r)i[r]=U(this,t[r],e)}else i=U(this,t,e);return e.ol_key=i,i}unInternal(t,e){const i=e.ol_key;if(i)!function(t){if(Array.isArray(t))for(let e=0,i=t.length;e<i;++e)Y(t[e]);else Y(t)}(i);else if(Array.isArray(t))for(let i=0,n=t.length;i<n;++i)this.removeEventListener(t[i],e);else this.removeEventListener(t,e)}};class tt extends N{constructor(t,e,i){super(t),this.key=e,this.oldValue=i}}const et="#000",it="round",nt="round";new class extends Q{constructor(t){super(),this.ol_uid||(this.ol_uid=String(++y)),this.values_=null,void 0!==t&&this.setProperties(t)}get(t){let e;return this.values_&&this.values_.hasOwnProperty(t)&&(e=this.values_[t]),e}getKeys(){return this.values_&&Object.keys(this.values_)||[]}getProperties(){return this.values_&&Object.assign({},this.values_)||{}}getPropertiesInternal(){return this.values_}hasProperties(){return!!this.values_}notify(t,e){let i;i=`change:${t}`,this.hasListener(i)&&this.dispatchEvent(new tt(i,t,e)),i="propertychange",this.hasListener(i)&&this.dispatchEvent(new tt(i,t,e))}addChangeListener(t,e){this.addEventListener(`change:${t}`,e)}removeChangeListener(t,e){this.removeEventListener(`change:${t}`,e)}set(t,e,i){const n=this.values_||(this.values_={});if(i)n[t]=e;else{const i=n[t];n[t]=e,i!==e&&this.notify(t,i)}}setProperties(t,e){for(const i in t)this.set(i,t[i],e)}applyProperties(t){t.values_&&Object.assign(this.values_||(this.values_={}),t.values_)}unset(t,e){if(this.values_&&t in this.values_){const i=this.values_[t];delete this.values_[t],function(t){let e;for(e in t)return!1;return!e}(this.values_)&&(this.values_=null),e||this.notify(t,i)}}};class rt extends _{constructor(t){super({opacity:1,rotateWithView:void 0!==t.rotateWithView&&t.rotateWithView,rotation:void 0!==t.rotation?t.rotation:0,scale:void 0!==t.scale?t.scale:1,displacement:void 0!==t.displacement?t.displacement:[0,0],declutterMode:t.declutterMode}),this.hitDetectionCanvas_=null,this.fill_=void 0!==t.fill?t.fill:null,this.origin_=[0,0],this.points_=t.points,this.radius=t.radius,this.radius2_=t.radius2,this.angle_=void 0!==t.angle?t.angle:0,this.stroke_=void 0!==t.stroke?t.stroke:null,this.imageState_=this.fill_&&this.fill_.loading()?1:2,1===this.imageState_&&this.ready().then(()=>this.imageState_=2),this.render()}clone(){const t=this.getScale(),e=new rt({fill:this.getFill()?this.getFill().clone():void 0,points:this.getPoints(),radius:this.getRadius(),radius2:this.getRadius2(),angle:this.getAngle(),stroke:this.getStroke()?this.getStroke().clone():void 0,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),scale:Array.isArray(t)?t.slice():t,displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()});return e.setOpacity(this.getOpacity()),e}getAnchor(){const t=this.size_,e=this.getDisplacement(),i=this.getScaleArray();return[t[0]/2-e[0]/i[0],t[1]/2+e[1]/i[1]]}getAngle(){return this.angle_}getFill(){return this.fill_}setFill(t){this.fill_=t,this.render()}getHitDetectionImage(){return this.hitDetectionCanvas_||(this.hitDetectionCanvas_=this.createHitDetectionCanvas_(this.renderOptions_)),this.hitDetectionCanvas_}getImage(t){let e=this.canvases_[t];if(!e){const i=this.renderOptions_,n=W(i.size*t,i.size*t);this.draw_(i,n,t),e=n.canvas,this.canvases_[t]=e}return e}getPixelRatio(t){return t}getImageSize(){return this.size_}getImageState(){return this.imageState_}getOrigin(){return this.origin_}getPoints(){return this.points_}getRadius(){return this.radius}getRadius2(){return this.radius2_}getSize(){return this.size_}getStroke(){return this.stroke_}setStroke(t){this.stroke_=t,this.render()}listenImageChange(t){}load(){}unlistenImageChange(t){}calculateLineJoinSize_(t,e,i){if(0===e||Infinity===this.points_||"bevel"!==t&&"miter"!==t)return e;let n=this.radius,r=void 0===this.radius2_?n:this.radius2_;if(n<r){const t=n;n=r,r=t}const o=2*Math.PI/(void 0===this.radius2_?this.points_:2*this.points_),s=r*Math.sin(o),a=n-Math.sqrt(r*r-s*s),l=Math.sqrt(s*s+a*a),c=l/s;if("miter"===t&&c<=i)return c*e;const h=e/2/c,d=e/2*(a/l),u=Math.sqrt((n+h)*(n+h)+d*d)-n;if(void 0===this.radius2_||"bevel"===t)return 2*u;const g=n*Math.sin(o),p=r-Math.sqrt(n*n-g*g),f=Math.sqrt(g*g+p*p)/g;return f<=i?2*Math.max(u,f*e/2-r-n):2*u}createRenderOptions(){let t,e=it,i=nt,n=0,r=null,o=0,s=0;this.stroke_&&(t=$(this.stroke_.getColor()??"#000"),s=this.stroke_.getWidth()??1,r=this.stroke_.getLineDash(),o=this.stroke_.getLineDashOffset()??0,i=this.stroke_.getLineJoin()??nt,e=this.stroke_.getLineCap()??it,n=this.stroke_.getMiterLimit()??10);const a=this.calculateLineJoinSize_(i,s,n),l=Math.max(this.radius,this.radius2_||0);return{strokeStyle:t,strokeWidth:s,size:Math.ceil(2*l+a),lineCap:e,lineDash:r,lineDashOffset:o,lineJoin:i,miterLimit:n}}render(){this.renderOptions_=this.createRenderOptions();const t=this.renderOptions_.size;this.canvases_={},this.hitDetectionCanvas_=null,this.size_=[t,t]}draw_(t,e,i){if(e.scale(i,i),e.translate(t.size/2,t.size/2),this.createPath_(e),this.fill_){let t=this.fill_.getColor();null===t&&(t=et),e.fillStyle=$(t),e.fill()}t.strokeStyle&&(e.strokeStyle=t.strokeStyle,e.lineWidth=t.strokeWidth,t.lineDash&&(e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset),e.lineCap=t.lineCap,e.lineJoin=t.lineJoin,e.miterLimit=t.miterLimit,e.stroke())}createHitDetectionCanvas_(t){let e;if(this.fill_){let i=this.fill_.getColor(),n=0;"string"==typeof i&&(i=k(i)),null===i?n=1:Array.isArray(i)&&(n=4===i.length?i[3]:1),0===n&&(e=W(t.size,t.size),this.drawHitDetectionCanvas_(t,e))}return e?e.canvas:this.getImage(1)}createPath_(t){let e=this.points_;const i=this.radius;if(Infinity===e)t.arc(0,0,i,0,2*Math.PI);else{const n=void 0===this.radius2_?i:this.radius2_;void 0!==this.radius2_&&(e*=2);const r=this.angle_-Math.PI/2,o=2*Math.PI/e;for(let s=0;s<e;s++){const e=r+s*o,a=s%2==0?i:n;t.lineTo(a*Math.cos(e),a*Math.sin(e))}t.closePath()}}drawHitDetectionCanvas_(t,e){e.translate(t.size/2,t.size/2),this.createPath_(e),e.fillStyle=et,e.fill(),t.strokeStyle&&(e.strokeStyle=t.strokeStyle,e.lineWidth=t.strokeWidth,t.lineDash&&(e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset),e.lineJoin=t.lineJoin,e.miterLimit=t.miterLimit,e.stroke())}ready(){return this.fill_?this.fill_.ready():Promise.resolve()}}var ot=rt;class st extends ot{constructor(t){super({points:Infinity,fill:(t=t||{radius:5}).fill,radius:t.radius,stroke:t.stroke,scale:void 0!==t.scale?t.scale:1,rotation:void 0!==t.rotation?t.rotation:0,rotateWithView:void 0!==t.rotateWithView&&t.rotateWithView,displacement:void 0!==t.displacement?t.displacement:[0,0],declutterMode:t.declutterMode})}clone(){const t=this.getScale(),e=new st({fill:this.getFill()?this.getFill().clone():void 0,stroke:this.getStroke()?this.getStroke().clone():void 0,radius:this.getRadius(),scale:Array.isArray(t)?t.slice():t,rotation:this.getRotation(),rotateWithView:this.getRotateWithView(),displacement:this.getDisplacement().slice(),declutterMode:this.getDeclutterMode()});return e.setOpacity(this.getOpacity()),e}setRadius(t){this.radius=t,this.render()}}var at=st;class lt{constructor(t){t=t||{},this.patternImage_=null,this.color_=null,void 0!==t.color&&this.setColor(t.color)}clone(){const t=this.getColor();return new lt({color:Array.isArray(t)?t.slice():t||void 0})}getColor(){return this.color_}setColor(t){if(null!==t&&"object"==typeof t&&"src"in t){const e=Z(null,t.src,"anonymous",void 0,t.offset?null:t.color?t.color:null,!(t.offset&&t.size));e.ready().then(()=>{this.patternImage_=null}),0===e.getImageState()&&e.load(),1===e.getImageState()&&(this.patternImage_=e)}this.color_=t}loading(){return!!this.patternImage_}ready(){return this.patternImage_?this.patternImage_.ready():Promise.resolve()}}var ct=lt;class ht{constructor(t){this.color_=void 0!==(t=t||{}).color?t.color:null,this.lineCap_=t.lineCap,this.lineDash_=void 0!==t.lineDash?t.lineDash:null,this.lineDashOffset_=t.lineDashOffset,this.lineJoin_=t.lineJoin,this.miterLimit_=t.miterLimit,this.width_=t.width}clone(){const t=this.getColor();return new ht({color:Array.isArray(t)?t.slice():t||void 0,lineCap:this.getLineCap(),lineDash:this.getLineDash()?this.getLineDash().slice():void 0,lineDashOffset:this.getLineDashOffset(),lineJoin:this.getLineJoin(),miterLimit:this.getMiterLimit(),width:this.getWidth()})}getColor(){return this.color_}getLineCap(){return this.lineCap_}getLineDash(){return this.lineDash_}getLineDashOffset(){return this.lineDashOffset_}getLineJoin(){return this.lineJoin_}getMiterLimit(){return this.miterLimit_}getWidth(){return this.width_}setColor(t){this.color_=t}setLineCap(t){this.lineCap_=t}setLineDash(t){this.lineDash_=t}setLineDashOffset(t){this.lineDashOffset_=t}setLineJoin(t){this.lineJoin_=t}setMiterLimit(t){this.miterLimit_=t}setWidth(t){this.width_=t}}var dt=ht;class ut{constructor(t){t=t||{},this.geometry_=null,this.geometryFunction_=gt,void 0!==t.geometry&&this.setGeometry(t.geometry),this.fill_=void 0!==t.fill?t.fill:null,this.image_=void 0!==t.image?t.image:null,this.renderer_=void 0!==t.renderer?t.renderer:null,this.hitDetectionRenderer_=void 0!==t.hitDetectionRenderer?t.hitDetectionRenderer:null,this.stroke_=void 0!==t.stroke?t.stroke:null,this.text_=void 0!==t.text?t.text:null,this.zIndex_=t.zIndex}clone(){let t=this.getGeometry();return t&&"object"==typeof t&&(t=t.clone()),new ut({geometry:t??void 0,fill:this.getFill()?this.getFill().clone():void 0,image:this.getImage()?this.getImage().clone():void 0,renderer:this.getRenderer()??void 0,stroke:this.getStroke()?this.getStroke().clone():void 0,text:this.getText()?this.getText().clone():void 0,zIndex:this.getZIndex()})}getRenderer(){return this.renderer_}setRenderer(t){this.renderer_=t}setHitDetectionRenderer(t){this.hitDetectionRenderer_=t}getHitDetectionRenderer(){return this.hitDetectionRenderer_}getGeometry(){return this.geometry_}getGeometryFunction(){return this.geometryFunction_}getFill(){return this.fill_}setFill(t){this.fill_=t}getImage(){return this.image_}setImage(t){this.image_=t}getStroke(){return this.stroke_}setStroke(t){this.stroke_=t}getText(){return this.text_}setText(t){this.text_=t}getZIndex(){return this.zIndex_}setGeometry(t){"function"==typeof t?this.geometryFunction_=t:"string"==typeof t?this.geometryFunction_=function(e){return e.get(t)}:t?void 0!==t&&(this.geometryFunction_=function(){return t}):this.geometryFunction_=gt,this.geometry_=t}setZIndex(t){this.zIndex_=t}}function gt(t){return t.getGeometry()}var pt=ut;const ft={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var yt=class{constructor(t){this.code_=t.code,this.units_=t.units,this.extent_=void 0!==t.extent?t.extent:null,this.worldExtent_=void 0!==t.worldExtent?t.worldExtent:null,this.axisOrientation_=void 0!==t.axisOrientation?t.axisOrientation:"enu",this.global_=void 0!==t.global&&t.global,this.canWrapX_=!(!this.global_||!this.extent_),this.getPointResolutionFunc_=t.getPointResolution,this.defaultTileGrid_=null,this.metersPerUnit_=t.metersPerUnit}canWrapX(){return this.canWrapX_}getCode(){return this.code_}getExtent(){return this.extent_}getUnits(){return this.units_}getMetersPerUnit(){return this.metersPerUnit_||ft[this.units_]}getWorldExtent(){return this.worldExtent_}getAxisOrientation(){return this.axisOrientation_}isGlobal(){return this.global_}setGlobal(t){this.global_=t,this.canWrapX_=!(!t||!this.extent_)}getDefaultTileGrid(){return this.defaultTileGrid_}setDefaultTileGrid(t){this.defaultTileGrid_=t}setExtent(t){this.extent_=t,this.canWrapX_=!(!this.global_||!t)}setWorldExtent(t){this.worldExtent_=t}setGetPointResolution(t){this.getPointResolutionFunc_=t}getPointResolutionFunc(){return this.getPointResolutionFunc_}};const vt=6378137,mt=Math.PI*vt,_t=[-mt,-mt,mt,mt],Ct=[-180,-85,180,85],Pt=vt*Math.log(Math.tan(Math.PI/2));class xt extends yt{constructor(t){super({code:t,units:"m",extent:_t,global:!0,worldExtent:Ct,getPointResolution:function(t,e){return t/Math.cosh(e[1]/vt)}})}}const Mt=[new xt("EPSG:3857"),new xt("EPSG:102100"),new xt("EPSG:102113"),new xt("EPSG:900913"),new xt("http://www.opengis.net/def/crs/EPSG/0/3857"),new xt("http://www.opengis.net/gml/srs/epsg.xml#3857")],wt=[-180,-90,180,90],bt=6378137*Math.PI/180;class St extends yt{constructor(t,e){super({code:t,units:"degrees",extent:wt,axisOrientation:e,global:!0,metersPerUnit:bt,worldExtent:wt})}}const Et=[new St("CRS:84"),new St("EPSG:4326","neu"),new St("urn:ogc:def:crs:OGC:1.3:CRS84"),new St("urn:ogc:def:crs:OGC:2:84"),new St("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new St("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new St("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let It={},Dt={};function kt(t,e,i){const n=t.getCode(),r=e.getCode();n in Dt||(Dt[n]={}),Dt[n][r]=i}function Ft(t,e){if(void 0!==e)for(let i=0,n=t.length;i<n;++i)e[i]=t[i];else e=t.slice();return e}function Ot(t,e){if(void 0!==e&&t!==e){for(let i=0,n=t.length;i<n;++i)e[i]=t[i];t=e}return t}function Lt(t){!function(t,e){It[t]=e}(t.getCode(),t),kt(t,t,Ft)}function jt(t){return"string"==typeof t?It[e=t]||It[e.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/,"EPSG:$3")]||null:t||null;var e}function Wt(t){!function(t){t.forEach(Lt)}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&kt(e,t,Ft)})})}function Bt(t,e,i){const n=function(t,e){return function(t,e){let i=function(t,e){let i;return t in Dt&&e in Dt[t]&&(i=Dt[t][e]),i}(t.getCode(),e.getCode());return i||(i=Ot),i}(jt(t),jt(e))}(e,i);return n(t,void 0,t.length)}var At,Gt,Nt;Wt(Mt),Wt(Et),At=Mt,Gt=function(t,e,i){const n=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(n));for(let r=0;r<n;r+=i){e[r]=mt*t[r]/180;let i=vt*Math.log(Math.tan(Math.PI*(+t[r+1]+90)/360));i>Pt?i=Pt:i<-Pt&&(i=-Pt),e[r+1]=i}return e},Nt=function(t,e,i){const n=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(n));for(let r=0;r<n;r+=i)e[r]=180*t[r]/mt,e[r+1]=360*Math.atan(Math.exp(t[r+1]/vt))/Math.PI-90;return e},Et.forEach(function(t){At.forEach(function(e){kt(t,e,Gt),kt(e,t,Nt)})});var Rt,Vt=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).stylingFunction=function(){return{}},i._lib=void 0,i._map=void 0,i._container=void 0,i._projection="EPSG:3857",i._vectorSource=void 0,i._geoJSONReader=void 0,i._map=e.map,i._lib=e.lib,i._geoJSONReader=new i._lib.GeoJSON,i._container=i._map.getViewport(),i._container.setAttribute("tabindex","0");var n=new i._lib.VectorSource({features:[]});i._vectorSource=n;var r=new i._lib.VectorLayer({source:n,style:function(t){return i.getStyles(t,i.stylingFunction())}});return i._map.addLayer(r),i}o(e,t);var i=e.prototype;return i.hexToRGB=function(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}},i.getStyles=function(t,e){var i=this,n=t.getGeometry();if(n)return{Point:function(t){var n=t.getProperties(),r=e[n.mode]({type:"Feature",geometry:{type:"Point",coordinates:[]},properties:n});return new i._lib.Style({image:new at({radius:r.pointWidth,fill:new ct({color:r.pointColor}),stroke:new dt({color:r.pointOutlineColor,width:r.pointOutlineWidth})})})},LineString:function(t){var n=t.getProperties(),r=e[n.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:n});return new i._lib.Style({stroke:new i._lib.Stroke({color:r.lineStringColor,width:r.lineStringWidth})})},Polygon:function(t){var n=t.getProperties(),r=e[n.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:n}),o=i.hexToRGB(r.polygonFillColor),s=o.r,a=o.g,l=o.b;return new pt({stroke:new dt({color:r.polygonOutlineColor,width:r.polygonOutlineWidth}),fill:new ct({color:"rgba("+s+","+a+","+l+","+r.polygonFillOpacity+")"})})}}[n.getType()](t)},i.clearLayers=function(){this._vectorSource&&this._vectorSource.clear()},i.addFeature=function(t){if(!this._vectorSource||!this._geoJSONReader)throw new Error("Vector Source not initalised");var e=this._geoJSONReader.readFeature(t,{featureProjection:this._projection});this._vectorSource.addFeature(e)},i.removeFeature=function(t){if(!this._vectorSource)throw new Error("Vector Source not initalised");var e=this._vectorSource.getFeatureById(t);e&&this._vectorSource.removeFeature(e)},i.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t),i=e.containerX,n=e.containerY;try{return this.unproject(i,n)}catch(t){return null}},i.getMapEventElement=function(){var t=this._container.querySelectorAll("canvas");if(t.length>1)throw Error("Terra Draw currently only supports 1 canvas with OpenLayers");return t[0]},i.setDraggability=function(t){this._map.getInteractions().forEach(function(e){"DragPan"===e.constructor.name&&e.setActive(t)})},i.project=function(t,e){var i=this._map.getPixelFromCoordinate(Bt([t,e],"EPSG:4326","EPSG:3857"));return{x:i[0],y:i[1]}},i.unproject=function(t,e){var i=function(t,e){const i=Bt(t,"EPSG:3857","EPSG:4326"),n=i[0];return(n<-180||n>180)&&(i[0]=function(t,e){const i=t%360;return 360*i<0?i+360:i}(n+180)-180),i}(this._map.getCoordinateFromPixel([t,e]));return{lng:i[0],lat:i[1]}},i.setCursor=function(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t},i.setDoubleClickToZoom=function(t){this._map.getInteractions().forEach(function(e){"DoubleClickZoom"===e.constructor.name&&e.setActive(t)})},i.render=function(t,e){var i=this;if(this.stylingFunction=function(){return e},!this._vectorSource)throw new Error("Vector Layer source has disappeared");t.deletedIds.forEach(function(t){i.removeFeature(t)}),t.updated.forEach(function(t){i.removeFeature(t.id),i.addFeature(t)}),t.created.forEach(function(t){i.addFeature(t)})},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},i.register=function(e){t.prototype.register.call(this,e),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.unregister=function(){return t.prototype.unregister.call(this)},e}(h),zt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._lib=void 0,i._mapView=void 0,i._container=void 0,i._featureIdAttributeName="__tdId",i._featureLayerName="__terraDrawFeatures",i._featureLayer=void 0,i._dragEnabled=!0,i._zoomEnabled=!0,i._dragHandler=void 0,i._doubleClickHandler=void 0,i._mapView=e.map,i._lib=e.lib,i._container=i._mapView.container,i._featureLayer=new i._lib.GraphicsLayer({id:i._featureLayerName}),i._mapView.map.add(i._featureLayer),i}o(e,t);var i=e.prototype;return i.register=function(e){var i=this;t.prototype.register.call(this,e),this._dragHandler=this._mapView.on("drag",function(t){i._dragEnabled||t.stopPropagation()}),this._doubleClickHandler=this._mapView.on("double-click",function(t){i._zoomEnabled||t.stopPropagation()}),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()},i.unregister=function(){t.prototype.unregister.call(this),this._dragHandler&&this._dragHandler.remove(),this._doubleClickHandler&&this._doubleClickHandler.remove()},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t);return this.unproject(e.containerX,e.containerY)},i.getMapEventElement=function(){return this._container.querySelector(".esri-view-surface")},i.setDraggability=function(t){this._dragEnabled=t},i.project=function(t,e){var i=new this._lib.Point({longitude:t,latitude:e}),n=this._mapView.toScreen(i);return{x:n.x,y:n.y}},i.unproject=function(t,e){var i=this._mapView.toMap({x:t,y:e});return{lng:i.longitude,lat:i.latitude}},i.setCursor=function(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t},i.setDoubleClickToZoom=function(t){this._zoomEnabled=t},i.render=function(t,e){var i=this;t.created.forEach(function(t){i.addFeature(t,e)}),t.updated.forEach(function(t){i.removeFeatureById(t.id),i.addFeature(t,e)}),t.deletedIds.forEach(function(t){i.removeFeatureById(t)})},i.clear=function(){this._featureLayer.graphics.removeAll()},i.removeFeatureById=function(t){var e=this,i=this._featureLayer.graphics.find(function(i){return i.attributes[e._featureIdAttributeName]===t});this._featureLayer.remove(i)},i.addFeature=function(t,e){var i,n=t.geometry,r=n.coordinates,o=n.type,s=e[t.properties.mode](t),a=void 0,l=void 0;switch(o){case"Point":l=new this._lib.Point({latitude:r[1],longitude:r[0]}),a=new this._lib.SimpleMarkerSymbol({color:this.getColorFromHex(s.pointColor),size:2*s.pointWidth+"px",outline:{color:this.getColorFromHex(s.pointOutlineColor),width:s.pointOutlineWidth+"px"}});break;case"LineString":l=new this._lib.Polyline({paths:[r]}),a=new this._lib.SimpleLineSymbol({color:this.getColorFromHex(s.lineStringColor),width:s.lineStringWidth+"px"});break;case"Polygon":l=new this._lib.Polygon({rings:r}),a=new this._lib.SimpleFillSymbol({color:this.getColorFromHex(s.polygonFillColor,s.polygonFillOpacity),outline:{color:this.getColorFromHex(s.polygonOutlineColor),width:s.polygonOutlineWidth+"px"}})}var c=new this._lib.Graphic({geometry:l,symbol:a,attributes:(i={},i[this._featureIdAttributeName]=t.id,i)});"Point"===o?this._featureLayer.graphics.add(c):this._featureLayer.graphics.add(c,0)},i.getColorFromHex=function(t,e){var i=this._lib.Color.fromHex(t);return e&&(i.a=e),i},e}(h);!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(Rt||(Rt={}));var Tt,Xt="selected",Ut="midPoint",Yt="closingPoint";function Ht(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function Kt(t){if(!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t))throw new Error("updatedAt and createdAt are not valid timestamps");return!0}!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(Tt||(Tt={}));var Jt=/*#__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=Tt.Drawing,this.mode="base",this._state="unregistered",this._styles=t&&t.styles?r({},t.styles):{},this.pointerDistance=t&&t.pointerDistance||40,this.validate=t&&t.validation,this.projection=t&&t.projection||"web-mercator"}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){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var i;if(Ht(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(Ht(t.geometry))if(Ht(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)throw new Error("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";if(i)throw new Error(i);return!0}(t,this.store.idStrategy.isValidId);return this.validate?this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Provisional}):e},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,i){return this.getStylingValue(t,e,i)},t.getNumericStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},t.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?t(i):t},n(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}(),qt=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];return(e=t.call.apply(t,[this].concat(n))||this).type=Tt.Select,e}return o(e,t),e}(Jt);function Zt(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),r=i(t[0]),o=i(e[1]),s=o-n,a=i(e[0])-r,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(o)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}var $t=6371008.8;function Qt(t){return t%360*Math.PI/180}function te(t){return t/($t/1e3)}function ee(t){return t%(2*Math.PI)*180/Math.PI}var ie=57.29577951308232,ne=.017453292519943295,re=6378137,oe=function(t,e){return{x:0===t?0:t*ne*re,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*ne/2))*re}},se=function(t,e){return{lng:0===t?0:ie*(t/re),lat:0===e?0:(2*Math.atan(Math.exp(e/re))-Math.PI/2)*ie}};function ae(t,e,i){var n=Qt(t[0]),r=Qt(t[1]),o=Qt(i),s=te(e),a=Math.asin(Math.sin(r)*Math.cos(s)+Math.cos(r)*Math.sin(s)*Math.cos(o));return[ee(n+Math.atan2(Math.sin(o)*Math.sin(s)*Math.cos(r),Math.cos(s)-Math.sin(r)*Math.sin(a))),ee(a)]}function le(t){for(var e=t.center,i=t.radiusKilometers,n=t.coordinatePrecision,r=t.steps?t.steps:64,o=[],s=0;s<r;s++){var l=ae(e,i,-360*s/r);o.push([a(l[0],n),a(l[1],n)])}return o.push(o[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[o]},properties:{}}}function ce(t){var e,i={epsilon:0};if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var n=[],r=0;r<e.length;r++)for(var o=0;o<e[r].length-1;o++)for(var s=0;s<e.length;s++)for(var a=0;a<e[s].length-1;a++)c(r,o,s,a);return n.length>0;function l(t){return t<0-i.epsilon||t>1+i.epsilon}function c(t,i,r,o){var s,a=e[t][i],c=e[t][i+1],h=e[r][o],d=e[r][o+1],u=function(t,e,i,n){if(he(t,i)||he(t,n)||he(e,i)||he(n,i))return null;var r=t[0],o=t[1],s=e[0],a=e[1],l=i[0],c=i[1],h=n[0],d=n[1],u=(r-s)*(c-d)-(o-a)*(l-h);return 0===u?null:[((r*a-o*s)*(l-h)-(r-s)*(l*d-c*h))/u,((r*a-o*s)*(c-d)-(o-a)*(l*d-c*h))/u]}(a,c,h,d);null!==u&&(s=d[0]!==h[0]?(u[0]-h[0])/(d[0]-h[0]):(u[1]-h[1])/(d[1]-h[1]),l(c[0]!==a[0]?(u[0]-a[0])/(c[0]-a[0]):(u[1]-a[1])/(c[1]-a[1]))||l(s)||(u.toString(),n.push(u)))}}function he(t,e){return t[0]===e[0]&&t[1]===e[1]}function de(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(n=t[0])>=-180&&n<=180&&(i=t[1])>=-90&&i<=90&&ue(t[0])<=e&&ue(t[1])<=e;var i,n}function ue(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}function ge(t,e){return"Polygon"===t.geometry.type&&1===t.geometry.coordinates.length&&t.geometry.coordinates[0].length>=4&&t.geometry.coordinates[0].every(function(t){return de(t,e)})&&(i=t.geometry.coordinates[0][0])[0]===(n=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]&&i[1]===n[1];var i,n}function pe(t,e){return ge(t,e)&&!ce(t)}var fe=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).mode="circle",n.center=void 0,n.clickCount=0,n.currentCircleId=void 0,n.keyEvents=void 0,n.cursors=void 0,n.startingRadiusKilometers=1e-5;var o={start:"crosshair"};if(n.cursors=e&&e.cursors?r({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))n.keyEvents={cancel:null,finish:null};else{var s={cancel:"Escape",finish:"Enter"};n.keyEvents=e&&e.keyEvents?r({},s,e.keyEvents):s}return n.startingRadiusKilometers=null!=(i=null==e?void 0:e.startingRadiusKilometers)?i:1e-5,n.validate=null==e?void 0:e.validation,n}o(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentCircleId){var t=this.currentCircleId;if(this.validate&&t){var e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Finish}))return}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=le({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=i[0],this.clickCount++,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.updateCircle(t),this.close()},i.onMouseMove=function(t){this.updateCircle(t)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t])}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&pe(e,this.coordinatePrecision)},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=Zt(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var n=function(t,e){var i=1e3*Zt(t,e);if(0===i)return 1;var n=oe(t[0],t[1]),r=n.x,o=n.y,s=oe(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-r,2)+Math.pow(a-o,2))/i}(this.center,[t.lng,t.lat]);e=function(t){for(var e=t.center,i=t.coordinatePrecision,n=t.steps?t.steps:64,r=1e3*t.radiusKilometers,o=oe(e[0],e[1]),s=o.x,l=o.y,c=[],h=0;h<n;h++){var d=360*h/n*Math.PI/180,u=r*Math.cos(d),g=r*Math.sin(d),p=se(s+u,l+g),f=p.lat;c.push([a(p.lng,i),a(f,i)])}return c.push(c[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[c]},properties:{}}}({center:this.center,radiusKilometers:i*n,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");e=le({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision})}if(this.validate&&!this.validate({type:"Feature",id:this.currentCircleId,geometry:e.geometry,properties:{radiusKilometers:i}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Provisional}))return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},e}(Jt),ye=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="freehand",i.startingClick=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=void 0,i.keyEvents=void 0,i.cursors=void 0,i.preventPointsNearClose=void 0;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,i.preventPointsNearClose=e&&e.preventPointsNearClose||!0,i.minDistance=e&&e.minDistance||20,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i.validate=null==e?void 0:e.validation,i}o(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.currentId;if(this.validate&&t){var e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Finish}))return}this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(void 0!==this.currentId&&!1!==this.startingClick){var e=this.store.getGeometryCopy(this.currentId),i=e.coordinates[0][e.coordinates[0].length-2],n=this.project(i[0],i[1]),r=l({x:n.x,y:n.y},{x:t.containerX,y:t.containerY}),o=e.coordinates[0][0],s=this.project(o[0],o[1]);if(l({x:s.x,y:s.y},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.setCursor(this.cursors.start);if(!(r<this.minDistance)){e.coordinates[0].pop();var a={type:"Polygon",coordinates:[[].concat(e.coordinates[0],[[t.lng,t.lat],e.coordinates[0][0]])]};if(this.validate&&!this.validate({type:"Feature",id:this.currentId,geometry:a,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Provisional}))return;this.store.updateGeometry([{id:this.currentId,geometry:a}])}}},i.onClick=function(t){if(!1===this.startingClick){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]),i=e[1];return this.currentId=e[0],this.closingPointId=i,this.startingClick=!0,void this.setDrawing()}this.close()},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==e&&this.store.delete([e])}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=40,e):e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ge(e,this.coordinatePrecision)},e}(Jt),ve=function(t){var e=t.store,i=t.mode,n=t.project,r=t.unproject,o=t.pointerDistance,s=t.coordinatePrecision,a=t.projection;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.store=e,this.mode=i,this.project=n,this.unproject=r,this.pointerDistance=o,this.coordinatePrecision=s,this.projection=a};function me(t){var e=t.unproject,i=t.point,n=t.pointerDistance/2,r=i.x,o=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(r-n,o-n),e(r+n,o-n),e(r+n,o+n),e(r-n,o+n),e(r-n,o-n)].map(function(t){return[t.lng,t.lat]})]}}}var _e=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.create=function(t){return me({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(ve),Ce=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return l({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(ve),Pe=/*#__PURE__*/function(t){function e(e,i,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.clickBoundingBox=void 0,r.getSnappableCoordinateFirstClick=function(t){return r.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===r.mode)})},r.getSnappableCoordinate=function(t,e){return r.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===r.mode&&t.id!==e)})},r.config=e,r.pixelDistance=i,r.clickBoundingBox=n,r}return o(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),r=this.store.search(n,e),o={coord:void 0,minDist:Infinity};return r.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(e){var n=i.pixelDistance.measure(t,e);n<o.minDist&&n<i.pointerDistance&&(o.coord=e,o.minDist=n)})}),o.coord},e}(ve);function xe(t,e,i){var n=Qt(t[0]),r=Qt(t[1]),o=Qt(i),s=te(e),a=Math.asin(Math.sin(r)*Math.cos(s)+Math.cos(r)*Math.sin(s)*Math.cos(o));return[ee(n+Math.atan2(Math.sin(o)*Math.sin(s)*Math.cos(r),Math.cos(s)-Math.sin(r)*Math.sin(a))),ee(a)]}function Me(t,e,i){var n=t.x,r=t.y,o=Qt(i);return{x:n+e*Math.cos(o),y:r+e*Math.sin(o)}}function we(t,e){var i=Qt(t[0]),n=Qt(e[0]),r=Qt(t[1]),o=Qt(e[1]),s=Math.sin(n-i)*Math.cos(o),a=Math.cos(r)*Math.sin(o)-Math.sin(r)*Math.cos(o)*Math.cos(n-i);return ee(Math.atan2(s,a))}function be(t,e){var i=Math.atan2(e.y-t.y,e.x-t.x);return(i*=180/Math.PI)>180?i-=360:i<-180&&(i+=360),i}function Se(t,e,i){for(var n,r,o,s=[],a=t.length,l=0,c=0;c<t.length&&!(e>=l&&c===t.length-1);c++){if(l>e&&0===s.length){if(!(n=e-l))return s.push(t[c]),s;r=we(t[c],t[c-1])-180,o=xe(t[c],n,r),s.push(o)}if(l>=i)return(n=i-l)?(r=we(t[c],t[c-1])-180,o=xe(t[c],n,r),s.push(o),s):(s.push(t[c]),s);if(l>=e&&s.push(t[c]),c===t.length-1)return s;l+=Zt(t[c],t[c+1])}if(l<e&&t.length===a)throw new Error("Start position is beyond line");var h=t[t.length-1];return[h,h]}function Ee(t){return t*(Math.PI/180)}function Ie(t){return t*(180/Math.PI)}var De=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}o(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var n=[t,e],r=0,o=0;o<n.length-1;o++)r+=Zt(n[0],n[1]);if(r<=i)return n;var s=r/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],l=0;l<s;l++){var c=Se(n,i*l,i*(l+1));a.push(c)}for(var h=[],d=0;d<a.length;d++)h.push(a[d][1]);return this.limitCoordinates(h)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var n=Zt(t,e),r=function(t,e,i){var n=[],r=Ee(t[1]),o=Ee(t[0]),s=Ee(e[1]),a=Ee(e[0]);i+=1;var l=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-r)/2),2)+Math.cos(r)*Math.cos(s)*Math.pow(Math.sin((a-o)/2),2)));if(0===l||isNaN(l))return n;for(var c=0;c<=i;c++){var h=c/i,d=Math.sin((1-h)*l)/Math.sin(l),u=Math.sin(h*l)/Math.sin(l),g=d*Math.cos(r)*Math.cos(o)+u*Math.cos(s)*Math.cos(a),p=d*Math.cos(r)*Math.sin(o)+u*Math.cos(s)*Math.sin(a),f=d*Math.sin(r)+u*Math.sin(s);if(!(isNaN(g)||isNaN(p)||isNaN(f))){var y=Math.atan2(f,Math.sqrt(Math.pow(g,2)+Math.pow(p,2))),v=Math.atan2(p,g);isNaN(y)||isNaN(v)||n.push([Ie(v),Ie(y)])}}return n.slice(1,-1)}(t,e,Math.floor(n/i));return this.limitCoordinates(r)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[a(t[0],e.config.coordinatePrecision),a(t[1],e.config.coordinatePrecision)]})},e}(ve);function ke(t,e){return t[0]===e[0]&&t[1]===e[1]}var Fe=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.closingPointId=void 0,i.keyEvents=void 0,i.snappingEnabled=void 0,i.cursors=void 0,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommitedCoordinates=void 0,i.snapping=void 0,i.insertPoint=void 0;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,i.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i.validate=null==e?void 0:e.validation,i.insertCoordinates=null==e?void 0:e.insertCoordinates,i}o(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.updateGeometries([].concat(t.coordinates),void 0,Rt.Commit);var e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.lastCommitedCoordinates=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}},i.updateGeometries=function(t,e,i){if(this.currentId){var n={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}))return;var r=[{id:this.currentId,geometry:n}];this.closingPointId&&e&&r.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=n.coordinates),this.store.updateGeometry(r)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=Zt(t,e)/(this.insertCoordinates.value+1),n=[];return"globe"===this.projection?n=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(n=this.insertPoint.generateInsertionCoordinates(t,e,i)),n},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var n=[].concat(e,[t]);this.updateGeometries(n,void 0,Rt.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,n=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],r=this.project(n[0],n[1]);if(l({x:r.x,y:r.y},{x:e.x,y:e.y})<this.pointerDistance)this.close();else{this.setCursor(this.cursors.close);var o=[].concat(i,[t]);this.updateGeometries(o,i[i.length-1],Rt.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.snapping=new Pe(t,new Ce(t),new _e(t)),this.insertPoint=new De(t)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId).coordinates;e.pop();var i=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(this.closingPointId){var n=e[e.length-1],r=this.project(n[0],n[1]);l({x:r.x,y:r.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var o=[].concat(e,[i]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var s=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],a=i;if(!ke(s,a)){var c=this.generateInsertCoordinates(s,a);o=[].concat(this.lastCommitedCoordinates.slice(0,-1),c,[i])}}this.updateGeometries(o,void 0,Rt.Provisional)}},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1;var e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];0===this.currentCoordinate?this.createLine(e):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(e,{x:t.containerX,y:t.containerY})},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode?(e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=10,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=40,e):e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&"LineString"===e.geometry.type&&e.properties.mode===this.mode&&e.geometry.coordinates.length>=2},e}(Jt);function Oe(t,e){return"Point"===t.geometry.type&&de(t.geometry.coordinates,e)}var Le=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="point",i.cursors=void 0;var n={create:"crosshair"};return i.cursors=e&&e.cursors?r({},n,e.cursors):n,i}o(e,t);var i=e.prototype;return i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");var e={type:"Point",coordinates:[t.lng,t.lat]},i={mode:this.mode};if(!this.validate||this.validate({type:"Feature",geometry:e,properties:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Finish})){var n=this.store.create([{geometry:e,properties:i}]);this.onFinish(n[0],{mode:this.mode,action:"draw"})}},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(e.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,t),e.zIndex=30),e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&Oe(e,this.coordinatePrecision)},e}(Jt),je=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n._startEndPoints=[],n.config=e,n.pixelDistance=i,n}o(e,t);var i=e.prototype;return i.create=function(t,e){var i,n;if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i[Yt]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(n={mode:e},n[Yt]=!0,n)}])},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},i.update=function(t){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:t[t.length-3]}}])},i.isClosingPoint=function(t){var e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),n=this.pixelDistance.measure(t,e.coordinates),r=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:r<this.pointerDistance}},n(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}]),e}(ve),We=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.snappingEnabled=void 0,i.snapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,i.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i}o(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId).coordinates[0];if(!(t.length<5)&&this.updatePolygonGeometry([].concat(t.slice(0,-2),[t[0]]),Rt.Finish)){var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}}},i.registerBehaviors=function(t){this.pixelDistance=new Ce(t),this.snapping=new Pe(t,this.pixelDistance,new _e(t)),this.closingPoints=new je(t,this.pixelDistance)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,n=this.store.getGeometryCopy(this.currentId).coordinates[0];if(i&&(t.lng=i[0],t.lat=i[1]),1===this.currentCoordinate){var r=1/Math.pow(10,this.coordinatePrecision-1),o=Math.max(1e-6,r);e=[n[0],[t.lng,t.lat],[t.lng,t.lat-o],n[0]]}else if(2===this.currentCoordinate)e=[n[0],n[1],[t.lng,t.lat],n[0]];else{var s=this.closingPoints.isClosingPoint(t);s.isPreviousClosing||s.isClosing?(this.setCursor(this.cursors.close),e=[].concat(n.slice(0,-2),[n[0],n[0]])):e=[].concat(n.slice(0,-2),[[t.lng,t.lat],n[0]])}this.updatePolygonGeometry(e,Rt.Provisional)}},i.updatePolygonGeometry=function(t,e){if(!this.currentId)return!1;var i={type:"Polygon",coordinates:[t]};return!(this.validate&&!this.validate({type:"Feature",geometry:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e})||(this.store.updateGeometry([{id:this.currentId,geometry:i}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.snappingEnabled?this.snapping.getSnappableCoordinateFirstClick(t):void 0;e&&(t.lng=e[0],t.lat=e[1]);var i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;n&&(t.lng=n[0],t.lat=n[1]);var r=this.store.getGeometryCopy(this.currentId);if(ke([t.lng,t.lat],r.coordinates[0][0]))return;if(!this.updatePolygonGeometry([r.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],r.coordinates[0][0]],Rt.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var o=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;o&&(t.lng=o[0],t.lat=o[1]);var s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(ke([t.lng,t.lat],s[1]))return;if(!this.updatePolygonGeometry([s[0],s[1],[t.lng,t.lat],[t.lng,t.lat],s[0]],Rt.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(s,"polygon"),this.currentCoordinate++}else if(this.currentId){var a=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,l=this.store.getGeometryCopy(this.currentId).coordinates[0],c=this.closingPoints.isClosingPoint(t);if(c.isPreviousClosing||c.isClosing)this.close();else{if(a&&(t.lng=a[0],t.lat=a[1]),ke([t.lng,t.lat],l[this.currentCoordinate-1]))return;var h=(void 0===(d=[[].concat(l.slice(0,-1),[[t.lng,t.lat],l[0]])])&&(d=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:d},properties:{}});if(!this.updatePolygonGeometry(h.geometry.coordinates[0],Rt.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(h.geometry.coordinates[0])}}var d},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){this.setCursor("unset")},i.onDrag=function(){},i.onDragEnd=function(){this.setCursor(this.cursors.start)},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(t.properties.mode===this.mode){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=30,e}return e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ge(e,this.coordinatePrecision)},e}(Jt),Be=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="rectangle",i.center=void 0,i.clickCount=0,i.currentRectangleId=void 0,i.keyEvents=void 0,i.cursors=void 0;var n={start:"crosshair"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i}o(e,t);var i=e.prototype;return i.updateRectangle=function(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){var i=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],n={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}))return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:n}])}},i.close=function(){var t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),t&&this.onFinish(t,{mode:this.mode,action:"draw"})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentRectangleId=e[0],this.clickCount++,this.setDrawing()}else this.updateRectangle(t,Rt.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,Rt.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&this.store.delete([t])},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&pe(e,this.coordinatePrecision)},e}(Jt),Ae=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).type=Tt.Render,i.mode="render",i.mode=e.modeName,i}o(e,t);var i=e.prototype;return i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}},i.validateFeature=function(e){return t.prototype.validateFeature.call(this,e)&&(Oe(e,this.coordinatePrecision)||ge(e,this.coordinatePrecision)||function(t,e){return"LineString"===t.geometry.type&&t.geometry.coordinates.length>=2&&t.geometry.coordinates.every(function(t){return de(t,e)})}(e,this.coordinatePrecision))},e}(Jt);function Ge(t,e){var i=t,n=e,r=Qt(i[1]),o=Qt(n[1]),s=Qt(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),l=(ee(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function Ne(t,e,i){var n=e;e<0&&(n=-Math.abs(n));var r=n/$t,o=t[0]*Math.PI/180,s=Qt(t[1]),a=Qt(i),l=r*Math.cos(a),c=s+l;Math.abs(c)>Math.PI/2&&(c=c>0?Math.PI-c:-Math.PI-c);var h=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),d=Math.abs(h)>1e-11?l/h:Math.cos(s),u=[(180*(o+r*Math.sin(a)/d)/Math.PI+540)%360-180,180*c/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function Re(t,e,i,n,r){var o=n(t[0],t[1]),s=n(e[0],e[1]),l=r((o.x+s.x)/2,(o.y+s.y)/2),c=l.lat;return[a(l.lng,i),a(c,i)]}function Ve(t,e,i){var n=Ne(t,1e3*Zt(t,e)/2,Ge(t,e));return[a(n[0],i),a(n[1],i)]}function ze(t){for(var e=t.featureCoords,i=t.precision,n=t.unproject,r=t.project,o=t.projection,s=[],a=0;a<e.length-1;a++){var l=void 0;if("web-mercator"===o)l=Re(e[a],e[a+1],i,r,n);else{if("globe"!==o)throw new Error("Invalid projection");l=Ve(e[a],e[a+1],i)}s.push(l)}return s}var Te=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n}o(e,t);var i=e.prototype;return i.insert=function(t,e){var i=this.store.getGeometryCopy(t),n=this.store.getPropertiesCopy(t),r=n.midPointFeatureId,o=n.midPointSegment,s=this.store.getGeometryCopy(r),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(o+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:r,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,r,e),this.selectionPointBehavior.create(a,s.type,r)},i.create=function(t,e,i){var n=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,n,r,o){return ze({featureCoords:t,precision:i,project:n,unproject:r,projection:o}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:n.mode})[Ut]=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i,this.config.project,this.config.unproject,this.projection))},i.delete=function(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])},i.getUpdated=function(t){var e=this;if(0!==this._midPoints.length)return ze({featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}).map(function(t,i){return{id:e._midPoints[i],geometry:{type:"Point",coordinates:t}}})},n(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}]),e}(ve),Xe=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}o(e,t);var i=e.prototype;return i.create=function(t,e,i){var n=this;this._selectionPoints=this.store.create(function(t,e,i){for(var n=[],r="Polygon"===e?t.length-1:t.length,o=0;o<r;o++)n.push({geometry:{type:"Point",coordinates:t[o]},properties:i(o)});return n}(t,e,function(t){return{mode:n.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])},i.getUpdated=function(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map(function(e,i){return{id:e,geometry:{type:"Point",coordinates:t[i]}}})},i.getOneUpdated=function(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}},n(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}]),e}(ve);function Ue(t,e){for(var i,n,r,o=!1,s=0,a=e.length;s<a;s++)for(var l=e[s],c=0,h=l.length,d=h-1;c<h;d=c++)(n=l[c])[1]>(i=t)[1]!=(r=l[d])[1]>i[1]&&i[0]<(r[0]-n[0])*(i[1]-n[1])/(r[1]-n[1])+n[0]&&(o=!o);return o}var Ye=function(t,e,i){var n=function(t){return t*t},r=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=r(e,i);if(0===n)return r(t,e);var o=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return o=Math.max(0,Math.min(1,o)),r(t,{x:e.x+o*(i.x-e.x),y:e.y+o*(i.y-e.y)})}(t,e,i))},He=/*#__PURE__*/function(t){function e(e,i,n){var r;return(r=t.call(this,e)||this).config=void 0,r.createClickBoundingBox=void 0,r.pixelDistance=void 0,r.config=e,r.createClickBoundingBox=i,r.pixelDistance=n,r}return o(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,r=void 0,o=Infinity,s=this.createClickBoundingBox.create(t),a=this.store.search(s),l=0;l<a.length;l++){var c=a[l],h=c.geometry;if("Point"===h.type){if(c.properties.selectionPoint||!e&&c.properties[Ut])continue;var d=this.pixelDistance.measure(t,h.coordinates);c.properties[Ut]&&d<this.pointerDistance&&d<o?(o=d,r=c):!c.properties[Ut]&&d<this.pointerDistance&&d<n&&(n=d,i=c)}else if("LineString"===h.type)for(var u=0;u<h.coordinates.length-1;u++){var g=h.coordinates[u],p=h.coordinates[u+1],f=Ye({x:t.containerX,y:t.containerY},this.project(g[0],g[1]),this.project(p[0],p[1]));f<this.pointerDistance&&f<n&&(n=f,i=c)}else"Polygon"===h.type&&Ue([t.lng,t.lat],h.coordinates)&&(n=0,i=c)}return{clickedFeature:i,clickedMidPoint:r}},e}(ve),Ke=/*#__PURE__*/function(t){function e(e,i,n,r){var o;return(o=t.call(this,e)||this).config=void 0,o.featuresAtMouseEvent=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.draggedFeatureId=null,o.dragPosition=void 0,o.config=e,o.featuresAtMouseEvent=i,o.selectionPoints=n,o.midPoints=r,o}o(e,t);var i=e.prototype;return i.startDragging=function(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]},i.stopDragging=function(){this.draggedFeatureId=null,this.dragPosition=void 0},i.isDragging=function(){return null!==this.draggedFeatureId},i.canDrag=function(t,e){var i=this.featuresAtMouseEvent.find(t,!0).clickedFeature;return!(!i||i.id!==e)},i.drag=function(t,e){if(this.draggedFeatureId){var i=this.store.getGeometryCopy(this.draggedFeatureId),n=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var r,o;if(o="Polygon"===i.type?(r=i.coordinates[0]).length-1:(r=i.coordinates).length,!this.dragPosition)return!1;for(var s=0;s<o;s++){var l=r[s],c=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]],h=a(l[0]-c[0],this.config.coordinatePrecision),d=a(l[1]-c[1],this.config.coordinatePrecision);if(h>180||h<-180||d>90||d<-90)return!1;r[s]=[h,d]}"Polygon"===i.type&&(r[r.length-1]=[r[0][0],r[0][1]]);var u=this.selectionPoints.getUpdated(r)||[],g=this.midPoints.getUpdated(r)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:Rt.Provisional}))return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(u,g)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:n}}]),this.dragPosition=[t.lng,t.lat])}},e}(ve),Je=/*#__PURE__*/function(t){function e(e,i,n,r){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.draggedCoordinate={id:null,index:-1},o.config=e,o.pixelDistance=i,o.selectionPoints=n,o.midPoints=r,o}o(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var r=0;r<i.length;r++){var o=this.pixelDistance.measure(t,i[r]);if(o<this.pointerDistance&&o<n.dist){var s="Polygon"===e.type&&(r===i.length-1||0===r);n.dist=o,n.index=s?0:r,n.isFirstOrLastPolygonCoord=s}}return n},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var n=this.draggedCoordinate.index,r=this.store.getGeometryCopy(this.draggedCoordinate.id),o="LineString"===r.type?r.coordinates:r.coordinates[0],s=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==r.type||n!==o.length-1&&0!==n)o[n]=s;else{var a=o.length-1;o[0]=s,o[a]=s}var l=this.selectionPoints.getOneUpdated(n,s),c=l?[l]:[],h=this.midPoints.getUpdated(o)||[];return!("Point"!==r.type&&!e&&ce({type:"Feature",geometry:r,properties:{}})||i&&!i({type:"Feature",id:this.draggedCoordinate.id,geometry:r,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:Rt.Provisional})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:r}].concat(c,h)),0))},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(ve);function qe(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}function Ze(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=$t,n=e[1]*Math.PI/180,r=t[1]*Math.PI/180,o=r-n,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),l=Math.abs(a)>1e-11?o/a:Math.cos(n);return Math.sqrt(o*o+l*l*s*s)*i}function $e(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=oe(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,n=0,r=t.length,o=0;o<r-1;o++){var s=t[o],a=s[0],l=s[1],c=t[o+1],h=c[0],d=c[1],u=a*d-h*l;e+=u,i+=(a+h)*u,n+=(l+d)*u}return{x:i/=6*(e/=2),y:n/=6*e}}(e):function(t){for(var e=t.length,i=0,n=0,r=0;r<e;r++){var o=t[r];i+=o[0],n+=o[1]}return{x:i/e,y:n/e}}(e)}var Qe=/*#__PURE__*/function(t){function e(e,i,n){var r;return(r=t.call(this,e)||this).config=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.lastBearing=void 0,r.config=e,r.selectionPoints=i,r.midPoints=n,r}o(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e,i){var n=this,r=this.store.getGeometryCopy(e);if("Polygon"===r.type||"LineString"===r.type){var o,s=[t.lng,t.lat],l={type:"Feature",geometry:r,properties:{}};if("web-mercator"===this.config.projection){if(o=be($e(l),oe(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=o);!function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return oe(t[0],t[1])}),r=n.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});r.x/=n.length,r.y/=n.length;var o=n.map(function(t){return{x:r.x+(t.x-r.x)*Math.cos(i)-(t.y-r.y)*Math.sin(i),y:r.y+(t.x-r.x)*Math.sin(i)+(t.y-r.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[se(e,i).lng,se(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=o:(console.log("rotatedCoordinates linestring",o),t.geometry.coordinates=o)}(l,-(this.lastBearing-o))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(o=Ge(qe({type:"Feature",geometry:r,properties:{}}),s),!this.lastBearing)return void(this.lastBearing=o+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=qe(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=Ge(i,t)+e,r=Ze(i,t),o=Ne(i,r,n);t[0]=o[0],t[1]=o[1]})}(l,-(this.lastBearing-(o+180)))}var c="Polygon"===r.type?r.coordinates[0]:r.coordinates;c.forEach(function(t){t[0]=a(t[0],n.coordinatePrecision),t[1]=a(t[1],n.coordinatePrecision)});var h=this.midPoints.getUpdated(c)||[],d=this.selectionPoints.getUpdated(c)||[];if(i&&!i({id:e,type:"Feature",geometry:r,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:Rt.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:r}].concat(d,h)),"web-mercator"===this.projection?this.lastBearing=o:"globe"===this.projection&&(this.lastBearing=o+180)}},e}(ve),ti=/*#__PURE__*/function(t){function e(e,i,n){var r;return(r=t.call(this,e)||this).config=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.lastDistance=void 0,r.config=e,r.selectionPoints=i,r.midPoints=n,r}o(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e,i){var n=this,r=this.store.getGeometryCopy(e);if("Polygon"===r.type||"LineString"===r.type){var o,s=[t.lng,t.lat],c={type:"Feature",geometry:r,properties:{}},h=$e(c);if("web-mercator"===this.config.projection){var d=oe(t.lng,t.lat);o=l(h,d)}else{if("globe"!==this.config.projection)throw new Error("Invalid projection");o=Zt(qe({type:"Feature",geometry:r,properties:{}}),s)}if(this.lastDistance){var u=1-(this.lastDistance-o)/o;if("web-mercator"===this.config.projection){var g=se(h.x,h.y);!function(t,e,i){if(1===e)return t;var n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return oe(t[0],t[1])}),r=oe(i[0],i[1]),o=n.map(function(t){return{x:r.x+(t.x-r.x)*e,y:r.y+(t.y-r.y)*e}}).map(function(t){var e=t.x,i=t.y;return[se(e,i).lng,se(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=o:t.geometry.coordinates=o}(c,u,[g.lng,g.lat])}else"globe"===this.config.projection&&function(t,e,i,n){void 0===n&&(n="xy"),1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var r=Ze(i,t),o=Ge(i,t),s=Ne(i,r*e,o);"x"!==n&&"xy"!==n||(t[0]=s[0]),"y"!==n&&"xy"!==n||(t[1]=s[1])})}(c,u,qe(c));var p="Polygon"===r.type?r.coordinates[0]:r.coordinates;p.forEach(function(t){t[0]=a(t[0],n.coordinatePrecision),t[1]=a(t[1],n.coordinatePrecision)});var f=this.midPoints.getUpdated(p)||[],y=this.selectionPoints.getUpdated(p)||[];if(i&&!i({id:e,type:"Feature",geometry:r,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:Rt.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:r}].concat(y,f)),this.lastDistance=o}else this.lastDistance=o}},e}(ve),ei=/*#__PURE__*/function(t){function e(e,i,n,r){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.minimumScale=1e-4,o.draggedCoordinate={id:null,index:-1},o.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},o.config=e,o.pixelDistance=i,o.selectionPoints=n,o.midPoints=r,o}o(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var r=0;r<i.length;r++){var o=this.pixelDistance.measure(t,i[r]);if(o<this.pointerDistance&&o<n.dist){var s="Polygon"===e.type&&(r===i.length-1||0===r);n.dist=o,n.index=s?0:r,n.isFirstOrLastPolygonCoord=s}}return n},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,r=e.selectedCoordinate,o=$e(e.feature);if(!o)return null;var s=oe(r[0],r[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=oe(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),n},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,r=e.selectedCoordinate,o=$e(e.feature);if(!o)return null;var s=oe(r[0],r[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=oe(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),n},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,n=t.webMercatorCursor,r=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-n.x,e.y-n.y))return null;var o=l(e,n)/l(e,i);return o<0&&(o=this.minimumScale),this.performWebMercatorScale(r,e.x,e.y,o,o),r},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,r=e.selectedCoordinate,o=oe(r[0],r[1]),s=this.getIndexesWebMercator(i,o),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},h=oe(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:l,updatedCoords:n,webMercatorCursor:h,webMercatorSelected:o,webMercatorOrigin:c}),n},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,r=e.selectedCoordinate,o=oe(r[0],r[1]),s=this.getIndexesWebMercator(i,o),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},h=oe(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:l,updatedCoords:n,webMercatorCursor:h,webMercatorSelected:o,webMercatorOrigin:c}),n},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,n=t.webMercatorSelected,r=t.webMercatorCursor,o=t.updatedCoords,s=i.x-r.x,a=i.y-r.y;if(!this.isValidDragWebMercator(e,s,a))return null;var l=1;0!==s&&1!==e&&5!==e&&(l=1-(i.x-n.x-s)/s);var c=1;return 0!==a&&3!==e&&7!==e&&(c=1-(i.y-n.y-a)/a),this.validateScale(l,c)?(l<0&&(l=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(o,i.x,i.y,l,c),o):null},i.getFeature=function(t){if(null===this.draggedCoordinate.id)return null;var e=this.store.getGeometryCopy(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{type:"Feature",geometry:e,properties:{}}},i.getNormalisedCoordinates=function(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates},i.validateScale=function(t,e){var i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,n=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&n},i.performWebMercatorScale=function(t,e,i,n,r){t.forEach(function(t){var o=oe(t[0],t[1]),s=se(e+(o.x-e)*n,i+(o.y-i)*r),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=oe(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],n=t[1];i<e[0]&&(e[0]=i),n<e[1]&&(e[1]=n),i>e[2]&&(e[2]=i),n>e[3]&&(e[3]=n)});var i=e[0],n=e[1],r=e[2],o=e[3];return[[i,o],[(i+r)/2,o],[r,o],[r,o+(n-o)/2],[r,n],[(i+r)/2,n],[i,n],[i,o+(n-o)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,n=Infinity,r=0;r<t.length;r++){var o=l({x:e.x,y:e.y},{x:t[r][0],y:t[r][1]});o<n&&(i=r,n=o)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var n=this.getFeature(this.draggedCoordinate.id);if(!n)return!1;var r=null;if("center"===e?r=this.centerWebMercatorDrag(t):"opposite"===e?r=this.oppositeWebMercatorDrag(t):"center-fixed"===e?r=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(r=this.oppositeFixedWebMercatorDrag(t)),!r)return!1;for(var o=0;o<r.length;o++){var s=r[o];if(s[0]=a(s[0],this.coordinatePrecision),s[1]=a(s[1],this.coordinatePrecision),!de(s,this.coordinatePrecision))return!1}var l=this.midPoints.getUpdated(r)||[],c=this.selectionPoints.getUpdated(r)||[],h={type:n.geometry.type,coordinates:"Polygon"===n.geometry.type?[r]:r};return!(i&&!i({id:this.draggedCoordinate.id,type:"Feature",geometry:h,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:Rt.Provisional})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:h}].concat(c,l)),0))},e}(ve),ii=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).mode="select",n.allowManualDeselection=!0,n.dragEventThrottle=5,n.dragEventCount=0,n.selected=[],n.flags=void 0,n.keyEvents=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.featuresAtMouseEvent=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.dragFeature=void 0,n.dragCoordinate=void 0,n.rotateFeature=void 0,n.scaleFeature=void 0,n.dragCoordinateResizeFeature=void 0,n.cursors=void 0,n.validations={},n.flags=e&&e.flags?e.flags:{};var o={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"};if(n.cursors=e&&e.cursors?r({},o,e.cursors):o,null===(null==e?void 0:e.keyEvents))n.keyEvents={deselect:null,delete:null,rotate:null,scale:null};else{var s={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]};n.keyEvents=e&&e.keyEvents?r({},s,e.keyEvents):s}if(n.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,n.allowManualDeselection=null==(i=null==e?void 0:e.allowManualDeselection)||i,e&&e.flags&&e.flags)for(var a in e.flags){var l=e.flags[a].feature;l&&l.validation&&(n.validations[a]=l.validation)}return n}o(e,t);var i=e.prototype;return i.selectFeature=function(t){this.select(t,!1)},i.setSelecting=function(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"},i.registerBehaviors=function(t){this.pixelDistance=new Ce(t),this.clickBoundingBox=new _e(t),this.featuresAtMouseEvent=new He(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Xe(t),this.midPoints=new Te(t,this.selectionPoints),this.rotateFeature=new Qe(t,this.selectionPoints,this.midPoints),this.scaleFeature=new ti(t,this.selectionPoints,this.midPoints),this.dragFeature=new Ke(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new Je(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new ei(t,this.pixelDistance,this.selectionPoints,this.midPoints)},i.deselectFeature=function(){this.deselect()},i.deselect=function(){var t=this,e=this.selected.filter(function(e){return t.store.has(e)}).map(function(t){return{id:t,property:Xt,value:!1}});this.store.updateProperty(e),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},i.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,n=Infinity;if(this.selectionPoints.ids.forEach(function(r){var o=e.store.getGeometryCopy(r),s=e.pixelDistance.measure(t,o.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.store.getPropertiesCopy(r))}),i){var r=i.selectionPointFeatureId,o=i.index,s=this.store.getPropertiesCopy(r),a=this.flags[s.mode],l=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var c,h=this.store.getGeometryCopy(r);if("Polygon"===h.type){if((c=h.coordinates[0]).length<=4)return}else if("LineString"===h.type&&(c=h.coordinates).length<=3)return;if(c){if("Polygon"===h.type&&0===o||o===c.length-1?(c.shift(),c.pop(),c.push([c[0][0],c[0][1]])):c.splice(o,1),l&&!l({id:r,type:"Feature",geometry:h,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:Rt.Commit}))return;this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:r,geometry:h}]),this.selectionPoints.create(c,h.type,r),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(c,r,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),n=this.flags[i.mode];if(n&&n.feature){var r=this.selected[0];if(r){if(r===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:"selected",value:!0}]),this.onSelect(t);var o=this.store.getGeometryCopy(t),s=o.type,a=o.coordinates;if("LineString"===s||"Polygon"===s){var l="LineString"===s?a:a[0];l&&n&&n.feature.coordinates&&(this.selectionPoints.create(l,s,t),n.feature.coordinates.midpoints&&this.midPoints.create(l,t,this.coordinatePrecision))}}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,n=e.clickedMidPoint;if(this.selected.length&&n)this.midPoints.insert(n.id,this.coordinatePrecision);else if(i&&i.id)this.select(i.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect()},i.onDragStart=function(t,e){if(this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),n=this.flags[i.mode];if(n&&n.feature&&(n.feature.draggable||n.feature.coordinates&&n.feature.coordinates.draggable||n.feature.coordinates&&n.feature.coordinates.resizable)){this.dragEventCount=0;var r=this.selected[0],o=this.dragCoordinate.getDraggableIndex(t,r);return n&&n.feature&&n.feature.coordinates&&(n.feature.coordinates.draggable||n.feature.coordinates.resizable)&&-1!==o?(this.setCursor(this.cursors.dragStart),n.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(r,o):this.dragCoordinate.startDragging(r,o),void e(!1)):n&&n.feature&&n.feature.draggable&&this.dragFeature.canDrag(t,r)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,r),void e(!1)):void 0}}},i.onDrag=function(t,e){var i=this.selected[0];if(i){var n=this.store.getPropertiesCopy(i),r=this.flags[n.mode],o=!0===(r&&r.feature&&r.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[n.mode];if(r&&r.feature&&r.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(r&&r.feature&&r.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&r.feature&&r.feature.coordinates&&r.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,r.feature.coordinates.resizable,s)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,o,s):this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}},i.onDragEnd=function(t,e){this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)},i.onMouseMove=function(t){var e=this;if(this.selected.length){if(!this.dragFeature.isDragging()){var i=!1;this.midPoints.ids.forEach(function(n){if(!i){var r=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!0)}});var n=!1;if(this.selectionPoints.ids.forEach(function(r){var o=e.store.getGeometryCopy(r);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!1,n=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var r=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(r&&r.id===this.selected[0]||n)?this.cursors.pointerOver:"unset")}}}else this.setCursor("unset")},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties.selectionPoint)return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties.midPoint)return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=40,e}else if(t.properties[Xt]){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=10,e}return e},e}(qt),ni=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];return(e=t.call.apply(t,[this].concat(n))||this).type=Tt.Static,e.mode="static",e}o(e,t);var i=e.prototype;return i.start=function(){},i.stop=function(){},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(){return r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0})},e}(Jt);function ri(t,e,i,n,r){for(;n>i;){if(n-i>600){var o=n-i+1,s=e-i+1,a=Math.log(o),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(o-l)/o)*(s-o/2<0?-1:1);ri(t,e,Math.max(i,Math.floor(e-s*l/o+c)),Math.min(n,Math.floor(e+(o-s)*l/o+c)),r)}var h=t[e],d=i,u=n;for(oi(t,i,e),r(t[n],h)>0&&oi(t,i,n);d<u;){for(oi(t,d,u),d++,u--;r(t[d],h)<0;)d++;for(;r(t[u],h)>0;)u--}0===r(t[i],h)?oi(t,i,u):oi(t,++u,n),u<=e&&(i=u+1),e<=u&&(n=u-1)}}function oi(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function si(t,e){ai(t,0,t.children.length,e,t)}function ai(t,e,i,n,r){r||(r=fi([])),r.minX=Infinity,r.minY=Infinity,r.maxX=-Infinity,r.maxY=-Infinity;for(var o=e;o<i;o++){var s=t.children[o];li(r,t.leaf?n(s):s)}return r}function li(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 ci(t,e){return t.minX-e.minX}function hi(t,e){return t.minY-e.minY}function di(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function ui(t){return t.maxX-t.minX+(t.maxY-t.minY)}function gi(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function pi(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function fi(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function yi(t,e,i,n,r){for(var o=[e,i];o.length;)if(!((i=o.pop())-(e=o.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;ri(t,s,e,i,r),o.push(e,s,s,i)}}var vi=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!pi(t,e))return i;for(var n=this.toBBox,r=[];e;){for(var o=0;o<e.children.length;o++){var s=e.children[o],a=e.leaf?n(s):s;pi(t,a)&&(e.leaf?i.push(s):gi(t,a)?this._all(s,i):r.push(s))}e=r.pop()}return i},e.collides=function(t){var e=this.data;if(pi(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var r=e.children[n],o=e.leaf?this.toBBox(r):r;if(pi(t,o)){if(e.leaf||gi(t,o))return!0;i.push(r)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var n=this.data;this.data=i,i=n}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=fi([])},e.remove=function(t){for(var e,i,n=this.data,r=this.toBBox(t),o=[],s=[],a=!1;n||o.length;){if(n||(n=o.pop(),i=o[o.length-1],e=s.pop(),a=!0),n.leaf){var l=n.children.indexOf(t);-1!==l&&(n.children.splice(l,1),o.push(n),this._condense(o))}a||n.leaf||!gi(n,r)?i?(e++,n=i.children[e],a=!1):n=null:(o.push(n),s.push(e),e=0,i=n,n=n.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,n){var r,o=i-e+1,s=this._maxEntries;if(o<=s)return si(r=fi(t.slice(e,i+1)),this.toBBox),r;n||(n=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/Math.pow(s,n-1))),(r=fi([])).leaf=!1,r.height=n;var a=Math.ceil(o/s),l=a*Math.ceil(Math.sqrt(s));yi(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var h=Math.min(c+l-1,i);yi(t,c,h,a,this.compareMinY);for(var d=c;d<=h;d+=a){var u=Math.min(d+a-1,h);r.children.push(this._build(t,d,u,n-1))}}return si(r,this.toBBox),r},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var r=Infinity,o=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=di(l),h=(d=t,u=l,(Math.max(u.maxX,d.maxX)-Math.min(u.minX,d.minX))*(Math.max(u.maxY,d.maxY)-Math.min(u.minY,d.minY))-c);h<o?(o=h,r=c<r?c:r,s=l):h===o&&c<r&&(r=c,s=l)}e=s||e.children[0]}var d,u;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),r=[],o=this._chooseSubtree(n,this.data,e,r);for(o.children.push(t),li(o,n);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(n,r,e)},e._split=function(t,e){var i=t[e],n=i.children.length,r=this._minEntries;this._chooseSplitAxis(i,r,n);var o=this._chooseSplitIndex(i,r,n),s=fi(i.children.splice(o,i.children.length-o));s.height=i.height,s.leaf=i.leaf,si(i,this.toBBox),si(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=fi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,si(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,r,o,s,a,l,c,h=Infinity,d=Infinity,u=e;u<=i-e;u++){var g=ai(t,0,u,this.toBBox),p=ai(t,u,i,this.toBBox),f=(r=g,o=p,s=Math.max(r.minX,o.minX),a=Math.max(r.minY,o.minY),l=Math.min(r.maxX,o.maxX),c=Math.min(r.maxY,o.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=di(g)+di(p);f<h?(h=f,n=u,d=y<d?y:d):f===h&&y<d&&(d=y,n=u)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:ci,r=t.leaf?this.compareMinY:hi;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,r)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var r=this.toBBox,o=ai(t,0,e,r),s=ai(t,i-e,i,r),a=ui(o)+ui(s),l=e;l<i-e;l++){var c=t.children[l];li(o,t.leaf?r(c):c),a+=ui(o)}for(var h=i-e-1;h>=e;h--){var d=t.children[h];li(s,t.leaf?r(d):d),a+=ui(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)li(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():si(t[i],this.toBBox)},t}(),mi=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new vi(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var r=0;r<e.length;r++)n.push(e[r][1]),i.push(e[r][0]);var o=Math.min.apply(Math,n),s=Math.max.apply(Math,n);return{minX:Math.min.apply(Math,i),minY:o,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],n=new Set;t.forEach(function(t){var r=e.toBBox(t);if(e.setMaps(t,r),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(r)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),_i={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}},Ci=/*#__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 mi,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:_i}var e=t.prototype;return e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.getId=function(){return this.idStrategy.getId()},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e){var i=this;if(0!==t.length){var n=this.clone(t);n.forEach(function(t){null==t.id&&(t.id=i.idStrategy.getId()),i.tracked&&(t.properties.createdAt?Kt(t.properties.createdAt):t.properties.createdAt=+new Date,t.properties.updatedAt?Kt(t.properties.updatedAt):t.properties.updatedAt=+new Date)});var r=[];n.forEach(function(t){var n=t.id;if(e&&!e(t))throw new Error("Feature is not "+n+" valid: "+JSON.stringify(t));if(i.has(n))throw new Error("Feature already exists with this id: "+n);i.store[n]=t,r.push(n)}),this.spatialIndex.load(n),this._onChange(r,"create")}},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,r=t.property,o=t.value,s=e.store[n];if(!s)throw new Error("No feature with this ("+n+"), can not update geometry");i.push(n),s.properties[r]=o,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,r=t.geometry;i.push(n);var o=e.store[n];if(!o)throw new Error("No feature with this ("+n+"), can not update geometry");o.geometry=e.clone(r),e.spatialIndex.update(o),e.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,i=[];return t.forEach(function(t){var n,o=t.geometry,s=t.properties,a=r({},s);e.tracked&&(n=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:n,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:n):a={createdAt:n,updatedAt:n});var l=e.getId(),c={id:l,type:"Feature",geometry:o,properties:a};e.store[l]=c,e.spatialIndex.insert(c),i.push(l)}),this._onChange&&this._onChange([].concat(i),"create"),i},e.delete=function(t){var e=this;t.forEach(function(t){if(!e.store[t])throw new Error("No feature with this id, can not delete");delete e.store[t],e.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete")},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.clear=function(){this.store={},this.spatialIndex.clear()},e.size=function(){return Object.keys(this.store).length},t}();function Pi(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(wi(e[0]));for(var n=1;n<e.length;n++)i-=Math.abs(wi(e[n]))}return i}var xi=$t*$t/2,Mi=Math.PI/180;function wi(t){var e=t.length;if(e<=2)return 0;for(var i=0,n=0;n<e;)i+=(t[n+2>=e?(n+2)%e:n+2][0]*Mi-t[n][0]*Mi)*Math.sin(t[n+1===e?0:n+1][1]*Mi),n++;return i*xi}function bi(t,e,i){var n=be(t,e),r=be(e,i)-n;return r<0&&(r+=360),180-Math.abs(r-90-90)}var Si=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.pixelDistance=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?r({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var o={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?r({},o,e.keyEvents):o}return i}o(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.registerBehaviors=function(t){this.pixelDistance=new Ce(t)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i,n,r,o,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var a=1/Math.pow(10,this.coordinatePrecision-1),c=Math.max(1e-6,a);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-c],s[0]]}else if(2===this.currentCoordinate){var h=s[0],d=s[1],u=Re(h,d,this.coordinatePrecision,this.project,this.unproject),g=oe(h[0],h[1]),p=oe(u[0],u[1]),f=oe(d[0],d[1]),y=oe(t.lng,t.lat),v=l(y,g)<l(y,f),m=bi(g,p,y),_=v?90-m:bi(g,p,y)-90,C=l(p,y),P=Math.cos(Qt(_))*C,x=be(g,f)+("right"==((o=((r=y).x-(n=f).x)*((i=g).y-n.y)-(r.y-n.y)*(i.x-n.x))>1e-10?"left":o<-1e-10?"right":"left")?-90:90),M=Me(g,P,x),w=Me(f,P,x),b=se(M.x,M.y),S=se(w.x,w.y);e=[s[0],s[1],[S.lng,S.lat],[b.lng,b.lat],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,Rt.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(ke([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]],Rt.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=r({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e},i.validateFeature=function(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ge(e,this.coordinatePrecision)},e}(Jt),Ei={TerraDrawBaseDrawMode:Jt,TerraDrawBaseAdapter:h};t.TerraDraw=/*#__PURE__*/function(){function t(t){var e=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectMode=void 0,this._adapter=t.adapter,this._mode=new ni;var i=new Set,n=t.modes.reduce(function(t,e){if(i.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return i.add(e.mode),t[e.mode]=e,t},{}),o=Object.keys(n);if(0===o.length)throw new Error("No modes provided");o.forEach(function(t){if(n[t].type===Tt.Select){if(e._instanceSelectMode)throw new Error("only one type of select mode can be provided");e._instanceSelectMode=t}}),this._modes=r({},n,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[]},this._store=new Ci({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],n=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:n}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},l=function(t,i){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i)});var n=s(t),r=n.changed,o=n.unchanged;"create"===i?e._adapter.render({created:r,deletedIds:[],unchanged:o,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:o,updated:r},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:o,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:o,updated:[]},e.getModeStyles())}},c=function(t){if(e._enabled){e._eventListeners.select.forEach(function(e){e(t)});var i=s([t]);e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:i.changed},e.getModeStyles())}},h=function(t){if(e._enabled){e._eventListeners.deselect.forEach(function(t){t()});var i=s([t]),n=i.changed;n&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:n},e.getModeStyles())}};Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor.bind(e._adapter),project:e._adapter.project.bind(e._adapter),unproject:e._adapter.unproject.bind(e._adapter),setDoubleClickToZoom:e._adapter.setDoubleClickToZoom.bind(e._adapter),onChange:l,onSelect:c,onDeselect:h,onFinish:a,coordinatePrecision:e._adapter.getCoordinatePrecision()})})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(i){e[i]=function(e){return t._instanceSelectMode&&e.properties[Xt]?t._modes[t._instanceSelectMode].styleFeature.bind(t._modes[t._instanceSelectMode])(e):t._modes[i].styleFeature.bind(t._modes[i])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,n=t.lat,r=e&&void 0!==e.pointerDistance?e.pointerDistance:30,o=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,s=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),c=a(i,n),h=me({unproject:s,point:c,pointerDistance:r});return this._store.search(h).filter(function(t){if(o&&(t.properties[Ut]||t.properties.selectionPoint))return!1;if("Point"===t.geometry.type){var e=t.geometry.coordinates,s=a(e[0],e[1]);return l(c,s)<r}if("LineString"===t.geometry.type){for(var h=t.geometry.coordinates,d=0;d<h.length-1;d++){var u=h[d],g=h[d+1];if(Ye(c,a(u[0],u[1]),a(g[0],g[1]))<r)return!0}return!1}return!!Ue([i,n],t.geometry.coordinates)||void 0})},e.getSelectMode=function(){if(this.checkEnabled(),!this._instanceSelectMode)throw new Error("No select mode defined in instance");return this.getMode()!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.getSnapshot=function(){return this._store.copyAll()},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},e.setMode=function(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},e.removeFeatures=function(t){this.checkEnabled(),this._store.delete(t)},e.selectFeature=function(t){this.getSelectMode().selectFeature(t)},e.deselectFeature=function(t){this.getSelectMode().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.addFeatures=function(t){var e=this;this.checkEnabled(),0!==t.length&&this._store.load(t,function(t){if(Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)){var i=e._modes[t.properties.mode];return!!i&&i.validateFeature.bind(i)(t)}return!1})},e.start=function(){var t=this;this._enabled=!0,this._adapter.register({onReady:function(){t._eventListeners.ready.forEach(function(t){t()})},getState:function(){return t._mode.state},onClick:function(e){t._mode.onClick(e)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyDown:function(e){t._mode.onKeyDown(e)},onKeyUp:function(e){t._mode.onKeyUp(e)},onDragStart:function(e,i){t._mode.onDragStart(e,i)},onDrag:function(e,i){t._mode.onDrag(e,i)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)},onClear:function(){t._mode.cleanUp(),t._store.clear()}})},e.getFeaturesAtLngLat=function(t,e){return this.featuresAtLocation({lng:t.lng,lat:t.lat},e)},e.getFeaturesAtPointerEvent=function(t,e){var i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)},e.stop=function(){this._enabled=!1,this._adapter.unregister()},e.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},e.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},n(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}]),t}(),t.TerraDrawAngledRectangleMode=Si,t.TerraDrawArcGISMapsSDKAdapter=zt,t.TerraDrawCircleMode=fe,t.TerraDrawExtend=Ei,t.TerraDrawFreehandMode=ye,t.TerraDrawGoogleMapsAdapter=d,t.TerraDrawLeafletAdapter=u,t.TerraDrawLineStringMode=Fe,t.TerraDrawMapLibreGLAdapter=p,t.TerraDrawMapboxGLAdapter=g,t.TerraDrawOpenLayersAdapter=Vt,t.TerraDrawPointMode=Le,t.TerraDrawPolygonMode=We,t.TerraDrawRectangleMode=Be,t.TerraDrawRenderMode=Ae,t.TerraDrawSelectMode=ii,t.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"===t.geometry.type&&Pi(t.geometry)<e},t.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"===t.geometry.type&&Pi(t.geometry)>e},t.ValidateNotSelfIntersecting=function(t){return("Polygon"===t.geometry.type||"LineString"===t.geometry.type)&&!ce(t)}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).terraDraw={})}(this,function(t){function e(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function i(t,i){for(var n=0;n<i.length;n++){var o=i[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,e(o.key),o)}}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o.apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function l(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return a(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?a(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var d=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)},u=function(t){var e=this,i=t.name,n=t.callback,o=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(n))},this.unregister=function(){e.register&&(e.registered=!1,o(n))},this.callback=n},h=/*#__PURE__*/function(){function t(t){this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement().getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t){var e=this.getLngLatFromEvent(t);if(!e)return null;var i=e.lng,n=e.lat,o=this.getMapElementXYPosition(t),r=o.containerX,s=o.containerY,a=this.getButton(t),l=Array.from(this._heldKeys);return{lng:c(i,this._coordinatePrecision),lat:c(n,this._coordinatePrecision),containerX:r,containerY:s,button:a,heldKeys:l}},e.register=function(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(function(t){t.register()})},e.getCoordinatePrecision=function(){return this._coordinatePrecision},e.getAdapterListeners=function(){var t=this;return[new u({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i)}},register:function(e){t.getMapEventElement().addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerdown",e)}}),new u({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var n={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},o={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=d(n,o);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new u({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 u({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement()&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(i,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||t._currentModeCallbacks.onClick(i),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement().addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointerup",e)}}),new u({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 u({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}(),p=/*#__PURE__*/function(t){function e(e){var i;if((i=t.call(this,e)||this)._cursor=void 0,i._cursorStyleSheet=void 0,i._lib=void 0,i._map=void 0,i._overlay=void 0,i._clickEventListener=void 0,i._mouseMoveEventListener=void 0,i.renderedFeatureIds=new Set,i._lib=e.lib,i._map=e.map,!i._map.getDiv().id)throw new Error("Google Map container div requires and id to be set");return i._coordinatePrecision="number"==typeof e.coordinatePrecision?e.coordinatePrecision:9,i}r(e,t);var i=e.prototype;return i.circlePath=function(t,e,i){var n=2*i;return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+n+",0 a "+i+","+i+" 0 1,0 -"+n+",0"},i.register=function(e){var i=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=i._currentModeCallbacks)&&t.onReady&&i._currentModeCallbacks.onReady()},this._overlay.setMap(this._map),this._clickEventListener=this._map.data.addListener("click",function(t){var e=i._listeners.find(function(t){return"click"===t.name});e&&e.callback(t)}),this._mouseMoveEventListener=this._map.data.addListener("mousemove",function(t){var e=i._listeners.find(function(t){return"mousemove"===t.name});e&&e.callback(t)})},i.unregister=function(){var e,i,n;t.prototype.unregister.call(this),null==(e=this._clickEventListener)||e.remove(),null==(i=this._mouseMoveEventListener)||i.remove(),null==(n=this._overlay)||n.setMap(null),this._overlay=void 0},i.getLngLatFromEvent=function(t){if(!this._overlay)throw new Error("cannot get overlay");var e=this._map.getBounds();if(!e)return null;var i=e.getNorthEast(),n=e.getSouthWest(),o=new this._lib.LatLngBounds(n,i),r=this._map.getDiv(),s=t.clientX-r.getBoundingClientRect().left,a=t.clientY-r.getBoundingClientRect().top,l=new this._lib.Point(s,a),c=this._overlay.getProjection();if(!c)return null;var d=c.fromContainerPixelToLatLng(l);return d&&o.contains(d)?{lng:d.lng(),lat:d.lat()}:null},i.getMapEventElement=function(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')},i.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 i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");var n=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===n)throw new Error("cannot project coordinates");return{x:n.x,y:n.y}},i.unproject=function(t,e){if(!this._overlay)throw new Error("cannot get overlay");var i=this._overlay.getProjection();if(void 0===i)throw new Error("cannot get projection");var n=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===n)throw new Error("cannot unproject coordinates");return{lng:n.lng(),lat:n.lat()}},i.setCursor=function(t){if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),"unset"!==t){var e=this._map.getDiv(),i=document.querySelector("#"+e.id+" .gm-style > div");if(i){i.classList.add("terra-draw-google-maps");var n=document.createElement("style");n.innerHTML=".terra-draw-google-maps { cursor: "+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(n),this._cursorStyleSheet=n}}this._cursor=t}},i.setDoubleClickToZoom=function(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})},i.setDraggability=function(t){this._map.setOptions({draggable:t})},i.render=function(t,e){var i=this;this._layers&&(t.deletedIds.forEach(function(t){var e=i._map.data.getFeatureById(t);e&&(i._map.data.remove(e),i.renderedFeatureIds.delete(t))}),t.updated.forEach(function(t){if(!t||!t.id)throw new Error("Feature is not valid");var e=i._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty(function(t,i){e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(function(i){e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":var n=t.geometry.coordinates;e.setGeometry(new i._lib.Data.Point(new i._lib.LatLng(n[1],n[0])));break;case"LineString":for(var o=t.geometry.coordinates,r=[],s=0;s<o.length;s++){var a=o[s],l=new i._lib.LatLng(a[1],a[0]);r.push(l)}e.setGeometry(new i._lib.Data.LineString(r));break;case"Polygon":for(var c=t.geometry.coordinates,d=[],u=0;u<c.length;u++){for(var h=[],p=0;p<c[u].length;p++){var g=new i._lib.LatLng(c[u][p][1],c[u][p][0]);h.push(g)}d.push(h)}e.setGeometry(new i._lib.Data.Polygon(d))}}),t.created.forEach(function(t){i.renderedFeatureIds.add(t.id),i._map.data.addGeoJson(t)})),t.created.forEach(function(t){i.renderedFeatureIds.add(t.id)});var n={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(n),this._map.data.setStyle(function(t){var n=t.getProperty("mode"),o=t.getGeometry();if(!o)throw new Error("Google Maps geometry not found");var r=o.getType(),s={};t.forEachProperty(function(t,e){s[e]=t});var a=e[n]({type:"Feature",geometry:{type:r,coordinates:[]},properties:s});switch(r){case"Point":return{clickable:!1,icon:{path:i.circlePath(0,0,a.pointWidth),fillColor:a.pointColor,fillOpacity:1,strokeColor:a.pointOutlineColor,strokeWeight:a.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:a.lineStringColor,strokeWeight:a.lineStringWidth};case"Polygon":return{strokeColor:a.polygonOutlineColor,strokeWeight:a.polygonOutlineWidth,fillOpacity:a.polygonFillOpacity,fillColor:a.polygonFillColor}}throw Error("Unknown feature type")})},i.clearLayers=function(){var t=this;this._layers&&(this._map.data.forEach(function(e){var i=e.getId();t.renderedFeatureIds.has(i)&&t._map.data.remove(e)}),this.renderedFeatureIds=new Set)},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},n(e,[{key:"_layers",get:function(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}}]),e}(h),g=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._lib=void 0,i._map=void 0,i._panes={},i._container=void 0,i._layers={},i._lib=e.lib,i._map=e.map,i._container=i._map.getContainer(),i}r(e,t);var i=e.prototype;return i.createPaneStyleSheet=function(t,e){var i=document.createElement("style");return i.innerHTML=".leaflet-"+t+"-pane {z-index: "+(e+600),document.getElementsByTagName("head")[0].appendChild(i),this._map.createPane(t),i},i.clearPanes=function(){Object.values(this._panes).forEach(function(t){t&&t.remove()}),this._panes={}},i.clearLayers=function(){var t=this;Object.values(this._layers).forEach(function(e){t._map.removeLayer(e)}),this._layers={}},i.styleGeoJSONLayer=function(t){var e=this;return{pointToLayer:function(i,n){if(!i.properties)throw new Error("Feature has no properties");if("string"!=typeof i.properties.mode)throw new Error("Feature mode is not a string");var o=(0,t[i.properties.mode])(i),r=String(o.zIndex);return e._panes[r]||(e._panes[r]=e.createPaneStyleSheet(r,o.zIndex)),e._lib.circleMarker(n,{radius:o.pointWidth,stroke:o.pointOutlineWidth||!1,color:o.pointOutlineColor,weight:o.pointOutlineWidth,fillOpacity:.8,fillColor:o.pointColor,pane:r,interactive:!1})},style:function(i){if(!i||!i.properties)return{};var n=i,o=(0,t[n.properties.mode])(n),r=String(o.zIndex);return e._panes[r]||(e._panes[r]=e.createPaneStyleSheet(r,o.zIndex)),"LineString"===n.geometry.type?{interactive:!1,color:o.lineStringColor,weight:o.lineStringWidth,pane:r}:"Polygon"===n.geometry.type?{interactive:!1,fillOpacity:o.polygonFillOpacity,fillColor:o.polygonFillColor,weight:o.polygonOutlineWidth,stroke:!0,color:o.polygonFillColor,pane:r}:{}}}},i.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t),i=this._map.containerPointToLatLng({x:e.containerX,y:e.containerY});return null===i.lng||isNaN(i.lng)||null===i.lat||isNaN(i.lat)?null:{lng:i.lng,lat:i.lat}},i.getMapEventElement=function(){return this._container},i.setDraggability=function(t){t?this._map.dragging.enable():this._map.dragging.disable()},i.project=function(t,e){var i=this._map.latLngToContainerPoint({lng:t,lat:e});return{x:i.x,y:i.y}},i.unproject=function(t,e){var i=this._map.containerPointToLatLng({x:t,y:e});return{lng:i.lng,lat:i.lat}},i.setCursor=function(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t},i.setDoubleClickToZoom=function(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()},i.render=function(t,e){var i=this;t.created.forEach(function(t){i._layers[t.id]=i._lib.geoJSON(t,i.styleGeoJSONLayer(e)),i._map.addLayer(i._layers[t.id])}),t.deletedIds.forEach(function(t){i._map.removeLayer(i._layers[t])}),t.updated.forEach(function(t){i._map.removeLayer(i._layers[t.id]),i._layers[t.id]=i._lib.geoJSON(t,i.styleGeoJSONLayer(e)),i._map.addLayer(i._layers[t.id])})},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers(),this.clearPanes())},i.register=function(e){var i;t.prototype.register.call(this,e),null!=(i=this._currentModeCallbacks)&&i.onReady&&this._currentModeCallbacks.onReady()},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.unregister=function(){return t.prototype.unregister.call(this)},e}(h),f=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._nextRender=void 0,i._map=void 0,i._container=void 0,i._rendered=!1,i.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},i._map=e.map,i._container=i._map.getContainer(),i}r(e,t);var i=e.prototype;return i.clearLayers=function(){var t=this;this._rendered&&(["point","linestring","polygon"].forEach(function(e){var i="td-"+e.toLowerCase();t._map.removeLayer(i),"polygon"===e&&t._map.removeLayer(i+"-outline"),t._map.removeSource(i)}),this._rendered=!1,this._nextRender&&(cancelAnimationFrame(this._nextRender),this._nextRender=void 0))},i._addGeoJSONSource=function(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e},tolerance:0})},i._addFillLayer=function(t){return this._map.addLayer({id:t,source:t,type:"fill",paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})},i._addFillOutlineLayer=function(t){return this._map.addLayer({id:t+"-outline",source:t,type:"line",paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}})},i._addLineLayer=function(t){return this._map.addLayer({id:t,source:t,type:"line",paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}})},i._addPointLayer=function(t){return this._map.addLayer({id:t,source:t,type:"circle",paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}})},i._addLayer=function(t,e){"Point"===e&&this._addPointLayer(t),"LineString"===e&&this._addLineLayer(t),"Polygon"===e&&(this._addFillLayer(t),this._addFillOutlineLayer(t))},i._addGeoJSONLayer=function(t,e){var i="td-"+t.toLowerCase();return this._addGeoJSONSource(i,e),this._addLayer(i,t),i},i._setGeoJSONLayerData=function(t,e){var i="td-"+t.toLowerCase();return this._map.getSource(i).setData({type:"FeatureCollection",features:e}),i},i.updateChangedIds=function(t){var e=this;[].concat(t.updated,t.created).forEach(function(t){"Point"===t.geometry.type?e.changedIds.points=!0:"LineString"===t.geometry.type?e.changedIds.linestrings=!0:"Polygon"===t.geometry.type&&(e.changedIds.polygons=!0)}),t.deletedIds.length>0&&(this.changedIds.deletion=!0),0===t.created.length&&0===t.updated.length&&0===t.deletedIds.length&&(this.changedIds.styling=!0)},i.getLngLatFromEvent=function(t){var e=this._container.getBoundingClientRect();return this.unproject(t.clientX-e.left,t.clientY-e.top)},i.getMapEventElement=function(){return this._map.getCanvas()},i.setDraggability=function(t){t?(this._map.dragRotate.enable(),this._map.dragPan.enable()):(this._map.dragRotate.disable(),this._map.dragPan.disable())},i.project=function(t,e){var i=this._map.project({lng:t,lat:e});return{x:i.x,y:i.y}},i.unproject=function(t,e){var i=this._map.unproject({x:t,y:e});return{lng:i.lng,lat:i.lat}},i.setCursor=function(t){var e=this._map.getCanvas();"unset"===t?e.style.removeProperty("cursor"):e.style.cursor=t},i.setDoubleClickToZoom=function(t){t?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()},i.render=function(t,e){var i=this;this.updateChangedIds(t),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(function(){for(var n=[].concat(t.created,t.updated,t.unchanged),o=[],r=[],s=[],a=0;a<n.length;a++){var l=n[a],c=l.properties,d=e[c.mode](l);"Point"===l.geometry.type?(c.pointColor=d.pointColor,c.pointOutlineColor=d.pointOutlineColor,c.pointOutlineWidth=d.pointOutlineWidth,c.pointWidth=d.pointWidth,o.push(l)):"LineString"===l.geometry.type?(c.lineStringColor=d.lineStringColor,c.lineStringWidth=d.lineStringWidth,r.push(l)):"Polygon"===l.geometry.type&&(c.polygonFillColor=d.polygonFillColor,c.polygonFillOpacity=d.polygonFillOpacity,c.polygonOutlineColor=d.polygonOutlineColor,c.polygonOutlineWidth=d.polygonOutlineWidth,s.push(l))}if(i._rendered){var u,h=i.changedIds.deletion||i.changedIds.styling,p=h||i.changedIds.linestrings,g=h||i.changedIds.polygons;(h||i.changedIds.points)&&(u=i._setGeoJSONLayerData("Point",o)),p&&i._setGeoJSONLayerData("LineString",r),g&&i._setGeoJSONLayerData("Polygon",s),u&&i._map.moveLayer(u)}else{var f=i._addGeoJSONLayer("Point",o);i._addGeoJSONLayer("LineString",r),i._addGeoJSONLayer("Polygon",s),i._rendered=!0,f&&i._map.moveLayer(f)}i.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.unregister=function(){return t.prototype.unregister.call(this)},i.register=function(e){var i;t.prototype.register.call(this,e),null!=(i=this._currentModeCallbacks)&&i.onReady&&this._currentModeCallbacks.onReady()},e}(h),y=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mapboxglAdapter=void 0,i.mapboxglAdapter=new f(e),i}r(e,t);var i=e.prototype;return i.register=function(t){this.mapboxglAdapter.register(t)},i.unregister=function(){this.mapboxglAdapter.unregister()},i.getCoordinatePrecision=function(){return this.mapboxglAdapter.getCoordinatePrecision()},i.getLngLatFromEvent=function(t){return this.mapboxglAdapter.getLngLatFromEvent(t)},i.getMapEventElement=function(){return this.mapboxglAdapter.getMapEventElement()},i.setDraggability=function(t){this.mapboxglAdapter.setDraggability(t)},i.project=function(t,e){return this.mapboxglAdapter.project(t,e)},i.unproject=function(t,e){return this.mapboxglAdapter.unproject(t,e)},i.setCursor=function(t){this.mapboxglAdapter.setCursor(t)},i.setDoubleClickToZoom=function(t){this.mapboxglAdapter.setDoubleClickToZoom(t)},i.render=function(t,e){this.mapboxglAdapter.render(t,e)},i.clear=function(){this.mapboxglAdapter.clear()},e}(h);const v={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var m=class{constructor(t){this.code_=t.code,this.units_=t.units,this.extent_=void 0!==t.extent?t.extent:null,this.worldExtent_=void 0!==t.worldExtent?t.worldExtent:null,this.axisOrientation_=void 0!==t.axisOrientation?t.axisOrientation:"enu",this.global_=void 0!==t.global&&t.global,this.canWrapX_=!(!this.global_||!this.extent_),this.getPointResolutionFunc_=t.getPointResolution,this.defaultTileGrid_=null,this.metersPerUnit_=t.metersPerUnit}canWrapX(){return this.canWrapX_}getCode(){return this.code_}getExtent(){return this.extent_}getUnits(){return this.units_}getMetersPerUnit(){return this.metersPerUnit_||v[this.units_]}getWorldExtent(){return this.worldExtent_}getAxisOrientation(){return this.axisOrientation_}isGlobal(){return this.global_}setGlobal(t){this.global_=t,this.canWrapX_=!(!t||!this.extent_)}getDefaultTileGrid(){return this.defaultTileGrid_}setDefaultTileGrid(t){this.defaultTileGrid_=t}setExtent(t){this.extent_=t,this.canWrapX_=!(!this.global_||!t)}setWorldExtent(t){this.worldExtent_=t}setGetPointResolution(t){this.getPointResolutionFunc_=t}getPointResolutionFunc(){return this.getPointResolutionFunc_}};const C=6378137,P=Math.PI*C,_=[-P,-P,P,P],x=[-180,-85,180,85],M=C*Math.log(Math.tan(Math.PI/2));class S extends m{constructor(t){super({code:t,units:"m",extent:_,global:!0,worldExtent:x,getPointResolution:function(t,e){return t/Math.cosh(e[1]/C)}})}}const b=[new S("EPSG:3857"),new S("EPSG:102100"),new S("EPSG:102113"),new S("EPSG:900913"),new S("http://www.opengis.net/def/crs/EPSG/0/3857"),new S("http://www.opengis.net/gml/srs/epsg.xml#3857")],I=[-180,-90,180,90],w=6378137*Math.PI/180;class E extends m{constructor(t,e){super({code:t,units:"degrees",extent:I,axisOrientation:e,global:!0,metersPerUnit:w,worldExtent:I})}}const F=[new E("CRS:84"),new E("EPSG:4326","neu"),new E("urn:ogc:def:crs:OGC:1.3:CRS84"),new E("urn:ogc:def:crs:OGC:2:84"),new E("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new E("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new E("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let D={},k={};function O(t,e,i){const n=t.getCode(),o=e.getCode();n in k||(k[n]={}),k[n][o]=i}function L(t,e){if(void 0!==e)for(let i=0,n=t.length;i<n;++i)e[i]=t[i];else e=t.slice();return e}function j(t,e){if(void 0!==e&&t!==e){for(let i=0,n=t.length;i<n;++i)e[i]=t[i];t=e}return t}function W(t){!function(t,e){D[t]=e}(t.getCode(),t),O(t,t,L)}function B(t){return"string"==typeof t?D[e=t]||D[e.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/,"EPSG:$3")]||null:t||null;var e}function G(t){!function(t){t.forEach(W)}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&O(e,t,L)})})}function N(t,e,i){const n=function(t,e){return function(t,e){let i=function(t,e){let i;return t in k&&e in k[t]&&(i=k[t][e]),i}(t.getCode(),e.getCode());return i||(i=j),i}(B(t),B(e))}(e,i);return n(t,void 0,t.length)}var V,A,T;G(b),G(F),V=b,A=function(t,e,i){const n=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(n));for(let o=0;o<n;o+=i){e[o]=P*t[o]/180;let i=C*Math.log(Math.tan(Math.PI*(+t[o+1]+90)/360));i>M?i=M:i<-M&&(i=-M),e[o+1]=i}return e},T=function(t,e,i){const n=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(n));for(let o=0;o<n;o+=i)e[o]=180*t[o]/P,e[o+1]=360*Math.atan(Math.exp(t[o+1]/C))/Math.PI-90;return e},F.forEach(function(t){V.forEach(function(e){O(t,e,A),O(e,t,T)})});var R,U=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).stylingFunction=function(){return{}},n._lib=void 0,n._map=void 0,n._container=void 0,n._projection=void 0,n._vectorSource=void 0,n._geoJSONReader=void 0,n.registeredLayerHandlers=void 0,n._map=e.map,n._lib=e.lib,n._geoJSONReader=new n._lib.GeoJSON,n._projection=function(){var t;return null!=(t=n._lib.getUserProjection())?t:new m({code:"EPSG:3857"})},n._container=n._map.getViewport(),n._container.setAttribute("tabindex","0");var o=new n._lib.VectorSource({features:[]});n._vectorSource=o;var r=new n._lib.VectorLayer({source:o,style:function(t){return n.getStyles(t,n.stylingFunction())},zIndex:null!=(i=e.zIndex)?i:1e5});return n._map.addLayer(r),n}r(e,t);var i=e.prototype;return i.hexToRGB=function(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}},i.getStyles=function(t,e){var i=this,n=t.getGeometry();if(n)return{Point:function(t){var n=t.getProperties(),o=e[n.mode]({type:"Feature",geometry:{type:"Point",coordinates:[]},properties:n});return new i._lib.Style({image:new i._lib.Circle({radius:o.pointWidth,fill:new i._lib.Fill({color:o.pointColor}),stroke:new i._lib.Stroke({color:o.pointOutlineColor,width:o.pointOutlineWidth})})})},LineString:function(t){var n=t.getProperties(),o=e[n.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:n});return new i._lib.Style({stroke:new i._lib.Stroke({color:o.lineStringColor,width:o.lineStringWidth})})},Polygon:function(t){var n=t.getProperties(),o=e[n.mode]({type:"Feature",geometry:{type:"Polygon",coordinates:[]},properties:n}),r=i.hexToRGB(o.polygonFillColor),s=r.r,a=r.g,l=r.b;return new i._lib.Style({stroke:new i._lib.Stroke({color:o.polygonOutlineColor,width:o.polygonOutlineWidth}),fill:new i._lib.Fill({color:"rgba("+s+","+a+","+l+","+o.polygonFillOpacity+")"})})}}[n.getType()](t)},i.clearLayers=function(){this._vectorSource&&this._vectorSource.clear()},i.addFeature=function(t){var e=this._geoJSONReader.readFeature(t,{dataProjection:"EPSG:4326",featureProjection:this._projection()});this._vectorSource.addFeature(e)},i.removeFeature=function(t){var e=this._vectorSource.getFeatureById(t);e&&this._vectorSource.removeFeature(e)},i.sortElementsByDOMOrder=function(t){return t.sort(function(t,e){var i=t.compareDocumentPosition(e);return i&Node.DOCUMENT_POSITION_FOLLOWING?-1:i&Node.DOCUMENT_POSITION_PRECEDING?1:0})},i.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t),i=e.containerX,n=e.containerY;try{return this.unproject(i,n)}catch(t){return null}},i.getMapEventElement=function(){var t=Array.from(this._container.querySelectorAll("canvas")),e=this.sortElementsByDOMOrder(t);return e[e.length-1]},i.setDraggability=function(t){this._map.getInteractions().forEach(function(e){"DragPan"===e.constructor.name&&e.setActive(t)})},i.project=function(t,e){var i,n=this._map.getPixelFromCoordinate(N([t,e],"EPSG:4326",void 0!==(i=this._projection())?i:"EPSG:3857"));return{x:n[0],y:n[1]}},i.unproject=function(t,e){var i=function(t,e){const i=N(t,void 0!==e?e:"EPSG:3857","EPSG:4326"),n=i[0];return(n<-180||n>180)&&(i[0]=function(t,e){const i=t%360;return 360*i<0?i+360:i}(n+180)-180),i}(this._map.getCoordinateFromPixel([t,e]),this._projection());return{lng:i[0],lat:i[1]}},i.setCursor=function(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t},i.setDoubleClickToZoom=function(t){this._map.getInteractions().forEach(function(e){"DoubleClickZoom"===e.constructor.name&&e.setActive(t)})},i.render=function(t,e){var i=this;this.stylingFunction=function(){return e},t.deletedIds.forEach(function(t){i.removeFeature(t)}),t.updated.forEach(function(t){i.removeFeature(t.id),i.addFeature(t)}),t.created.forEach(function(t){i.addFeature(t)})},i.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},i.register=function(e){var i,n=this;if(t.prototype.register.call(this,e),!this.registeredLayerHandlers){var o=this._map.getLayerGroup().getLayers(),r=function(){n._listeners.forEach(function(t){t.unregister()})},s=function(){n._listeners=n.getAdapterListeners(),n._listeners.forEach(function(t){t.register()})};this.registeredLayerHandlers={addLayers:function(){r(),n._map.once("rendercomplete",function(){n._currentModeCallbacks&&s()})},removeLayers:function(){r(),n._map.once("rendercomplete",function(){n._currentModeCallbacks&&s()})}},o.on("add",function(){r(),n._map.once("rendercomplete",function(){n._currentModeCallbacks&&s()})}),o.on("remove",function(){r(),n._map.once("rendercomplete",function(){n._currentModeCallbacks&&s()})})}null!=(i=this._currentModeCallbacks)&&i.onReady&&this._currentModeCallbacks.onReady()},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.unregister=function(){if(this.registeredLayerHandlers){var e=this._map.getLayerGroup();if(e){var i=e.getLayers();i&&(i.un("add",this.registeredLayerHandlers.addLayers),i.un("remove",this.registeredLayerHandlers.removeLayers))}}return t.prototype.unregister.call(this)},e}(h),X=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._lib=void 0,i._mapView=void 0,i._container=void 0,i._featureIdAttributeName="__tdId",i._featureLayerName="__terraDrawFeatures",i._featureLayer=void 0,i._dragEnabled=!0,i._zoomEnabled=!0,i._dragHandler=void 0,i._doubleClickHandler=void 0,i._mapView=e.map,i._lib=e.lib,i._container=i._mapView.container,i._featureLayer=new i._lib.GraphicsLayer({id:i._featureLayerName}),i._mapView.map.add(i._featureLayer),i}r(e,t);var i=e.prototype;return i.register=function(e){var i,n=this;t.prototype.register.call(this,e),this._dragHandler=this._mapView.on("drag",function(t){n._dragEnabled||t.stopPropagation()}),this._doubleClickHandler=this._mapView.on("double-click",function(t){n._zoomEnabled||t.stopPropagation()}),null!=(i=this._currentModeCallbacks)&&i.onReady&&this._currentModeCallbacks.onReady()},i.unregister=function(){t.prototype.unregister.call(this),this._dragHandler&&this._dragHandler.remove(),this._doubleClickHandler&&this._doubleClickHandler.remove()},i.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t);return this.unproject(e.containerX,e.containerY)},i.getMapEventElement=function(){return this._container.querySelector(".esri-view-surface")},i.setDraggability=function(t){this._dragEnabled=t},i.project=function(t,e){var i=new this._lib.Point({longitude:t,latitude:e}),n=this._mapView.toScreen(i);return{x:n.x,y:n.y}},i.unproject=function(t,e){var i=this._mapView.toMap({x:t,y:e});return{lng:i.longitude,lat:i.latitude}},i.setCursor=function(t){"unset"===t?this.getMapEventElement().style.removeProperty("cursor"):this.getMapEventElement().style.cursor=t},i.setDoubleClickToZoom=function(t){this._zoomEnabled=t},i.render=function(t,e){var i=this;t.created.forEach(function(t){i.addFeature(t,e)}),t.updated.forEach(function(t){i.removeFeatureById(t.id),i.addFeature(t,e)}),t.deletedIds.forEach(function(t){i.removeFeatureById(t)})},i.clear=function(){this._featureLayer.graphics.removeAll()},i.removeFeatureById=function(t){var e=this,i=this._featureLayer.graphics.find(function(i){return i.attributes[e._featureIdAttributeName]===t});this._featureLayer.remove(i)},i.addFeature=function(t,e){var i,n=t.geometry,o=n.coordinates,r=n.type,s=e[t.properties.mode](t),a=void 0,l=void 0;switch(r){case"Point":l=new this._lib.Point({latitude:o[1],longitude:o[0]}),a=new this._lib.SimpleMarkerSymbol({color:this.getColorFromHex(s.pointColor),size:2*s.pointWidth+"px",outline:{color:this.getColorFromHex(s.pointOutlineColor),width:s.pointOutlineWidth+"px"}});break;case"LineString":l=new this._lib.Polyline({paths:[o]}),a=new this._lib.SimpleLineSymbol({color:this.getColorFromHex(s.lineStringColor),width:s.lineStringWidth+"px"});break;case"Polygon":l=new this._lib.Polygon({rings:o}),a=new this._lib.SimpleFillSymbol({color:this.getColorFromHex(s.polygonFillColor,s.polygonFillOpacity),outline:{color:this.getColorFromHex(s.polygonOutlineColor),width:s.polygonOutlineWidth+"px"}})}var c=new this._lib.Graphic({geometry:l,symbol:a,attributes:(i={},i[this._featureIdAttributeName]=t.id,i)});"Point"===r?this._featureLayer.graphics.add(c):this._featureLayer.graphics.add(c,0)},i.getColorFromHex=function(t,e){var i=this._lib.Color.fromHex(t);return e&&(i.a=e),i},e}(h);!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(R||(R={}));var z="selected",H="midPoint",Y="closingPoint",K="snappingPoint";function J(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function q(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var Z,$="Feature is not a Polygon",Q="Feature mode property does not match the mode being added to";!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(Z||(Z={}));var tt=/*#__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=Z.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 i;if(J(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(J(t.geometry))if(J(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)return{valid:!1,reason:"Feature does not have a valid mode property"}}else i="Feature coordinates is not an array";else i="Feature is not Point, LineString or Polygon";else i="Feature has no properties";else i="Feature has no geometry";else i="Feature must match the id strategy (default is UUID4)";else i="Feature is not object";return i?{valid:!1,reason:i}:{valid:!0}}(t,this.store.idStrategy.isValidId);if(this.validate){var i=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Provisional});return{valid:e.valid&&i.valid,reason:i.reason}}return{valid:e.valid,reason:e.reason}},t.validateModeFeature=function(t,e){var i=this.performFeatureValidation(t);return i.valid?t.properties.mode===this.mode?e(t):{valid:!1,reason:Q}:{valid:!1,reason:i.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,i){return this.getStylingValue(t,e,i)},t.getNumericStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},t.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?t(i):t},n(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}(),et=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=Z.Select,e}return r(e,t),e}(tt);function it(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}var nt=6371008.8;function ot(t){return t%360*Math.PI/180}function rt(t){return t/(nt/1e3)}function st(t){return t%(2*Math.PI)*180/Math.PI}var at=57.29577951308232,lt=.017453292519943295,ct=6378137,dt=function(t,e){return{x:0===t?0:t*lt*ct,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*lt/2))*ct}},ut=function(t,e){return{lng:0===t?0:at*(t/ct),lat:0===e?0:(2*Math.atan(Math.exp(e/ct))-Math.PI/2)*at}};function ht(t,e,i){var n=ot(t[0]),o=ot(t[1]),r=ot(i),s=rt(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[st(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),st(a)]}function pt(t){for(var e=t.center,i=t.radiusKilometers,n=t.coordinatePrecision,o=t.steps?t.steps:64,r=[],s=0;s<o;s++){var a=ht(e,i,-360*s/o);r.push([c(a[0],n),c(a[1],n)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function gt(t){var e,i={epsilon:0};if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var n=[],o=0;o<e.length;o++)for(var r=0;r<e[o].length-1;r++)for(var s=0;s<e.length;s++)for(var a=0;a<e[s].length-1;a++)c(o,r,s,a);return n.length>0;function l(t){return t<0-i.epsilon||t>1+i.epsilon}function c(t,i,o,r){var s,a=e[t][i],c=e[t][i+1],d=e[o][r],u=e[o][r+1],h=function(t,e,i,n){if(ft(t,i)||ft(t,n)||ft(e,i)||ft(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],l=i[0],c=i[1],d=n[0],u=n[1],h=(o-s)*(c-u)-(r-a)*(l-d);return 0===h?null:[((o*a-r*s)*(l-d)-(o-s)*(l*u-c*d))/h,((o*a-r*s)*(c-u)-(r-a)*(l*u-c*d))/h]}(a,c,d,u);null!==h&&(s=u[0]!==d[0]?(h[0]-d[0])/(u[0]-d[0]):(h[1]-d[1])/(u[1]-d[1]),l(c[0]!==a[0]?(h[0]-a[0])/(c[0]-a[0]):(h[1]-a[1])/(c[1]-a[1]))||l(s)||(h.toString(),n.push(h)))}}function ft(t,e){return t[0]===e[0]&&t[1]===e[1]}function yt(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(n=t[0])>=-180&&n<=180&&(i=t[1])>=-90&&i<=90&&vt(t[0])<=e&&vt(t[1])<=e;var i,n}function vt(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var mt="Feature is not a Polygon",Ct="Feature has holes",Pt="Feature has less than 4 coordinates",_t="Feature has invalid coordinates",xt="Feature coordinates are not closed";function Mt(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:mt}:1!==t.geometry.coordinates.length?{valid:!1,reason:Ct}:t.geometry.coordinates[0].length<4?{valid:!1,reason:Pt}:t.geometry.coordinates[0].every(function(t){return yt(t,e)})?(i=t.geometry.coordinates[0][0])[0]!==(n=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||i[1]!==n[1]?{valid:!1,reason:xt}:{valid:!0}:{valid:!1,reason:_t};var i,n}function St(t,e){var i=Mt(t,e);return i.valid?gt(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var bt=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).mode="circle",n.center=void 0,n.clickCount=0,n.currentCircleId=void 0,n.keyEvents=void 0,n.cursors=void 0,n.startingRadiusKilometers=1e-5,n.cursorMovedAfterInitialCursorDown=!1;var r={start:"crosshair"};if(n.cursors=e&&e.cursors?o({},r,e.cursors):r,null===(null==e?void 0:e.keyEvents))n.keyEvents={cancel:null,finish:null};else{var s={cancel:"Escape",finish:"Enter"};n.keyEvents=e&&e.keyEvents?o({},s,e.keyEvents):s}return n.startingRadiusKilometers=null!=(i=null==e?void 0:e.startingRadiusKilometers)?i:1e-5,n.validate=null==e?void 0:e.validation,n}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentCircleId){var t=this.currentCircleId;if(this.validate&&t){var e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Finish}).valid)return}this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=pt({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers}}]);this.currentCircleId=i[0],this.clickCount++,this.cursorMovedAfterInitialCursorDown=!1,this.setDrawing()}else 1===this.clickCount&&this.center&&void 0!==this.currentCircleId&&this.cursorMovedAfterInitialCursorDown&&this.updateCircle(t),this.close()},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.updateCircle(t)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t])}catch(t){}},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return St(t,e.coordinatePrecision)})},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=it(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var n=function(t,e){var i=1e3*it(t,e);if(0===i)return 1;var n=dt(t[0],t[1]),o=n.x,r=n.y,s=dt(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-o,2)+Math.pow(a-r,2))/i}(this.center,[t.lng,t.lat]);e=function(t){for(var e=t.center,i=t.coordinatePrecision,n=t.steps?t.steps:64,o=1e3*t.radiusKilometers,r=dt(e[0],e[1]),s=r.x,a=r.y,l=[],d=0;d<n;d++){var u=360*d/n*Math.PI/180,h=o*Math.cos(u),p=o*Math.sin(u),g=ut(s+h,a+p),f=g.lat;l.push([c(g.lng,i),c(f,i)])}return l.push(l[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[l]},properties:{}}}({center:this.center,radiusKilometers:i*n,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");e=pt({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision})}if(this.validate&&!this.validate({type:"Feature",id:this.currentCircleId,geometry:e.geometry,properties:{radiusKilometers:i}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},e}(tt),It=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="freehand",i.startingClick=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=void 0,i.keyEvents=void 0,i.cursors=void 0,i.preventPointsNearClose=void 0,i.autoClose=void 0,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,i.preventPointsNearClose=e&&e.preventPointsNearClose||!0,e&&e.autoCloseTimeout&&!e.autoClose)throw new Error("autoCloseTimeout is set, but autoClose is not enabled");if(i.autoClose=e&&e.autoClose||!1,i.autoCloseTimeout=e&&e.autoCloseTimeout||500,i.minDistance=e&&e.minDistance||20,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i.validate=null==e?void 0:e.validation,i}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.currentId;if(this.validate&&t){var e=this.store.getGeometryCopy(t);if(!this.validate({type:"Feature",id:t,geometry:e,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Finish}).valid)return}this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){var e=this;if(void 0!==this.currentId&&!1!==this.startingClick){var i=this.store.getGeometryCopy(this.currentId),n=i.coordinates[0][i.coordinates[0].length-2],o=this.project(n[0],n[1]),r=d({x:o.x,y:o.y},{x:t.containerX,y:t.containerY}),s=i.coordinates[0][0],a=this.project(s[0],s[1]);if(d({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(function(){e.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(!(r<this.minDistance)){i.coordinates[0].pop();var l={type:"Polygon",coordinates:[[].concat(i.coordinates[0],[[t.lng,t.lat],i.coordinates[0][0]])]};if(this.validate&&!this.validate({type:"Feature",id:this.currentId,geometry:l,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Provisional}).valid)return;this.store.updateGeometry([{id:this.currentId,geometry:l}])}}},i.onClick=function(t){if(!this.preventNewFeature){if(!1===this.startingClick){var e,i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}},{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:(e={mode:this.mode},e[Y]=!0,e)}]),n=i[1];return this.currentId=i[0],this.closingPointId=n,this.startingClick=!0,void this.setDrawing()}this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==e&&this.store.delete([e])}catch(t){}},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=40,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Mt(t,e.coordinatePrecision)})},e}(tt),wt=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.store=e,this.mode=i,this.project=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a};function Et(t){var e=t.unproject,i=t.point,n=t.pointerDistance/2,o=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(o-n,r-n),e(o+n,r-n),e(o+n,r+n),e(o-n,r+n),e(o-n,r-n)].map(function(t){return[t.lng,t.lat]})]}}}var Ft=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.create=function(t){return Et({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(wt),Dt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return d({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(wt),kt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)})},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)})},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={coord:void 0,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(e){var n=i.pixelDistance.measure(t,e);n<r.minDist&&n<i.pointerDistance&&(r.coord=e,r.minDist=n)})}),r.coord},e}(wt);function Ot(t,e,i){var n=ot(t[0]),o=ot(t[1]),r=ot(i),s=rt(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[st(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),st(a)]}function Lt(t,e,i){var n=t.x,o=t.y,r=ot(i);return{x:n+e*Math.cos(r),y:o+e*Math.sin(r)}}function jt(t,e){var i=ot(t[0]),n=ot(e[0]),o=ot(t[1]),r=ot(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return st(Math.atan2(s,a))}function Wt(t,e){var i=Math.atan2(e.y-t.y,e.x-t.x);return(i*=180/Math.PI)>180?i-=360:i<-180&&(i+=360),i}function Bt(t){return(t+360)%360}function Gt(t,e,i){for(var n,o,r,s=[],a=t.length,l=0,c=0;c<t.length&&!(e>=l&&c===t.length-1);c++){if(l>e&&0===s.length){if(!(n=e-l))return s.push(t[c]),s;o=jt(t[c],t[c-1])-180,r=Ot(t[c],n,o),s.push(r)}if(l>=i)return(n=i-l)?(o=jt(t[c],t[c-1])-180,r=Ot(t[c],n,o),s.push(r),s):(s.push(t[c]),s);if(l>=e&&s.push(t[c]),c===t.length-1)return s;l+=it(t[c],t[c+1])}if(l<e&&t.length===a)throw new Error("Start position is beyond line");var d=t[t.length-1];return[d,d]}function Nt(t){return t*(Math.PI/180)}function Vt(t){return t*(180/Math.PI)}var At=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}r(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var n=[t,e],o=0,r=0;r<n.length-1;r++)o+=it(n[0],n[1]);if(o<=i)return n;var s=o/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],l=0;l<s;l++){var c=Gt(n,i*l,i*(l+1));a.push(c)}for(var d=[],u=0;u<a.length;u++)d.push(a[u][1]);return this.limitCoordinates(d)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var n=it(t,e),o=function(t,e,i){var n=[],o=Nt(t[1]),r=Nt(t[0]),s=Nt(e[1]),a=Nt(e[0]);i+=1;var l=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-o)/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===l||isNaN(l))return n;for(var c=0;c<=i;c++){var d=c/i,u=Math.sin((1-d)*l)/Math.sin(l),h=Math.sin(d*l)/Math.sin(l),p=u*Math.cos(o)*Math.cos(r)+h*Math.cos(s)*Math.cos(a),g=u*Math.cos(o)*Math.sin(r)+h*Math.cos(s)*Math.sin(a),f=u*Math.sin(o)+h*Math.sin(s);if(!(isNaN(p)||isNaN(g)||isNaN(f))){var y=Math.atan2(f,Math.sqrt(Math.pow(p,2)+Math.pow(g,2))),v=Math.atan2(g,p);isNaN(y)||isNaN(v)||n.push([Vt(v),Vt(y)])}}return n.slice(1,-1)}(t,e,Math.floor(n/i));return this.limitCoordinates(o)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[c(t[0],e.config.coordinatePrecision),c(t[1],e.config.coordinatePrecision)]})},e}(wt);function Tt(t,e){return t[0]===e[0]&&t[1]===e[1]}function Rt(t,e){return"LineString"!==t.geometry.type?{valid:!1,reason:"Feature is not a LineString"}:t.geometry.coordinates.length<2?{valid:!1,reason:"Feature has less than 2 coordinates"}:t.geometry.coordinates.every(function(t){return yt(t,e)})?{valid:!0}:{valid:!1,reason:"Feature has invalid coordinates"}}var Ut=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.closingPointId=void 0,i.keyEvents=void 0,i.snapping=void 0,i.cursors=void 0,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommitedCoordinates=void 0,i.snappedPointId=void 0,i.coordinateSnapping=void 0,i.insertPoint=void 0;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,i.snapping=e&&e.snapping?e.snapping:void 0,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i.validate=null==e?void 0:e.validation,i.insertCoordinates=null==e?void 0:e.insertCoordinates,i}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.updateGeometries([].concat(t.coordinates),void 0,R.Commit);var e=this.currentId;this.closingPointId&&this.store.delete([this.closingPointId]),this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0,this.snappedPointId=void 0,this.lastCommitedCoordinates=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}},i.updateGeometries=function(t,e,i){if(this.currentId){var n={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid)return;var o=[{id:this.currentId,geometry:n}];this.closingPointId&&e&&o.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=n.coordinates),this.store.updateGeometry(o)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=it(t,e)/(this.insertCoordinates.value+1),n=[];return"globe"===this.projection?n=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(n=this.insertPoint.generateInsertionCoordinates(t,e,i)),n},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var n=[].concat(e,[t]);this.updateGeometries(n,void 0,R.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,n=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],o=this.project(n[0],n[1]);if(d({x:o.x,y:o.y},{x:e.x,y:e.y})<this.pointerDistance)this.close();else{this.setCursor(this.cursors.close);var r=[].concat(i,[t]);this.updateGeometries(r,i[i.length-1],R.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.coordinateSnapping=new kt(t,new Dt(t),new Ft(t)),this.insertPoint=new At(t)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,n=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[K]=!0,i)}]);this.snappedPointId=n[0]}t.lng=e[0],t.lat=e[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);var o=e||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){var r=this.store.getGeometryCopy(this.currentId).coordinates;if(r.pop(),this.closingPointId){var s=r[r.length-1],a=this.project(s[0],s[1]);d({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var l=[].concat(r,[o]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var c=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],u=o;if(!Tt(c,u)){var h=this.generateInsertCoordinates(c,u);l=[].concat(this.lastCommitedCoordinates.slice(0,-1),h,[o])}}this.updateGeometries(l,void 0,R.Provisional)}},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);var e=this.snapCoordinate(t)||[t.lng,t.lat];0===this.currentCoordinate?this.createLine(e):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(e,{x:t.containerX,y:t.containerY})},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId,i=this.snappedPointId;this.closingPointId=void 0,this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==i&&this.store.delete([i]),void 0!==e&&this.store.delete([e])}catch(t){}},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if("Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode)return e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=10,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[Y];return e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:this.styles.snappingPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:this.styles.snappingPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:this.styles.snappingPointOutlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:this.styles.snappingPointOutlineWidth,2,t),e.zIndex=40,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Rt(t,e.coordinatePrecision)})},i.snapCoordinate=function(t){var e,i,n;return null!=(e=this.snapping)&&e.toCoordinate&&(n=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t)),null!=(i=this.snapping)&&i.toCustom&&(n=this.snapping.toCustom(t)),n},e}(tt),Xt="Feature is not a Point",zt="Feature has invalid coordinates";function Ht(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:Xt}:yt(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:zt}}var Yt=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="point",i.cursors=void 0;var n={create:"crosshair"};return i.cursors=e&&e.cursors?o({},n,e.cursors):n,i}r(e,t);var i=e.prototype;return i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");var e={type:"Point",coordinates:[t.lng,t.lat]},i={mode:this.mode};if(!this.validate||this.validate({type:"Feature",geometry:e,properties:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Finish}).valid){var n=this.store.create([{geometry:e,properties:i}]);this.onFinish(n[0],{mode:this.mode,action:"draw"})}},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(e.pointWidth=this.getNumericStylingValue(this.styles.pointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.pointOutlineWidth,2,t),e.zIndex=30),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Ht(t,e.coordinatePrecision)})},e}(tt),Kt=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n._startEndPoints=[],n.config=e,n.pixelDistance=i,n}r(e,t);var i=e.prototype;return i.create=function(t,e){var i,n;if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i[Y]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(n={mode:e},n[Y]=!0,n)}])},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},i.update=function(t){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:t[t.length-3]}}])},i.isClosingPoint=function(t){var e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},n(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}]),e}(wt);function Jt(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function qt(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(Jt(t)*Jt(e));return Math.acos(Math.min(Math.max(i,-1),1))}function Zt(t){var e=ot(t[1]),i=ot(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function $t(t){var e=t[0],i=t[1],n=st(Math.asin(t[2]));return[st(Math.atan2(i,e)),n]}var Qt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)})},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)})},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={coord:void 0,minDistance:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}for(var o,s=[],a=0;a<n.length-1;a++)s.push([n[a],n[a+1]]);var c=[t.lng,t.lat];if("web-mercator"===i.config.projection?o=function(t,e){for(var i,n,o,r,s,a,c,u,h=[Infinity,Infinity],p=Infinity,g=l(e);!(i=g()).done;){var f=i.value,y=f[0],v=f[1],m=void 0,C=Infinity,P=dt(y[0],y[1]),_=dt(v[0],v[1]),x=dt(t[0],t[1]);if(y[0]===t[0]&&y[1]===t[1])m=y;else if(v[0]===t[0]&&v[1]===t[1])m=v;else{var M=(c=(a={x:(r=x).x-(n=P).x,y:r.y-n.y}).x*(s={x:(o=_).x-n.x,y:o.y-n.y}).x+a.y*s.y,u=Math.max(0,Math.min(1,c/(s.x*s.x+s.y*s.y))),{x:n.x+u*s.x,y:n.y+u*s.y}),S=ut(M.x,M.y);m=[S.lng,S.lat]}m&&(C=d(x,dt(m[0],m[1])))<p&&(h=m,p=C)}return Infinity===p?void 0:{coordinate:h,distance:p}}(c,s):"globe"===i.config.projection&&(o=function(t,e){for(var i,n=[Infinity,Infinity],o=Infinity,r=l(e);!(i=r()).done;){var s,a=i.value,c=a[0],d=a[1],u=Infinity;(s=c[0]===t[0]&&c[1]===t[1]?c:d[0]===t[0]&&d[1]===t[1]?d:(h=c,p=d,g=t,S=Zt(h),b=Zt(p),I=Zt(g),w=I[0],E=I[1],F=I[2],D=[(m=(f=S)[1])*(x=(y=b)[2])-(C=f[2])*(_=y[1]),C*(P=y[0])-(v=f[0])*x,v*_-m*P],k=D[0],O=D[1],L=D[2],j=O*F-L*E,W=L*w-k*F,B=k*E-O*w,G=B*O-W*L,N=j*L-B*k,V=W*k-j*O,A=1/Math.sqrt(Math.pow(G,2)+Math.pow(N,2)+Math.pow(V,2)),T=[G*A,N*A,V*A],R=[-1*G*A,-1*N*A,-1*V*A],U=qt(S,b),X=qt(S,T),z=qt(b,T),H=qt(S,R),Y=qt(b,R),qt(S,M=X<H&&X<Y||z<H&&z<Y?T:R)>U||qt(b,M)>U?it($t(M),$t(S))<=it($t(M),$t(b))?[$t(S),!0,!1]:[$t(b),!1,!0]:[$t(M),!1,!1])[0])&&(u=it(t,s))<o&&(n=s,o=u)}var h,p,g,f,y,v,m,C,P,_,x,M,S,b,I,w,E,F,D,k,O,L,j,W,B,G,N,V,A,T,R,U,X,z,H,Y;return Infinity===o?void 0:{coordinate:n,distance:o}}(c,s)),o){var u=i.pixelDistance.measure(t,o.coordinate);u<r.minDistance&&u<i.pointerDistance&&(r.coord=o.coordinate,r.minDistance=u)}}),r.coord},e}(wt),te=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,i.snapping=e&&e.snapping?e.snapping:void 0,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.store.getGeometryCopy(this.currentId).coordinates[0];if(!(t.length<5)&&this.updatePolygonGeometry([].concat(t.slice(0,-2),[t[0]]),R.Finish)){var e=this.currentId;this.snappedPointId&&this.store.delete([this.snappedPointId]),this.currentCoordinate=0,this.currentId=void 0,this.snappedPointId=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:"draw"})}}},i.registerBehaviors=function(t){var e=new Ft(t);this.pixelDistance=new Dt(t),this.lineSnapping=new Qt(t,this.pixelDistance,e),this.coordinateSnapping=new kt(t,this.pixelDistance,e),this.closingPoints=new Kt(t,this.pixelDistance)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start);var e=this.snapCoordinate(t);if(e){if(this.snappedPointId)this.store.updateGeometry([{id:this.snappedPointId,geometry:{type:"Point",coordinates:e}}]);else{var i,n=this.store.create([{geometry:{type:"Point",coordinates:e},properties:(i={mode:this.mode},i[K]=!0,i)}]);this.snappedPointId=n[0]}t.lng=e[0],t.lat=e[1]}else this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0);if(void 0!==this.currentId&&0!==this.currentCoordinate){var o,r=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var s=1/Math.pow(10,this.coordinatePrecision-1),a=Math.max(1e-6,s);o=[r[0],[t.lng,t.lat],[t.lng,t.lat-a],r[0]]}else if(2===this.currentCoordinate)o=[r[0],r[1],[t.lng,t.lat],r[0]];else{var l=this.closingPoints.isClosingPoint(t);l.isPreviousClosing||l.isClosing?(this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),this.setCursor(this.cursors.close),o=[].concat(r.slice(0,-2),[r[0],r[0]])):o=[].concat(r.slice(0,-2),[[t.lng,t.lat],r[0]])}this.updatePolygonGeometry(o,R.Provisional)}},i.updatePolygonGeometry=function(t,e){if(!this.currentId)return!1;var i={type:"Polygon",coordinates:[t]};return!(this.validate&&!this.validate({type:"Feature",geometry:i},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid||(this.store.updateGeometry([{id:this.currentId,geometry:i}]),0))},i.snapCoordinate=function(t){var e,i,n,o,r,s=void 0;return null!=(e=this.snapping)&&e.toLine&&(o=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(s=o),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(s=r),null!=(n=this.snapping)&&n.toCustom&&(s=this.snapping.toCustom(t)),s},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,this.snappedPointId&&(this.store.delete([this.snappedPointId]),this.snappedPointId=void 0),0===this.currentCoordinate){var e=this.snapCoordinate(t);e&&(t.lng=e[0],t.lat=e[1]);var i=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=i[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.snapCoordinate(t);n&&(t.lng=n[0],t.lat=n[1]);var o=this.store.getGeometryCopy(this.currentId);if(Tt([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]],R.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var r=this.snapCoordinate(t);r&&(t.lng=r[0],t.lat=r[1]);var s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(Tt([t.lng,t.lat],s[1]))return;if(!this.updatePolygonGeometry([s[0],s[1],[t.lng,t.lat],[t.lng,t.lat],s[0]],R.Commit))return;2===this.currentCoordinate&&this.closingPoints.create(s,"polygon"),this.currentCoordinate++}else if(this.currentId){var a=this.store.getGeometryCopy(this.currentId).coordinates[0],l=this.closingPoints.isClosingPoint(t);if(l.isPreviousClosing||l.isClosing)this.close();else{var c=this.snapCoordinate(t);if(c&&(t.lng=c[0],t.lat=c[1]),Tt([t.lng,t.lat],a[this.currentCoordinate-1]))return;var d=(void 0===(u=[[].concat(a.slice(0,-1),[[t.lng,t.lat],a[0]])])&&(u=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:u},properties:{}});if(!this.updatePolygonGeometry(d.geometry.coordinates[0],R.Commit))return;this.currentCoordinate++,this.closingPoints.ids.length&&this.closingPoints.update(d.geometry.coordinates[0])}}var u},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){this.setCursor("unset")},i.onDrag=function(){},i.onDragEnd=function(){this.setCursor(this.cursors.start)},i.cleanUp=function(){var t=this.currentId,e=this.snappedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted();try{void 0!==t&&this.store.delete([t]),void 0!==e&&this.store.delete([e]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(t.properties.mode===this.mode){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e;if("Point"===t.geometry.type){var i=t.properties[Y],n=t.properties[K];return e.pointWidth=this.getNumericStylingValue(i?this.styles.closingPointWidth:n?this.styles.snappingPointWidth:e.pointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.closingPointColor:n?this.styles.snappingPointColor:e.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.closingPointOutlineColor:n?this.styles.snappingPointOutlineColor:e.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.closingPointOutlineWidth:n?this.styles.snappingPointOutlineWidth:2,2,t),e.zIndex=30,e}}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Mt(t,e.coordinatePrecision)})},e}(tt),ee=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="rectangle",i.center=void 0,i.clickCount=0,i.currentRectangleId=void 0,i.keyEvents=void 0,i.cursors=void 0;var n={start:"crosshair"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i}r(e,t);var i=e.prototype;return i.updateRectangle=function(t,e){if(1===this.clickCount&&this.center&&this.currentRectangleId){var i=this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0],n={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}).valid)return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:n}])}},i.close=function(){var t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&this.onFinish(t,{mode:this.mode,action:"draw"})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentRectangleId=e[0],this.clickCount++,this.setDrawing()}else this.updateRectangle(t,R.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,R.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentRectangleId;this.center=void 0,this.currentRectangleId=void 0,this.clickCount=0,"drawing"===this.state&&this.setStarted(),void 0!==t&&this.store.delete([t])},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return St(t,e.coordinatePrecision)})},e}(tt),ie=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).type=Z.Render,i.mode="render",i.mode=e.modeName,i}r(e,t);var i=e.prototype;return i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}},i.validateFeature=function(e){var i=t.prototype.validateFeature.call(this,e);if(i.valid){var n=e,o=Ht(n,this.coordinatePrecision).valid||Mt(n,this.coordinatePrecision).valid||Rt(n,this.coordinatePrecision).valid;return o?{valid:!0}:{valid:o,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(tt);function ne(t,e){var i=t,n=e,o=ot(i[1]),r=ot(n[1]),s=ot(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=(st(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function oe(t,e,i){var n=e;e<0&&(n=-Math.abs(n));var o=n/nt,r=t[0]*Math.PI/180,s=ot(t[1]),a=ot(i),l=o*Math.cos(a),c=s+l;Math.abs(c)>Math.PI/2&&(c=c>0?Math.PI-c:-Math.PI-c);var d=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),u=Math.abs(d)>1e-11?l/d:Math.cos(s),h=[(180*(r+o*Math.sin(a)/u)/Math.PI+540)%360-180,180*c/Math.PI];return h[0]+=h[0]-t[0]>180?-360:t[0]-h[0]>180?360:0,h}function re(t,e,i,n,o){var r=n(t[0],t[1]),s=n(e[0],e[1]),a=o((r.x+s.x)/2,(r.y+s.y)/2),l=a.lat;return[c(a.lng,i),c(l,i)]}function se(t,e,i){var n=oe(t,1e3*it(t,e)/2,ne(t,e));return[c(n[0],i),c(n[1],i)]}function ae(t){for(var e=t.featureCoords,i=t.precision,n=t.unproject,o=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var l=void 0;if("web-mercator"===r)l=re(e[a],e[a+1],i,o,n);else{if("globe"!==r)throw new Error("Invalid projection");l=se(e[a],e[a+1],i)}s.push(l)}return s}var le=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n}r(e,t);var i=e.prototype;return i.insert=function(t,e){var i=this.store.getGeometryCopy(t),n=this.store.getPropertiesCopy(t),o=n.midPointFeatureId,r=n.midPointSegment,s=this.store.getGeometryCopy(o),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:o,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,o,e),this.selectionPointBehavior.create(a,s.type,o)},i.create=function(t,e,i){var n=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,n,o,r){return ae({featureCoords:t,precision:i,project:n,unproject:o,projection:r}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:n.mode})[H]=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i,this.config.project,this.config.unproject,this.projection))},i.delete=function(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])},i.getUpdated=function(t){var e=this;if(0!==this._midPoints.length)return ae({featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}).map(function(t,i){return{id:e._midPoints[i],geometry:{type:"Point",coordinates:t}}})},n(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}]),e}(wt),ce=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}r(e,t);var i=e.prototype;return i.create=function(t,e,i){var n=this;this._selectionPoints=this.store.create(function(t,e,i){for(var n=[],o="Polygon"===e?t.length-1:t.length,r=0;r<o;r++)n.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return n}(t,e,function(t){return{mode:n.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},i.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])},i.getUpdated=function(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map(function(e,i){return{id:e,geometry:{type:"Point",coordinates:t[i]}}})},i.getOneUpdated=function(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}},n(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}]),e}(wt);function de(t,e){for(var i,n,o,r=!1,s=0,a=e.length;s<a;s++)for(var l=e[s],c=0,d=l.length,u=d-1;c<d;u=c++)(n=l[c])[1]>(i=t)[1]!=(o=l[u])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var ue=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},he=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return r(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=void 0,a=Infinity,l=void 0,c=this.createClickBoundingBox.create(t),d=this.store.search(c),u=0;u<d.length;u++){var h=d[u],p=h.geometry;if("Point"===p.type){if(h.properties.selectionPoint||!e&&h.properties[H])continue;var g=this.pixelDistance.measure(t,p.coordinates);h.properties[H]&&g<this.pointerDistance&&g<a?(a=g,s=h):!h.properties[H]&&g<this.pointerDistance&&g<n&&(n=g,i=h)}else if("LineString"===p.type){if(i)continue;for(var f=0;f<p.coordinates.length-1;f++){var y=p.coordinates[f],v=p.coordinates[f+1],m=ue({x:t.containerX,y:t.containerY},this.project(y[0],y[1]),this.project(v[0],v[1]));m<this.pointerDistance&&m<r&&(r=m,o=h)}}else if("Polygon"===p.type){if(i||o)continue;de([t.lng,t.lat],p.coordinates)&&(l=h)}}return{clickedFeature:i||o||l,clickedMidPoint:s}},e}(wt),pe=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.featuresAtCursorEvent=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedFeatureId=null,r.dragPosition=void 0,r.config=e,r.featuresAtCursorEvent=i,r.selectionPoints=n,r.midPoints=o,r}r(e,t);var i=e.prototype;return i.startDragging=function(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]},i.stopDragging=function(){this.draggedFeatureId=null,this.dragPosition=void 0},i.isDragging=function(){return null!==this.draggedFeatureId},i.canDrag=function(t,e){var i=this.featuresAtCursorEvent.find(t,!0).clickedFeature;return!(!i||i.id!==e)},i.drag=function(t,e){if(this.draggedFeatureId){var i=this.store.getGeometryCopy(this.draggedFeatureId),n=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var o,r;if(r="Polygon"===i.type?(o=i.coordinates[0]).length-1:(o=i.coordinates).length,!this.dragPosition)return!1;for(var s=0;s<r;s++){var a=o[s],l=void 0,d=void 0;if("web-mercator"===this.config.projection){var u=dt(this.dragPosition[0],this.dragPosition[1]),h=dt(n[0],n[1]),p=dt(a[0],a[1]),g={x:u.x-h.x,y:u.y-h.y},f=ut(p.x-g.x,p.y-g.y);l=f.lng,d=f.lat}else{var y=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]];l=a[0]-y[0],d=a[1]-y[1]}if(l=c(l,this.config.coordinatePrecision),d=c(d,this.config.coordinatePrecision),l>180||l<-180||d>90||d<-90)return!1;o[s]=[l,d]}"Polygon"===i.type&&(o[o.length-1]=[o[0][0],o[0][1]]);var v=this.selectionPoints.getUpdated(o)||[],m=this.midPoints.getUpdated(o)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:R.Provisional}).valid)return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(v,m)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:n}}]),this.dragPosition=[t.lng,t.lat])}},e}(wt),ge=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedCoordinate={id:null,index:-1},r.config=e,r.pixelDistance=i,r.selectionPoints=n,r.midPoints=o,r}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var n=this.draggedCoordinate.index,o=this.store.getGeometryCopy(this.draggedCoordinate.id),r="LineString"===o.type?o.coordinates:o.coordinates[0],s=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==o.type||n!==r.length-1&&0!==n)r[n]=s;else{var a=r.length-1;r[0]=s,r[a]=s}var l=this.selectionPoints.getOneUpdated(n,s),c=l?[l]:[],d=this.midPoints.getUpdated(r)||[];return!("Point"!==o.type&&!e&&gt({type:"Feature",geometry:o,properties:{}})||i&&!i({type:"Feature",id:this.draggedCoordinate.id,geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:R.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:o}].concat(c,d)),0))},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(wt);function fe(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}function ye(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=nt,n=e[1]*Math.PI/180,o=t[1]*Math.PI/180,r=o-n,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),l=Math.abs(a)>1e-11?r/a:Math.cos(n);return Math.sqrt(r*r+l*l*s*s)*i}function ve(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=dt(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,n=0,o=t.length,r=0;r<o-1;r++){var s=t[r],a=s[0],l=s[1],c=t[r+1],d=c[0],u=c[1],h=a*u-d*l;e+=h,i+=(a+d)*h,n+=(l+u)*h}return{x:i/=6*(e/=2),y:n/=6*e}}(e):function(t){for(var e=t.length,i=0,n=0,o=0;o<e;o++){var r=t[o];i+=r[0],n+=r[1]}return{x:i/e,y:n/e}}(e)}var me=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastBearing=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}r(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e,i){var n=this,o=this.store.getGeometryCopy(e);if("Polygon"===o.type||"LineString"===o.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:o,properties:{}};if("web-mercator"===this.config.projection){if(r=Wt(ve(a),dt(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=r);!function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return dt(t[0],t[1])}),o=n.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});o.x/=n.length,o.y/=n.length;var r=n.map(function(t){return{x:o.x+(t.x-o.x)*Math.cos(i)-(t.y-o.y)*Math.sin(i),y:o.y+(t.x-o.x)*Math.sin(i)+(t.y-o.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[ut(e,i).lng,ut(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(a,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(r=ne(fe({type:"Feature",geometry:o,properties:{}}),s),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=fe(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=ne(i,t)+e,o=ye(i,t),r=oe(i,o,n);t[0]=r[0],t[1]=r[1]})}(a,-(this.lastBearing-(r+180)))}var l="Polygon"===o.type?o.coordinates[0]:o.coordinates;l.forEach(function(t){t[0]=c(t[0],n.coordinatePrecision),t[1]=c(t[1],n.coordinatePrecision)});var d=this.midPoints.getUpdated(l)||[],u=this.selectionPoints.getUpdated(l)||[];if(i&&!i({id:e,type:"Feature",geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:R.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:o}].concat(u,d)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}(wt),Ce=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastDistance=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}r(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e,i){var n=this,o=this.store.getGeometryCopy(e);if("Polygon"===o.type||"LineString"===o.type){var r,s=[t.lng,t.lat],a={type:"Feature",geometry:o,properties:{}},l=ve(a);if("web-mercator"===this.config.projection){var u=dt(t.lng,t.lat);r=d(l,u)}else{if("globe"!==this.config.projection)throw new Error("Invalid projection");r=it(fe({type:"Feature",geometry:o,properties:{}}),s)}if(this.lastDistance){var h=1-(this.lastDistance-r)/r;if("web-mercator"===this.config.projection){var p=ut(l.x,l.y);!function(t,e,i){if(1===e)return t;var n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return dt(t[0],t[1])}),o=dt(i[0],i[1]),r=n.map(function(t){return{x:o.x+(t.x-o.x)*e,y:o.y+(t.y-o.y)*e}}).map(function(t){var e=t.x,i=t.y;return[ut(e,i).lng,ut(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(a,h,[p.lng,p.lat])}else"globe"===this.config.projection&&function(t,e,i,n){void 0===n&&(n="xy"),1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=ye(i,t),r=ne(i,t),s=oe(i,o*e,r);"x"!==n&&"xy"!==n||(t[0]=s[0]),"y"!==n&&"xy"!==n||(t[1]=s[1])})}(a,h,fe(a));var g="Polygon"===o.type?o.coordinates[0]:o.coordinates;g.forEach(function(t){t[0]=c(t[0],n.coordinatePrecision),t[1]=c(t[1],n.coordinatePrecision)});var f=this.midPoints.getUpdated(g)||[],y=this.selectionPoints.getUpdated(g)||[];if(i&&!i({id:e,type:"Feature",geometry:o,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:R.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:o}].concat(y,f)),this.lastDistance=r}else this.lastDistance=r}},e}(wt),Pe=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.minimumScale=1e-4,r.draggedCoordinate={id:null,index:-1},r.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},r.config=e,r.pixelDistance=i,r.selectionPoints=n,r.midPoints=o,r}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=ve(e.feature);if(!r)return null;var s=dt(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=dt(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),n},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=ve(e.feature);if(!r)return null;var s=dt(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=dt(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),n},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,n=t.webMercatorCursor,o=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-n.x,e.y-n.y))return null;var r=d(e,n)/d(e,i);return r<0&&(r=this.minimumScale),this.performWebMercatorScale(o,e.x,e.y,r,r),o},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=dt(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=dt(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:l,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),n},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=dt(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=dt(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:l,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),n},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,n=t.webMercatorSelected,o=t.webMercatorCursor,r=t.updatedCoords,s=i.x-o.x,a=i.y-o.y;if(!this.isValidDragWebMercator(e,s,a))return null;var l=1;0!==s&&1!==e&&5!==e&&(l=1-(i.x-n.x-s)/s);var c=1;return 0!==a&&3!==e&&7!==e&&(c=1-(i.y-n.y-a)/a),this.validateScale(l,c)?(l<0&&(l=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(r,i.x,i.y,l,c),r):null},i.getFeature=function(t){if(null===this.draggedCoordinate.id)return null;var e=this.store.getGeometryCopy(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{type:"Feature",geometry:e,properties:{}}},i.getNormalisedCoordinates=function(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates},i.validateScale=function(t,e){var i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,n=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&n},i.performWebMercatorScale=function(t,e,i,n,o){t.forEach(function(t){var r=dt(t[0],t[1]),s=ut(e+(r.x-e)*n,i+(r.y-i)*o),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=dt(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],n=t[1];i<e[0]&&(e[0]=i),n<e[1]&&(e[1]=n),i>e[2]&&(e[2]=i),n>e[3]&&(e[3]=n)});var i=e[0],n=e[1],o=e[2],r=e[3];return[[i,r],[(i+o)/2,r],[o,r],[o,r+(n-r)/2],[o,n],[(i+o)/2,n],[i,n],[i,r+(n-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,n=Infinity,o=0;o<t.length;o++){var r=d({x:e.x,y:e.y},{x:t[o][0],y:t[o][1]});r<n&&(i=o,n=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var n=this.getFeature(this.draggedCoordinate.id);if(!n)return!1;var o=null;if("center"===e?o=this.centerWebMercatorDrag(t):"opposite"===e?o=this.oppositeWebMercatorDrag(t):"center-fixed"===e?o=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(o=this.oppositeFixedWebMercatorDrag(t)),!o)return!1;for(var r=0;r<o.length;r++){var s=o[r];if(s[0]=c(s[0],this.coordinatePrecision),s[1]=c(s[1],this.coordinatePrecision),!yt(s,this.coordinatePrecision))return!1}var a=this.midPoints.getUpdated(o)||[],l=this.selectionPoints.getUpdated(o)||[],d={type:n.geometry.type,coordinates:"Polygon"===n.geometry.type?[o]:o};return!(i&&!i({id:this.draggedCoordinate.id,type:"Feature",geometry:d,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:R.Provisional}).valid||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:d}].concat(l,a)),0))},e}(wt),_e=/*#__PURE__*/function(t){function e(e){var i,n;(n=t.call(this,e)||this).mode="select",n.allowManualDeselection=!0,n.dragEventThrottle=5,n.dragEventCount=0,n.selected=[],n.flags=void 0,n.keyEvents=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.featuresAtMouseEvent=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.dragFeature=void 0,n.dragCoordinate=void 0,n.rotateFeature=void 0,n.scaleFeature=void 0,n.dragCoordinateResizeFeature=void 0,n.cursors=void 0,n.validations={},n.flags=e&&e.flags?e.flags:{};var r={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"};if(n.cursors=e&&e.cursors?o({},r,e.cursors):r,null===(null==e?void 0:e.keyEvents))n.keyEvents={deselect:null,delete:null,rotate:null,scale:null};else{var s={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]};n.keyEvents=e&&e.keyEvents?o({},s,e.keyEvents):s}if(n.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,n.allowManualDeselection=null==(i=null==e?void 0:e.allowManualDeselection)||i,e&&e.flags&&e.flags)for(var a in e.flags){var l=e.flags[a].feature;l&&l.validation&&(n.validations[a]=l.validation)}return n}r(e,t);var i=e.prototype;return i.selectFeature=function(t){this.select(t,!1)},i.setSelecting=function(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"},i.registerBehaviors=function(t){this.pixelDistance=new Dt(t),this.clickBoundingBox=new Ft(t),this.featuresAtMouseEvent=new he(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new ce(t),this.midPoints=new le(t,this.selectionPoints),this.rotateFeature=new me(t,this.selectionPoints,this.midPoints),this.scaleFeature=new Ce(t,this.selectionPoints,this.midPoints),this.dragFeature=new pe(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new ge(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new Pe(t,this.pixelDistance,this.selectionPoints,this.midPoints)},i.deselectFeature=function(){this.deselect()},i.deselect=function(){var t=this,e=this.selected.filter(function(e){return t.store.has(e)}).map(function(t){return{id:t,property:z,value:!1}});this.store.updateProperty(e),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},i.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,n=Infinity;if(this.selectionPoints.ids.forEach(function(o){var r=e.store.getGeometryCopy(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.store.getPropertiesCopy(o))}),i){var o=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(o),a=this.flags[s.mode],l=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var c,d=this.store.getGeometryCopy(o);if("Polygon"===d.type){if((c=d.coordinates[0]).length<=4)return}else if("LineString"===d.type&&(c=d.coordinates).length<=3)return;if(c){if("Polygon"===d.type&&0===r||r===c.length-1?(c.shift(),c.pop(),c.push([c[0][0],c[0][1]])):c.splice(r,1),l&&!l({id:o,type:"Feature",geometry:d,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:R.Commit}).valid)return;this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:o,geometry:d}]),this.selectionPoints.create(c,d.type,o),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(c,o,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),n=this.flags[i.mode];if(n&&n.feature){var o=this.selected[0];if(o){if(o===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:"selected",value:!0}]),this.onSelect(t);var r=this.store.getGeometryCopy(t),s=r.type,a=r.coordinates;if("LineString"===s||"Polygon"===s){var l="LineString"===s?a:a[0];l&&n&&n.feature.coordinates&&(this.selectionPoints.create(l,s,t),n.feature.coordinates.midpoints&&this.midPoints.create(l,t,this.coordinatePrecision))}}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,n=e.clickedMidPoint;if(this.selected.length&&n)this.midPoints.insert(n.id,this.coordinatePrecision);else if(i&&i.id)this.select(i.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect()},i.onDragStart=function(t,e){if(this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),n=this.flags[i.mode];if(n&&n.feature&&(n.feature.draggable||n.feature.coordinates&&n.feature.coordinates.draggable||n.feature.coordinates&&n.feature.coordinates.resizable)){this.dragEventCount=0;var o=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,o);return n&&n.feature&&n.feature.coordinates&&(n.feature.coordinates.draggable||n.feature.coordinates.resizable)&&-1!==r?(this.setCursor(this.cursors.dragStart),n.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(o,r):this.dragCoordinate.startDragging(o,r),void e(!1)):n&&n.feature&&n.feature.draggable&&this.dragFeature.canDrag(t,o)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,o),void e(!1)):void 0}}},i.onDrag=function(t,e){var i=this.selected[0];if(i){var n=this.store.getPropertiesCopy(i),o=this.flags[n.mode],r=!0===(o&&o.feature&&o.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[n.mode];if(o&&o.feature&&o.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(o&&o.feature&&o.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,o.feature.coordinates.resizable,s)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,r,s):this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}},i.onDragEnd=function(t,e){this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)},i.onMouseMove=function(t){var e=this;if(this.selected.length){if(!this.dragFeature.isDragging()){var i=!1;this.midPoints.ids.forEach(function(n){if(!i){var o=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!0)}});var n=!1;if(this.selectionPoints.ids.forEach(function(o){var r=e.store.getGeometryCopy(o);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!1,n=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var o=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(o&&o.id===this.selected[0]||n)?this.cursors.pointerOver:"unset")}}}else this.setCursor("unset")},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties.selectionPoint)return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties.midPoint)return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=40,e}else if(t.properties[z]){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=10,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=10,e}return e},e}(et),xe=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=Z.Static,e.mode="static",e}r(e,t);var i=e.prototype;return i.start=function(){},i.stop=function(){},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(){return o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0})},e}(tt);function Me(t,e,i,n,o){for(;n>i;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(r-l)/r)*(s-r/2<0?-1:1);Me(t,e,Math.max(i,Math.floor(e-s*l/r+c)),Math.min(n,Math.floor(e+(r-s)*l/r+c)),o)}var d=t[e],u=i,h=n;for(Se(t,i,e),o(t[n],d)>0&&Se(t,i,n);u<h;){for(Se(t,u,h),u++,h--;o(t[u],d)<0;)u++;for(;o(t[h],d)>0;)h--}0===o(t[i],d)?Se(t,i,h):Se(t,++h,n),h<=e&&(i=h+1),e<=h&&(n=h-1)}}function Se(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function be(t,e){Ie(t,0,t.children.length,e,t)}function Ie(t,e,i,n,o){o||(o=je([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];we(o,t.leaf?n(s):s)}return o}function we(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 Ee(t,e){return t.minX-e.minX}function Fe(t,e){return t.minY-e.minY}function De(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function ke(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Oe(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Le(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function je(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function We(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;Me(t,s,e,i,o),r.push(e,s,s,i)}}var Be=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!Le(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?n(s):s;Le(t,a)&&(e.leaf?i.push(s):Oe(t,a)?this._all(s,i):o.push(s))}e=o.pop()}return i},e.collides=function(t){var e=this.data;if(Le(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var o=e.children[n],r=e.leaf?this.toBBox(o):o;if(Le(t,r)){if(e.leaf||Oe(t,r))return!0;i.push(o)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var n=this.data;this.data=i,i=n}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=je([])},e.remove=function(t){for(var e,i,n=this.data,o=this.toBBox(t),r=[],s=[],a=!1;n||r.length;){if(n||(n=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),n.leaf){var l=n.children.indexOf(t);-1!==l&&(n.children.splice(l,1),r.push(n),this._condense(r))}a||n.leaf||!Oe(n,o)?i?(e++,n=i.children[e],a=!1):n=null:(r.push(n),s.push(e),e=0,i=n,n=n.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,n){var o,r=i-e+1,s=this._maxEntries;if(r<=s)return be(o=je(t.slice(e,i+1)),this.toBBox),o;n||(n=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,n-1))),(o=je([])).leaf=!1,o.height=n;var a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));We(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var d=Math.min(c+l-1,i);We(t,c,d,a,this.compareMinY);for(var u=c;u<=d;u+=a){var h=Math.min(u+a-1,d);o.children.push(this._build(t,u,h,n-1))}}return be(o,this.toBBox),o},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var o=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=De(l),d=(u=t,h=l,(Math.max(h.maxX,u.maxX)-Math.min(h.minX,u.minX))*(Math.max(h.maxY,u.maxY)-Math.min(h.minY,u.minY))-c);d<r?(r=d,o=c<o?c:o,s=l):d===r&&c<o&&(o=c,s=l)}e=s||e.children[0]}var u,h;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),we(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=je(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,be(i,this.toBBox),be(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=je([t,e]),this.data.height=t.height+1,this.data.leaf=!1,be(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,l,c,d=Infinity,u=Infinity,h=e;h<=i-e;h++){var p=Ie(t,0,h,this.toBBox),g=Ie(t,h,i,this.toBBox),f=(o=p,r=g,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),l=Math.min(o.maxX,r.maxX),c=Math.min(o.maxY,r.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=De(p)+De(g);f<d?(d=f,n=h,u=y<u?y:u):f===d&&y<u&&(u=y,n=h)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:Ee,o=t.leaf?this.compareMinY:Fe;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,o)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var o=this.toBBox,r=Ie(t,0,e,o),s=Ie(t,i-e,i,o),a=ke(r)+ke(s),l=e;l<i-e;l++){var c=t.children[l];we(r,t.leaf?o(c):c),a+=ke(r)}for(var d=i-e-1;d>=e;d--){var u=t.children[d];we(s,t.leaf?o(u):u),a+=ke(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)we(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():be(t[i],this.toBBox)},t}(),Ge=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new Be(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o<e.length;o++)n.push(e[o][1]),i.push(e[o][0]);var r=Math.min.apply(Math,n),s=Math.max.apply(Math,n);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],n=new Set;t.forEach(function(t){var o=e.toBBox(t);if(e.setMaps(t,o),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(o)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),Ne={getId:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},isValidId:function(t){return"string"==typeof t&&36===t.length}},Ve=/*#__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 Ge,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ne}var e=t.prototype;return e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.getId=function(){return this.idStrategy.getId()},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e){var i=this;if(0===t.length)return[];var n=this.clone(t),o=[],r=[];return n=n.filter(function(t){null==t.id&&(t.id=i.idStrategy.getId());var n=t.id;if(e){var s=e(t);if(!s.valid)return r.push({id:n,valid:!1,reason:s.reason}),!1}if(i.tracked){if(t.properties.createdAt){if(!q(t.properties.createdAt))return r.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!q(t.properties.updatedAt))return r.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return i.has(n)?(r.push({id:n,valid:!1,reason:"Feature already exists with this id: "+n}),!1):(i.store[n]=t,o.push(n),r.push({id:n,valid:!0}),!0)}),this.spatialIndex.load(n),this._onChange(o,"create"),r},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.property,r=t.value,s=e.store[n];if(!s)throw new Error("No feature with this ("+n+"), can not update geometry");i.push(n),s.properties[o]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.geometry;i.push(n);var r=e.store[n];if(!r)throw new Error("No feature with this ("+n+"), can not update geometry");r.geometry=e.clone(o),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,i=[];return t.forEach(function(t){var n,r=t.geometry,s=t.properties,a=o({},s);e.tracked&&(n=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:n,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:n):a={createdAt:n,updatedAt:n});var l=e.getId(),c={id:l,type:"Feature",geometry:r,properties:a};e.store[l]=c,e.spatialIndex.insert(c),i.push(l)}),this._onChange&&this._onChange([].concat(i),"create"),i},e.delete=function(t){var e=this;t.forEach(function(t){if(!e.store[t])throw new Error("No feature with this id, can not delete");delete e.store[t],e.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete")},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.clear=function(){this.store={},this.spatialIndex.clear()},e.size=function(){return Object.keys(this.store).length},t}();function Ae(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Ue(e[0]));for(var n=1;n<e.length;n++)i-=Math.abs(Ue(e[n]))}return i}var Te=nt*nt/2,Re=Math.PI/180;function Ue(t){var e=t.length;if(e<=2)return 0;for(var i=0,n=0;n<e;)i+=(t[n+2>=e?(n+2)%e:n+2][0]*Re-t[n][0]*Re)*Math.sin(t[n+1===e?0:n+1][1]*Re),n++;return i*Te}var Xe="Feature is smaller than the minimum area",ze="Feature is not a Polygon or LineString",He="Feature intersects itself";function Ye(t,e,i){var n=Wt(t,e),o=Wt(e,i)-n;return o<0&&(o+=360),180-Math.abs(o-90-90)}var Ke=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i,n,o,r,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var a=1/Math.pow(10,this.coordinatePrecision-1),l=Math.max(1e-6,a);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-l],s[0]]}else if(2===this.currentCoordinate){var c=s[0],u=s[1],h=re(c,u,this.coordinatePrecision,this.project,this.unproject),p=dt(c[0],c[1]),g=dt(h[0],h[1]),f=dt(u[0],u[1]),y=dt(t.lng,t.lat),v=d(y,p)<d(y,f),m=Ye(p,g,y),C=v?90-m:Ye(p,g,y)-90,P=d(g,y),_=Math.cos(ot(C))*P,x=Wt(p,f)+("right"==((r=((o=y).x-(n=f).x)*((i=p).y-n.y)-(o.y-n.y)*(i.x-n.x))>1e-10?"left":r<-1e-10?"right":"left")?-90:90),M=Lt(p,_,x),S=Lt(f,_,x),b=ut(M.x,M.y),I=ut(S.x,S.y);e=[s[0],s[1],[I.lng,I.lat],[b.lng,b.lat],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,R.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(Tt([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]],R.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return St(t,e.coordinatePrecision)})},e}(tt);function Je(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var qe=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="sector",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=void 0,i.direction=void 0,i.arcPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i.arcPoints=(null==e?void 0:e.arcPoints)||64,i}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentId){var t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e,i=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var n=1/Math.pow(10,this.coordinatePrecision-1),o=Math.max(1e-6,n);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-o],i[0]]}else if(2===this.currentCoordinate){var r=i[0],s=i[1],a=[t.lng,t.lat],l=dt(r[0],r[1]),u=dt(s[0],s[1]),h=dt(a[0],a[1]);if(void 0===this.direction){var p=Je(l,u,h);this.direction=p?"clockwise":"anticlockwise"}var g,f=d(l,u),y=Wt(l,u),v=Wt(l,h),m=this.arcPoints,C=[r],P=Bt(y),_=Bt(v);"anticlockwise"===this.direction?(g=_-P)<0&&(g+=360):(g=P-_)<0&&(g+=360);var x=("anticlockwise"===this.direction?1:-1)*g/m;C.push(s);for(var M=0;M<=m;M++){var S=Lt(l,f,P+M*x),b=ut(S.x,S.y),I=b.lat,w=[c(b.lng,this.coordinatePrecision),c(I,this.coordinatePrecision)];w[0]!==C[C.length-1][0]&&w[1]!==C[C.length-1][1]&&C.push(w)}C.push(r),e=[].concat(C)}e&&this.updatePolygonGeometry(this.currentId,e,R.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(Tt([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]],R.Commit))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return St(t,e.coordinatePrecision)})},e}(tt),Ze=/*#__PURE__*/function(t){function e(e){var i;(i=t.call(this,e)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=void 0,i.direction=void 0,i.arcPoints=void 0,i.cursors=void 0,i.mouseMove=!1;var n={start:"crosshair",close:"pointer"};if(i.cursors=e&&e.cursors?o({},n,e.cursors):n,null===(null==e?void 0:e.keyEvents))i.keyEvents={cancel:null,finish:null};else{var r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i.arcPoints=(null==e?void 0:e.arcPoints)||64,i}r(e,t);var i=e.prototype;return i.close=function(){if(void 0!==this.currentStartingPointId){var t=this.currentStartingPointId,e=this.currentInitialArcId,i=this.currentId;t&&this.store.delete([t]),e&&this.store.delete([e]),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),i&&this.onFinish(i,{mode:this.mode,action:"draw"})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentInitialArcId&&void 0!==this.currentStartingPointId&&0!==this.currentCoordinate)if(2===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentInitialArcId).coordinates,i=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,n=e[0],o=[t.lng,t.lat],r=dt(n[0],n[1]),s=dt(o[0],o[1]),a=dt(i[0],i[1]),l=d(a,r);if(void 0===this.direction){var u=Je(a,r,s);this.direction=u?"clockwise":"anticlockwise"}var h,p=Wt(a,r),g=Wt(a,s),f=this.arcPoints,y=[n],v=Bt(p),m=Bt(g);"anticlockwise"===this.direction?(h=m-v)<0&&(h+=360):(h=v-m)<0&&(h+=360);for(var C=("anticlockwise"===this.direction?1:-1)*h/f,P=0;P<=f;P++){var _=Lt(a,l,v+P*C),x=ut(_.x,_.y),M=x.lat,S=[c(x.lng,this.coordinatePrecision),c(M,this.coordinatePrecision)];S[0]!==y[y.length-1][0]&&S[1]!==y[y.length-1][1]&&y.push(S)}this.updateLineStringGeometry(this.currentInitialArcId,y,R.Provisional)}else if(3===this.currentCoordinate){var b=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(b.length<2)return;if(!this.direction)return;var I=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,w=b[0],E=b[b.length-1],F=dt(t.lng,t.lat),D=dt(w[0],w[1]),k=dt(E[0],E[1]),O=dt(I[0],I[1]),L=d(O,D),j=d(O,F)<L?D:F,W=Wt(O,F),B=Wt(O,D),G=Wt(O,k),N=Bt(B),V=Bt(G),A=Bt(W);if(this.notInSector({normalizedCursor:A,normalizedStart:N,normalizedEnd:V,direction:this.direction}))return;for(var T=this.getDeltaBearing(this.direction,N,V),U=this.arcPoints,X=("anticlockwise"===this.direction?1:-1)*T/U,z=d(O,j),H=[],Y=0;Y<=U;Y++){var K=Lt(O,z,N+Y*X),J=ut(K.x,K.y),q=J.lat,Z=[c(J.lng,this.coordinatePrecision),c(q,this.coordinatePrecision)];Z[0]!==b[b.length-1][0]&&Z[1]!==b[b.length-1][1]&&H.unshift(Z)}if(b.push.apply(b,H),b.push(b[0]),this.currentId)this.updatePolygonGeometry(this.currentId,b,R.Provisional);else{var $=this.store.create([{geometry:{type:"Polygon",coordinates:[b]},properties:{mode:this.mode}}]);this.currentId=$[0]}}},i.updateLineStringGeometry=function(t,e,i){var n={type:"LineString",coordinates:e};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.updatePolygonGeometry=function(t,e,i){var n={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:n},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}).valid||(this.store.updateGeometry([{id:t,geometry:n}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.currentStartingPointId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:{mode:this.mode}}]);this.currentInitialArcId=i[0],this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0});return t.properties.mode===this.mode&&("Polygon"===t.geometry.type?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=10):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=10):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=20)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return St(t,e.coordinatePrecision)})},i.getDeltaBearing=function(t,e,i){var n;return"anticlockwise"===t?(n=i-e)<0&&(n+=360):(n=e-i)<0&&(n+=360),n},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,n=t.normalizedEnd;return"clockwise"===t.direction?i<=n?e>=i&&e<=n:e>=i||e<=n:i>=n?e<=i&&e>=n:e<=i||e>=n},e}(tt),$e={__proto__:null,TerraDrawBaseDrawMode:tt,TerraDrawBaseAdapter:h},Qe={ValidationReasonFeatureNotPoint:Xt,ValidationReasonFeatureInvalidCoordinates:zt,ValidationReasonFeatureNotPolygon:$,ValidationReasonFeatureHasHoles:Ct,ValidationReasonFeatureLessThanFourCoordinates:Pt,ValidationReasonFeatureHasInvalidCoordinates:_t,ValidationReasonFeatureCoordinatesNotClosed:xt,ValidationReasonFeatureNotPolygonOrLineString:ze,ValidationReasonFeatureSelfIntersects:He,ValidationReasonFeatureLessThanMinSize:Xe,ValidationReasonModeMismatch:Q};t.TerraDraw=/*#__PURE__*/function(){function t(t){var e=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectMode=void 0,this._adapter=t.adapter,this._mode=new xe;var i=new Set,n=t.modes.reduce(function(t,e){if(i.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return i.add(e.mode),t[e.mode]=e,t},{}),r=Object.keys(n);if(0===r.length)throw new Error("No modes provided");r.forEach(function(t){if(n[t].type===Z.Select){if(e._instanceSelectMode)throw new Error("only one type of select mode can be provided");e._instanceSelectMode=t}}),this._modes=o({},n,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[]},this._store=new Ve({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],n=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:n}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},l=function(t,i){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i)});var n=s(t),o=n.changed,r=n.unchanged;"create"===i?e._adapter.render({created:o,deletedIds:[],unchanged:r,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:o},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},e.getModeStyles())}},c=function(t){if(e._enabled){e._eventListeners.select.forEach(function(e){e(t)});var i=s([t]);e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:i.changed},e.getModeStyles())}},d=function(t){if(e._enabled){e._eventListeners.deselect.forEach(function(t){t()});var i=s([t]),n=i.changed;n&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:n},e.getModeStyles())}};Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor.bind(e._adapter),project:e._adapter.project.bind(e._adapter),unproject:e._adapter.unproject.bind(e._adapter),setDoubleClickToZoom:e._adapter.setDoubleClickToZoom.bind(e._adapter),onChange:l,onSelect:c,onDeselect:d,onFinish:a,coordinatePrecision:e._adapter.getCoordinatePrecision()})})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(i){e[i]=function(e){return t._instanceSelectMode&&e.properties[z]?t._modes[t._instanceSelectMode].styleFeature.bind(t._modes[t._instanceSelectMode])(e):t._modes[i].styleFeature.bind(t._modes[i])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,n=t.lat,o=e&&void 0!==e.pointerDistance?e.pointerDistance:30,r=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,s=this._adapter.unproject.bind(this._adapter),a=this._adapter.project.bind(this._adapter),l=a(i,n),c=Et({unproject:s,point:l,pointerDistance:o});return this._store.search(c).filter(function(t){if(r&&(t.properties[H]||t.properties.selectionPoint))return!1;if("Point"===t.geometry.type){var e=t.geometry.coordinates,s=a(e[0],e[1]);return d(l,s)<o}if("LineString"===t.geometry.type){for(var c=t.geometry.coordinates,u=0;u<c.length-1;u++){var h=c[u],p=c[u+1];if(ue(l,a(h[0],h[1]),a(p[0],p[1]))<o)return!0}return!1}return!!de([i,n],t.geometry.coordinates)||void 0})},e.getSelectMode=function(){if(this.checkEnabled(),!this._instanceSelectMode)throw new Error("No select mode defined in instance");return this.getMode()!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.getSnapshot=function(){return this._store.copyAll()},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},e.setMode=function(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},e.removeFeatures=function(t){this.checkEnabled(),this._store.delete(t)},e.selectFeature=function(t){this.getSelectMode().selectFeature(t)},e.deselectFeature=function(t){this.getSelectMode().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(function(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}(t)){var i=t.properties.mode,n=e._modes[i];if(!n)return{id:t.id,valid:!1,reason:i+" mode is not in the list of instantiated modes"};var o=n.validateFeature.bind(n)(t);return{id:t.id,valid:o.valid,reason:o.reason?o.reason:o.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}})},e.start=function(){var t=this;this._enabled=!0,this._adapter.register({onReady:function(){t._eventListeners.ready.forEach(function(t){t()})},getState:function(){return t._mode.state},onClick:function(e){t._mode.onClick(e)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyDown:function(e){t._mode.onKeyDown(e)},onKeyUp:function(e){t._mode.onKeyUp(e)},onDragStart:function(e,i){t._mode.onDragStart(e,i)},onDrag:function(e,i){t._mode.onDrag(e,i)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)},onClear:function(){t._mode.cleanUp(),t._store.clear()}})},e.getFeaturesAtLngLat=function(t,e){return this.featuresAtLocation({lng:t.lng,lat:t.lat},e)},e.getFeaturesAtPointerEvent=function(t,e){var i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)},e.stop=function(){this._enabled=!1,this._adapter.unregister()},e.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},e.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},n(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}]),t}(),t.TerraDrawAngledRectangleMode=Ke,t.TerraDrawArcGISMapsSDKAdapter=X,t.TerraDrawCircleMode=bt,t.TerraDrawExtend=$e,t.TerraDrawFreehandMode=It,t.TerraDrawGoogleMapsAdapter=p,t.TerraDrawLeafletAdapter=g,t.TerraDrawLineStringMode=Ut,t.TerraDrawMapLibreGLAdapter=y,t.TerraDrawMapboxGLAdapter=f,t.TerraDrawOpenLayersAdapter=U,t.TerraDrawPointMode=Yt,t.TerraDrawPolygonMode=te,t.TerraDrawRectangleMode=ee,t.TerraDrawRenderMode=ie,t.TerraDrawSectorMode=qe,t.TerraDrawSelectMode=_e,t.TerraDrawSensorMode=Ze,t.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:$}:Ae(t.geometry)>e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0}},t.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:$}:Ae(t.geometry)<e?{valid:!1,reason:Xe}:{valid:!0}},t.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:ze}:gt(t)?{valid:!1,reason:He}:{valid:!0}},t.ValidationReasons=Qe});
2
2
  //# sourceMappingURL=terra-draw.umd.js.map